release 0.1

This commit is contained in:
willem oldemans
2020-11-22 16:55:23 +01:00
parent 6d9f14f5b4
commit 43fcb87efc
10 changed files with 114 additions and 89 deletions

View File

@@ -14,5 +14,6 @@ board = nucleo_l031K6
framework = arduino framework = arduino
upload_port = stlink upload_port = stlink
debug_tool = stlink debug_tool = stlink
lib_deps = http://192.168.2.3/Bonobo.Git.Server/JCButton.git lib_deps =
http://192.168.2.3/Bonobo.Git.Server/JCButton.git

View File

@@ -9,14 +9,15 @@
#define DETECT2 PA5 //A4 #define DETECT2 PA5 //A4
#define DETECT3 PA4 //A3 #define DETECT3 PA4 //A3
#define SWITCH1 PA7 //A6 #define SWITCH1 PA7 //A6 TOGGLE1
#define SWITCH12 PA2 //A7 #define SWITCH12 PA2 //A7 MOMENTARY1
#define SWITCH2 PA1 //A1 #define SWITCH2 PA1 //A1 TOGGLE1
#define SWITCH22 PA3 //A2 #define SWITCH22 PA3 //A2 MOMENTARY1
#define SWITCH3 PB5 //D11 #define SWITCH3 PB5 //D11 TOGGLE1
#define SWITCH32 PB4 //D12 #define SWITCH32 PB4 //D12 MOMENTARY1
#define LD3LED PB3 #define LD3LED PB3
#define WAKEUPPIN PA2
#define REDLEDRES #define REDLEDRES
#define YELLOWLEDRES #define YELLOWLEDRES

View File

@@ -5,17 +5,14 @@
#include "JC_Button.h" #include "JC_Button.h"
std::vector<ToggleButton *> buttonlist; std::vector<c_button *> buttonlist;
ToggleButton button1(SWITCH12); c_button button1(SWITCH1, YELLOW);
ToggleButton button2(SWITCH22); c_button button2(SWITCH2, RED);
ToggleButton button3(SWITCH32); c_button button3(SWITCH3, GREEN);
ToggleButton button4(SWITCH1);
ToggleButton button5(SWITCH2);
ToggleButton button6(SWITCH3);
void buttonbegin( ToggleButton *thisbutton ) void buttonbegin( c_button *thisbutton )
{ {
thisbutton->begin(); thisbutton->begin();
buttonlist.push_back(thisbutton); buttonlist.push_back(thisbutton);
@@ -26,9 +23,6 @@ void initButtons( void )
buttonbegin(&button1); buttonbegin(&button1);
buttonbegin(&button2); buttonbegin(&button2);
buttonbegin(&button3); buttonbegin(&button3);
buttonbegin(&button4);
buttonbegin(&button5);
buttonbegin(&button6);
} }
@@ -53,7 +47,7 @@ bool anybutton(void)
return false; return false;
} }
ToggleButton* getButton(unsigned int index) c_button* getButton(unsigned int index)
{ {
if(index > buttonlist.size()) if(index > buttonlist.size())
{ {
@@ -61,3 +55,14 @@ ToggleButton* getButton(unsigned int index)
} }
return buttonlist[index-1]; return buttonlist[index-1];
} }
c_button* getButton(e_ledcolor color)
{
for(auto&& button : buttonlist)
{
if(button->getColor() == color)
{
return button;
}
}
}

View File

@@ -4,10 +4,21 @@
#include <Arduino.h> #include <Arduino.h>
#include <vector> #include <vector>
#include "JC_Button.h" #include "JC_Button.h"
#include "led.h"
class c_button : public ToggleButton
{
const e_ledcolor _color;
public:
c_button(uint8_t pin, e_ledcolor color) : ToggleButton(pin), _color(color){}
e_ledcolor getColor( void ){return _color;}
};
bool anybutton(void); bool anybutton(void);
void initButtons(void); void initButtons(void);
void handleButtons(void); void handleButtons(void);
ToggleButton* getButton(unsigned int index); c_button *getButton(unsigned int index);
#endif //BUTTONSH #endif //BUTTONSH

View File

@@ -1,11 +1,11 @@
#include "chainGame.h" #include "chainGame.h"
#include "Arduino.h" #include "Arduino.h"
#include "JC_Button.h" //#include "JC_Button.h"
#include "buttons.h"
extern ToggleButton button4;
extern ToggleButton button5;
extern ToggleButton button6;
extern c_button button1;
extern c_button button2;
extern c_button button3;
uint8_t patternIndex = 0; uint8_t patternIndex = 0;
bool patternFlag = false; bool patternFlag = false;
@@ -33,7 +33,7 @@ void nextPattern(void)
void HandleChainGame(void) void HandleChainGame(void)
{ {
if ((button4.isPressed()) | (button6.isPressed())) if ((button1.isPressed()) | (button3.isPressed()))
{ {
if (!patternFlag) if (!patternFlag)
{ {
@@ -51,13 +51,14 @@ void HandleChainGame( void )
} }
} }
if (button5.isPressed()) if (button2.isPressed())
{ {
if (!patternFlag) if (!patternFlag)
{ {
if (!firstpattern) if (!firstpattern)
{ {
firstpattern = true; firstpattern = true;
nextPattern();
} }
else else
{ {
@@ -69,7 +70,7 @@ void HandleChainGame( void )
} }
} }
if ((button4.isPressed()) | (button5.isPressed()) | (button6.isPressed())) if (anybutton() && patternFlag)
{ {
//write pattern to the LEDs //write pattern to the LEDs
digitalWrite(LED1, ledpattern[patternIndex][0]); digitalWrite(LED1, ledpattern[patternIndex][0]);

View File

@@ -3,13 +3,16 @@
#include "buttons.h" #include "buttons.h"
#include "board.h" #include "board.h"
#include "led.h" #include "led.h"
#include "vector"
#define CHANNELS 3 #define CHANNELS 3
#define SAMPLES 20 #define SAMPLES 20
extern ToggleButton button4; extern ToggleButton button1;
extern ToggleButton button5; extern ToggleButton button2;
extern ToggleButton button6; extern ToggleButton button3;
extern std::vector<c_button *> buttonlist;
unsigned int detectled[CHANNELS] = {0, 0, 0}; unsigned int detectled[CHANNELS] = {0, 0, 0};
uint32_t detectledRaw[CHANNELS][SAMPLES]; uint32_t detectledRaw[CHANNELS][SAMPLES];
@@ -19,32 +22,20 @@ uint32_t sampleIndex = 0;
c_leds *ledlist_ptr; c_leds *ledlist_ptr;
void handleDetectLed(void) void handleDetectLed(void)
{ {
bool ledon = false;
if (button4.isPressed()) for(auto &&button : buttonlist)
{ {
ledlist_ptr->turnOnLed(YELLOW); if(button->isPressed())
ledon = true; {
ledlist_ptr->turnOnLed(button->getColor());
} }
else
if (button5.isPressed())
{ {
ledlist_ptr->turnOnLed(RED); ledlist_ptr->turnOffLed(button->getColor());
ledon = true;
} }
if (button6.isPressed())
{
ledlist_ptr->turnOnLed(GREEN);
ledon = true;
}
if (!ledon)
{
ledlist_ptr->turnAllOff();
} }
} }

View File

@@ -36,6 +36,17 @@ void c_leds::begin(void)
} }
void c_leds::turnOnLed(e_ledcolor color) void c_leds::turnOnLed(e_ledcolor color)
{
getLed(color)->turnOn();
}
void c_leds::turnOffLed(e_ledcolor color)
{
getLed(color)->turnOff();
}
c_ledport* c_leds::getLed( e_ledcolor color )
{ {
for (auto &&port : v_ledports) for (auto &&port : v_ledports)
{ {
@@ -44,7 +55,7 @@ void c_leds::turnOnLed(e_ledcolor color)
{ {
if (thisled.checkThreshold(read) & thisled.checkcolor(color)) if (thisled.checkThreshold(read) & thisled.checkcolor(color))
{ {
port.turnOn(); return &port;
} }
} }
} }

View File

@@ -8,7 +8,8 @@
enum e_ledcolor{ enum e_ledcolor{
RED, RED,
GREEN, GREEN,
YELLOW YELLOW,
NONE
}; };
class c_ledport class c_ledport
@@ -62,7 +63,10 @@ class c_leds
void begin( void ); void begin( void );
void turnOnLed(e_ledcolor color); void turnOnLed(e_ledcolor color);
void turnOffLed(e_ledcolor color);
void turnOnLed(uint16_t index); void turnOnLed(uint16_t index);
c_ledport* getLed(e_ledcolor color);
void turnAllOff( void ); void turnAllOff( void );
}; };

View File

@@ -1,7 +1,7 @@
#include "magicSwitchBoard.h" #include "magicSwitchBoard.h"
#include "Arduino.h" #include "Arduino.h"
#include "buttons.h" #include "buttons.h"
#include "JC_Button.h" //#include "JC_Button.h"
#define CHANNELS 3 #define CHANNELS 3
#define TIMEOUT 7000 //game timeout #define TIMEOUT 7000 //game timeout
@@ -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] = {4, 5, 6}; const uint8_t buttonIndex[CHANNELS] = {1, 2, 3};
const uint32_t leds[CHANNELS] = {LED1, LED2, LED3}; const uint32_t leds[CHANNELS] = {LED1, LED2, LED3};
uint64_t lastTime = 0; uint64_t lastTime = 0;
@@ -29,7 +29,7 @@ void showLeds(void)
for (int i = 0; i < CHANNELS; i++) for (int i = 0; i < CHANNELS; i++)
{ {
//get the button pointer //get the button pointer
ToggleButton *currentbutton = getButton(buttonIndex[sequence[i]]); c_button *currentbutton = getButton(buttonIndex[sequence[i]]);
//verify that the button pointer is not NULL //verify that the button pointer is not NULL
if (currentbutton == NULL) if (currentbutton == NULL)
@@ -94,7 +94,7 @@ void handleLearn(void)
{ {
for (int i = 0; i < CHANNELS; i++) for (int i = 0; i < CHANNELS; i++)
{ {
ToggleButton *currentbutton = getButton(buttonIndex[i]); c_button *currentbutton = getButton(buttonIndex[i]);
if (currentbutton == NULL) if (currentbutton == NULL)
{ {
return; return;

View File

@@ -5,21 +5,18 @@
#include "detectled.h" #include "detectled.h"
#include "magicSwitchBoard.h" #include "magicSwitchBoard.h"
#include "buttons.h" #include "buttons.h"
#include "JC_Button.h" //#include "JC_Button.h"
#include "vector"
#include "led.h" #include "led.h"
// extern ToggleButton button1;
// extern ToggleButton button2; extern c_button button1;
// extern ToggleButton button3; extern c_button button2;
extern ToggleButton button4; extern c_button button3;
extern ToggleButton button5;
extern ToggleButton button6;
typedef enum typedef enum
{ {
none, none,
powerOff, sleep,
ChainGame, ChainGame,
magicSwitchBoard, magicSwitchBoard,
detectLED, detectLED,
@@ -28,13 +25,13 @@ typedef enum
game currentGame = none; game currentGame = none;
uint8_t gameState = 0; uint8_t gameState = 0;
unsigned long gameTimeout = 0;
void setup() void setup()
{ {
pinMode(LED1, OUTPUT); pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT); pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT); pinMode(LED3, OUTPUT);
pinMode(SYS_WKUP3, INPUT);
c_leds *ledlist = getledlist(); c_leds *ledlist = getledlist();
@@ -51,6 +48,7 @@ void setup()
void loop() void loop()
{ {
handleButtons(); handleButtons();
//handleSystemTimeout();
switch (currentGame) switch (currentGame)
{ {
@@ -79,17 +77,17 @@ void loop()
digitalWrite(LED1, 0); digitalWrite(LED1, 0);
digitalWrite(LED2, 0); digitalWrite(LED2, 0);
digitalWrite(LED3, 0); digitalWrite(LED3, 0);
if (button4.isPressed()) if (button1.isPressed())
{ {
digitalWrite(LED1, 1); digitalWrite(LED1, 1);
} }
if (button5.isPressed()) if (button2.isPressed())
{ {
currentGame = magicSwitchBoard; currentGame = magicSwitchBoard;
digitalWrite(LED2, 1); digitalWrite(LED2, 1);
} }
if (button6.isPressed()) if (button3.isPressed())
{ {
digitalWrite(LED3, 1); digitalWrite(LED3, 1);
currentGame = detectLED; currentGame = detectLED;
@@ -98,5 +96,7 @@ void loop()
while (anybutton()); while (anybutton());
} }
break; break;
} }
} }