1 Commits

Author SHA1 Message Date
54c326c784 remove variant 2021-10-22 19:52:26 +02:00
28 changed files with 99 additions and 290 deletions

View File

@@ -1,13 +1,2 @@
#!/bin/bash #!/bin/bash
TOOLPATH="/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin" /Applications/STMicroelectronics/STM32Cube/STM32_Programmer_CLI -c port=SWD -e all -w /Users/willem/Documents/PROJECTS/Leo-led-truck/manufacturing/programming/firmware20210720_short.bin 0x08000000 -ob RDP=0xBB
$TOOLPATH/STM32_Programmer_CLI -c port=SWD -ob RDP=0xAA
status=$?
if [ $status -ne 0 ]; then
echo "Failed to set Optiobytes, EXIT!"
exit 1
fi
$TOOLPATH/STM32_Programmer_CLI -c port=SWD -e all -w firmware_v21_20211028.bin 0x08000000 -ob RDP=0xBB

View File

@@ -1,3 +0,0 @@
#!/bin/bash
/Applications/STMicroelectronics/STM32Cube/STM32_Programmer_CLI -c port=SWD -ob RDP=0xAA
/Applications/STMicroelectronics/STM32Cube/STM32_Programmer_CLI -c port=SWD -e all

View File

@@ -19,9 +19,6 @@ lib_ldf_mode = deep+
board = nucleo_l031K6 board = nucleo_l031K6
build_flags = build_flags =
-DHARDWAREVERSION=11 -DHARDWAREVERSION=11
; -fexceptions
; build_unflags =
; -fno-exceptions
; [env:LedBoardV10] ; [env:LedBoardV10]
; board = STM32L031K6 ; board = STM32L031K6

View File

@@ -16,118 +16,59 @@ void c_chaingame::nextPattern(void)
void c_chaingame::runGame(void) void c_chaingame::runGame(void)
{ {
switch (state) //check if we are idle
if (!patternFlag && !cheatButtonFlag)
{ {
case cg_reset:
{
// clear all vars
turnOnAllLed();
cheatbutton = 0;
playNextTimer = 0;
patternIndex = 0;
state = cg_idle;
}
break;
case cg_idle:
{
updateCheatButton();
turnOffAllLed();
// wait for button
if (buttonIsPressed(ledpattern[patternIndex]) && (cheatbutton == 0))
{
state = cg_play;
}
// -> cg_cheat
else if (buttonIsPressed(cheatbutton))
{
state = cg_cheat;
}
}
break;
case cg_play:
{
// enable pattern LED and wait for all switches OFF
if (buttonIsPressed(ledpattern[patternIndex])) if (buttonIsPressed(ledpattern[patternIndex]))
{ {
//pattern button pressed, turn on LED, set flag
turnOnLed(ledpattern[patternIndex]); turnOnLed(ledpattern[patternIndex]);
} patternFlag = true;
else
{
turnOffLed(ledpattern[patternIndex]);
}
if (!anybutton())
{
// -> cg_play_next
turnOffAllLed();
playNextTimer = millis();
state = cg_play_next;
}
}
break;
case cg_play_next:
{
uint32_t timeNow = millis();
if (anybutton())
{
// switched on again, return to cg_play state
state = cg_play;
}
if (timeNow - playNextTimer > PLAYNEXTTIMEOUT)
{
// increase patterm counter after 3sec timeout -> cg_idle
nextPattern();
state = cg_idle;
}
}
break;
case cg_cheat:
{
// enable CHEAT LED on
if (buttonIsPressed(cheatbutton))
{
turnOnLed(cheatbutton);
}
else
{
turnOffLed(cheatbutton);
}
if (!anybutton())
{
turnOffAllLed();
playNextTimer = millis();
state = cg_cheat_next;
}
// wait for all switches off
// -> cg_idle
}
break;
case cg_cheat_next:
{
uint32_t timeNow = millis();
if (anybutton())
{
// switched on again, return to cg_play state
state = cg_cheat;
}
if (timeNow - playNextTimer > PLAYNEXTTIMEOUT)
{
// increase patterm counter after 3sec timeout -> cg_idle
cheatbutton = 0; cheatbutton = 0;
state = cg_idle; }
else if (buttonIsPressed(cheatbutton))
{
// cheatbutton pressed, turn on cheat led, set flag
turnOnLed(cheatbutton);
cheatButtonFlag = true;
}
else if (anybutton())
{
// if any other button is pressed, clear cheat button
//cheatbutton = 0;
} }
} }
break;
default:
{
state = cg_reset;
}
}
}
void c_chaingame::updateCheatButton(void) // check if the actual pattern switch is off
{ if (!buttonIsPressed(ledpattern[patternIndex]))
// check cheatbuttons {
// pattern switch is open, turn off pattern LED
turnOffLed(ledpattern[patternIndex]);
}
// check if the game is in cheat mode and cheat switch is off
if (!buttonIsPressed(cheatbutton) && cheatButtonFlag)
{
// cheat switch is open, turn of cheat LED
turnOffLed(cheatbutton);
cheatButtonFlag = false;
cheatbutton = 0;
}
// if all siwtches are off turn all LEDs off
if (!anybutton())
{
//all switches are open, turn off all LEDs
turnOffAllLed();
if (patternFlag)
{
// pattern LED was triggerd, reset flag, move to next pattern
patternFlag = false;
nextPattern();
}
}
//check cheatbuttons
if (buttonIsPressed(4) && (cheatbutton == 0)) if (buttonIsPressed(4) && (cheatbutton == 0))
{ {
// cheatbutton 4 (momentary 1) was closed, set cheatbutton to 1 // cheatbutton 4 (momentary 1) was closed, set cheatbutton to 1
@@ -144,13 +85,12 @@ void c_chaingame::updateCheatButton(void)
cheatbutton = 3; cheatbutton = 3;
} }
} }
bool c_chaingame::initGame(void) bool c_chaingame::initGame(void)
{ {
// patternFlag = false; patternIndex = 0;
// cheatbutton = 0; patternFlag = false;
// cheatButtonFlag = false; cheatbutton = 0;
state = cg_reset; cheatButtonFlag = false;
return true; return true;
} }
void c_chaingame::resetGame(void) void c_chaingame::resetGame(void)

View File

@@ -5,35 +5,20 @@
#include "buttons.h" #include "buttons.h"
#include "game.h" #include "game.h"
#define PLAYNEXTTIMEOUT 1500 // 3sec * 1000ms
typedef enum
{
cg_idle,
cg_play,
cg_play_next,
cg_cheat,
cg_cheat_next,
cg_reset
} cg_states;
class c_chaingame : public c_game class c_chaingame : public c_game
{ {
private: private:
uint8_t patternIndex; uint8_t patternIndex;
//bool patternFlag = false; bool patternFlag = false;
uint16_t cheatbutton = 0; uint16_t cheatbutton = 0;
//bool cheatButtonFlag = false; bool cheatButtonFlag = false;
uint16_t ledpattern[4] = {1, 3, 1, 2}; uint16_t ledpattern[4] = {1, 3, 1, 2};
int patternlength = sizeof(ledpattern) / sizeof(ledpattern[0]); int patternlength = sizeof(ledpattern) / sizeof(ledpattern[0]);
cg_states state = cg_reset;
uint32_t playNextTimer=0;
void nextPattern(void); void nextPattern(void);
void updateCheatButton(void);
public: public:
c_chaingame(e_ledcolor gamecolor) : c_game{chaingame, gamecolor} {} c_chaingame(e_ledcolor gamecolor): c_game{chaingame, gamecolor} {}
void runGame(void); void runGame(void);
bool initGame(void); bool initGame(void);
void resetGame(void); void resetGame(void);
@@ -42,4 +27,5 @@ public:
// void HandleChainGame( bool newstate ); // void HandleChainGame( bool newstate );
// void ResetChainGame(void); // void ResetChainGame(void);
#endif // CHAINGAMEH
#endif //CHAINGAMEH

View File

@@ -4,37 +4,26 @@
#include "simpleled.h" #include "simpleled.h"
#include "magicSwitchBoard.h" #include "magicSwitchBoard.h"
#include "chainGame.h" #include "chainGame.h"
//#include "detectled.h" #include "detectled.h"
std::vector<c_game *> gameslist; std::vector<c_game *> gameslist;
uint64_t GameSelectTimer = 0; uint64_t GameSelectTimer = 0;
e_state currentState = state_init; e_state currentState = state_init;
bool gamesConstructed = false;
c_game *game_simpleled = new c_simpleLed(YELLOW); c_game *game_simpleled = new c_simpleLed(YELLOW);
c_game *game_magicswitchboard = new c_magicSwitchBoard(RED); c_game *game_magicswitchboard = new c_magicSwitchBoard(RED);
c_game *game_chaingame = new c_chaingame(GREEN); c_game *game_chaingame = new c_chaingame(GREEN);
// c_game *game_detectled = new c_detectled(NONE); c_game *game_detectled = new c_detectled(NONE);
void setGameState(e_state newstate);
void constructGames(void);
void initGames(void) void initGames(void)
{ {
constructGames(); gameslist.clear();
setGameState(state_init); gameslist.push_back(game_simpleled);
} gameslist.push_back(game_magicswitchboard);
gameslist.push_back(game_chaingame);
gameslist.push_back(game_detectled);
void constructGames(void) activateGame(simpleled);
{
if (!gamesConstructed)
{
gameslist.clear();
gameslist.push_back(game_simpleled);
gameslist.push_back(game_magicswitchboard);
gameslist.push_back(game_chaingame);
gamesConstructed = true;
}
} }
c_game *getGame(e_game game) c_game *getGame(e_game game)
@@ -146,14 +135,14 @@ void HandleGameSelectTimeout(void)
// yellow && red && green all on // yellow && red && green all on
if (allButtons()) if (allButtons())
{ {
// all buttons pressed, wait for next game //all buttons pressed, wait for next game
if (!GameSelectTimer) if (!GameSelectTimer)
{ {
GameSelectTimer = currentmillis; GameSelectTimer = currentmillis;
} }
else else
{ {
// check timeout //check timeout
if (currentmillis - GameSelectTimer > GAMESELECTTIMEOUT) if (currentmillis - GameSelectTimer > GAMESELECTTIMEOUT)
{ {
currentState = state_idle; currentState = state_idle;
@@ -163,7 +152,7 @@ void HandleGameSelectTimeout(void)
} }
else else
{ {
// no gameselect sequence initiated //no gameselect sequence initiated
GameSelectTimer = currentmillis; GameSelectTimer = currentmillis;
} }
} }
@@ -171,36 +160,29 @@ void HandleGameSelectTimeout(void)
void HandleGameIdle(void) void HandleGameIdle(void)
{ {
e_game nextGame = none; e_game nextGame = none;
if(!gamesConstructed)
{
initGames();
}
for (auto &&thisgame : gameslist) for (auto &&thisgame : gameslist)
{ {
if (onlyButton(thisgame->getGameColor()) && (nextGame == none)) if (onlyButton(thisgame->getGameColor()) && (nextGame == none))
{ {
// prepare for next game //prepare for next game
nextGame = thisgame->getIndex(); nextGame = thisgame->getIndex();
turnOnLed(thisgame->getGameColor()); turnOffLed(thisgame->getGameColor());
break; break;
} }
} }
// wait for all buttons to be switched off //wait for all buttons to be switched off
if (!anybutton()) if (!anybutton())
{ {
if (nextGame != none) activateGame(nextGame);
{ currentState = state_play;
activateGame(nextGame);
setGameState(state_play);
}
} }
} }
void setGameState(e_state newstate) void setGameState(e_state newstate)
{ {
currentState = newstate; currentState = state_play;
} }
e_state getCurrentState(void) e_state getCurrentState(void)
@@ -214,24 +196,6 @@ void handleGames(void)
switch (getCurrentState()) switch (getCurrentState())
{ {
case state_init:
{
disableAllGames();
setGameState(state_init);
GameSelectTimer = 0;
if (anybutton())
{
setGameState(state_idle);
}
else
{
activateGame(simpleled);
setGameState(state_play);
}
}
break;
case state_idle: case state_idle:
{ {
HandleGameIdle(); HandleGameIdle();
@@ -243,9 +207,32 @@ void handleGames(void)
runGames(); runGames();
} }
break; break;
default:
case state_init:
{ {
currentState = state_init; //delay(1000);
turnOffAllLed();
activateGame(simpleled);
for (auto &&thisgame : gameslist)
{
if (onlyButton(thisgame->getGameColor()))
{
//prepare for next game
activateGame(thisgame->getIndex());
turnOnLed(thisgame->getGameColor());
break;
}
}
//wait for all buttons idle
while (anybutton())
{
}
turnOffAllLed();
setGameState(state_play);
} }
break;
} }
} }

View File

@@ -48,15 +48,12 @@ public:
e_ledcolor getGameColor(void) { return _gamecolor; } e_ledcolor getGameColor(void) { return _gamecolor; }
}; };
e_game getActiveGame(void);
c_game *getGame(e_game game, e_ledcolor gamecolor); c_game *getGame(e_game game, e_ledcolor gamecolor);
void runGame(e_game game); void runGame(e_game game);
void runGames(void); void runGames(void);
void activateGame(e_game nextgame); void activateGame(e_game nextgame);
void disableAllGames(void);
void initGames(void); void initGames(void);
void handleGames(); void handleGames();
#endif //GAMEH #endif //GAMEH

View File

@@ -71,78 +71,6 @@ void setAllLeds( bool state)
} }
} }
uint32_t lasttime = 0;
bool laststate = false;
void blinkAllLeds(void)
{
uint32_t timeNow = millis();
if(timeNow - lasttime > BLINKINTERVAL)
{
if(laststate)
{
turnOnAllLed();
laststate = false;
}
else
{
turnOffAllLed();
laststate = true;
}
lasttime = timeNow;
}
}
void blinkLed(e_ledcolor blinkled)
{
uint32_t timeNow = millis();
if(timeNow - lasttime > BLINKINTERVAL)
{
if(laststate)
{
turnOnLed(blinkled);
laststate = false;
}
else
{
turnOffLed(blinkled);
laststate = true;
}
lasttime = timeNow;
}
}
//e_ledcolor lastLed = e_ledcolor::YELLOW;
// void runningLeds(void)
// {
// uint32_t timeNow = millis();
// if(timeNow - lasttime > BLINKINTERVAL)
// {
// switch (lastLed)
// {
// case e_ledcolor::YELLOW:
// turnOffAllLed();
// turnOnLed(YELLOW);
// lastLed = e_ledcolor::RED;
// break;
// case e_ledcolor::RED:
// turnOffAllLed();
// turnOnLed(RED);
// lastLed = e_ledcolor::GREEN;
// break;
// case e_ledcolor::GREEN:
// turnOffAllLed();
// turnOnLed(GREEN);
// lastLed = e_ledcolor::YELLOW;
// break;
// default:
// break;
// }
// lasttime = timeNow;
// }
// }
//############################################# //#############################################
//# leds functions # //# leds functions #
//############################################# //#############################################

View File

@@ -5,8 +5,6 @@
#include "vector" #include "vector"
#include "board.h" #include "board.h"
#define BLINKINTERVAL 200
enum e_ledcolor enum e_ledcolor
{ {
YELLOW, YELLOW,
@@ -99,8 +97,6 @@ void turnOnLed(uint16_t index);
void turnOffAllLed(void); void turnOffAllLed(void);
void turnOnAllLed(void); void turnOnAllLed(void);
void setAllLeds( bool state); void setAllLeds( bool state);
void blinkAllLeds(void);
void blinkLed(e_ledcolor blinkled);
#endif //LEDH #endif //LEDH

View File

@@ -1,4 +1,4 @@
#include "Arduino.h" #include "arduino.h"
#include "board.h" #include "board.h"
#include "buttons.h" #include "buttons.h"
#include "led.h" #include "led.h"

View File

@@ -150,7 +150,7 @@ void handlePowerState(void)
{ {
if (!buttonread) if (!buttonread)
{ {
powerstate = powerinit; powerstate = on;
powerOn(); powerOn();
turnOffAllLed(); turnOffAllLed();
delay(200); delay(200);
@@ -164,12 +164,6 @@ void handlePowerState(void)
} }
} }
break; break;
case powerinit:
{
initGames();
powerstate = on;
}
break;
case on: case on:
{ {
if (buttonPower.pressedFor(100)) if (buttonPower.pressedFor(100))

View File

@@ -3,7 +3,6 @@
#include "led.h" #include "led.h"
#include "buttons.h" #include "buttons.h"
#include "board.h" #include "board.h"
#include "game.h"
#ifdef BTN_PWR #ifdef BTN_PWR
#include "JC_Button.h" #include "JC_Button.h"
@@ -22,7 +21,6 @@ typedef enum
off, off,
poweringOn, poweringOn,
poweringOn2, poweringOn2,
powerinit,
on, on,
poweringOff, poweringOff,
poweringOff2, poweringOff2,