fix serial data display

This commit is contained in:
interfisch 2021-03-26 17:02:23 +01:00
parent 994571b60e
commit 8c42a7ffd0
1 changed files with 42 additions and 34 deletions

View File

@ -45,6 +45,8 @@ Table logdata;
int nextID=0; //next row number to be displayed int nextID=0; //next row number to be displayed
long nextTime=0; //time of nextID row long nextTime=0; //time of nextID row
int dataErrorCount=0;
//Data from log //Data from log
int cmd_FrontL; int cmd_FrontL;
int cmd_FrontR; int cmd_FrontR;
@ -193,35 +195,37 @@ void draw() {
if (useSerial) { if (useSerial) {
while (serial.available() > 0) { while (serial.available() > 0) {
println("readUntilLoop");
serialString = serial.readStringUntil(serial_endchar); serialString = serial.readStringUntil(serial_endchar);
println("read:"+serialString); //println("read:"+serialString);
if (serialString != null) { if (serialString != null) {
println(serialString); println(serialString);
lastTimeData=nextTime;
nextTime=loopmillis;
String[] list = split(serialString, ','); String[] list = split(serialString, ',');
cmd_FrontL=parseInt(list[0]);
cmd_FrontR=parseInt(list[1]); if (list.length==20) {
cmd_RearL=parseInt(list[2]); lastTimeData=nextTime;
cmd_RearR=parseInt(list[3]); nextTime=int(parseFloat(list[0])*1000);
current_FrontL=parseFloat(list[4]); cmd_FrontL=parseInt(list[1]);
current_FrontR=parseFloat(list[5]); cmd_FrontR=parseInt(list[2]);
current_RearL=parseFloat(list[6]); cmd_RearL=parseInt(list[3]);
current_RearR=parseFloat(list[7]); cmd_RearR=parseInt(list[4]);
speed_FrontL=parseInt(list[8]); current_FrontL=parseFloat(list[5]);
speed_FrontR=parseInt(list[9]); current_FrontR=parseFloat(list[6]);
speed_RearL=parseInt(list[10]); current_RearL=parseFloat(list[7]);
speed_RearR=parseInt(list[11]); current_RearR=parseFloat(list[8]);
temp_Front=parseFloat(list[12]); speed_FrontL=parseInt(list[9]);
temp_Rear=parseFloat(list[13]); speed_FrontR=parseInt(list[10]);
vbat_Front=parseFloat(list[14]); speed_RearL=parseInt(list[11]);
vbat_Rear=parseFloat(list[15]); speed_RearR=parseInt(list[12]);
currentAll=parseFloat(list[16]); temp_Front=parseFloat(list[13]);
throttle=parseInt(list[17]); temp_Rear=parseFloat(list[14]);
brake=parseInt(list[18]); vbat_Front=parseFloat(list[15]);
vbat_Rear=parseFloat(list[16]);
currentAll=parseFloat(list[17]);
throttle=parseInt(list[18]);
brake=parseInt(list[19]);
}else{ //data missing or too much
dataErrorCount++;
}
} }
} }
@ -275,10 +279,10 @@ void draw() {
vis_speed_RearL.setValue(speed_RearL); vis_speed_RearL.drawVis(); vis_speed_RearL.setValue(speed_RearL); vis_speed_RearL.drawVis();
vis_speed_RearR.setValue(speed_RearR); vis_speed_RearR.drawVis(); vis_speed_RearR.setValue(speed_RearR); vis_speed_RearR.drawVis();
vis_current_FrontL.setValue(-current_FrontL); vis_current_FrontL.drawVis(); //TODO: remove negative sign vis_current_FrontL.setValue(current_FrontL); vis_current_FrontL.drawVis();
vis_current_FrontR.setValue(-current_FrontR); vis_current_FrontR.drawVis(); //TODO: remove negative sign vis_current_FrontR.setValue(current_FrontR); vis_current_FrontR.drawVis();
vis_current_RearL.setValue(-current_RearL); vis_current_RearL.drawVis(); //TODO: remove negative sign vis_current_RearL.setValue(current_RearL); vis_current_RearL.drawVis();
vis_current_RearR.setValue(-current_RearR); vis_current_RearR.drawVis(); //TODO: remove negative sign vis_current_RearR.setValue(current_RearR); vis_current_RearR.drawVis();
vis_throttle.setValue(throttle); vis_throttle.drawVis(); vis_throttle.setValue(throttle); vis_throttle.drawVis();
vis_brake.setValue(-brake); vis_brake.drawVis(); vis_brake.setValue(-brake); vis_brake.drawVis();
@ -286,10 +290,10 @@ void draw() {
int speed_mean=int((speed_FrontL+speed_FrontR+speed_RearL+speed_RearR)/4.0); int speed_mean=int((speed_FrontL+speed_FrontR+speed_RearL+speed_RearR)/4.0);
vis_c_speed_mean.setValue(speed_mean); vis_c_speed_mean.drawVis(); vis_c_speed_mean.setValue(speed_mean); vis_c_speed_mean.drawVis();
vis_currentAll.setValue(-currentAll); vis_currentAll.drawVis(); //TODO: remove negative sign vis_currentAll.setValue(currentAll); vis_currentAll.drawVis();
vis_graph_speed_mean.setValue(speed_mean); vis_graph_speed_mean.drawVis(); vis_graph_speed_mean.setValue(speed_mean); vis_graph_speed_mean.drawVis();
vis_graph_currentAll.setValue(-currentAll); vis_graph_currentAll.drawVis(); vis_graph_currentAll.setValue(currentAll); vis_graph_currentAll.drawVis();
@ -304,19 +308,23 @@ void draw() {
PVector pos_voltage = new PVector(pos_temperature.x+150,12); PVector pos_voltage = new PVector(pos_temperature.x+150,12);
colorMode(HSB, 360, 100, 100); colorMode(HSB, 360, 100, 100);
fill(color(map(vbat_Front,12*3,12*4.2,0,120),50,100)); fill(color(map(vbat_Front,12*3,12*4.2,0,120),50,100));
text("vbat_Front="+(vbat_Front/100.0)+"V", pos_voltage.x,pos_voltage.y); //TODO: remove /100 text("vbat_Front="+(vbat_Front)+"V", pos_voltage.x,pos_voltage.y);
fill(color(map(vbat_Rear,12*3,12*4.2,0,120),50,100)); fill(color(map(vbat_Rear,12*3,12*4.2,0,120),50,100));
text("vbat_Rear="+(vbat_Rear/100.0)+"V", pos_voltage.x,pos_voltage.y+12); //TODO: remove /100 text("vbat_Rear="+(vbat_Rear)+"V", pos_voltage.x,pos_voltage.y+12);
colorMode(RGB, 255, 255, 255); colorMode(RGB, 255, 255, 255);
fill(color(200,200,200)); fill(color(200,200,200));
textAlign(LEFT); textAlign(LEFT);
textSize(12); textSize(vis_textsize);
text("d="+(nextTime-lastTimeData)+"ms", 5+70,12); text("d="+(nextTime-lastTimeData)+"ms", 5+70,12);
if (!useSerial && loopmillis-lastTimeData>(nextTime-lastTimeData)*10) { //deviation too high when reading from file if (!useSerial && loopmillis-lastTimeData>(nextTime-lastTimeData)*10) { //deviation too high when reading from file
text("ff="+(loopmillis-lastTimeData)+"ms", 5+70+70,12); //show warning text("ff="+(loopmillis-lastTimeData)+"ms", 5+70+70,12); //show warning
} }
text("t="+(loopmillis/1000.0)+"s", 5,12); text("t="+(loopmillis/1000.0)+"s", 5,12);
text(""+(dataErrorCount)+" errors", 5,12+vis_textsize);
} }