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, refresh, selectSerial, versionArduino, selectSpeed, onOff;
1314 boolean conectado= false ;
1415 boolean erro= false ;
1516 color cor= color (0 );
@@ -19,26 +20,47 @@ 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- }
23+ dh= h/ 3 ;
24+ // line 1
25+ title= new TextBox (" Configurar Serial" ,CENTER ,x,y,int (0.7 * w),dh);
26+ refresh= new TextBox (" refresh" ,CENTER ,int (x+ 0.7 * w),y,int (0.3 * w),dh);
27+ // line 2
28+ selectSerial= new TextBox (" select serial" ,CENTER ,x,y+ h/ 3 ,w,dh);
29+ // line 3
30+ selectSpeed= new TextBox (" select speed" ,CENTER ,x,y+ 2 * h/ 3 ,int (0.4 * w),dh);
31+ versionArduino= new TextBox (" " ,CENTER ,int (x+ 0.4 * w),int (y+ 2 * h/ 3 ),int (0.4 * w),dh);
32+ onOff= new TextBox (" off" ,CENTER ,int (x+ 0.8 * w),y+ 2 * h/ 3 ,int (0.2 * w),dh);
33+ // onOff=new TextBox("off",CENTER,int(x+0.7*w),y,int(0.3*w),dh);
34+ }
2435 void display (){
2536 strokeWeight (1 ); stroke (0 );fill (200 );
37+ onOff. tex= " off" ;
2638 if (conectado) {
2739 cor= color (0 ,255 ,0 );
40+ onOff. tex= " on" ;
2841 // fill(cor);
2942 } else if (erro) {
3043 cor= color (255 ,0 ,255 );
3144 } else {
3245 cor= color (200 );
3346 // fill(200);
3447 }
35- fill (cor); rect (x,y- 20 ,11 * u,20 );
48+ // fill(cor);
49+ title. display(cor);
50+ refresh. display(cor);
51+ selectSerial. display(cor);
52+ selectSpeed. display(cor);
53+ versionArduino. display(cor);
54+ onOff. display(cor);
55+ /*
56+ rect(x,y-20,11*u,20);
3657 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);
3758 fill(0);textAlign(CENTER,CENTER); text("Configurar a Serial",x+w/2,y-12);
3859 //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);
3960 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";
4162 text(tex,x+10*u,y+h/2);//9*u,y+h/2);
63+ */
4264 }
4365 // int mouseLeftClick(){
4466
@@ -58,37 +80,51 @@ class Com{
5880
5981 int mouseClicado (){
6082 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 ;
83+
84+ // if (mouseY>y && mouseY<y+h){
85+ if (refresh. mouseClicado()) { // recarregar a lista das COMs
86+ if (! conectado) { // not connected
87+ ports= append (Serial . list()," select serial" );
88+ if (ports. length> 1 ){
89+ indPort= ports. length- 2 ;
90+ }else {
91+ indPort= ports. length- 1 ;
92+ }
93+ selectSerial. tex= ports[indPort];
94+ indSpeed= 1 ;
95+ selectSpeed. tex= speeds[indSpeed];
96+ versionArduino. tex= " " ;
6697 }
67- } else if (mouseX > x+ u && mouseX < x+ 5 * u) { // mudar porta serial
98+ } else if (selectSerial. mouseClicado()) { // mudar porta serial
99+ // println("Com=mouseClicado");
68100 if (! conectado){
69101 indPort++ ;
70102 if (indPort>= ports. length) indPort= 0 ;
71103 }
72- } else if (mouseX > x+ 5 * u && mouseX < x+ 9 * u) { // mudar speed (baudrate)
104+ selectSerial. tex= ports[indPort];
105+ } else if (selectSpeed. mouseClicado()) { // mudar speed (baudrate)
73106 if (! conectado){
74107 indSpeed++ ;
75108 if (indSpeed>= speeds. length) indSpeed= 0 ;
76109 }
77- } else if (mouseX > x+ 9 * u && mouseX < x+ w){ // mudar X (desconectado) para ok (conectado)
110+ selectSpeed. tex= speeds[indSpeed];
111+ } else if (onOff. mouseClicado()){ // mudar X (desconectado) para ok (conectado)
78112 if (conectado){ // desconectar
79113 r= - 1 ; // -1 => desconectar
80114 // port.stop();
81115 // conectado=false;
82116 } else { // conectar
83117 // if (indPort<ports.length-1 && indSpeed<speeds.length-1){
84- if (indPort< ports. length- 1 ){
118+ if (indPort< ports. length- 1 && indSpeed< 3 ){
119+ // println("speeds[",indSpeed,"]=",speeds[indSpeed]);
85120 // port=new Serial(this,"COM3",9600);
86121 // port=new Serial(this,ports[indPort],int(speeds[indSpeed]));
87122 r= 1 ; // retorna 1 para conectar
88123 }
89124 }
90125 }
91- }
126+ // }
92127 return r;
93128 }
129+
94130}
0 commit comments