OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [java/] [src/] [edu/] [byu/] [cc/] [plieber/] [fpgaenet/] [modmod/] [StaticModulesWidget.java] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
package edu.byu.cc.plieber.fpgaenet.modmod;
2 7 peteralieb
import java.util.ArrayList;
3
 
4 2 peteralieb
import com.trolltech.qt.core.Qt;
5
import com.trolltech.qt.gui.*;
6
 
7 7 peteralieb
import edu.byu.cc.plieber.fpgaenet.examples.ClockControl;
8
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
9 2 peteralieb
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
10
 
11
public class StaticModulesWidget extends QWidget{
12
 
13
    public static void main(String[] args) {
14
        QApplication.initialize(args);
15
 
16
        StaticModulesWidget testStaticModulesWidget = new StaticModulesWidget(null, null);
17
        testStaticModulesWidget.show();
18
 
19
        QApplication.exec();
20
    }
21
 
22
    private FCPProtocol fcpprotocol;
23 7 peteralieb
    private ClockControl clockControl;
24 2 peteralieb
 
25
    public StaticModulesWidget(QWidget parent, FCPProtocol protocol){
26
        super(parent);
27
        fcpprotocol = protocol;
28 7 peteralieb
        clockControl = new ClockControl(protocol, 2);
29 2 peteralieb
        createWidgets();
30
        createLayout();
31
        connectSignalsAndSlots();
32
    }
33
 
34 7 peteralieb
    private QGroupBox grpLEDDIP = new QGroupBox("LED / DIP Control");
35
    private QGroupBox grpClockControl = new QGroupBox("Clock Control");
36
 
37 2 peteralieb
    private QLabel labelStaticModules = new QLabel("Static Module Control");
38
    private QLabel labelLEDValue = new QLabel("LED Value:");
39
    private QLabel labelDIPValue = new QLabel("DIP Value:");
40
    private QLabel labelStepClock = new QLabel("Step Clock:");
41
 
42
    private QPushButton btnSetLED = new QPushButton("Set LED");
43
    private QPushButton btnGetDIP = new QPushButton("Get DIP");
44
    private QPushButton btnStep = new QPushButton("Step");
45
    private QPushButton btnSingleStep = new QPushButton("Single Step");
46 7 peteralieb
    private QPushButton btnFreeRun = new QPushButton("Free Run");
47 2 peteralieb
    private QPushButton btnCCReset = new QPushButton("Reset");
48
 
49
    private QLineEdit txtLEDValue = new QLineEdit();
50
    private QLineEdit txtDIPValue = new QLineEdit();
51
    private QLineEdit txtNumCycles = new QLineEdit();
52
 
53 7 peteralieb
    private int LEDDIPChannel = 1;
54
 
55 2 peteralieb
    private void createWidgets() {
56 7 peteralieb
        QFont font =labelStaticModules.font();
57
        font.setPointSize(labelStaticModules.font().pointSize()+2);
58
        labelStaticModules.setFont(font);
59 2 peteralieb
        labelLEDValue.setAlignment(Qt.AlignmentFlag.AlignRight);
60
        labelDIPValue.setAlignment(Qt.AlignmentFlag.AlignRight);
61
        labelStepClock.setAlignment(Qt.AlignmentFlag.AlignRight);
62
    }
63
 
64
    private void createLayout() {
65
        QVBoxLayout mainLayout = new QVBoxLayout(this);
66
        QGridLayout leddipLayout = new QGridLayout();
67
        QGridLayout clockControlLayout = new QGridLayout();
68
 
69
        leddipLayout.setColumnMinimumWidth(0, 20);
70
        //leddipLayout.setColumnMinimumWidth(3, 20);
71
        leddipLayout.setColumnStretch(2, 1);
72
        leddipLayout.addWidget(labelLEDValue, 0, 1);
73
        leddipLayout.addWidget(txtLEDValue, 0, 2);
74
        leddipLayout.addWidget(btnSetLED, 0, 3);
75
        leddipLayout.addWidget(labelDIPValue, 1, 1);
76
        leddipLayout.addWidget(btnGetDIP, 1, 3);
77
        leddipLayout.addWidget(txtDIPValue, 1, 2);
78
 
79
        clockControlLayout.setColumnMinimumWidth(0, 20);
80
        //clockControlLayout.setColumnMinimumWidth(3, 20);
81
        clockControlLayout.setColumnStretch(2, 1);
82
        clockControlLayout.addWidget(labelStepClock, 0, 1);
83
        clockControlLayout.addWidget(txtNumCycles, 0, 2);
84
        clockControlLayout.addWidget(btnStep, 0, 3);
85 7 peteralieb
        clockControlLayout.addWidget(btnFreeRun, 1, 1);
86
        clockControlLayout.addWidget(btnSingleStep, 1, 2);
87 2 peteralieb
        clockControlLayout.addWidget(btnCCReset, 1, 3);
88
 
89 7 peteralieb
        grpLEDDIP.setLayout(leddipLayout);
90
        grpClockControl.setLayout(clockControlLayout);
91
 
92 2 peteralieb
        mainLayout.addWidget(labelStaticModules);
93 7 peteralieb
        mainLayout.addWidget(grpLEDDIP);
94
        mainLayout.addWidget(grpClockControl);
95 2 peteralieb
        mainLayout.addStretch();
96
    }
97
 
98
    private void connectSignalsAndSlots() {
99 7 peteralieb
        btnCCReset.clicked.connect(this, "resetModules()");
100
        btnFreeRun.clicked.connect(this, "freeRun()");
101
        btnGetDIP.clicked.connect(this, "getDIP()");
102
        btnSetLED.clicked.connect(this, "setLED()");
103
        btnSingleStep.clicked.connect(this, "singleStep()");
104
        btnStep.clicked.connect(this, "stepClock()");
105 2 peteralieb
    }
106 7 peteralieb
 
107
    @SuppressWarnings("unused")
108
        private void setLED() {
109
        byte ledVal = Byte.parseByte(txtLEDValue.text());
110
        try {
111
                        fcpprotocol.sendData(LEDDIPChannel, ledVal);
112
                } catch (FCPException e) {
113
                        // TODO Auto-generated catch block
114
                        e.printStackTrace();
115
                }
116
    }
117
 
118
    @SuppressWarnings("unused")
119
    private void getDIP() {
120
        try {
121
                        fcpprotocol.sendDataRequest(LEDDIPChannel, 1);
122
                        byte[] data = fcpprotocol.getDataResponse();
123
                        if (data.length > 0) txtDIPValue.setText(String.valueOf(data[0]));
124
                        else txtDIPValue.setText("-error-");
125
                } catch (FCPException e) {
126
                        // TODO Auto-generated catch block
127
                        e.printStackTrace();
128
                }
129
    }
130
 
131
    @SuppressWarnings("unused")
132
    private void stepClock() {
133
        clockControl.runClock(Integer.parseInt(txtNumCycles.text()));
134
    }
135
 
136
    @SuppressWarnings("unused")
137
    private void freeRun() {
138
        clockControl.freeRunClock();
139
    }
140
 
141
    @SuppressWarnings("unused")
142
    private void singleStep() {
143
        clockControl.singleStep();
144
    }
145
 
146
    @SuppressWarnings("unused")
147
    private void resetModules() {
148
        clockControl.assertReset();
149
        clockControl.deassertAll();
150
    }
151
 
152
    public void setChannels(int LEDDIP, int ClockControl) {
153
        this.LEDDIPChannel = LEDDIP;
154
        clockControl.setChannel(ClockControl);
155
    }
156
 
157
        public int getLEDDIPChannel() {
158
                return LEDDIPChannel;
159
        }
160
 
161
        public int getClockControlChannel() {
162
                return clockControl.getChannel();
163
        }
164
 
165
 
166 2 peteralieb
}
167 7 peteralieb
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.