11class Com {
22 Serial port;
3- String ports[]= append (Serial . list()," Serial " );
3+ String ports[]= append (Serial . list()," select serial " );
44 String portName;
55 int indPort= ports. length- 1 ;
66 // String speed="115200";
77 // String speed="250000";
8- String speeds[]= {" 9600" ," 115200" ," 250000" ," speed" };
8+ String speeds[]= {" 9600" ," 115200" ," 250000" ," select speed" };
99 // int portSpeed;
1010 int indSpeed= speeds. length- 1 ;
1111 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;
1314 boolean conectado= false ;
1415 boolean erro= false ;
1516 color cor= color (0 );
@@ -19,27 +20,53 @@ class Com{
1920 // constructor
2021 Com (Serial portt ,int xt , int yt , int wt , int ht ){
2122 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);
2331 }
2432 void display (){
2533 strokeWeight (1 ); stroke (0 );fill (200 );
34+ onOff. tex= " off" ;
2635 if (conectado) {
2736 cor= color (0 ,255 ,0 );
37+ onOff. tex= " on" ;
2838 // fill(cor);
2939 } else if (erro) {
3040 cor= color (255 ,0 ,255 );
3141 } else {
3242 cor= color (200 );
3343 // fill(200);
3444 }
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);
3860 //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 );
4061 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+ }
4370 // int mouseLeftClick(){
4471
4572 void mouseMoveu (){
@@ -58,37 +85,49 @@ class Com{
5885
5986 int mouseClicado (){
6087 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];
66101 }
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");
68104 if (! conectado){
69105 indPort++ ;
70106 if (indPort>= ports. length) indPort= 0 ;
71107 }
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)
73110 if (! conectado){
74111 indSpeed++ ;
75112 if (indSpeed>= speeds. length) indSpeed= 0 ;
76113 }
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)
78116 if (conectado){ // desconectar
79117 r= - 1 ; // -1 => desconectar
80118 // port.stop();
81119 // conectado=false;
82120 } else { // conectar
83121 // 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]);
85124 // port=new Serial(this,"COM3",9600);
86125 // port=new Serial(this,ports[indPort],int(speeds[indSpeed]));
87126 r= 1 ; // retorna 1 para conectar
88127 }
89128 }
90129 }
91- }
130+ // }
92131 return r;
93132 }
94133}
0 commit comments