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
upload_port = 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 DETECT3 PA4 //A3
#define SWITCH1 PA7 //A6
#define SWITCH12 PA2 //A7
#define SWITCH2 PA1 //A1
#define SWITCH22 PA3 //A2
#define SWITCH3 PB5 //D11
#define SWITCH32 PB4 //D12
#define SWITCH1 PA7 //A6 TOGGLE1
#define SWITCH12 PA2 //A7 MOMENTARY1
#define SWITCH2 PA1 //A1 TOGGLE1
#define SWITCH22 PA3 //A2 MOMENTARY1
#define SWITCH3 PB5 //D11 TOGGLE1
#define SWITCH32 PB4 //D12 MOMENTARY1
#define LD3LED PB3
#define WAKEUPPIN PA2
#define REDLEDRES
#define YELLOWLEDRES

View File

@@ -5,17 +5,14 @@
#include "JC_Button.h"
std::vector<ToggleButton *> buttonlist;
std::vector<c_button *> buttonlist;
ToggleButton button1(SWITCH12);
ToggleButton button2(SWITCH22);
ToggleButton button3(SWITCH32);
ToggleButton button4(SWITCH1);
ToggleButton button5(SWITCH2);
ToggleButton button6(SWITCH3);
c_button button1(SWITCH1, YELLOW);
c_button button2(SWITCH2, RED);
c_button button3(SWITCH3, GREEN);
void buttonbegin( ToggleButton *thisbutton )
void buttonbegin( c_button *thisbutton )
{
thisbutton->begin();
buttonlist.push_back(thisbutton);
@@ -26,9 +23,6 @@ void initButtons( void )
buttonbegin(&button1);
buttonbegin(&button2);
buttonbegin(&button3);
buttonbegin(&button4);
buttonbegin(&button5);
buttonbegin(&button6);
}
@@ -53,7 +47,7 @@ bool anybutton(void)
return false;
}
ToggleButton* getButton(unsigned int index)
c_button* getButton(unsigned int index)
{
if(index > buttonlist.size())
{
@@ -61,3 +55,14 @@ ToggleButton* getButton(unsigned int index)
}
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 <vector>
#include "JC_Button.h"
#include "led.h"
bool anybutton( void );
void initButtons( void );
void handleButtons( void );
ToggleButton* getButton(unsigned int index);
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);
void initButtons(void);
void handleButtons(void);
c_button *getButton(unsigned int index);
#endif //BUTTONSH

View File

@@ -1,44 +1,44 @@
#include "chainGame.h"
#include "Arduino.h"
#include "JC_Button.h"
extern ToggleButton button4;
extern ToggleButton button5;
extern ToggleButton button6;
//#include "JC_Button.h"
#include "buttons.h"
extern c_button button1;
extern c_button button2;
extern c_button button3;
uint8_t patternIndex = 0;
bool patternFlag = false;
bool firstpattern = false;
uint8_t ledpattern[4][3] = {
{1,0,0},
{0,0,1},
{1,0,0},
{0,1,0},
{1, 0, 0},
{0, 0, 1},
{1, 0, 0},
{0, 1, 0},
};
int patternlength = sizeof(ledpattern)/sizeof(ledpattern[0]);
int patternlength = sizeof(ledpattern) / sizeof(ledpattern[0]);
void nextPattern(void)
{
if (patternIndex < patternlength-1)
if (patternIndex < patternlength - 1)
{
patternIndex++;
}
else
{
{
patternIndex = 0;
}
}
void HandleChainGame( void )
void HandleChainGame(void)
{
if ((button4.isPressed()) | (button6.isPressed()))
if ((button1.isPressed()) | (button3.isPressed()))
{
if (!patternFlag)
{
//button detected, increase pattern
if(!firstpattern)
if (!firstpattern)
{
firstpattern = true;
}
@@ -46,30 +46,31 @@ void HandleChainGame( void )
{
nextPattern();
}
patternFlag = true;
}
}
if (button5.isPressed())
if (button2.isPressed())
{
if (!patternFlag)
{
if(!firstpattern)
if (!firstpattern)
{
firstpattern = true;
nextPattern();
}
else
{
//second input, skip a pattern
nextPattern();
nextPattern();
//second input, skip a pattern
nextPattern();
nextPattern();
}
patternFlag = true;
}
}
if ((button4.isPressed()) | (button5.isPressed()) | (button6.isPressed()))
if (anybutton() && patternFlag)
{
//write pattern to the LEDs
digitalWrite(LED1, ledpattern[patternIndex][0]);

View File

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

View File

@@ -36,6 +36,17 @@ void c_leds::begin(void)
}
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)
{
@@ -44,7 +55,7 @@ void c_leds::turnOnLed(e_ledcolor color)
{
if (thisled.checkThreshold(read) & thisled.checkcolor(color))
{
port.turnOn();
return &port;
}
}
}

View File

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

View File

@@ -1,7 +1,7 @@
#include "magicSwitchBoard.h"
#include "Arduino.h"
#include "buttons.h"
#include "JC_Button.h"
//#include "JC_Button.h"
#define CHANNELS 3
#define TIMEOUT 7000 //game timeout
@@ -16,7 +16,7 @@ typedef enum
states state = last;
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};
uint64_t lastTime = 0;
@@ -29,7 +29,7 @@ void showLeds(void)
for (int i = 0; i < CHANNELS; i++)
{
//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
if (currentbutton == NULL)
@@ -94,7 +94,7 @@ void handleLearn(void)
{
for (int i = 0; i < CHANNELS; i++)
{
ToggleButton *currentbutton = getButton(buttonIndex[i]);
c_button *currentbutton = getButton(buttonIndex[i]);
if (currentbutton == NULL)
{
return;

View File

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