batt display, low batt shutdown, timeout shutdown
This commit is contained in:
79
src/main.cpp
79
src/main.cpp
@@ -8,9 +8,10 @@
|
||||
#include "simpleled.h"
|
||||
#include "buttons.h"
|
||||
#include "led.h"
|
||||
#include "power.h"
|
||||
|
||||
|
||||
#define TIMEOUT 300000 // 5min* 60 sec * 1000ms
|
||||
#define TIMEOUT 900000 // 15min* 60 sec * 1000ms
|
||||
#define GAMESELECTTIMEOUT 10000 // 7sec * 1000ms
|
||||
|
||||
typedef enum
|
||||
@@ -55,7 +56,7 @@ void HandleIdle(void)
|
||||
if (buttonIsPressed(YELLOW) && buttonIsPressed(RED) && !buttonIsPressed(GREEN) & (nextGame == none))
|
||||
{
|
||||
//prepare for next game
|
||||
nextGame = detectLED;
|
||||
nextGame = SimpleLed;
|
||||
turnOffLed(GREEN);
|
||||
}
|
||||
|
||||
@@ -70,8 +71,8 @@ void HandleIdle(void)
|
||||
void HandleGameSelectTimeout(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
// yellow && red && green all on
|
||||
if (buttonIsPressed(YELLOW) && buttonIsPressed(RED) && buttonIsPressed(GREEN))
|
||||
//if (yellow && red && green)
|
||||
{
|
||||
//all buttons pressed, wait for next game
|
||||
if (!GameSelectTimer)
|
||||
@@ -95,35 +96,33 @@ void HandleGameSelectTimeout(void)
|
||||
}
|
||||
}
|
||||
|
||||
// void HandleTimeOut(void)
|
||||
// {
|
||||
// uint64_t currentmillis = millis();
|
||||
// if (!lasttimeOut)
|
||||
// {
|
||||
// lasttimeOut = currentmillis;
|
||||
// buttonChanged = anybutton();
|
||||
// }
|
||||
void HandleTimeOut(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
if (!lasttimeOut)
|
||||
{
|
||||
lasttimeOut = currentmillis;
|
||||
buttonChanged = anybutton();
|
||||
}
|
||||
|
||||
// //check if lastTime is initialized or timeout expired
|
||||
// if ((currentmillis - lasttimeOut > TIMEOUT))
|
||||
// {
|
||||
// LowPower.shutdown();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (buttonChanged != anybutton())
|
||||
// {
|
||||
// buttonChanged = anybutton();
|
||||
// //game in progress, update timer
|
||||
// lasttimeOut = currentmillis;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//check if lastTime is initialized or timeout expired
|
||||
if ((currentmillis - lasttimeOut > TIMEOUT))
|
||||
{
|
||||
currentGame = sleep;
|
||||
turnOffAllLed();
|
||||
shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buttonChanged != anybutton())
|
||||
{
|
||||
buttonChanged = anybutton();
|
||||
//game in progress, update timer
|
||||
lasttimeOut = currentmillis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void initSleep( void )
|
||||
// {
|
||||
// LowPower.begin();
|
||||
// }
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -131,12 +130,14 @@ void setup()
|
||||
initButtons();
|
||||
initDetectLed();
|
||||
initSimpleLed();
|
||||
initLowPower();
|
||||
initBattery();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
handleButtons();
|
||||
//HandleTimeOut();
|
||||
HandleTimeOut();
|
||||
HandleGameSelectTimeout();
|
||||
|
||||
switch (currentGame)
|
||||
@@ -175,10 +176,13 @@ void loop()
|
||||
case none:
|
||||
{
|
||||
currentGame = SimpleLed;
|
||||
if (buttonIsPressed(YELLOW))
|
||||
batteryCheck();
|
||||
batterydisplay();
|
||||
delay(1000);
|
||||
if (buttonIsPressed(GREEN))
|
||||
{
|
||||
currentGame = ChainGame;
|
||||
turnOnLed(YELLOW);
|
||||
turnOnLed(GREEN);
|
||||
}
|
||||
if (buttonIsPressed(RED))
|
||||
{
|
||||
@@ -186,14 +190,15 @@ void loop()
|
||||
turnOnLed(RED);
|
||||
}
|
||||
|
||||
if (buttonIsPressed(GREEN))
|
||||
if (buttonIsPressed(YELLOW))
|
||||
{
|
||||
currentGame = detectLED;
|
||||
turnOnLed(GREEN);
|
||||
currentGame = SimpleLed;
|
||||
turnOnLed(YELLOW);
|
||||
}
|
||||
|
||||
//wait for all buttons idle
|
||||
while (anybutton())
|
||||
;
|
||||
{}
|
||||
|
||||
turnOffAllLed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user