Compare commits
1 Commits
Firmware_2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 54c326c784 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,13 +1,2 @@
|
||||
#!/bin/bash
|
||||
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
|
||||
/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
|
||||
@@ -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
|
||||
@@ -19,9 +19,6 @@ lib_ldf_mode = deep+
|
||||
board = nucleo_l031K6
|
||||
build_flags =
|
||||
-DHARDWAREVERSION=11
|
||||
; -fexceptions
|
||||
; build_unflags =
|
||||
; -fno-exceptions
|
||||
|
||||
; [env:LedBoardV10]
|
||||
; board = STM32L031K6
|
||||
|
||||
@@ -16,117 +16,58 @@ void c_chaingame::nextPattern(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]))
|
||||
{
|
||||
//pattern button pressed, turn on LED, set flag
|
||||
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
|
||||
patternFlag = true;
|
||||
cheatbutton = 0;
|
||||
state = cg_idle;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
else if (buttonIsPressed(cheatbutton))
|
||||
{
|
||||
state = cg_reset;
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
void c_chaingame::updateCheatButton(void)
|
||||
// check if the actual pattern switch is off
|
||||
if (!buttonIsPressed(ledpattern[patternIndex]))
|
||||
{
|
||||
// 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))
|
||||
{
|
||||
@@ -144,13 +85,12 @@ void c_chaingame::updateCheatButton(void)
|
||||
cheatbutton = 3;
|
||||
}
|
||||
}
|
||||
|
||||
bool c_chaingame::initGame(void)
|
||||
{
|
||||
// patternFlag = false;
|
||||
// cheatbutton = 0;
|
||||
// cheatButtonFlag = false;
|
||||
state = cg_reset;
|
||||
patternIndex = 0;
|
||||
patternFlag = false;
|
||||
cheatbutton = 0;
|
||||
cheatButtonFlag = false;
|
||||
return true;
|
||||
}
|
||||
void c_chaingame::resetGame(void)
|
||||
|
||||
@@ -5,32 +5,17 @@
|
||||
#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} {}
|
||||
@@ -42,4 +27,5 @@ public:
|
||||
// void HandleChainGame( bool newstate );
|
||||
// void ResetChainGame(void);
|
||||
|
||||
|
||||
#endif //CHAINGAMEH
|
||||
79
src/game.cpp
79
src/game.cpp
@@ -4,37 +4,26 @@
|
||||
#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);
|
||||
|
||||
void setGameState(e_state newstate);
|
||||
void constructGames(void);
|
||||
c_game *game_detectled = new c_detectled(NONE);
|
||||
|
||||
void initGames(void)
|
||||
{
|
||||
constructGames();
|
||||
setGameState(state_init);
|
||||
}
|
||||
|
||||
void constructGames(void)
|
||||
{
|
||||
if (!gamesConstructed)
|
||||
{
|
||||
gameslist.clear();
|
||||
gameslist.push_back(game_simpleled);
|
||||
gameslist.push_back(game_magicswitchboard);
|
||||
gameslist.push_back(game_chaingame);
|
||||
gamesConstructed = true;
|
||||
}
|
||||
gameslist.push_back(game_detectled);
|
||||
|
||||
activateGame(simpleled);
|
||||
}
|
||||
|
||||
c_game *getGame(e_game game)
|
||||
@@ -171,10 +160,6 @@ void HandleGameSelectTimeout(void)
|
||||
void HandleGameIdle(void)
|
||||
{
|
||||
e_game nextGame = none;
|
||||
if(!gamesConstructed)
|
||||
{
|
||||
initGames();
|
||||
}
|
||||
|
||||
for (auto &&thisgame : gameslist)
|
||||
{
|
||||
@@ -182,25 +167,22 @@ void HandleGameIdle(void)
|
||||
{
|
||||
//prepare for next game
|
||||
nextGame = thisgame->getIndex();
|
||||
turnOnLed(thisgame->getGameColor());
|
||||
turnOffLed(thisgame->getGameColor());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//wait for all buttons to be switched off
|
||||
if (!anybutton())
|
||||
{
|
||||
if (nextGame != none)
|
||||
{
|
||||
activateGame(nextGame);
|
||||
setGameState(state_play);
|
||||
}
|
||||
currentState = state_play;
|
||||
}
|
||||
}
|
||||
|
||||
void setGameState(e_state newstate)
|
||||
{
|
||||
currentState = newstate;
|
||||
currentState = state_play;
|
||||
}
|
||||
|
||||
e_state getCurrentState(void)
|
||||
@@ -214,24 +196,6 @@ 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();
|
||||
@@ -243,9 +207,32 @@ void handleGames(void)
|
||||
runGames();
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,15 +48,12 @@ 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,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 #
|
||||
//#############################################
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include "vector"
|
||||
#include "board.h"
|
||||
|
||||
#define BLINKINTERVAL 200
|
||||
|
||||
enum e_ledcolor
|
||||
{
|
||||
YELLOW,
|
||||
@@ -99,8 +97,6 @@ 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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Arduino.h"
|
||||
#include "arduino.h"
|
||||
#include "board.h"
|
||||
#include "buttons.h"
|
||||
#include "led.h"
|
||||
|
||||
@@ -150,7 +150,7 @@ void handlePowerState(void)
|
||||
{
|
||||
if (!buttonread)
|
||||
{
|
||||
powerstate = powerinit;
|
||||
powerstate = on;
|
||||
powerOn();
|
||||
turnOffAllLed();
|
||||
delay(200);
|
||||
@@ -164,12 +164,6 @@ void handlePowerState(void)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case powerinit:
|
||||
{
|
||||
initGames();
|
||||
powerstate = on;
|
||||
}
|
||||
break;
|
||||
case on:
|
||||
{
|
||||
if (buttonPower.pressedFor(100))
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "led.h"
|
||||
#include "buttons.h"
|
||||
#include "board.h"
|
||||
#include "game.h"
|
||||
|
||||
#ifdef BTN_PWR
|
||||
#include "JC_Button.h"
|
||||
@@ -22,7 +21,6 @@ typedef enum
|
||||
off,
|
||||
poweringOn,
|
||||
poweringOn2,
|
||||
powerinit,
|
||||
on,
|
||||
poweringOff,
|
||||
poweringOff2,
|
||||
|
||||
Reference in New Issue
Block a user