Compare commits
9 Commits
master
...
Firmware_2
| Author | SHA1 | Date | |
|---|---|---|---|
| 141aee7066 | |||
| 409e78300d | |||
| 4c5d68d1ab | |||
| d364497804 | |||
| e7f436118f | |||
| 2e5caea417 | |||
| 56c3f749e1 | |||
| 4cc0c33cce | |||
| 48a1126a1c |
BIN
manufacturing/programming/STM32_Programmer_CLI
Executable file
BIN
manufacturing/programming/STM32_Programmer_CLI
Executable file
Binary file not shown.
BIN
manufacturing/programming/firmware_v21_20211024.bin
Executable file
BIN
manufacturing/programming/firmware_v21_20211024.bin
Executable file
Binary file not shown.
BIN
manufacturing/programming/firmware_v21_20211028.bin
Executable file
BIN
manufacturing/programming/firmware_v21_20211028.bin
Executable file
Binary file not shown.
@@ -1,2 +1,13 @@
|
||||
#!/bin/bash
|
||||
/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="/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin"
|
||||
|
||||
|
||||
$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
|
||||
3
manufacturing/programming/unlockOB.sh
Executable file
3
manufacturing/programming/unlockOB.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/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
|
||||
@@ -19,6 +19,9 @@ lib_ldf_mode = deep+
|
||||
board = nucleo_l031K6
|
||||
build_flags =
|
||||
-DHARDWAREVERSION=11
|
||||
; -fexceptions
|
||||
; build_unflags =
|
||||
; -fno-exceptions
|
||||
|
||||
; [env:LedBoardV10]
|
||||
; board = STM32L031K6
|
||||
|
||||
@@ -16,55 +16,118 @@ void c_chaingame::nextPattern(void)
|
||||
|
||||
void c_chaingame::runGame(void)
|
||||
{
|
||||
if (!patternFlag && !cheatButtonFlag)
|
||||
switch (state)
|
||||
{
|
||||
if (buttonIsPressed(ledpattern[patternIndex]))
|
||||
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))
|
||||
{
|
||||
//pattern button pressed, turn on LED, set flag
|
||||
turnOnLed(ledpattern[patternIndex]);
|
||||
patternFlag = true;
|
||||
cheatbutton = 0;
|
||||
state = cg_play;
|
||||
}
|
||||
// -> cg_cheat
|
||||
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;
|
||||
state = cg_cheat;
|
||||
}
|
||||
}
|
||||
|
||||
if (!buttonIsPressed(ledpattern[patternIndex]))
|
||||
break;
|
||||
case cg_play:
|
||||
{
|
||||
// pattern switch is open, turn off pattern LED
|
||||
turnOffLed(ledpattern[patternIndex]);
|
||||
}
|
||||
|
||||
if (!buttonIsPressed(cheatbutton) && cheatButtonFlag)
|
||||
{
|
||||
// cheat switch is open, turn of cheat LED
|
||||
turnOffLed(cheatbutton);
|
||||
cheatButtonFlag = false;
|
||||
cheatbutton = 0;
|
||||
}
|
||||
|
||||
if (!anybutton())
|
||||
{
|
||||
//all switches are open, turn off all LEDs
|
||||
turnOffAllLed();
|
||||
if (patternFlag)
|
||||
// enable pattern LED and wait for all switches OFF
|
||||
if (buttonIsPressed(ledpattern[patternIndex]))
|
||||
{
|
||||
// pattern LED was triggerd, reset flag, move to next pattern
|
||||
patternFlag = false;
|
||||
turnOnLed(ledpattern[patternIndex]);
|
||||
}
|
||||
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;
|
||||
state = cg_idle;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
state = cg_reset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check cheatbuttons
|
||||
void c_chaingame::updateCheatButton(void)
|
||||
{
|
||||
// check cheatbuttons
|
||||
if (buttonIsPressed(4) && (cheatbutton == 0))
|
||||
{
|
||||
// cheatbutton 4 (momentary 1) was closed, set cheatbutton to 1
|
||||
@@ -81,12 +144,13 @@ void c_chaingame::runGame(void)
|
||||
cheatbutton = 3;
|
||||
}
|
||||
}
|
||||
|
||||
bool c_chaingame::initGame(void)
|
||||
{
|
||||
patternIndex = 0;
|
||||
patternFlag = false;
|
||||
cheatbutton = 0;
|
||||
cheatButtonFlag = false;
|
||||
// patternFlag = false;
|
||||
// cheatbutton = 0;
|
||||
// cheatButtonFlag = false;
|
||||
state = cg_reset;
|
||||
return true;
|
||||
}
|
||||
void c_chaingame::resetGame(void)
|
||||
|
||||
@@ -5,20 +5,35 @@
|
||||
#include "buttons.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
|
||||
{
|
||||
private:
|
||||
uint8_t patternIndex;
|
||||
bool patternFlag = false;
|
||||
//bool patternFlag = false;
|
||||
uint16_t cheatbutton = 0;
|
||||
bool cheatButtonFlag = false;
|
||||
//bool cheatButtonFlag = false;
|
||||
uint16_t ledpattern[4] = {1, 3, 1, 2};
|
||||
int patternlength = sizeof(ledpattern) / sizeof(ledpattern[0]);
|
||||
cg_states state = cg_reset;
|
||||
uint32_t playNextTimer=0;
|
||||
|
||||
void nextPattern(void);
|
||||
void updateCheatButton(void);
|
||||
|
||||
public:
|
||||
c_chaingame(e_ledcolor gamecolor): c_game{chaingame, gamecolor} {}
|
||||
c_chaingame(e_ledcolor gamecolor) : c_game{chaingame, gamecolor} {}
|
||||
void runGame(void);
|
||||
bool initGame(void);
|
||||
void resetGame(void);
|
||||
@@ -27,5 +42,4 @@ public:
|
||||
// void HandleChainGame( bool newstate );
|
||||
// void ResetChainGame(void);
|
||||
|
||||
|
||||
#endif //CHAINGAMEH
|
||||
#endif // CHAINGAMEH
|
||||
97
src/game.cpp
97
src/game.cpp
@@ -4,26 +4,37 @@
|
||||
#include "simpleled.h"
|
||||
#include "magicSwitchBoard.h"
|
||||
#include "chainGame.h"
|
||||
#include "detectled.h"
|
||||
//#include "detectled.h"
|
||||
|
||||
std::vector<c_game *> gameslist;
|
||||
uint64_t GameSelectTimer = 0;
|
||||
e_state currentState = state_init;
|
||||
bool gamesConstructed = false;
|
||||
|
||||
c_game *game_simpleled = new c_simpleLed(YELLOW);
|
||||
c_game *game_magicswitchboard = new c_magicSwitchBoard(RED);
|
||||
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)
|
||||
{
|
||||
gameslist.clear();
|
||||
gameslist.push_back(game_simpleled);
|
||||
gameslist.push_back(game_magicswitchboard);
|
||||
gameslist.push_back(game_chaingame);
|
||||
gameslist.push_back(game_detectled);
|
||||
constructGames();
|
||||
setGameState(state_init);
|
||||
}
|
||||
|
||||
activateGame(simpleled);
|
||||
void constructGames(void)
|
||||
{
|
||||
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)
|
||||
@@ -135,14 +146,14 @@ void HandleGameSelectTimeout(void)
|
||||
// yellow && red && green all on
|
||||
if (allButtons())
|
||||
{
|
||||
//all buttons pressed, wait for next game
|
||||
// all buttons pressed, wait for next game
|
||||
if (!GameSelectTimer)
|
||||
{
|
||||
GameSelectTimer = currentmillis;
|
||||
}
|
||||
else
|
||||
{
|
||||
//check timeout
|
||||
// check timeout
|
||||
if (currentmillis - GameSelectTimer > GAMESELECTTIMEOUT)
|
||||
{
|
||||
currentState = state_idle;
|
||||
@@ -152,7 +163,7 @@ void HandleGameSelectTimeout(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
//no gameselect sequence initiated
|
||||
// no gameselect sequence initiated
|
||||
GameSelectTimer = currentmillis;
|
||||
}
|
||||
}
|
||||
@@ -160,29 +171,36 @@ void HandleGameSelectTimeout(void)
|
||||
void HandleGameIdle(void)
|
||||
{
|
||||
e_game nextGame = none;
|
||||
if(!gamesConstructed)
|
||||
{
|
||||
initGames();
|
||||
}
|
||||
|
||||
for (auto &&thisgame : gameslist)
|
||||
{
|
||||
if (onlyButton(thisgame->getGameColor()) && (nextGame == none))
|
||||
{
|
||||
//prepare for next game
|
||||
// prepare for next game
|
||||
nextGame = thisgame->getIndex();
|
||||
turnOffLed(thisgame->getGameColor());
|
||||
turnOnLed(thisgame->getGameColor());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//wait for all buttons to be switched off
|
||||
// wait for all buttons to be switched off
|
||||
if (!anybutton())
|
||||
{
|
||||
activateGame(nextGame);
|
||||
currentState = state_play;
|
||||
if (nextGame != none)
|
||||
{
|
||||
activateGame(nextGame);
|
||||
setGameState(state_play);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setGameState(e_state newstate)
|
||||
{
|
||||
currentState = state_play;
|
||||
currentState = newstate;
|
||||
}
|
||||
|
||||
e_state getCurrentState(void)
|
||||
@@ -196,6 +214,24 @@ void handleGames(void)
|
||||
|
||||
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:
|
||||
{
|
||||
HandleGameIdle();
|
||||
@@ -207,32 +243,9 @@ void handleGames(void)
|
||||
runGames();
|
||||
}
|
||||
break;
|
||||
|
||||
case state_init:
|
||||
default:
|
||||
{
|
||||
//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);
|
||||
currentState = state_init;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,12 +48,15 @@ public:
|
||||
e_ledcolor getGameColor(void) { return _gamecolor; }
|
||||
};
|
||||
|
||||
e_game getActiveGame(void);
|
||||
c_game *getGame(e_game game, e_ledcolor gamecolor);
|
||||
void runGame(e_game game);
|
||||
void runGames(void);
|
||||
void activateGame(e_game nextgame);
|
||||
void disableAllGames(void);
|
||||
|
||||
void initGames(void);
|
||||
void handleGames();
|
||||
|
||||
|
||||
#endif //GAMEH
|
||||
72
src/led.cpp
72
src/led.cpp
@@ -71,6 +71,78 @@ 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 #
|
||||
//#############################################
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "vector"
|
||||
#include "board.h"
|
||||
|
||||
#define BLINKINTERVAL 200
|
||||
|
||||
enum e_ledcolor
|
||||
{
|
||||
YELLOW,
|
||||
@@ -97,6 +99,8 @@ void turnOnLed(uint16_t index);
|
||||
void turnOffAllLed(void);
|
||||
void turnOnAllLed(void);
|
||||
void setAllLeds( bool state);
|
||||
void blinkAllLeds(void);
|
||||
void blinkLed(e_ledcolor blinkled);
|
||||
|
||||
|
||||
#endif //LEDH
|
||||
|
||||
@@ -150,7 +150,7 @@ void handlePowerState(void)
|
||||
{
|
||||
if (!buttonread)
|
||||
{
|
||||
powerstate = on;
|
||||
powerstate = powerinit;
|
||||
powerOn();
|
||||
turnOffAllLed();
|
||||
delay(200);
|
||||
@@ -164,6 +164,12 @@ void handlePowerState(void)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case powerinit:
|
||||
{
|
||||
initGames();
|
||||
powerstate = on;
|
||||
}
|
||||
break;
|
||||
case on:
|
||||
{
|
||||
if (buttonPower.pressedFor(100))
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "led.h"
|
||||
#include "buttons.h"
|
||||
#include "board.h"
|
||||
#include "game.h"
|
||||
|
||||
#ifdef BTN_PWR
|
||||
#include "JC_Button.h"
|
||||
@@ -21,6 +22,7 @@ typedef enum
|
||||
off,
|
||||
poweringOn,
|
||||
poweringOn2,
|
||||
powerinit,
|
||||
on,
|
||||
poweringOff,
|
||||
poweringOff2,
|
||||
|
||||
Reference in New Issue
Block a user