Compare commits

..

No commits in common. "480445d31e6ba889fc3a0981a25e959ea02e04cb" and "ae1766b3b09ba40c72ac1f14cd3a2268a786694f" have entirely different histories.

8 changed files with 32 additions and 135 deletions

View File

@ -221,7 +221,7 @@ void init_speaker(void) {
// start task
xTaskCreate(speaker_task, "play_audio", 4096, NULL, 5, NULL);
play_clip_wav(MOUNT_POINT "/startup.wav", true, false, 4, 0);
play_clip_wav(MOUNT_POINT "/startup.wav", true, false, 3, 0);
ESP_LOGI(TAG, "Speaker initialized!");
}

View File

@ -1,14 +1,10 @@
#include "wires.h"
extern uint32_t current_step;
uint32_t total_strikes;
uint32_t step_strikes[N_STEPS] = {0};
uint32_t step_finish_times[N_STEPS] = {0};
static const char *TAG = "wires";
const uint32_t STRIKE_TIME_PENALTY = 30'000;
static const uint32_t STRIKE_TIME_PENALTY = 30'000;
static bool button_state;
static bool button_pressed;
@ -87,10 +83,7 @@ void strike(const char* reason) {
ESP_LOGW("strike!", "%s", reason);
lcd_print(0, 3, reason);
time_penalty(STRIKE_TIME_PENALTY);
if (current_step > 0 && current_step <= N_STEPS) {
total_strikes += 1;
step_strikes[current_step - 1] += 1;
}
total_strikes += 1;
uint8_t reg = 6;
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_to_device(WIRES_I2C_NUM, WIRES_I2C_ADDR, &reg, 1, (100 / portTICK_PERIOD_MS)));
}

View File

@ -7,7 +7,6 @@
#include <esp_log.h>
#include "drivers/char_lcd.h"
#include "drivers/game_timer.h"
#include "main.h"
#define WIRES_PIN_DELTA GPIO_NUM_2
#define WIRES_I2C_NUM I2C_NUM_1
@ -16,10 +15,6 @@
#define DELTA_BIT_WIRES 0
#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;
void init_wires(void);

View File

@ -89,106 +89,40 @@ void do_star_codes(StarCodeHandler* star_codes, int star_codes_len) {
}
}
static lv_obj_t* old_scr;
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 lv_obj_t* game_results_label;
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 minutes = (game_time / (1000*60)) % 60;
uint8_t seconds = (game_time / (1000)) % 60;
sprintf(buf, "%s%d:%02d:%02d", minus, hours, minutes, seconds);
sprintf(str_buf, "%d:%02d:%02d", hours, minutes, seconds);
return str_buf;
}
extern uint32_t initial_game_time;
void display_game_results(void) {
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_set_text_color(&game_results_style, lv_color_white());
// lv_style_set_bg_color(&game_results_style, lv_color_black());
lv_style_set_text_align(&game_results_style, LV_TEXT_ALIGN_LEFT);
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
lv_style_init(&game_results_style);
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_opa(&game_results_style, LV_OPA_100);
lv_style_set_text_align(&game_results_style, LV_TEXT_ALIGN_CENTER);
overall_results_label = lv_label_create(scr);
lv_obj_align(overall_results_label, LV_ALIGN_TOP_LEFT, 20, 20);
lv_obj_set_size(overall_results_label, 460, 140);
lv_obj_add_style(overall_results_label, &game_results_style, LV_STATE_DEFAULT);
game_results_label = lv_label_create(lv_scr_act());
lv_obj_align(game_results_label, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_style(game_results_label, &game_results_style, LV_STATE_DEFAULT);
breakdown_results_label = lv_label_create(scr);
lv_obj_align(breakdown_results_label, LV_ALIGN_BOTTOM_LEFT, 20, 0);
lv_obj_set_size(breakdown_results_label, 460, 140);
lv_obj_add_style(breakdown_results_label, &game_results_style, LV_STATE_DEFAULT);
char buf[100] = {0};
int32_t time_s = get_game_time();
int32_t time_spent = initial_game_time - time_s;
char* time = write_time(time_spent);
sprintf(buf, "Finished!\nTotal Time (w/ penalties): %s\nTotal Strikes: %ld", time, total_strikes);
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);
lv_label_set_text(game_results_label, buf);
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);
}
}

View File

@ -1,5 +1,3 @@
#include "main.h"
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
@ -19,10 +17,8 @@
#include "steps/step6.h"
static const char *TAG = "main";
uint32_t initial_game_time = 90*60*1000 + 1000;
uint32_t initial_game_time = 90*60*1000;
uint32_t skip_to_step = 0;
uint32_t current_step = 0;
extern uint32_t total_strikes;
extern "C" void app_main(void) {
printf("app_main\n");
@ -35,34 +31,20 @@ extern "C" void app_main(void) {
clean_bomb();
step0();
set_game_time(initial_game_time);
set_game_time(initial_game_time + 1000);
start_game_timer();
total_strikes = 0;
clean_bomb();
current_step = 1;
if (skip_to_step <= 1) step1();
step_finish_times[current_step-1] = get_game_time();
clean_bomb();
current_step = 2;
if (skip_to_step <= 2) step2();
step_finish_times[current_step-1] = get_game_time();
clean_bomb();
current_step = 3;
if (skip_to_step <= 3) step3();
step_finish_times[current_step-1] = get_game_time();
clean_bomb();
current_step = 4;
if (skip_to_step <= 4) step4();
step_finish_times[current_step-1] = get_game_time();
clean_bomb();
current_step = 5;
if (skip_to_step <= 5) step5();
step_finish_times[current_step-1] = get_game_time();
clean_bomb();
current_step = 6;
if (skip_to_step <= 6) step6();
start_game_timer();
step_finish_times[current_step-1] = get_game_time();
clean_bomb();
stop_game_timer();
@ -71,3 +53,4 @@ extern "C" void app_main(void) {
display_game_results();
}

View File

@ -1,8 +0,0 @@
#ifndef MAIN_H
#define MAIN_H
#include <cstddef>
constexpr size_t N_STEPS = 6;
#endif /* MAIN_H */

View File

@ -361,10 +361,10 @@ static bool six_second() {
}
}
int pink_led_on_bottom_count = 0;
int purple_led_on_bottom_count = 0;
for (int i = IndicatorLED::LED_RFID; i < LED_COUNT; i++) {
if (indicator_led_idxs[i] == 5) {
pink_led_on_bottom_count++;
purple_led_on_bottom_count++;
}
}
@ -372,7 +372,7 @@ static bool six_second() {
vowels > 7,
second_switch_correct_state,
true,
!(pink_led_on_bottom_count > 1)
!(purple_led_on_bottom_count > 1)
);
uint8_t correct_button_mask = 0b1101;

View File

@ -834,7 +834,7 @@ void step5(void) {
{1, "Red"},
{2, "Yellow"},
{3, "Blue"},
{4, "Pink"},
{4, "Purple"},
};
int answer_color = answer_color_dist(gen);