firmware release 1.2
fixed MSboard, game class prep, power impr.
This commit is contained in:
95
src/main.cpp
95
src/main.cpp
@@ -10,9 +10,7 @@
|
||||
#include "led.h"
|
||||
#include "power.h"
|
||||
|
||||
|
||||
#define TIMEOUT 900000 // 15min* 60 sec * 1000ms
|
||||
#define GAMESELECTTIMEOUT 10000 // 7sec * 1000ms
|
||||
#define GAMESELECTTIMEOUT 10000 // 10sec * 1000ms
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -28,12 +26,20 @@ typedef enum
|
||||
|
||||
game currentGame = none;
|
||||
game nextGame = none;
|
||||
bool newstate = false;
|
||||
uint8_t gameState = 0;
|
||||
uint64_t lasttimeOut = 0;
|
||||
uint64_t GameSelectTimer = 0;
|
||||
bool buttonChanged = false;
|
||||
|
||||
void HandleIdle(void)
|
||||
void setNewState(game nextstate)
|
||||
{
|
||||
if (nextstate != currentGame)
|
||||
{
|
||||
currentGame = nextstate;
|
||||
newstate = true;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleIdle(bool newstate)
|
||||
{
|
||||
//green button first released
|
||||
if (!buttonIsPressed(YELLOW) && buttonIsPressed(RED) && buttonIsPressed(GREEN) && (nextGame == none))
|
||||
@@ -63,7 +69,7 @@ void HandleIdle(void)
|
||||
//wait for all buttons to be switched off
|
||||
if (!anybutton())
|
||||
{
|
||||
currentGame = nextGame;
|
||||
setNewState(nextGame);
|
||||
nextGame = none;
|
||||
}
|
||||
}
|
||||
@@ -84,7 +90,7 @@ void HandleGameSelectTimeout(void)
|
||||
//check timeout
|
||||
if (currentmillis - GameSelectTimer > GAMESELECTTIMEOUT)
|
||||
{
|
||||
currentGame = idle;
|
||||
setNewState(idle);
|
||||
GameSelectTimer = 0;
|
||||
}
|
||||
}
|
||||
@@ -96,109 +102,94 @@ void HandleGameSelectTimeout(void)
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
currentGame = sleep;
|
||||
turnOffAllLed();
|
||||
shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buttonChanged != anybutton())
|
||||
{
|
||||
buttonChanged = anybutton();
|
||||
//game in progress, update timer
|
||||
lasttimeOut = currentmillis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
initLeds();
|
||||
initButtons();
|
||||
initDetectLed();
|
||||
initSimpleLed();
|
||||
initLowPower();
|
||||
initBattery();
|
||||
|
||||
initDetectLed();
|
||||
initMagicSwitchBoard();
|
||||
initSimpleLed();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
handleButtons();
|
||||
HandleTimeOut();
|
||||
HandlePower();
|
||||
HandleGameSelectTimeout();
|
||||
|
||||
switch (currentGame)
|
||||
{
|
||||
case idle:
|
||||
{
|
||||
HandleIdle();
|
||||
HandleIdle(newstate);
|
||||
newstate = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case SimpleLed:
|
||||
{
|
||||
handleSimpleLed();
|
||||
handleSimpleLed(newstate);
|
||||
newstate = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case magicSwitchBoard:
|
||||
{
|
||||
handleMagicSwitchBoard();
|
||||
handleMagicSwitchBoard(newstate);
|
||||
newstate = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case detectLED:
|
||||
{
|
||||
handleDetectLed();
|
||||
handleDetectLed(newstate);
|
||||
newstate = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case ChainGame:
|
||||
default:
|
||||
{
|
||||
HandleChainGame();
|
||||
HandleChainGame(newstate);
|
||||
newstate = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case none:
|
||||
{
|
||||
currentGame = SimpleLed;
|
||||
batteryCheck();
|
||||
batterydisplay();
|
||||
delay(1000);
|
||||
if (buttonIsPressed(GREEN))
|
||||
turnOffAllLed();
|
||||
if (buttonIsPressed(GREEN) && currentGame == none)
|
||||
{
|
||||
currentGame = ChainGame;
|
||||
setNewState(ChainGame);
|
||||
turnOnLed(GREEN);
|
||||
}
|
||||
if (buttonIsPressed(RED))
|
||||
if (buttonIsPressed(RED) && currentGame == none)
|
||||
{
|
||||
currentGame = magicSwitchBoard;
|
||||
setNewState(magicSwitchBoard);
|
||||
turnOnLed(RED);
|
||||
}
|
||||
|
||||
if (buttonIsPressed(YELLOW))
|
||||
if (buttonIsPressed(YELLOW) && currentGame == none)
|
||||
{
|
||||
currentGame = SimpleLed;
|
||||
setNewState(SimpleLed);
|
||||
turnOnLed(YELLOW);
|
||||
}
|
||||
|
||||
if (currentGame == none)
|
||||
{
|
||||
setNewState(SimpleLed);
|
||||
}
|
||||
|
||||
//wait for all buttons idle
|
||||
while (anybutton())
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
turnOffAllLed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user