add pause button
This commit is contained in:
parent
dfc53c494b
commit
e11defbd88
|
@ -59,14 +59,17 @@ int timeoffset=0; //for moving timeslider
|
||||||
Table logdata;
|
Table logdata;
|
||||||
int nextID=0; //next row number to be displayed
|
int nextID=0; //next row number to be displayed
|
||||||
long lastTimeData=0; //last time data received
|
long lastTimeData=0; //last time data received
|
||||||
long nextTimeData=0; //time of nextID row
|
int nextTimeData=0; //time of nextID row
|
||||||
long lastTimeMillis=0; //local time
|
int lastTimeMillis=0; //local time
|
||||||
long nextTimeMillis=0; //local time
|
int nextTimeMillis=0; //local time
|
||||||
|
|
||||||
boolean newdataforced=true;
|
boolean newdataforced=true;
|
||||||
|
|
||||||
int dataErrorCount=0;
|
int dataErrorCount=0;
|
||||||
|
|
||||||
|
boolean running=true;
|
||||||
|
int timePaused=0;
|
||||||
|
|
||||||
//Data from log
|
//Data from log
|
||||||
int cmd_FrontL;
|
int cmd_FrontL;
|
||||||
int cmd_FrontR;
|
int cmd_FrontR;
|
||||||
|
@ -260,7 +263,12 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
long loopmillis=millis()-timeoffset;
|
int loopmillis=0;
|
||||||
|
if (running) {
|
||||||
|
loopmillis=millis()-timeoffset;
|
||||||
|
}else{ //paused
|
||||||
|
loopmillis=timePaused-timeoffset;
|
||||||
|
}
|
||||||
|
|
||||||
if (useSerial) {
|
if (useSerial) {
|
||||||
if (serial.available() > 0) {
|
if (serial.available() > 0) {
|
||||||
|
@ -308,7 +316,7 @@ void draw() {
|
||||||
TableRow row = logdata.getRow(nextID);
|
TableRow row = logdata.getRow(nextID);
|
||||||
|
|
||||||
lastTimeData=nextTimeData;
|
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;
|
lastTimeMillis=nextTimeMillis;
|
||||||
nextTimeMillis=loopmillis;
|
nextTimeMillis=loopmillis;
|
||||||
|
@ -405,8 +413,14 @@ void draw() {
|
||||||
if (!useSerial && loopmillis-lastTimeData>(nextTimeData-lastTimeData)*10) { //deviation too high when reading from file
|
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
|
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("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);
|
text(""+(dataErrorCount)+" errors", 5+70*3,12);
|
||||||
|
|
||||||
|
@ -421,12 +435,15 @@ void draw() {
|
||||||
|
|
||||||
void keyPressed() {
|
void keyPressed() {
|
||||||
if (key == CODED) {
|
if (key == CODED) {
|
||||||
/*if (keyCode == UP) {
|
if (!running) { //paused
|
||||||
fillVal = 255;
|
if (keyCode == LEFT) {
|
||||||
} else if (keyCode == DOWN) {
|
|
||||||
fillVal = 0;
|
} else if (keyCode == RIGHT) {
|
||||||
|
timeoffset=timePaused-nextTimeData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//println("key="+keyCode);
|
//println("key="+keyCode);
|
||||||
if (keyCode==82) { //82=r
|
if (keyCode==82) { //82=r
|
||||||
|
@ -435,6 +452,14 @@ void keyPressed() {
|
||||||
nextID=0;
|
nextID=0;
|
||||||
newdataforced=true;
|
newdataforced=true;
|
||||||
}
|
}
|
||||||
|
if (keyCode == 32) {
|
||||||
|
if (running) { //switching from running to pause
|
||||||
|
timePaused=millis();
|
||||||
|
}else{ //unpause
|
||||||
|
timeoffset=+millis()-timePaused+timeoffset;
|
||||||
|
}
|
||||||
|
running=!running;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue