Skip to content

Commit 8bd0066

Browse files
committed
added final screen
1 parent 58ce3e2 commit 8bd0066

File tree

14 files changed

+249
-85
lines changed

14 files changed

+249
-85
lines changed

KeepTalking/src/Game.h

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const uint8_t PROGMEM pgm_segChars[] =
1919
B01100111 // B
2020
};
2121

22+
float batVoltage = 0;
23+
2224
uint64_t startTime = 0;
2325
uint64_t setTime = 300000;
2426
uint8_t strikes;
@@ -85,6 +87,17 @@ void statusPixelReset() {
8587

8688
#include "Menu.h"
8789

90+
void mReset() {
91+
pixel.clear();
92+
pixel.show();
93+
inputReset();
94+
menuReset();
95+
dpPwd.clearDisplay();
96+
dpPwd.display();
97+
dpKpd.clearDisplay();
98+
dpKpd.display();
99+
}
100+
88101
#include "MTimer.h"
89102
#include "MPassword.h"
90103
#include "MMorse.h"
@@ -126,7 +139,12 @@ void gameBegin()
126139
void gameMenu()
127140
{
128141
disableModules();
142+
129143
menuReset();
144+
inputReset();
145+
outputReset();
146+
147+
batVoltage = analogRead(A0) / 102.4;
130148

131149
while(1) {
132150
inputUpdate();
@@ -144,32 +162,22 @@ void gameMenu()
144162

145163
void gameReset()
146164
{
147-
outputReset();
148-
inputReset();
149-
150165
// Set serial number
151166
serialEven = false;
152167
serialVowel = false;
153168

154169
for(uint8_t i=0; i<4; i++) {
155170
serialNumber[i] = random(10, SEGCHARS_LENGTH+10);
156171
if(serialNumber[i] <= 12) serialVowel = true;
157-
max.setRow(MAX_7SEG, 7-i, pgm_read_byte_near(pgm_segChars + serialNumber[i]-SEGCHARS_LENGTH+1));
158172
}
159173
for(uint8_t i=4; i<8; i++) {
160174
serialNumber[i] = random(10);
161175
serialEven = serialNumber[i] % 2 == 0;
162-
max.setDigit(MAX_7SEG, 7-i, serialNumber[i], 0);
163176
}
164177

165178
// Set indicators
166179
batteryLevel = random(1, 4);
167-
max.setLed(MAX_LEDS, LED_BAT1_R, LED_BAT1_C, batteryLevel>0);
168-
max.setLed(MAX_LEDS, LED_BAT2_R, LED_BAT2_C, batteryLevel>1);
169-
max.setLed(MAX_LEDS, LED_BAT3_R, LED_BAT3_C, batteryLevel>2);
170-
171180
indicators = random(256);
172-
for(uint8_t i=0; i<N_LED_OUT; i++) digitalWrite(PIN_LED_OUT+i, bitRead(indicators, i));
173181

174182
// Enable modules
175183
if(bombType != BOMBCUSTOM) {
@@ -187,56 +195,105 @@ void gameReset()
187195
}
188196
}
189197

190-
191198
// Reset all modules
192199
for(uint8_t i=0; i<N_MODULE; i++) {
193200
if(modules[i]->state == 1) modules[i]->reset();
194201
}
195202
}
196203

197-
void gameSetup()
204+
uint8_t gameSetup()
198205
{
199-
bool state;
206+
mReset();
207+
outputReset();
208+
uint8_t state;
200209

201210
do {
202211
inputUpdate();
203-
statusPixelReset();
204-
state = true;
212+
state = 1;
205213

206214
for(uint8_t i=0; i<N_MODULE; i++)
207215
{
208216
if(modules[i]->state == 1) {
209217
modules[i]->setup();
210-
state = false;
218+
state = 0;
211219
}
212-
modules[i]->updateStatus();
213220
}
214221
pixel.show();
215222

216-
} while(!state);
223+
if(menuSetup()) return 2;
224+
modules[TIMER_ID]->setup();
225+
226+
} while(state == 0);
227+
228+
mReset();
229+
outputReset();
230+
231+
do {
232+
inputUpdate();
233+
state = menuStart();
234+
pixel.show();
235+
modules[TIMER_ID]->setup();
236+
} while(state == 0);
237+
238+
return state;
217239
}
218240

219-
void gameRun()
241+
uint8_t gameRun()
220242
{
221-
bool state;
243+
// Serial number
244+
for(uint8_t i=0; i<4; i++) max.setRow(MAX_7SEG, 7-i, pgm_read_byte_near(pgm_segChars + serialNumber[i]-SEGCHARS_LENGTH+1));
245+
for(uint8_t i=4; i<8; i++) max.setDigit(MAX_7SEG, 7-i, serialNumber[i], 0);
246+
247+
// Battery level
248+
max.setLed(MAX_LEDS, LED_BAT1_R, LED_BAT1_C, batteryLevel>0);
249+
max.setLed(MAX_LEDS, LED_BAT2_R, LED_BAT2_C, batteryLevel>1);
250+
max.setLed(MAX_LEDS, LED_BAT3_R, LED_BAT3_C, batteryLevel>2);
251+
252+
// Indicators
253+
for(uint8_t i=0; i<N_LED_OUT; i++) digitalWrite(PIN_LED_OUT+i, bitRead(indicators, i));
254+
255+
mReset();
256+
uint8_t state;
222257

223258
do {
224259
inputUpdate();
225260
statusPixelReset();
226261

227-
state = true;
262+
state = 1;
228263
for(uint8_t i=0; i<N_MODULE; i++)
229264
{
230265
if(modules[i]->state == 2) {
231266
modules[i]->run();
232-
state = false;
267+
state = 0;
233268
}
234269
else if(modules[i]->state == 4) modules[i]->run();
235-
else if(modules[i]->state == 5) return;
270+
else if(modules[i]->state == 5) return 2;
236271

237272
modules[i]->updateStatus();
238273
}
239274
pixel.show();
240275

241-
} while(!state);
276+
} while(state == 0);
277+
return state;
278+
}
279+
280+
void gameFinal(uint8_t state)
281+
{
282+
mReset();
283+
for(uint8_t i=0; i<N_MODULE; i++) {
284+
modules[i]->melodyEnd = 0;
285+
modules[i]->blinkCtr = 0;
286+
modules[i]->blinkState = 0;
287+
}
288+
289+
if(state == 2) {
290+
digitalWrite(PIN_VIBRATOR, 1);
291+
delay(1000);
292+
digitalWrite(PIN_VIBRATOR, 0);
293+
}
294+
295+
do {
296+
inputUpdate();
297+
298+
} while(!menuFinal(state));
242299
}

KeepTalking/src/MButton.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#define BUTTON_NUMCOLOR 5
55
#define BUTTON_NUMLABEL 3
66
#define BUTTON_TIME 1000
7-
#define BUTTON_BRIGHTNESS 0.5
7+
#define BUTTON_BRIGHTNESS 1.8
88

99
#define BUTTON_DETONATE 0
1010
#define BUTTON_ABORT 1
@@ -25,7 +25,7 @@ class MButton : public Module
2525
void setButtonColor(uint8_t c)
2626
{
2727
for(int i=0; i<BUTTON_NUMRGB; i++)
28-
pixel.setPixelColor(RGB_BUTTON+i, colors[3*c]*BUTTON_BRIGHTNESS, colors[3*c+1]*BUTTON_BRIGHTNESS, colors[3*c+2]*BUTTON_BRIGHTNESS);
28+
pixel.setPixelColor(RGB_BUTTON+i, colors[3*c]*pixelB*BUTTON_BRIGHTNESS, colors[3*c+1]*pixelB*BUTTON_BRIGHTNESS, colors[3*c+2]*pixelB*BUTTON_BRIGHTNESS);
2929
}
3030

3131
public:

KeepTalking/src/MCWire.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,15 @@ class MCWire : public Module
111111
}
112112

113113
if(divergentWires > 0) {
114-
pixel.setPixelColor(statusPixel[slotID], 180, 75, 0);
114+
pixel.setPixelColor(statusPixel[slotID], 180*pixelB, 75*pixelB, 0);
115115
wireState = 0;
116116
}
117117
else {
118-
pixel.setPixelColor(statusPixel[slotID], 0, 0, 255);
118+
pixel.setPixelColor(statusPixel[slotID], 0, 0, 255*pixelB);
119119

120120
if(wireState < 1) wireState++;
121121
else {
122-
// Show wire colors and quit setup
123-
showWireColors();
122+
// quit setup
124123
wireState = 0;
125124
state = 2;
126125
}
@@ -131,6 +130,8 @@ class MCWire : public Module
131130

132131
void run()
133132
{
133+
showWireColors();
134+
134135
checkWires();
135136

136137
if(millis() - updateTime >= 500)

KeepTalking/src/MKeypad.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ const uint8_t PROGMEM pgm_keypad_table[] = {
288288
14, 24, 20, 22, 2, 8, 17,
289289
0, 7, 22, 4, 13, 25, 2,
290290
9, 18, 26, 6, 4, 17, 3,
291-
21, 3, 26, 19, 18, 13, 1,
291+
21, 3, 26, 19, 18, 16, 1,
292292
9, 14, 23, 12, 21, 15, 5
293293
};
294294

KeepTalking/src/MMaze.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ class MMaze : public Module
125125
if(mazeTarget[i] >= MAZE_SIZE) mazeTarget[i] = 0;
126126
}
127127
}
128-
129-
// Display border
130-
max.setRow(MAX_MATRIX, 0, 255);
131-
max.setRow(MAX_MATRIX, 7, 255);
132-
max.setColumn(MAX_MATRIX, 0, 255);
133-
max.setColumn(MAX_MATRIX, 7, 255);
134128
}
135129

136130
void setup()
@@ -167,13 +161,18 @@ class MMaze : public Module
167161

168162
// Display maze
169163
for(uint8_t y=0; y<MAZE_SIZE; y++) {
170-
uint8_t row=B10000001;
164+
//uint8_t row=B10000001;
165+
uint8_t row = 0;
166+
171167
for(uint8_t x=0; x<MAZE_SIZE; x++) {
172168
if(mazePos[0]==x && mazePos[1]==y) bitWrite(row, MAZE_SIZE-x, blinkState%2);
173169
else if(mazeTarget[0]==x && mazeTarget[1]==y) bitWrite(row, MAZE_SIZE-x, blinkState<10);
174170
else bitWrite(row, MAZE_SIZE-x, bitRead(getField(x, y), 4));
175171
}
176172
max.setRow(MAX_MATRIX, y+1, row);
177173
}
174+
// Display border
175+
//max.setRow(MAX_MATRIX, 0, 255);
176+
//max.setRow(MAX_MATRIX, 7, 255);
178177
}
179178
};

KeepTalking/src/MPIN.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class MPIN : public Module
6565
else solution[i] = abs(y + sds*bitRead(indicators, INDICATOR_CAR) - batteryLevel) % 10;
6666
}
6767

68-
updateLeds();
69-
7068
/*
7169
// Debug info
7270
dpKpd.clearDisplay();
@@ -82,7 +80,7 @@ class MPIN : public Module
8280
}
8381

8482
void run()
85-
{
83+
{
8684
// Handle button input
8785
char in = inputClicked(BTN_PIN, PIN_NBUTTON);
8886

@@ -97,7 +95,7 @@ class MPIN : public Module
9795
else defused();
9896
}
9997
else add_strike();
100-
updateLeds();
10198
}
99+
updateLeds();
102100
}
103101
};

KeepTalking/src/MPassword.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class MPassword : public Module
5959
uint8_t solution;
6060
uint8_t selectors[PWD_NUM_CHARS];
6161

62-
bool act = true;
62+
bool act;
6363
uint8_t arrows[2];
6464

6565
public:
@@ -74,6 +74,8 @@ class MPassword : public Module
7474

7575
void reset()
7676
{
77+
act = true;
78+
7779
// Empty character array
7880
for(uint8_t n=0; n<PWD_NUM_CHARS; n++) {
7981
for(uint8_t i=0; i<PWD_NUM_POSITIONS; i++) characters[n][i] = 0;

KeepTalking/src/MTimer.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ class MTimer : public Module
3838
void menu()
3939
{
4040
displayTime(setTime);
41+
brightnessAdjust();
4142
}
4243

4344
void setup()
4445
{
4546
state = 4;
4647
displayTime(setTime);
48+
brightnessAdjust();
4749
}
4850

4951
void run()
@@ -70,5 +72,15 @@ class MTimer : public Module
7072
state = 5;
7173
}
7274

75+
brightnessAdjust();
76+
}
77+
78+
private:
79+
void brightnessAdjust()
80+
{
81+
if(inputClicked(BTN_TIMER)) {
82+
brightness = (brightness >= BRIGHTNESS_MAX) ? BRIGHTNESS_MIN : brightness+1;
83+
updateBrightness();
84+
}
7385
}
7486
};

KeepTalking/src/MWire.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,15 @@ class MWire : public Module
121121
}
122122

123123
if(divergentWires > 0) {
124-
pixel.setPixelColor(statusPixel[slotID], 180, 75, 0);
124+
pixel.setPixelColor(statusPixel[slotID], 180*pixelB, 75*pixelB, 0);
125125
wireState = 0;
126126
}
127127
else {
128-
pixel.setPixelColor(statusPixel[slotID], 0, 0, 255);
128+
pixel.setPixelColor(statusPixel[slotID], 0, 0, 255*pixelB);
129129

130130
if(wireState < 1) wireState++;
131131
else {
132-
// Show wire colors and quit setup
133-
for(uint8_t i=0; i<WIRE_NUM; i++) setWireRGB(i, wires[i]);
132+
// quit setup
134133
wireState = 0;
135134
state = 2;
136135
}
@@ -141,6 +140,8 @@ class MWire : public Module
141140

142141
void run()
143142
{
143+
for(uint8_t i=0; i<WIRE_NUM; i++) setWireRGB(i, wires[i]);
144+
144145
checkWires();
145146

146147
if(millis() - updateTime >= 500)

0 commit comments

Comments
 (0)