diff --git a/Software/ChainLube/src/lubeapp.cpp b/Software/ChainLube/src/lubeapp.cpp index e73382f..4338587 100644 --- a/Software/ChainLube/src/lubeapp.cpp +++ b/Software/ChainLube/src/lubeapp.cpp @@ -1,11 +1,40 @@ #include "lubeapp.h" -extern void LED_Process(tSystem_Status newStatus = sysStat_NOP); - uint32_t lubePulseTimestamp = 0; void RunLubeApp(volatile uint32_t *wheelPulseCounter) { + static uint32_t buttonTimestamp = 0; + static boolean buttonActionDone = false; + + if (digitalRead(GPIO_BUTTON) == LOW) + { + if (buttonTimestamp == 0) + buttonTimestamp = millis() + BUTTON_HOLD_DELAY; + + if (buttonTimestamp < millis() && buttonActionDone == false) + { + switch (globals.systemStatus) + { + case sysStat_Normal: + globals.systemStatus = sysStat_Rain; + globals.resumeStatus = sysStat_Rain; + break; + + case sysStat_Rain: + globals.systemStatus = sysStat_Normal; + globals.resumeStatus = sysStat_Normal; + break; + } + buttonActionDone = true; + } + } + else + { + buttonTimestamp = 0; + buttonActionDone = false; + } + // Calculate traveled Distance in mm TravelDistance_highRes += (*wheelPulseCounter * (LubeConfig.DistancePerRevolution_mm / LubeConfig.PulsePerRevolution)); *wheelPulseCounter = 0; diff --git a/Software/ChainLube/src/lubeapp.h b/Software/ChainLube/src/lubeapp.h index dcc87eb..bf6c2fb 100644 --- a/Software/ChainLube/src/lubeapp.h +++ b/Software/ChainLube/src/lubeapp.h @@ -8,6 +8,7 @@ #define LUBE_PULSE_LENGHT_MS 100 #define LUBE_PULSE_PAUSE_MS 100 +#define BUTTON_HOLD_DELAY 1000 void RunLubeApp(volatile uint32_t * wheelPulseCounter); void LubePulse();