add mode change nipple not centered failsafe

This commit is contained in:
interfisch 2019-12-29 17:07:33 +01:00
parent 583bf9898a
commit 448db8a6d8
1 changed files with 26 additions and 8 deletions

View File

@ -59,7 +59,7 @@ struct nrfdata {
}; };
long last_sendNRF=0; long last_sendNRF=0;
#define NRFSEND_DELAY 10 //ms #define NRFSEND_DELAY 20 //ms
#define PIN_TOUCH 5 #define PIN_TOUCH 5
long last_touch=0; long last_touch=0;
@ -107,6 +107,8 @@ long led_nextswitch=0;
long time_lastactivity=0; long time_lastactivity=0;
#define ACTIVITYMOVEMENT 5//Stick movement for activity recognition #define ACTIVITYMOVEMENT 5//Stick movement for activity recognition
boolean touching=false;
int voltage=4000; int voltage=4000;
#define VOLTAGE_WARN 3400 #define VOLTAGE_WARN 3400
/* /*
@ -329,10 +331,18 @@ void loop() {
last_touch=millis(); last_touch=millis();
} }
boolean touching=false;
if(millis()-last_touch <= TOUCH_TIMEOUT){ if(millis()-last_touch <= TOUCH_TIMEOUT){ //is touched
touching=true; if (!touching && setupmode!=SETUP_DONE) { //was false, is touching again (and not during setup_done wait)
Serial.println("touching was false");
if (last_xin==0 && last_yin==0) { //stick at center position
touching=true; //enable only if stick is at center again
motorenabled=true; motorenabled=true;
Serial.println("touching reactivated");
}
}else{
motorenabled=true;
}
}else{ }else{
touching=false; touching=false;
motorenabled=false; motorenabled=false;
@ -403,6 +413,9 @@ void loop() {
} }
break; break;
case SETUP_DONE: case SETUP_DONE:
touching=false;
motorenabled=false;
Serial.println("touching set false");
if (millis()>setupmode_waitstarttime+SETUP_DONE_TIME){ if (millis()>setupmode_waitstarttime+SETUP_DONE_TIME){
setupmode=SETUP_NONE; //return to control mode, allows enabling motors setupmode=SETUP_NONE; //return to control mode, allows enabling motors
} }
@ -421,10 +434,15 @@ void loop() {
led_ton=1000; //blink slowly regulary led_ton=1000; //blink slowly regulary
led_toff=1000; led_toff=1000;
} }
}else{ //not connected
if (touching){ //=touching
led_ton=5; //short flash
led_toff=200;
}else{ }else{
led_ton=0; //off led_ton=0; //off
led_toff=500; led_toff=500;
} }
}
if (voltage<=VOLTAGE_WARN){ if (voltage<=VOLTAGE_WARN){
led_ton=25; //flash on fast led_ton=25; //flash on fast
led_toff=75; led_toff=75;