Compare commits
2 Commits
ae1766b3b0
...
480445d31e
| Author | SHA1 | Date | |
|---|---|---|---|
| 480445d31e | |||
| 7d43f9957a |
@ -221,7 +221,7 @@ void init_speaker(void) {
|
|||||||
// start task
|
// start task
|
||||||
xTaskCreate(speaker_task, "play_audio", 4096, NULL, 5, NULL);
|
xTaskCreate(speaker_task, "play_audio", 4096, NULL, 5, NULL);
|
||||||
|
|
||||||
play_clip_wav(MOUNT_POINT "/startup.wav", true, false, 3, 0);
|
play_clip_wav(MOUNT_POINT "/startup.wav", true, false, 4, 0);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Speaker initialized!");
|
ESP_LOGI(TAG, "Speaker initialized!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
#include "wires.h"
|
#include "wires.h"
|
||||||
|
|
||||||
|
extern uint32_t current_step;
|
||||||
|
|
||||||
uint32_t total_strikes;
|
uint32_t total_strikes;
|
||||||
|
uint32_t step_strikes[N_STEPS] = {0};
|
||||||
|
uint32_t step_finish_times[N_STEPS] = {0};
|
||||||
|
|
||||||
static const char *TAG = "wires";
|
static const char *TAG = "wires";
|
||||||
|
|
||||||
static const uint32_t STRIKE_TIME_PENALTY = 30'000;
|
const uint32_t STRIKE_TIME_PENALTY = 30'000;
|
||||||
|
|
||||||
static bool button_state;
|
static bool button_state;
|
||||||
static bool button_pressed;
|
static bool button_pressed;
|
||||||
@ -83,7 +87,10 @@ void strike(const char* reason) {
|
|||||||
ESP_LOGW("strike!", "%s", reason);
|
ESP_LOGW("strike!", "%s", reason);
|
||||||
lcd_print(0, 3, reason);
|
lcd_print(0, 3, reason);
|
||||||
time_penalty(STRIKE_TIME_PENALTY);
|
time_penalty(STRIKE_TIME_PENALTY);
|
||||||
|
if (current_step > 0 && current_step <= N_STEPS) {
|
||||||
total_strikes += 1;
|
total_strikes += 1;
|
||||||
|
step_strikes[current_step - 1] += 1;
|
||||||
|
}
|
||||||
uint8_t reg = 6;
|
uint8_t reg = 6;
|
||||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_to_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, (100 / portTICK_PERIOD_MS)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_to_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, ®, 1, (100 / portTICK_PERIOD_MS)));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include "drivers/char_lcd.h"
|
#include "drivers/char_lcd.h"
|
||||||
#include "drivers/game_timer.h"
|
#include "drivers/game_timer.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#define WIRES_PIN_DELTA GPIO_NUM_2
|
#define WIRES_PIN_DELTA GPIO_NUM_2
|
||||||
#define WIRES_I2C_NUM I2C_NUM_1
|
#define WIRES_I2C_NUM I2C_NUM_1
|
||||||
@ -15,6 +16,10 @@
|
|||||||
#define DELTA_BIT_WIRES 0
|
#define DELTA_BIT_WIRES 0
|
||||||
#define DELTA_BIT_BUTTON 1
|
#define DELTA_BIT_BUTTON 1
|
||||||
|
|
||||||
|
extern const uint32_t STRIKE_TIME_PENALTY;
|
||||||
|
extern uint32_t step_strikes[N_STEPS];
|
||||||
|
extern uint32_t step_finish_times[N_STEPS];
|
||||||
|
|
||||||
extern uint32_t total_strikes;
|
extern uint32_t total_strikes;
|
||||||
|
|
||||||
void init_wires(void);
|
void init_wires(void);
|
||||||
|
|||||||
106
main/helper.cpp
106
main/helper.cpp
@ -89,40 +89,106 @@ void do_star_codes(StarCodeHandler* star_codes, int star_codes_len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static lv_style_t game_results_style;
|
static lv_obj_t* old_scr;
|
||||||
static lv_obj_t* game_results_label;
|
static lv_obj_t* scr;
|
||||||
|
|
||||||
|
static lv_style_t game_results_style;
|
||||||
|
static lv_obj_t* overall_results_label;
|
||||||
|
static lv_obj_t* breakdown_results_label;
|
||||||
|
static lv_obj_t* strike_numbers_label;
|
||||||
|
static lv_obj_t* step_times_label;
|
||||||
|
|
||||||
|
static void write_time(char* buf, int32_t game_time) {
|
||||||
|
char minus[2] = "\0";
|
||||||
|
if (game_time < 0) {
|
||||||
|
minus[0] = '-';
|
||||||
|
game_time = -game_time;
|
||||||
|
}
|
||||||
|
|
||||||
static char str_buf[10] = {0};
|
|
||||||
static char* write_time(uint32_t game_time) {
|
|
||||||
uint8_t hours = (game_time / (1000*60*60)) % 10;
|
uint8_t hours = (game_time / (1000*60*60)) % 10;
|
||||||
uint8_t minutes = (game_time / (1000*60)) % 60;
|
uint8_t minutes = (game_time / (1000*60)) % 60;
|
||||||
uint8_t seconds = (game_time / (1000)) % 60;
|
uint8_t seconds = (game_time / (1000)) % 60;
|
||||||
|
|
||||||
sprintf(str_buf, "%d:%02d:%02d", hours, minutes, seconds);
|
sprintf(buf, "%s%d:%02d:%02d", minus, hours, minutes, seconds);
|
||||||
return str_buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern uint32_t initial_game_time;
|
extern uint32_t initial_game_time;
|
||||||
void display_game_results(void) {
|
void display_game_results(void) {
|
||||||
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
|
while (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdFALSE) vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
scr = lv_obj_create(NULL);
|
||||||
|
lv_obj_set_style_bg_color(scr, lv_color_black(), LV_STATE_DEFAULT);
|
||||||
|
|
||||||
lv_style_init(&game_results_style);
|
lv_style_init(&game_results_style);
|
||||||
lv_style_set_text_color(&game_results_style, lv_color_white());
|
lv_style_set_text_color(&game_results_style, lv_color_white());
|
||||||
lv_style_set_bg_color(&game_results_style, lv_color_black());
|
// lv_style_set_bg_color(&game_results_style, lv_color_black());
|
||||||
lv_style_set_bg_opa(&game_results_style, LV_OPA_100);
|
lv_style_set_text_align(&game_results_style, LV_TEXT_ALIGN_LEFT);
|
||||||
lv_style_set_text_align(&game_results_style, LV_TEXT_ALIGN_CENTER);
|
|
||||||
|
|
||||||
game_results_label = lv_label_create(lv_scr_act());
|
overall_results_label = lv_label_create(scr);
|
||||||
lv_obj_align(game_results_label, LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(overall_results_label, LV_ALIGN_TOP_LEFT, 20, 20);
|
||||||
lv_obj_add_style(game_results_label, &game_results_style, LV_STATE_DEFAULT);
|
lv_obj_set_size(overall_results_label, 460, 140);
|
||||||
|
lv_obj_add_style(overall_results_label, &game_results_style, LV_STATE_DEFAULT);
|
||||||
|
|
||||||
char buf[100] = {0};
|
breakdown_results_label = lv_label_create(scr);
|
||||||
int32_t time_s = get_game_time();
|
lv_obj_align(breakdown_results_label, LV_ALIGN_BOTTOM_LEFT, 20, 0);
|
||||||
int32_t time_spent = initial_game_time - time_s;
|
lv_obj_set_size(breakdown_results_label, 460, 140);
|
||||||
char* time = write_time(time_spent);
|
lv_obj_add_style(breakdown_results_label, &game_results_style, LV_STATE_DEFAULT);
|
||||||
sprintf(buf, "Finished!\nTotal Time (w/ penalties): %s\nTotal Strikes: %ld", time, total_strikes);
|
|
||||||
|
|
||||||
lv_label_set_text(game_results_label, buf);
|
strike_numbers_label = lv_label_create(scr);
|
||||||
|
lv_obj_align(strike_numbers_label, LV_ALIGN_BOTTOM_LEFT, 90, 0);
|
||||||
|
lv_obj_set_size(strike_numbers_label, 60, 140);
|
||||||
|
lv_obj_add_style(strike_numbers_label, &game_results_style, LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_style_text_align(strike_numbers_label, LV_TEXT_ALIGN_RIGHT, LV_STATE_DEFAULT);
|
||||||
|
|
||||||
|
step_times_label = lv_label_create(scr);
|
||||||
|
lv_obj_align(step_times_label, LV_ALIGN_BOTTOM_LEFT, 140, 0);
|
||||||
|
lv_obj_set_size(step_times_label, 80, 140);
|
||||||
|
lv_obj_add_style(step_times_label, &game_results_style, LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_style_text_align(step_times_label, LV_TEXT_ALIGN_RIGHT, LV_STATE_DEFAULT);
|
||||||
|
|
||||||
|
char buf[1024] = {0};
|
||||||
|
|
||||||
|
char time_buf_1[32] = {0};
|
||||||
|
char time_buf_2[32] = {0};
|
||||||
|
char time_buf_3[32] = {0};
|
||||||
|
char time_buf_4[32] = {0};
|
||||||
|
char time_buf_5[32] = {0};
|
||||||
|
char time_buf_6[32] = {0};
|
||||||
|
|
||||||
|
int32_t time_left = get_game_time();
|
||||||
|
int32_t time_spent = initial_game_time - time_left;
|
||||||
|
int32_t true_time_spent = time_spent - (total_strikes * STRIKE_TIME_PENALTY);
|
||||||
|
write_time(time_buf_1, time_left);
|
||||||
|
write_time(time_buf_2, time_spent);
|
||||||
|
write_time(time_buf_3, true_time_spent);
|
||||||
|
|
||||||
|
sprintf(buf,
|
||||||
|
"Finished!\n\tTotal Strikes: %ld\n\tTime Left (w/ penalties): %s\n\tTime Spent (w/ penalties): %s\n\tTrue Time Spent: %s\n\n",
|
||||||
|
total_strikes, time_buf_1, time_buf_2, time_buf_3
|
||||||
|
);
|
||||||
|
lv_label_set_text(overall_results_label, buf);
|
||||||
|
|
||||||
|
lv_label_set_text(breakdown_results_label, "Step Breakdown:\n\tStep 1: \n\tStep 2:\n\tStep 3:\n\tStep 4:\n\tStep 5:\n\tStep 6:");
|
||||||
|
|
||||||
|
sprintf(buf,
|
||||||
|
"\n%ld strikes\n%ld strikes\n%ld strikes\n%ld strikes\n%ld strikes\n%ld strikes",
|
||||||
|
step_strikes[0], step_strikes[1], step_strikes[2], step_strikes[3], step_strikes[4], step_strikes[5]
|
||||||
|
);
|
||||||
|
lv_label_set_text(strike_numbers_label, buf);
|
||||||
|
|
||||||
|
write_time(time_buf_1, initial_game_time - step_finish_times[0]);
|
||||||
|
write_time(time_buf_2, step_finish_times[0] - step_finish_times[1]);
|
||||||
|
write_time(time_buf_3, step_finish_times[1] - step_finish_times[2]);
|
||||||
|
write_time(time_buf_4, step_finish_times[2] - step_finish_times[3]);
|
||||||
|
write_time(time_buf_5, step_finish_times[3] - step_finish_times[4]);
|
||||||
|
write_time(time_buf_6, step_finish_times[4] - step_finish_times[5]);
|
||||||
|
sprintf(buf,
|
||||||
|
"\n%s\n%s\n%s\n%s\n%s\n%s",
|
||||||
|
time_buf_1, time_buf_2, time_buf_3, time_buf_4, time_buf_5, time_buf_6
|
||||||
|
);
|
||||||
|
lv_label_set_text(step_times_label, buf);
|
||||||
|
|
||||||
|
old_scr = lv_scr_act();
|
||||||
|
lv_scr_load(scr);
|
||||||
|
|
||||||
xSemaphoreGive(xGuiSemaphore);
|
xSemaphoreGive(xGuiSemaphore);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#include "main.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
@ -17,8 +19,10 @@
|
|||||||
#include "steps/step6.h"
|
#include "steps/step6.h"
|
||||||
|
|
||||||
static const char *TAG = "main";
|
static const char *TAG = "main";
|
||||||
uint32_t initial_game_time = 90*60*1000;
|
uint32_t initial_game_time = 90*60*1000 + 1000;
|
||||||
uint32_t skip_to_step = 0;
|
uint32_t skip_to_step = 0;
|
||||||
|
uint32_t current_step = 0;
|
||||||
|
extern uint32_t total_strikes;
|
||||||
|
|
||||||
extern "C" void app_main(void) {
|
extern "C" void app_main(void) {
|
||||||
printf("app_main\n");
|
printf("app_main\n");
|
||||||
@ -31,20 +35,34 @@ extern "C" void app_main(void) {
|
|||||||
|
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
step0();
|
step0();
|
||||||
set_game_time(initial_game_time + 1000);
|
set_game_time(initial_game_time);
|
||||||
start_game_timer();
|
start_game_timer();
|
||||||
|
total_strikes = 0;
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
|
current_step = 1;
|
||||||
if (skip_to_step <= 1) step1();
|
if (skip_to_step <= 1) step1();
|
||||||
|
step_finish_times[current_step-1] = get_game_time();
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
|
current_step = 2;
|
||||||
if (skip_to_step <= 2) step2();
|
if (skip_to_step <= 2) step2();
|
||||||
|
step_finish_times[current_step-1] = get_game_time();
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
|
current_step = 3;
|
||||||
if (skip_to_step <= 3) step3();
|
if (skip_to_step <= 3) step3();
|
||||||
|
step_finish_times[current_step-1] = get_game_time();
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
|
current_step = 4;
|
||||||
if (skip_to_step <= 4) step4();
|
if (skip_to_step <= 4) step4();
|
||||||
|
step_finish_times[current_step-1] = get_game_time();
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
|
current_step = 5;
|
||||||
if (skip_to_step <= 5) step5();
|
if (skip_to_step <= 5) step5();
|
||||||
|
step_finish_times[current_step-1] = get_game_time();
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
|
current_step = 6;
|
||||||
if (skip_to_step <= 6) step6();
|
if (skip_to_step <= 6) step6();
|
||||||
|
start_game_timer();
|
||||||
|
step_finish_times[current_step-1] = get_game_time();
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
|
|
||||||
stop_game_timer();
|
stop_game_timer();
|
||||||
@ -53,4 +71,3 @@ extern "C" void app_main(void) {
|
|||||||
|
|
||||||
display_game_results();
|
display_game_results();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
main/main.h
Normal file
8
main/main.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef MAIN_H
|
||||||
|
#define MAIN_H
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
constexpr size_t N_STEPS = 6;
|
||||||
|
|
||||||
|
#endif /* MAIN_H */
|
||||||
@ -361,10 +361,10 @@ static bool six_second() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int purple_led_on_bottom_count = 0;
|
int pink_led_on_bottom_count = 0;
|
||||||
for (int i = IndicatorLED::LED_RFID; i < LED_COUNT; i++) {
|
for (int i = IndicatorLED::LED_RFID; i < LED_COUNT; i++) {
|
||||||
if (indicator_led_idxs[i] == 5) {
|
if (indicator_led_idxs[i] == 5) {
|
||||||
purple_led_on_bottom_count++;
|
pink_led_on_bottom_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,7 +372,7 @@ static bool six_second() {
|
|||||||
vowels > 7,
|
vowels > 7,
|
||||||
second_switch_correct_state,
|
second_switch_correct_state,
|
||||||
true,
|
true,
|
||||||
!(purple_led_on_bottom_count > 1)
|
!(pink_led_on_bottom_count > 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
uint8_t correct_button_mask = 0b1101;
|
uint8_t correct_button_mask = 0b1101;
|
||||||
|
|||||||
@ -834,7 +834,7 @@ void step5(void) {
|
|||||||
{1, "Red"},
|
{1, "Red"},
|
||||||
{2, "Yellow"},
|
{2, "Yellow"},
|
||||||
{3, "Blue"},
|
{3, "Blue"},
|
||||||
{4, "Purple"},
|
{4, "Pink"},
|
||||||
};
|
};
|
||||||
|
|
||||||
int answer_color = answer_color_dist(gen);
|
int answer_color = answer_color_dist(gen);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user