-
Notifications
You must be signed in to change notification settings - Fork 0
/
st_checkBoard.c
99 lines (78 loc) · 1.86 KB
/
st_checkBoard.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "st_checkBoard.h"
#include "switch.h"
#include "st_fixBoard.h"
#include "event.h"
#include "display.h"
#include "stdio.h"
#include "constants.h"
#include "led.h"
#include "hsm.h"
#include "hsmDefs.h"
extern game_t game;
color_t currentColor;
piece_t currentPiece;
static void showCurrentPiece( color_t color, piece_t piece);
void checkBoardEntry( event_t ev)
{
currentColor = WHITE;
currentPiece = KING;
displayWriteLine(0, "Verifying Board...", true);
showCurrentPiece( currentColor, currentPiece );
displayWriteLine(3, "Press a btn to exit", true);
}
void checkBoardExit( event_t ev)
{
LED_AllOff();
displayClear();
}
void checkBoard_handleNavButtons (event_t ev)
{
int dir;
switch(ev.ev)
{
case EV_BUTTON_UP:
case EV_BUTTON_LEFT:
dir = 1;
break;
case EV_BUTTON_DOWN:
case EV_BUTTON_RIGHT:
dir = -1;
break;
}
do
{
bool wrap = false;
if(dir == 1)
{
if(currentPiece == KING)
{
currentPiece = PAWN;
wrap = true;
}
else currentPiece++;
}
else // dir = -1
{
if(currentPiece == PAWN)
{
currentPiece = KING;
wrap = true;
}
else currentPiece--;
}
if(wrap)
{
if(currentColor == WHITE) currentColor = BLACK; else currentColor = WHITE;
}
}while( !(game.brd.colors[currentColor] & game.brd.pieces[currentPiece]));
showCurrentPiece(currentColor, currentPiece);
}
static void showCurrentPiece( color_t color, piece_t piece)
{
char tempStr[6];
sprintf(tempStr, "%s", colorNames[color]);
displayWriteLine(1, tempStr, true);
sprintf(tempStr, "%s", pieceNames[piece]);
displayWriteLine(2, tempStr, true);
LED_SetGridState(game.brd.colors[color] & game.brd.pieces[piece]);
}