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;
#define NRFSEND_DELAY 10 //ms
#define NRFSEND_DELAY 20 //ms
#define PIN_TOUCH 5
long last_touch=0;
@ -107,6 +107,8 @@ long led_nextswitch=0;
long time_lastactivity=0;
#define ACTIVITYMOVEMENT 5//Stick movement for activity recognition
boolean touching=false;
int voltage=4000;
#define VOLTAGE_WARN 3400
/*
@ -329,10 +331,18 @@ void loop() {
last_touch=millis();
}
boolean touching=false;
if(millis()-last_touch <= TOUCH_TIMEOUT){
touching=true;
motorenabled=true;
if(millis()-last_touch <= TOUCH_TIMEOUT){ //is touched
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;
Serial.println("touching reactivated");
}
}else{
motorenabled=true;
}
}else{
touching=false;
motorenabled=false;
@ -403,6 +413,9 @@ void loop() {
}
break;
case SETUP_DONE:
touching=false;
motorenabled=false;
Serial.println("touching set false");
if (millis()>setupmode_waitstarttime+SETUP_DONE_TIME){
setupmode=SETUP_NONE; //return to control mode, allows enabling motors
}
@ -421,9 +434,14 @@ void loop() {
led_ton=1000; //blink slowly regulary
led_toff=1000;
}
}else{
led_ton=0; //off
led_toff=500;
}else{ //not connected
if (touching){ //=touching
led_ton=5; //short flash
led_toff=200;
}else{
led_ton=0; //off
led_toff=500;
}
}
if (voltage<=VOLTAGE_WARN){
led_ton=25; //flash on fast