unit testing
This commit is contained in:
62
src/board.h
62
src/board.h
@@ -1,27 +1,55 @@
|
||||
#ifndef BOARDH
|
||||
#define BOARDH
|
||||
|
||||
#define LED1 PB0 //D3
|
||||
#define LED2 PB7 //D4
|
||||
#define LED3 PB6 //D5
|
||||
#ifndef UNIT_TEST
|
||||
|
||||
#define DETECT1 PA6 //A5
|
||||
#define DETECT2 PA5 //A4
|
||||
#define DETECT3 PA4 //A3
|
||||
#define LED1 PB0 //D3
|
||||
#define LED2 PB7 //D4
|
||||
#define LED3 PB6 //D5
|
||||
|
||||
#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 DETECT1 PA6 //A5
|
||||
#define DETECT2 PA5 //A4
|
||||
#define DETECT3 PA4 //A3
|
||||
|
||||
#define LD3LED PB3
|
||||
#define WAKEUPPIN PA2
|
||||
#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 REDLEDRES
|
||||
#define YELLOWLEDRES
|
||||
#define GREENLEDRES
|
||||
#define LD3LED PB3
|
||||
#define WAKEUPPIN PA2
|
||||
|
||||
#define REDLEDRES
|
||||
#define YELLOWLEDRES
|
||||
#define GREENLEDRES
|
||||
|
||||
#else
|
||||
|
||||
#define LED1 0 //D3
|
||||
#define LED2 1 //D4
|
||||
#define LED3 2 //D5
|
||||
|
||||
#define DETECT1 3 //A5
|
||||
#define DETECT2 4 //A4
|
||||
#define DETECT3 5 //A3
|
||||
|
||||
#define SWITCH1 6 //A6 TOGGLE1
|
||||
#define SWITCH12 7 //A7 MOMENTARY1
|
||||
#define SWITCH2 8 //A1 TOGGLE1
|
||||
#define SWITCH22 9 //A2 MOMENTARY1
|
||||
#define SWITCH3 10 //D11 TOGGLE1
|
||||
#define SWITCH32 11 //D12 MOMENTARY1
|
||||
|
||||
#define LD3LED 12
|
||||
#define WAKEUPPIN 13
|
||||
|
||||
#define REDLEDRES
|
||||
#define YELLOWLEDRES
|
||||
#define GREENLEDRES
|
||||
|
||||
#endif //unit_test
|
||||
|
||||
|
||||
#endif //BOARDH
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
|
||||
#include "buttons.h"
|
||||
#include "board.h"
|
||||
#include <vector>
|
||||
#include "Arduino.h"
|
||||
#include "JC_Button.h"
|
||||
|
||||
std::vector<c_button *> buttonlist;
|
||||
|
||||
@@ -113,4 +111,4 @@ c_button *getButton(e_ledcolor color)
|
||||
std::vector<c_button *> *getButtonlist(void)
|
||||
{
|
||||
return &buttonlist;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
#ifndef BUTTONSH
|
||||
#define BUTTONSH
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Arduino.h"
|
||||
#include <vector>
|
||||
#include "JC_Button.h"
|
||||
#ifndef UNIT_TEST
|
||||
#include "JC_Button.h"
|
||||
#endif
|
||||
#include "board.h"
|
||||
#include "led.h"
|
||||
|
||||
class c_button : public ToggleButton
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
#include "chainGame.h"
|
||||
#include "Arduino.h"
|
||||
#include "buttons.h"
|
||||
#ifndef UNIT_TEST
|
||||
#ifdef ARDUINO
|
||||
|
||||
#include "chainGame.h"
|
||||
|
||||
uint8_t patternIndex = 0;
|
||||
bool patternFlag = false;
|
||||
bool firstpattern = false;
|
||||
//e_ledcolor cheatbutton = NONE;
|
||||
//bool firstpattern = false;
|
||||
uint16_t cheatbutton = 0;
|
||||
bool cheatButtonFlag = false;
|
||||
|
||||
|
||||
// e_ledcolor ledpattern[4] =
|
||||
// {
|
||||
// YELLOW,
|
||||
// GREEN,
|
||||
// YELLOW,
|
||||
// RED};
|
||||
|
||||
uint16_t ledpattern[4] =
|
||||
{
|
||||
1,
|
||||
3,
|
||||
1,
|
||||
2
|
||||
};
|
||||
{
|
||||
1,
|
||||
3,
|
||||
1,
|
||||
2};
|
||||
|
||||
int patternlength = sizeof(ledpattern) / sizeof(ledpattern[0]);
|
||||
|
||||
@@ -44,36 +35,44 @@ void ResetChainGame(void)
|
||||
{
|
||||
patternIndex = 0;
|
||||
patternFlag = false;
|
||||
firstpattern = false;
|
||||
//firstpattern = false;
|
||||
cheatbutton = 0;
|
||||
cheatButtonFlag = false;
|
||||
}
|
||||
|
||||
void HandleChainGame(void)
|
||||
{
|
||||
if (buttonIsPressed(ledpattern[patternIndex]) && !patternFlag && !cheatButtonFlag)
|
||||
if (!patternFlag && !cheatButtonFlag)
|
||||
{
|
||||
turnOnLed(ledpattern[patternIndex]);
|
||||
patternFlag = true;
|
||||
cheatbutton = 0;
|
||||
}
|
||||
else if (buttonIsPressed(cheatbutton) && !patternFlag && !cheatButtonFlag)
|
||||
{
|
||||
turnOnLed(cheatbutton);
|
||||
cheatButtonFlag = true;
|
||||
}
|
||||
else if (anybutton() && !patternFlag && !cheatButtonFlag )
|
||||
{
|
||||
cheatbutton = 0;
|
||||
if (buttonIsPressed(ledpattern[patternIndex]))
|
||||
{
|
||||
//pattern button pressed, turn on LED, set flag
|
||||
turnOnLed(ledpattern[patternIndex]);
|
||||
patternFlag = true;
|
||||
cheatbutton = 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (!buttonIsPressed(ledpattern[patternIndex]))
|
||||
{
|
||||
// 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;
|
||||
@@ -81,25 +80,33 @@ void HandleChainGame(void)
|
||||
|
||||
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))
|
||||
{
|
||||
// cheatbutton 4 (momentary 1) was closed, set cheatbutton to 1
|
||||
cheatbutton = 1;
|
||||
}
|
||||
else if (buttonIsPressed(5) && (cheatbutton == 0))
|
||||
{
|
||||
// cheatbutton 5 (momentary 2) was closed, set cheatbutton to 2
|
||||
cheatbutton = 2;
|
||||
}
|
||||
else if (buttonIsPressed(6) && (cheatbutton == 0))
|
||||
{
|
||||
// cheatbutton 5 (momentary 3) was closed, set cheatbutton to 3
|
||||
cheatbutton = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef CHAINGAMEH
|
||||
#define CHAINGAMEH
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "buttons.h"
|
||||
|
||||
void HandleChainGame( void );
|
||||
void ResetChainGame(void);
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
#include "Arduino.h"
|
||||
#include "detectled.h"
|
||||
#include "buttons.h"
|
||||
#include "board.h"
|
||||
#include "led.h"
|
||||
#include "vector"
|
||||
|
||||
|
||||
#define CHANNELS 3
|
||||
#define SAMPLES 20
|
||||
@@ -36,4 +32,5 @@ void initDetectLed(void)
|
||||
ledlist_ptr = getledlist();
|
||||
|
||||
analogReadResolution(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#ifndef DETECTLEDH
|
||||
#define DETECTLEDH
|
||||
|
||||
#include "buttons.h"
|
||||
#include "board.h"
|
||||
#include "led.h"
|
||||
#include "vector"
|
||||
|
||||
void handleDetectLed( void );
|
||||
void initDetectLed( void );
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
|
||||
#include "led.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
c_leds ledlist;
|
||||
|
||||
@@ -237,3 +238,4 @@ bool c_led::checkIndex(uint16_t index)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#ifndef LEDH
|
||||
#define LEDH
|
||||
|
||||
#include "arduino.h"
|
||||
#include "Arduino.h"
|
||||
#include "vector"
|
||||
#include "board.h"
|
||||
|
||||
enum e_ledcolor
|
||||
{
|
||||
@@ -92,4 +93,5 @@ void turnOffLed(uint16_t index);
|
||||
void turnOnLed(uint16_t index);
|
||||
void turnOffAllLed();
|
||||
|
||||
#endif //LEDH
|
||||
#endif //LEDH
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
|
||||
#include "magicSwitchBoard.h"
|
||||
#include "Arduino.h"
|
||||
#include "buttons.h"
|
||||
//#include "JC_Button.h"
|
||||
|
||||
#define CHANNELS 3
|
||||
#define TIMEOUT 7000 //game timeout
|
||||
@@ -171,3 +170,5 @@ void handleMagicSwitchBoard(void)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef MAGICSWITCHBOARDH
|
||||
#define MAGICSWITCHBOARDH
|
||||
|
||||
#include "buttons.h"
|
||||
|
||||
void handleMagicSwitchBoard( void );
|
||||
|
||||
#endif //MAGICSWITCHBOARDH
|
||||
@@ -1,4 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#include "board.h"
|
||||
#include "chainGame.h"
|
||||
#include "detectled.h"
|
||||
@@ -8,7 +11,7 @@
|
||||
#include "led.h"
|
||||
|
||||
#define TIMEOUT 15000 // 15sec * 1000ms
|
||||
#define GAMESELECTTIMEOUT 5000 // 7sec * 1000ms
|
||||
#define GAMESELECTTIMEOUT 10000 // 7sec * 1000ms
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -188,4 +191,4 @@ void loop()
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "simpleled.h"
|
||||
#include "led.h"
|
||||
#include "buttons.h"
|
||||
#include "vector"
|
||||
|
||||
|
||||
extern std::vector<c_button *> buttonlist;
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef SIMPLELEDH
|
||||
#define SIMPLELEDH
|
||||
|
||||
#include "led.h"
|
||||
#include "buttons.h"
|
||||
#include "vector"
|
||||
|
||||
void initSimpleLed( void );
|
||||
void handleSimpleLed( void );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user