unit testing

This commit is contained in:
2021-01-27 08:27:08 +01:00
parent f78f3c5eaa
commit d36d67bd2c
20 changed files with 360 additions and 78 deletions

View File

@@ -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