add pause button

This commit is contained in:
interfisch 2021-05-24 18:40:23 +02:00
parent dfc53c494b
commit e11defbd88
1 changed files with 37 additions and 12 deletions

View File

@ -59,14 +59,17 @@ int timeoffset=0; //for moving timeslider
Table logdata;
int nextID=0; //next row number to be displayed
long lastTimeData=0; //last time data received
long nextTimeData=0; //time of nextID row
long lastTimeMillis=0; //local time
long nextTimeMillis=0; //local time
int nextTimeData=0; //time of nextID row
int lastTimeMillis=0; //local time
int nextTimeMillis=0; //local time
boolean newdataforced=true;
int dataErrorCount=0;
boolean running=true;
int timePaused=0;
//Data from log
int cmd_FrontL;
int cmd_FrontR;
@ -260,7 +263,12 @@ void setup() {
}
void draw() {
long loopmillis=millis()-timeoffset;
int loopmillis=0;
if (running) {
loopmillis=millis()-timeoffset;
}else{ //paused
loopmillis=timePaused-timeoffset;
}
if (useSerial) {
if (serial.available() > 0) {
@ -308,7 +316,7 @@ void draw() {
TableRow row = logdata.getRow(nextID);
lastTimeData=nextTimeData;
nextTimeData=(long)(logdata.getRow(nextID+1).getFloat("time")*1000); //get time and convert from seconds to ms
nextTimeData=(int)(logdata.getRow(nextID+1).getFloat("time")*1000); //get time and convert from seconds to ms
lastTimeMillis=nextTimeMillis;
nextTimeMillis=loopmillis;
@ -405,8 +413,14 @@ void draw() {
if (!useSerial && loopmillis-lastTimeData>(nextTimeData-lastTimeData)*10) { //deviation too high when reading from file
text("ff="+(loopmillis-lastTimeData)+"ms", 5+75*2,12); //show warning
}
if (!running) {
fill(color(255,100,100));
}
text("t="+(loopmillis/1000.0)+"s", 5,12);
text("nextID="+nextID, 5,12+12);
fill(color(200,200,200));
text(""+(dataErrorCount)+" errors", 5+70*3,12);
@ -421,12 +435,15 @@ void draw() {
void keyPressed() {
if (key == CODED) {
/*if (keyCode == UP) {
fillVal = 255;
} else if (keyCode == DOWN) {
fillVal = 0;
}
*/
if (!running) { //paused
if (keyCode == LEFT) {
} else if (keyCode == RIGHT) {
timeoffset=timePaused-nextTimeData;
}
}
} else {
//println("key="+keyCode);
if (keyCode==82) { //82=r
@ -435,6 +452,14 @@ void keyPressed() {
nextID=0;
newdataforced=true;
}
if (keyCode == 32) {
if (running) { //switching from running to pause
timePaused=millis();
}else{ //unpause
timeoffset=+millis()-timePaused+timeoffset;
}
running=!running;
}
}
}