Skip to content

Commit 3140b3a

Browse files
committed
Merge branch 'dynamic-qtd-bug' into dynamic-qtd
2 parents 62c3ee8 + 88e5ac8 commit 3140b3a

File tree

5 files changed

+315
-61
lines changed

5 files changed

+315
-61
lines changed

arduino/oscilloscope_arduino/oscilloscope_arduino.ino

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// 03/08/2016 => versão 1.2 => ler resistor em A5
77
// 26/07/2015 => versão 1.1 => ler em microsegundos
88
//String versao="1.2"; // versão do programa -
9-
#define versao "1.5"
9+
#define versao "v1.5"
1010

1111
/* trabalhando com TimerOne
1212
Timer1.initializa(us); // inicializa o timer1 (chamar primeiro)
@@ -79,7 +79,7 @@ char unidade='m'; // unidade: m=milisegundo, u=microsegundo
7979
// 1 canal deve dar 120us
8080

8181
boolean varias=false; // v = varias
82-
boolean uma=true; // u = uma
82+
boolean uma=false; // u = uma
8383
boolean fluxo=false; // f = fluxo de dados (envia cada leitura sem guardar na memoria)
8484
// velocidade limitada pela serial 115200
8585
unsigned long dtReal, tIni, tFim; // contador de final de tempo para o fluxo
@@ -137,8 +137,10 @@ void setup() {
137137
//Serial.begin(9600);
138138
Serial.begin(115200);
139139
//Serial.begin(250000);
140-
printHelp();
141-
printConfig();
140+
Serial.println();
141+
Serial.print(">init="); Serial.println(versao);
142+
//printHelp();
143+
//printConfig();
142144

143145
//ler Resistor e Capacitor
144146
//pinMode(pinCarga,OUTPUT);
@@ -207,8 +209,8 @@ void lerSerial(){
207209
if (k>=1 && k<=qmax) {
208210
q=k;
209211
}
210-
calcBuffer();
211-
// Serial.print("=> q="); Serial.println(q);
212+
//calcBuffer(); //não precisa pois será usado o qmax
213+
Serial.print("=> q="); Serial.println(q);
212214
break;
213215
case 'c': //cnm : n=0-3, m=(o)ativa/(x)desativa canal n exemplo: c0x, c2o
214216
delay(100);
@@ -396,24 +398,25 @@ void calcBuffer(){
396398
q=qmax;
397399
}
398400
//Serial.print("q=408/chq=");Serial.print("408/");Serial.print(chq);Serial.print("=");Serial.println(q);
401+
// qtdCanais-qmax (chq-qmax) (4-100) (3-130) (2-200) (1-400)
399402
int chInit=0;
400403
for (int k=0; k<4; k++){
401404
if (Ch[k]) {
402405
chi[k]=chInit;
403-
chInit+=q;
406+
chInit+=qmax;
404407
}
405408
}
406409

407-
Serial.print("chq="); Serial.print(chq); Serial.print(" q="); Serial.print(q); Serial.print(" qmax="); Serial.println(qmax);
408-
for (int k=0; k<4; k++){
409-
Serial.print("k=");Serial.print(k); Serial.print(" chi[k]="); Serial.println(chi[k]);
410-
}
410+
// Serial.print("chq="); Serial.print(chq); Serial.print(" q="); Serial.print(q); Serial.print(" qmax="); Serial.println(qmax);
411+
// for (int k=0; k<4; k++){
412+
// Serial.print("k=");Serial.print(k); Serial.print(" chi[k]="); Serial.println(chi[k]);
413+
// }
411414

412415
}
413416

414417
void printHelp(){
415418
Serial.println("-----------------------");
416-
Serial.print("! BegOscopio v"); Serial.print(versao); Serial.println(" - [email protected] !");
419+
Serial.print("! BegOscopio "); Serial.print(versao); Serial.println(" - [email protected] !");
417420
Serial.println("-----------------------");
418421
/*
419422
Serial.println("----------- help ---------------------");
@@ -593,12 +596,13 @@ void lerEnviar(){
593596
if (Ch[3]) {Serial.print(vb[chi[3]+k]); Serial.print("\t");}
594597
Serial.println("");
595598

599+
/*
596600
if (Ch[0]) {Serial.print(chi[0]+k); Serial.print("\t");}
597601
if (Ch[1]) {Serial.print(chi[1]+k); Serial.print("\t");}
598602
if (Ch[2]) {Serial.print(chi[2]+k); Serial.print("\t");}
599603
if (Ch[3]) {Serial.print(chi[3]+k); Serial.print("\t");}
600604
Serial.println("");
601-
605+
*/
602606
}
603607
/* -- eliminado em 07/May/2017 - criei buffer dinamico vb[408] --
604608
for (int k=0; k<q; k++){
@@ -645,10 +649,10 @@ void lerFluxo(){
645649
Serial.print("e-6");
646650
}
647651
Serial.print("\t");
648-
Serial.print(v0); Serial.print("\t");
649-
Serial.print(v1); Serial.print("\t");
650-
Serial.print(v2); Serial.print("\t");
651-
Serial.println(v3);
652+
if (Ch[0]) {Serial.print(v0);} else {Serial.print("0");} Serial.print("\t");
653+
if (Ch[1]) {Serial.print(v1);} else {Serial.print("0");} Serial.print("\t");
654+
if (Ch[2]) {Serial.print(v2);} else {Serial.print("0");} Serial.print("\t");
655+
if (Ch[3]) {Serial.println(v3);} else {Serial.println("0");}
652656
}
653657
}
654658

processing/oscilloscope_4ch/Canal.pde

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Canal{
119119
//float p0Out=tela.x+tela.w-qInit*fq;
120120
triangle(p0Out,p0,p0Out-10,p0+10,p0Out+10,p0+10);
121121
} else {
122-
//qInit=0;
122+
qInit=0;
123123
p0Out=tela.x+tela.w;
124124
}
125125

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
class 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
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class TextBox{
2+
int x,y,w,h;
3+
int hAlign;
4+
String tex;
5+
//constructor
6+
TextBox(String texi,int hAligni, int xi, int yi, int wi, int hi){
7+
tex=texi; hAlign=hAligni;
8+
x=xi; y=yi; w=wi; h=hi;
9+
}
10+
void display(color bgColor){
11+
fill(bgColor);
12+
rect(x,y,w,h);
13+
fill(0);
14+
if (hAlign==LEFT){
15+
textAlign(LEFT,CENTER);
16+
text(tex,x+5,y+h/2);
17+
} else{
18+
textAlign(CENTER,CENTER);
19+
text(tex,x+w/2,y+h/2);
20+
}
21+
}
22+
23+
boolean mouseClicado(){
24+
boolean r=false;
25+
if (mouseX>x && mouseX<x+w && mouseY>y && mouseY<y+h){
26+
r=true;
27+
// println(tex," mouseClicado=",r);
28+
}
29+
return r;
30+
}
31+
}

0 commit comments

Comments
 (0)