1
1
class Com {
2
2
Serial port;
3
- String ports[]= append (Serial . list()," Serial " );
3
+ String ports[]= append (Serial . list()," select serial " );
4
4
String portName;
5
5
int indPort= ports. length- 1 ;
6
6
// String speed="115200";
7
7
// String speed="250000";
8
- String speeds[]= {" 9600" ," 115200" ," 250000" ," speed" };
8
+ String speeds[]= {" 9600" ," 115200" ," 250000" ," select speed" };
9
9
// int portSpeed;
10
10
int indSpeed= speeds. length- 1 ;
11
11
int p= - 1 ;
12
- int x,y,w,h,u; // u=w/7 com1(4u), speed(4u), ok/x(2u)
12
+ int x,y,w,h,dh;
13
+ TextBox title, onOff,selectSerial,selectSpeed,refresh;
13
14
boolean conectado= false ;
14
15
boolean erro= false ;
15
16
color cor= color (0 );
@@ -19,27 +20,53 @@ class Com{
19
20
// constructor
20
21
Com (Serial portt ,int xt , int yt , int wt , int ht ){
21
22
x= xt; y= yt; w= wt; h= ht;
22
- u= w/ 11 ;
23
+ dh= h/ 3 ;
24
+ title= new TextBox (" Configurar Serial" ,CENTER ,x,y,int (0.7 * w),dh);
25
+ refresh= new TextBox (" refresh" ,CENTER ,int (x+ 0.7 * w),y,int (0.3 * w),dh);
26
+ // refresh=new TextBox("refresh",CENTER,int(x+0.6*w),y+2*h/3,int(0.4*w),dh);
27
+ selectSerial= new TextBox (" select serial" ,CENTER ,x,y+ h/ 3 ,w,dh);
28
+ selectSpeed= new TextBox (" select speed" ,CENTER ,x,y+ 2 * h/ 3 ,int (0.7 * w),dh);
29
+ onOff= new TextBox (" off" ,CENTER ,int (x+ 0.7 * w),y+ 2 * h/ 3 ,int (0.3 * w),dh);
30
+ // onOff=new TextBox("off",CENTER,int(x+0.7*w),y,int(0.3*w),dh);
23
31
}
24
32
void display (){
25
33
strokeWeight (1 ); stroke (0 );fill (200 );
34
+ onOff. tex= " off" ;
26
35
if (conectado) {
27
36
cor= color (0 ,255 ,0 );
37
+ onOff. tex= " on" ;
28
38
// fill(cor);
29
39
} else if (erro) {
30
40
cor= color (255 ,0 ,255 );
31
41
} else {
32
42
cor= color (200 );
33
43
// fill(200);
34
44
}
35
- fill (cor); rect (x,y- 20 ,11 * u,20 );
36
- rect (x,y,u,h); rect (x+ u,y,4 * u,h); rect (x+ 5 * u,y,4 * u,h); rect (x+ 9 * u,y,2 * u,h);
37
- fill (0 );textAlign (CENTER ,CENTER ); text (" Configurar a Serial" ,x+ w/ 2 ,y- 12 );
45
+ // fill(cor);
46
+ title. display(cor);
47
+ onOff. display(cor);
48
+ selectSerial. display(cor);
49
+ selectSpeed. display(cor);
50
+ refresh. display(cor);
51
+
52
+ /*
53
+ rect(x,y,0.7*w,dh); // Config Serial text Box - line 1
54
+ rect(x+0.7*w,y,0.3*w,dh); // on-off box - line 1
55
+ rect(x,y+dh,w,dh); // select serial port box - line 2
56
+ rect(x,y+2*dh,0.6*w,dh); // select speed box - line 3
57
+ rect(x,y+2*dh,0.4*w,dh); // refresh serial list box - line 3
58
+
59
+ fill(0);textAlign(CENTER,CENTER); text("Configurar Serial",x+0.7*w/2,y+dh/2);
38
60
//text("*",x+u/2,y+h/2); text(ports[indPort],x+3*u,y+h/2); text(speeds[indSpeed],x+7*u,y+h/2);
39
- text (" *" ,x+ u/ 2 ,y+ h/ 2 ); text (ports[indPort],x+ 3 * u,y+ h/ 2 ); text (speeds[indSpeed],x+ 7 * u,y+ h/ 2 );
40
61
if (conectado) tex="on"; else tex="off";
41
- text (tex,x+ 10 * u,y+ h/ 2 );// 9*u,y+h/2);
42
- }
62
+ text(tex,x+0.85*w,y+dh/2);//9*u,y+h/2);
63
+ textAlign(LEFT,CENTER);
64
+ text(ports[indPort],x+10,y+dh+dh/2);
65
+ textAlign(CENTER,CENTER);
66
+ text(speeds[indSpeed],x+0.3*w,y+2*dh+dh/2);
67
+ text("reflesh",x+0.8*w,y+2*dh+dh/2);
68
+ */
69
+ }
43
70
// int mouseLeftClick(){
44
71
45
72
void mouseMoveu (){
@@ -58,37 +85,49 @@ class Com{
58
85
59
86
int mouseClicado (){
60
87
int r= 0 ;
61
- if (mouseY > y && mouseY < y+ h){
62
- if (mouseX > x && mouseX < x+ u) { // recarregar a lista das COMs
63
- if (! conectado) {
64
- ports= append (Serial . list()," Serial" );
65
- indPort= ports. length- 1 ;
88
+
89
+ // if (mouseY>y && mouseY<y+h){
90
+ if (refresh. mouseClicado()) { // recarregar a lista das COMs
91
+ if (! conectado) { // not connected
92
+ ports= append (Serial . list()," select serial" );
93
+ if (ports. length> 1 ){
94
+ indPort= ports. length- 2 ;
95
+ }else {
96
+ indPort= ports. length- 1 ;
97
+ }
98
+ selectSerial. tex= ports[indPort];
99
+ indSpeed= 1 ;
100
+ selectSpeed. tex= speeds[indSpeed];
66
101
}
67
- } else if (mouseX > x+ u && mouseX < x+ 5 * u) { // mudar porta serial
102
+ } else if (selectSerial. mouseClicado()) { // mudar porta serial
103
+ // println("Com=mouseClicado");
68
104
if (! conectado){
69
105
indPort++ ;
70
106
if (indPort>= ports. length) indPort= 0 ;
71
107
}
72
- } else if (mouseX > x+ 5 * u && mouseX < x+ 9 * u) { // mudar speed (baudrate)
108
+ selectSerial. tex= ports[indPort];
109
+ } else if (selectSpeed. mouseClicado()) { // mudar speed (baudrate)
73
110
if (! conectado){
74
111
indSpeed++ ;
75
112
if (indSpeed>= speeds. length) indSpeed= 0 ;
76
113
}
77
- } else if (mouseX > x+ 9 * u && mouseX < x+ w){ // mudar X (desconectado) para ok (conectado)
114
+ selectSpeed. tex= speeds[indSpeed];
115
+ } else if (onOff. mouseClicado()){ // mudar X (desconectado) para ok (conectado)
78
116
if (conectado){ // desconectar
79
117
r= - 1 ; // -1 => desconectar
80
118
// port.stop();
81
119
// conectado=false;
82
120
} else { // conectar
83
121
// if (indPort<ports.length-1 && indSpeed<speeds.length-1){
84
- if (indPort< ports. length- 1 ){
122
+ if (indPort< ports. length- 1 && indSpeed< 3 ){
123
+ // println("speeds[",indSpeed,"]=",speeds[indSpeed]);
85
124
// port=new Serial(this,"COM3",9600);
86
125
// port=new Serial(this,ports[indPort],int(speeds[indSpeed]));
87
126
r= 1 ; // retorna 1 para conectar
88
127
}
89
128
}
90
129
}
91
- }
130
+ // }
92
131
return r;
93
132
}
94
133
}
0 commit comments