firmware release 1.2
fixed MSboard, game class prep, power impr.
This commit is contained in:
@@ -8,23 +8,19 @@
|
|||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[env:LedBoardV10]
|
[env]
|
||||||
platform = ststm32
|
platform = ststm32
|
||||||
board = STM32L031K6
|
|
||||||
framework = arduino
|
framework = arduino
|
||||||
upload_port = stlink
|
upload_port = stlink
|
||||||
debug_tool = stlink
|
debug_tool = stlink
|
||||||
lib_ldf_mode = deep+
|
lib_ldf_mode = deep+
|
||||||
|
|
||||||
|
[env:LedBoardV10]
|
||||||
|
board = STM32L031K6
|
||||||
build_flags =
|
build_flags =
|
||||||
-DHARDWAREVERSION=10
|
-DHARDWAREVERSION=10
|
||||||
|
|
||||||
[env:ledboard_PROTO]
|
[env:ledboard_PROTO]
|
||||||
platform = ststm32
|
|
||||||
board = nucleo_l031K6
|
board = nucleo_l031K6
|
||||||
framework = arduino
|
|
||||||
upload_port = stlink
|
|
||||||
debug_tool = stlink
|
|
||||||
boards_dir = boards
|
|
||||||
lib_ldf_mode = deep+
|
|
||||||
build_flags =
|
build_flags =
|
||||||
-DHARDWAREVERSION=09
|
-DHARDWAREVERSION=09
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
#ifndef BOARDH
|
#ifndef BOARDH
|
||||||
#define BOARDH
|
#define BOARDH
|
||||||
|
|
||||||
|
#define IDLESHUTDOWN 900000 // 15min* 60 sec * 1000ms
|
||||||
|
#define VBATTMIN 3200
|
||||||
|
#define VBATTMAX 4180
|
||||||
|
#define VBATTREF 3300
|
||||||
|
|
||||||
#ifndef UNIT_TEST
|
#ifndef UNIT_TEST
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,20 @@ bool anybutton(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool anyButtonChanged(void)
|
||||||
|
{
|
||||||
|
handleButtons();
|
||||||
|
for (auto &&i : buttonlist)
|
||||||
|
{
|
||||||
|
if (i->isChanged())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool buttonIsPressed(e_ledcolor index)
|
bool buttonIsPressed(e_ledcolor index)
|
||||||
{
|
{
|
||||||
c_button *thisbutton = getButton(index);
|
c_button *thisbutton = getButton(index);
|
||||||
|
|||||||
@@ -18,10 +18,12 @@ public:
|
|||||||
|
|
||||||
e_ledcolor getColor( void ){return _color;}
|
e_ledcolor getColor( void ){return _color;}
|
||||||
uint8_t getIndex( void ) {return _index;}
|
uint8_t getIndex( void ) {return _index;}
|
||||||
|
bool isChanged( void ) {return changed();}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool anybutton(void);
|
bool anybutton(void);
|
||||||
|
bool anyButtonChanged(void);
|
||||||
void initButtons(void);
|
void initButtons(void);
|
||||||
void handleButtons(void);
|
void handleButtons(void);
|
||||||
c_button *getButton(unsigned int index);
|
c_button *getButton(unsigned int index);
|
||||||
@@ -34,4 +36,5 @@ bool buttonIsPressed(uint16_t index);
|
|||||||
bool buttonWasPressed(e_ledcolor index);
|
bool buttonWasPressed(e_ledcolor index);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //BUTTONSH
|
#endif //BUTTONSH
|
||||||
@@ -40,7 +40,7 @@ void ResetChainGame(void)
|
|||||||
cheatButtonFlag = false;
|
cheatButtonFlag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleChainGame(void)
|
void HandleChainGame(bool newstate)
|
||||||
{
|
{
|
||||||
if (!patternFlag && !cheatButtonFlag)
|
if (!patternFlag && !cheatButtonFlag)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
|
|
||||||
void HandleChainGame( void );
|
void HandleChainGame( bool newstate );
|
||||||
void ResetChainGame(void);
|
void ResetChainGame(void);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ extern std::vector<c_button *> buttonlist;
|
|||||||
c_leds *ledlist_ptr;
|
c_leds *ledlist_ptr;
|
||||||
|
|
||||||
|
|
||||||
void handleDetectLed(void)
|
void handleDetectLed(bool newstate)
|
||||||
{
|
{
|
||||||
|
|
||||||
for(auto &&button : buttonlist)
|
for(auto &&button : buttonlist)
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "vector"
|
#include "vector"
|
||||||
|
|
||||||
void handleDetectLed( void );
|
void handleDetectLed(bool newstate);
|
||||||
void initDetectLed( void );
|
void initDetectLed(void);
|
||||||
|
|
||||||
|
|
||||||
#endif //DETECTLED
|
#endif //DETECTLED
|
||||||
54
src/game.cpp
Normal file
54
src/game.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "game.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "simpleled.h"
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<c_game *> gameslist;
|
||||||
|
|
||||||
|
void initGames(void)
|
||||||
|
{
|
||||||
|
gameslist.clear();
|
||||||
|
gameslist.push_back(new c_simpleLed(simpleled));
|
||||||
|
}
|
||||||
|
|
||||||
|
void runGame(void)
|
||||||
|
{
|
||||||
|
for(auto &&game: gameslist)
|
||||||
|
{
|
||||||
|
if(game->getStatus() == active)
|
||||||
|
{
|
||||||
|
game->runGame();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(game->getStatus() == init)
|
||||||
|
{
|
||||||
|
game->initGame();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void activateGame(e_game nextgame)
|
||||||
|
{
|
||||||
|
for(auto &&game: gameslist)
|
||||||
|
{
|
||||||
|
if(game->getIndex() == nextgame)
|
||||||
|
{
|
||||||
|
if(game->getStatus() != active)
|
||||||
|
{
|
||||||
|
game->setStatus(init);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
game->setStatus(disabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
31
src/game.h
31
src/game.h
@@ -1,18 +1,35 @@
|
|||||||
#ifndef GAMEH
|
#ifndef GAMEH
|
||||||
#define GAMEH
|
#define GAMEH
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
simpleled,
|
||||||
|
chaingame,
|
||||||
|
magicswitchboard,
|
||||||
|
detectled
|
||||||
|
} e_game;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
disabled,
|
||||||
|
init,
|
||||||
|
active
|
||||||
|
} e_state;
|
||||||
|
|
||||||
class c_game
|
class c_game
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
protected:
|
const e_game _gameindex;
|
||||||
bool _status;
|
e_state _status;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
c_game(void): _status(false) {};
|
c_game(e_game index) : _gameindex(index) {_status = disabled;}
|
||||||
|
|
||||||
void runGame(void);
|
virtual void runGame(void);
|
||||||
void initGame(void);
|
virtual void initGame(void);
|
||||||
bool getStatus(void) { return _status;}
|
e_state getStatus(void) { return _status; }
|
||||||
|
e_game getIndex(void) { return _gameindex; }
|
||||||
|
void setStatus(e_state newstate) { _status = newstate;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //GAMEH
|
#endif //GAMEH
|
||||||
@@ -16,7 +16,7 @@ typedef enum
|
|||||||
states state = last;
|
states state = last;
|
||||||
uint8_t sequence[CHANNELS] = {0xFF, 0xFF, 0xFF};
|
uint8_t sequence[CHANNELS] = {0xFF, 0xFF, 0xFF};
|
||||||
const uint8_t buttonIndex[CHANNELS] = {1, 2, 3};
|
const uint8_t buttonIndex[CHANNELS] = {1, 2, 3};
|
||||||
const uint32_t leds[CHANNELS] = {LED1, LED2, LED3};
|
const uint16_t leds[CHANNELS] = {1, 2, 3};
|
||||||
|
|
||||||
uint64_t lastTime = 0;
|
uint64_t lastTime = 0;
|
||||||
|
|
||||||
@@ -41,12 +41,14 @@ void showLeds(void)
|
|||||||
{
|
{
|
||||||
//check if the position is already programmed
|
//check if the position is already programmed
|
||||||
//write sequence led on
|
//write sequence led on
|
||||||
digitalWrite(leds[i], 1);
|
turnOnLed(leds[i]);
|
||||||
|
//digitalWrite(leds[i], 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//write sequence led off
|
//write sequence led off
|
||||||
digitalWrite(leds[i], 0);
|
turnOffLed(leds[i]);
|
||||||
|
//digitalWrite(leds[i], 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,8 +61,8 @@ void resetMagicSwitchBoard(void)
|
|||||||
for (int i = 0; i < CHANNELS; i++)
|
for (int i = 0; i < CHANNELS; i++)
|
||||||
{
|
{
|
||||||
sequence[i] = 0xff;
|
sequence[i] = 0xff;
|
||||||
digitalWrite(leds[i], 0);
|
|
||||||
}
|
}
|
||||||
|
turnOffAllLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckTimeOut(void)
|
bool CheckTimeOut(void)
|
||||||
@@ -131,14 +133,11 @@ void handleIdle(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (auto &&i : leds)
|
turnOffAllLed();
|
||||||
{
|
|
||||||
digitalWrite(i, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMagicSwitchBoard(void)
|
void handleMagicSwitchBoard(bool newstate)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
@@ -171,4 +170,7 @@ void handleMagicSwitchBoard(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initMagicSwitchBoard(void)
|
||||||
|
{
|
||||||
|
resetMagicSwitchBoard();
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
|
|
||||||
void handleMagicSwitchBoard( void );
|
void handleMagicSwitchBoard( bool newstate );
|
||||||
|
void initMagicSwitchBoard(void);
|
||||||
|
|
||||||
#endif //MAGICSWITCHBOARDH
|
#endif //MAGICSWITCHBOARDH
|
||||||
95
src/main.cpp
95
src/main.cpp
@@ -10,9 +10,7 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
|
|
||||||
|
#define GAMESELECTTIMEOUT 10000 // 10sec * 1000ms
|
||||||
#define TIMEOUT 900000 // 15min* 60 sec * 1000ms
|
|
||||||
#define GAMESELECTTIMEOUT 10000 // 7sec * 1000ms
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@@ -28,12 +26,20 @@ typedef enum
|
|||||||
|
|
||||||
game currentGame = none;
|
game currentGame = none;
|
||||||
game nextGame = none;
|
game nextGame = none;
|
||||||
|
bool newstate = false;
|
||||||
uint8_t gameState = 0;
|
uint8_t gameState = 0;
|
||||||
uint64_t lasttimeOut = 0;
|
|
||||||
uint64_t GameSelectTimer = 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
|
//green button first released
|
||||||
if (!buttonIsPressed(YELLOW) && buttonIsPressed(RED) && buttonIsPressed(GREEN) && (nextGame == none))
|
if (!buttonIsPressed(YELLOW) && buttonIsPressed(RED) && buttonIsPressed(GREEN) && (nextGame == none))
|
||||||
@@ -63,7 +69,7 @@ void HandleIdle(void)
|
|||||||
//wait for all buttons to be switched off
|
//wait for all buttons to be switched off
|
||||||
if (!anybutton())
|
if (!anybutton())
|
||||||
{
|
{
|
||||||
currentGame = nextGame;
|
setNewState(nextGame);
|
||||||
nextGame = none;
|
nextGame = none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +90,7 @@ void HandleGameSelectTimeout(void)
|
|||||||
//check timeout
|
//check timeout
|
||||||
if (currentmillis - GameSelectTimer > GAMESELECTTIMEOUT)
|
if (currentmillis - GameSelectTimer > GAMESELECTTIMEOUT)
|
||||||
{
|
{
|
||||||
currentGame = idle;
|
setNewState(idle);
|
||||||
GameSelectTimer = 0;
|
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()
|
void setup()
|
||||||
{
|
{
|
||||||
initLeds();
|
initLeds();
|
||||||
initButtons();
|
initButtons();
|
||||||
initDetectLed();
|
|
||||||
initSimpleLed();
|
|
||||||
initLowPower();
|
initLowPower();
|
||||||
initBattery();
|
initBattery();
|
||||||
|
|
||||||
|
initDetectLed();
|
||||||
|
initMagicSwitchBoard();
|
||||||
|
initSimpleLed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
handleButtons();
|
handleButtons();
|
||||||
HandleTimeOut();
|
HandlePower();
|
||||||
HandleGameSelectTimeout();
|
HandleGameSelectTimeout();
|
||||||
|
|
||||||
switch (currentGame)
|
switch (currentGame)
|
||||||
{
|
{
|
||||||
case idle:
|
case idle:
|
||||||
{
|
{
|
||||||
HandleIdle();
|
HandleIdle(newstate);
|
||||||
|
newstate = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SimpleLed:
|
case SimpleLed:
|
||||||
{
|
{
|
||||||
handleSimpleLed();
|
handleSimpleLed(newstate);
|
||||||
|
newstate = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case magicSwitchBoard:
|
case magicSwitchBoard:
|
||||||
{
|
{
|
||||||
handleMagicSwitchBoard();
|
handleMagicSwitchBoard(newstate);
|
||||||
|
newstate = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case detectLED:
|
case detectLED:
|
||||||
{
|
{
|
||||||
handleDetectLed();
|
handleDetectLed(newstate);
|
||||||
|
newstate = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ChainGame:
|
case ChainGame:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
HandleChainGame();
|
HandleChainGame(newstate);
|
||||||
|
newstate = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case none:
|
case none:
|
||||||
{
|
{
|
||||||
currentGame = SimpleLed;
|
|
||||||
batteryCheck();
|
batteryCheck();
|
||||||
batterydisplay();
|
batterydisplay();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
if (buttonIsPressed(GREEN))
|
turnOffAllLed();
|
||||||
|
if (buttonIsPressed(GREEN) && currentGame == none)
|
||||||
{
|
{
|
||||||
currentGame = ChainGame;
|
setNewState(ChainGame);
|
||||||
turnOnLed(GREEN);
|
turnOnLed(GREEN);
|
||||||
}
|
}
|
||||||
if (buttonIsPressed(RED))
|
if (buttonIsPressed(RED) && currentGame == none)
|
||||||
{
|
{
|
||||||
currentGame = magicSwitchBoard;
|
setNewState(magicSwitchBoard);
|
||||||
turnOnLed(RED);
|
turnOnLed(RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttonIsPressed(YELLOW))
|
if (buttonIsPressed(YELLOW) && currentGame == none)
|
||||||
{
|
{
|
||||||
currentGame = SimpleLed;
|
setNewState(SimpleLed);
|
||||||
turnOnLed(YELLOW);
|
turnOnLed(YELLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentGame == none)
|
||||||
|
{
|
||||||
|
setNewState(SimpleLed);
|
||||||
|
}
|
||||||
|
|
||||||
//wait for all buttons idle
|
//wait for all buttons idle
|
||||||
while (anybutton())
|
while (anybutton())
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
turnOffAllLed();
|
turnOffAllLed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,35 +3,25 @@
|
|||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
#include "low_Power.h"
|
#include "low_Power.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
#include "buttons.h"
|
||||||
|
|
||||||
#ifdef VBATTPIN
|
#ifdef VBATTPIN
|
||||||
#include "Battery.h"
|
#include "Battery.h"
|
||||||
Battery battery(2500, 4160, VBATTPIN);
|
Battery battery(VBATTMIN, VBATTMAX, VBATTPIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void initBattery(void)
|
void initBattery(void)
|
||||||
{
|
{
|
||||||
#ifdef VBATTPIN
|
#ifdef VBATTPIN
|
||||||
battery.begin(3300, (R12+R13)/R13); //R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
|
battery.begin(VBATTREF, (R12+R13)/R13); //R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t batteryGetVoltage( void )
|
|
||||||
{
|
|
||||||
#ifdef VBATTPIN
|
|
||||||
return battery.voltage();
|
|
||||||
#endif
|
|
||||||
return 4200;
|
|
||||||
}
|
|
||||||
|
|
||||||
void batterydisplay(void)
|
void batterydisplay(void)
|
||||||
{
|
{
|
||||||
#ifdef VBATTPIN
|
#ifdef VBATTPIN
|
||||||
uint16_t currentlevel = battery.level();
|
uint16_t currentlevel = battery.level();
|
||||||
uint16_t currentvoltage = batteryGetVoltage();
|
|
||||||
|
|
||||||
if(currentvoltage)
|
|
||||||
{
|
|
||||||
if (currentlevel > 90)
|
if (currentlevel > 90)
|
||||||
{
|
{
|
||||||
turnOnLed(3);
|
turnOnLed(3);
|
||||||
@@ -44,14 +34,14 @@ void batterydisplay(void)
|
|||||||
{
|
{
|
||||||
turnOnLed(1);
|
turnOnLed(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void batteryCheck(void)
|
void batteryCheck(void)
|
||||||
{
|
{
|
||||||
#ifdef VBATTPIN
|
#ifdef VBATTPIN
|
||||||
if (battery.level() < 10)
|
if (battery.voltage() < VBATTMIN)
|
||||||
{
|
{
|
||||||
for( int i = 0; i < 10;i++)
|
for( int i = 0; i < 10;i++)
|
||||||
{
|
{
|
||||||
@@ -76,3 +66,39 @@ void shutdown(void)
|
|||||||
{
|
{
|
||||||
LowPower_shutdown();
|
LowPower_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HandlePower(void)
|
||||||
|
{
|
||||||
|
HandleTimeOut();
|
||||||
|
batteryCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HandleTimeOut(void)
|
||||||
|
{
|
||||||
|
uint64_t currentmillis = millis();
|
||||||
|
static uint64_t lasttimeOut = 0;
|
||||||
|
static bool buttonChanged = false;
|
||||||
|
|
||||||
|
if (!lasttimeOut)
|
||||||
|
{
|
||||||
|
lasttimeOut = currentmillis;
|
||||||
|
buttonChanged = anybutton();
|
||||||
|
}
|
||||||
|
|
||||||
|
//check if lastTime is initialized or timeout expired
|
||||||
|
if ((currentmillis - lasttimeOut > IDLESHUTDOWN))
|
||||||
|
{
|
||||||
|
turnOffAllLed();
|
||||||
|
shutdown();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (buttonChanged != anybutton())
|
||||||
|
{
|
||||||
|
buttonChanged = anybutton();
|
||||||
|
//game in progress, update timer
|
||||||
|
lasttimeOut = currentmillis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/power.h
10
src/power.h
@@ -1,10 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//battery
|
//battery
|
||||||
void initBattery( void );
|
void initBattery(void);
|
||||||
void batterydisplay( void );
|
void batterydisplay(void);
|
||||||
void batteryCheck(void);
|
void batteryCheck(void);
|
||||||
|
|
||||||
//low power
|
//low power
|
||||||
void initLowPower( void );
|
void initLowPower(void);
|
||||||
void shutdown( void );
|
void shutdown(void);
|
||||||
|
void HandleTimeOut(void);
|
||||||
|
void HandlePower(void);
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
#include "simpleled.h"
|
#include "simpleled.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void c_simpleLed::runGame(void)
|
void c_simpleLed::runGame(void)
|
||||||
{
|
{
|
||||||
handleSimpleLed();
|
handleSimpleLed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_simpleLed::initGame(void)
|
void c_simpleLed::initGame(void)
|
||||||
{
|
{
|
||||||
initSimpleLed();
|
initSimpleLed();
|
||||||
_status = true;
|
setStatus(active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ void initSimpleLed(void)
|
|||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleSimpleLed(void)
|
void handleSimpleLed(bool newstate)
|
||||||
{
|
{
|
||||||
for (auto &&button : buttonlist)
|
for (auto &&button : buttonlist)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,14 +8,14 @@
|
|||||||
|
|
||||||
class c_simpleLed : public c_game
|
class c_simpleLed : public c_game
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
c_simpleLed(e_game game): c_game{game} {}
|
||||||
void runGame(void);
|
void runGame(void);
|
||||||
void initGame(void);
|
void initGame(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void initSimpleLed(void);
|
||||||
void initSimpleLed( void );
|
void handleSimpleLed(bool newstate);
|
||||||
void handleSimpleLed( void );
|
bool getStatusSimpleLed(void);
|
||||||
bool getStatusSimpleLed( void );
|
|
||||||
|
|
||||||
|
|
||||||
#endif //SIMPLELEDH
|
#endif //SIMPLELEDH
|
||||||
Reference in New Issue
Block a user