add manual poweroff feature

This commit is contained in:
interfisch 2019-06-20 18:06:10 +02:00
parent 60f69b9099
commit 583bf9898a
2 changed files with 18 additions and 2 deletions

View File

@ -4,3 +4,12 @@ RC Remote using the IBM/Lenovo Trackpoint ("Nipple") to control a vehicle over N
The PCB ist designed for DIY PCB etching with one layer.
The second layer shows bridges with enameled copper wire.
The Atmega328 is flashed with the Arduino Bootloader for an Arduino Pro Mini 328 16Mhz.
Remote Usage:
Lower button is Power button. Hold down to turn off. Has no other function than turning the remote on.
Upper button is the config button. Press and release to change modes (Led will flash). Push Nipple in one of the four directions to change settings / modes.
Push up to increase speed limit, down to decrease speed limit. Left and Right changes modes (slow acceleration mode).
Remote turns itself off after some time of inactivity or if touch sensor released when in setup mode (flashing led) or if config button is held down for some time (when not in config mode).

View File

@ -93,6 +93,7 @@ int16_t maxaccsteer_brake=0;
uint8_t setupmode=SETUP_NONE;
long setupmode_waitstarttime=0; //starttime of SETUP_WAIT mode
#define SETUP_WAIT_TIMEOUT 10000 //maximum time to wait for input before canceling
#define SETUP_HOLD_POWEROFF 2000 //if button held down after x ms in setup mode, power off
#define SETUP_DONE_TIME 1000 //time to keep motors disabled after exiting setup
#define SETUP_MOVE_THRESHOLD 275 //500*TRACKPOINT_MAX/127
uint8_t speedmode=1; //0 (slow), 1(medium), 2(fast)
@ -337,7 +338,7 @@ void loop() {
motorenabled=false;
}
if (!digitalRead(PIN_BUTTON)){ //Button pressed
if (!digitalRead(PIN_BUTTON) && setupmode==SETUP_NONE){ //Button pressed, and not in setup mode
setupmode=SETUP_WAIT;
setupmode_waitstarttime=millis();
Serial.println("Entering Setup");
@ -347,6 +348,7 @@ void loop() {
//inactivity poweroff
if (millis()>time_lastactivity+TIME_INACTIVITY_POWEROFF){
Serial.println("Inactivity Poweroff");
delay(100);
digitalWrite(PIN_POWERON, LOW); //Power off
}
@ -386,12 +388,17 @@ void loop() {
maxaccsteer_brake=0;
setupmode=SETUP_DONE; //exit setupmode
setupmode_waitstarttime=millis();//use this value for done timer
}else if (millis()>setupmode_waitstarttime+SETUP_HOLD_POWEROFF && !digitalRead(PIN_BUTTON)){ //if button held down after SETUP_HOLD_POWEROFF
Serial.println("Manual Power Off");
delay(100);
digitalWrite(PIN_POWERON, LOW); //Power off
}
if (!touching){ //remote got put away (not touch)
Serial.println("Poweroff");
delay(100);
digitalWrite(PIN_POWERON, LOW); //Power off
}
break;