-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controls.pde
128 lines (110 loc) · 2.79 KB
/
Controls.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import controlP5.*;
ControlP5 cp5;
Textarea status;
Textfield input;
DropdownList ports;
String[] sent = {"$$"};
int sentID = 0;
String command = "";
void setupControls() {
cp5 = new ControlP5(this);
// INPUT
input = cp5.addTextfield("input")
.setPosition(20, height-60)
.setSize(width-200, 40)
.setFont(createFont("arial", 20))
.setCaptionLabel("")
;
// TEXTAREA
status = cp5.addTextarea("status")
.setPosition(20, 40)
.setSize(width-40, height-100)
.setFont(createFont("arial", 16))
.setLineHeight(18)
.setColor(color(64))
.setColorBackground(color(255))
.setColorForeground(color(255));
;
// BIND ENTER
cp5.mapKeyFor(new ControlKey() {
public void keyEvent() {
submit();
}
}
, ENTER);
// RESET BUTTON
cp5.addBang("clear")
.setPosition(width-200+20, height-60)
.setSize(80, 40)
.setFont(createFont("arial", 12))
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
;
// SUBMIT BUTTON
cp5.addBang("submit")
.setPosition(width-200+80+20, height-60)
.setSize(80, 40)
.setFont(createFont("arial", 12))
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
;
// DROPDOWN
ports = cp5.addDropdownList("ports")
.setPosition(20, 20)
.setSize(width-40, 200)
.setBackgroundColor(color(190))
.setFont(createFont("arial", 12))
.setItemHeight(20)
.setBarHeight(20)
.setValueLabel("")
.setLabel("Select Port");
for (int i=0; i<Serial.list().length; i++) {
ports.addItem(Serial.list()[i], i);
};
ports.close();
}
// CLEAR INPUT
public void clear() {
input.clear();
}
// SUBMIT INPUT
void submit() {
String text = cp5.get(Textfield.class, "input").getText();
if (text != "") {
sent = append(sent, text);
sentID = sent.length;
sendGcode(text);
updateStatus(">> "+text+"\n");
input.clear();
}
}
// UPDATE STATUS
void updateStatus(String statusText) {
String currentText = status.getText();
currentText+=statusText;
status.setText(currentText);
status.scroll(100);
}
// KEYBINDINGS
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
if (sentID > 0) sentID--;
command = sent[sentID];
}
if (keyCode == DOWN) {
sentID++;
if (sentID >= sent.length) sentID = sent.length -1;
command = sent[sentID];
}
}
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isGroup()) {
println("event from group : "+theEvent.getGroup().getValue()+" from "+theEvent.getGroup());
}
else if (theEvent.isController()) {
if(theEvent.getController().getName() == "ports") {
myPort = new Serial(this, Serial.list()[int(theEvent.getController().getValue())], 115200);
if (!grblInit) senderInit("$$");
}
}
}