fix warnings
This commit is contained in:
parent
afdbbeb233
commit
0b816aca68
@ -51,7 +51,7 @@ void stop_module_timer(void) {
|
||||
is_module_playing = false;
|
||||
}
|
||||
|
||||
void set_game_time(uint32_t new_time) {
|
||||
void set_game_time(int32_t new_time) {
|
||||
if (new_time > 0) {
|
||||
game_time_count_up = false;
|
||||
game_time_left = new_time;
|
||||
@ -62,8 +62,12 @@ void set_game_time(uint32_t new_time) {
|
||||
write_game_time(game_time_left);
|
||||
}
|
||||
|
||||
uint32_t get_game_time() {
|
||||
return game_time_left;
|
||||
int32_t get_game_time() {
|
||||
if (game_time_count_up) {
|
||||
return -((int32_t) game_time_left);
|
||||
} else {
|
||||
return ((int32_t) game_time_left);
|
||||
}
|
||||
}
|
||||
|
||||
void set_module_time(uint32_t new_time) {
|
||||
|
||||
@ -18,9 +18,9 @@ void start_module_timer(void);
|
||||
void stop_module_timer(void);
|
||||
|
||||
/// Sets the game time in ms
|
||||
void set_game_time(uint32_t new_time);
|
||||
void set_game_time(int32_t new_time);
|
||||
/// Gets the current game time in ms
|
||||
uint32_t get_game_time();
|
||||
int32_t get_game_time();
|
||||
|
||||
/// Gets the current game time in ms
|
||||
void time_penalty(uint32_t penalty);
|
||||
|
||||
@ -79,7 +79,7 @@ void clear_wires_pressed_released_cut(void) {
|
||||
button_released = false;
|
||||
}
|
||||
|
||||
void strike(char* reason) {
|
||||
void strike(const char* reason) {
|
||||
ESP_LOGW("strike!", "%s", reason);
|
||||
lcd_set_cursor(&lcd, 0, 3);
|
||||
lcd_print(&lcd, reason);
|
||||
|
||||
@ -29,6 +29,6 @@ void clear_wires_pressed_released_cut(void);
|
||||
|
||||
void set_leds(uint8_t led_states);
|
||||
|
||||
void strike(char* reason);
|
||||
void strike(const char* reason);
|
||||
|
||||
#endif /* WIRES_HPP */
|
||||
@ -102,3 +102,39 @@ void do_star_codes(StarCodeHandler* star_codes, int star_codes_len) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
|
||||
static lv_style_t game_results_style;
|
||||
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(str_buf, "%d:%d:%d", hours, minutes, seconds);
|
||||
return str_buf;
|
||||
}
|
||||
|
||||
void display_game_results(void) {
|
||||
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);
|
||||
|
||||
game_results_label = lv_label_create(lv_scr_act());
|
||||
lv_obj_add_flag(game_results_label, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_align(game_results_label, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_style(game_results_label, &game_results_style, LV_STATE_DEFAULT);
|
||||
|
||||
char buf[100] = {0};
|
||||
char* time = write_time(get_game_time());
|
||||
sprintf(buf, "Finished!\nTotal Time (w/ penalties): %s\nTotal Strikes: %ld", time, total_strikes);
|
||||
|
||||
lv_label_set_text(game_results_label, buf);
|
||||
|
||||
xSemaphoreGive(xGuiSemaphore);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,10 +8,11 @@
|
||||
#include "drivers/char_lcd.h"
|
||||
#include "drivers/leds.h"
|
||||
#include "drivers/speaker.h"
|
||||
#include "drivers/tft.h"
|
||||
|
||||
struct StarCodeHandler {
|
||||
char* code;
|
||||
char* display_text;
|
||||
const char* code;
|
||||
const char* display_text;
|
||||
bool should_exit;
|
||||
void (*callback)(void);
|
||||
};
|
||||
@ -23,5 +24,6 @@ struct StarCodeHandler {
|
||||
void clean_bomb(void);
|
||||
void poster_child_task(void* arg);
|
||||
void do_star_codes(StarCodeHandler* star_codes, int star_codes_len);
|
||||
void display_game_results();
|
||||
|
||||
#endif /* HELPER_H */
|
||||
|
||||
@ -28,38 +28,6 @@ static const char *TAG = "main";
|
||||
uint32_t initial_game_time = 60*60*1000;
|
||||
uint32_t skip_to_step = 0;
|
||||
|
||||
static void print_bin(char* out_str, uint8_t n) {
|
||||
out_str[0] = ((n & 0b1000) ? '1' : '0');
|
||||
out_str[1] = ((n & 0b0100) ? '1' : '0');
|
||||
out_str[2] = ((n & 0b0010) ? '1' : '0');
|
||||
out_str[3] = ((n & 0b0001) ? '1' : '0');
|
||||
}
|
||||
|
||||
static void debug_switches() {
|
||||
uint8_t switch_state = 0;
|
||||
uint8_t button_state = 0;
|
||||
|
||||
char buff[5] = {0};
|
||||
|
||||
while (1) {
|
||||
uint8_t new_button_state = get_button_state();
|
||||
if (new_button_state != button_state) {
|
||||
button_state = new_button_state;
|
||||
print_bin(buff, button_state);
|
||||
ESP_LOGI("main", "b: 0b%s", buff);
|
||||
}
|
||||
|
||||
uint8_t new_switch_state = get_switch_state();
|
||||
if (new_switch_state != switch_state) {
|
||||
switch_state = new_switch_state;
|
||||
print_bin(buff, switch_state);
|
||||
ESP_LOGI("main", "s: 0b%s", buff);
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void app_main(void) {
|
||||
printf("app_main\n");
|
||||
|
||||
@ -95,5 +63,7 @@ extern "C" void app_main(void) {
|
||||
stop_game_timer();
|
||||
ESP_LOGI(TAG, "Bomb has been diffused. Counter-Terrorists win.");
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(play_raw("/sdcard/diffused.pcm"));
|
||||
|
||||
display_game_results();
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ static void try_step4(void) { clean_bomb(); step4(); }
|
||||
static void try_step5(void) { clean_bomb(); step5(); }
|
||||
static void try_step6(void) { clean_bomb(); step6(); }
|
||||
static void issue_strike(void) { strike("Strike Issued"); }
|
||||
static void debug_switches(void);
|
||||
|
||||
/// Wait for "*9819"
|
||||
void step0(void) {
|
||||
@ -43,6 +44,12 @@ void step0(void) {
|
||||
.should_exit = false,
|
||||
.callback = set_game_time,
|
||||
},
|
||||
{
|
||||
.code = "*598623",
|
||||
.display_text = "Debug Switches",
|
||||
.should_exit = false,
|
||||
.callback = debug_switches,
|
||||
},
|
||||
{
|
||||
.code = "*59871",
|
||||
.display_text = "Try Step 1",
|
||||
@ -232,3 +239,43 @@ static void set_game_time(void) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void print_bin(char* out_str, uint8_t n) {
|
||||
out_str[0] = ((n & 0b1000) ? '1' : '0');
|
||||
out_str[1] = ((n & 0b0100) ? '1' : '0');
|
||||
out_str[2] = ((n & 0b0010) ? '1' : '0');
|
||||
out_str[3] = ((n & 0b0001) ? '1' : '0');
|
||||
}
|
||||
|
||||
static void debug_switches(void) {
|
||||
clean_bomb();
|
||||
uint8_t switch_state = 0;
|
||||
uint8_t button_state = 0;
|
||||
|
||||
char buff[5] = {0};
|
||||
|
||||
KeypadKey key;
|
||||
while (1) {
|
||||
uint8_t new_button_state = get_button_state();
|
||||
if (new_button_state != button_state) {
|
||||
button_state = new_button_state;
|
||||
print_bin(buff, button_state);
|
||||
ESP_LOGI("main", "b: 0b%s", buff);
|
||||
}
|
||||
|
||||
uint8_t new_switch_state = get_switch_state();
|
||||
if (new_switch_state != switch_state) {
|
||||
switch_state = new_switch_state;
|
||||
print_bin(buff, switch_state);
|
||||
ESP_LOGI("main", "s: 0b%s", buff);
|
||||
}
|
||||
|
||||
if (get_pressed_keypad(&key) && key == KeypadKey::pound) {
|
||||
return;
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -90,8 +90,7 @@ void step2(void) {
|
||||
int solved_times = 0;
|
||||
|
||||
new_puzzle();
|
||||
int strike_time = xTaskGetTickCount();
|
||||
bool striked = false;
|
||||
int strike_time = 0;
|
||||
while(solved_times < NUM_SOLVES) {
|
||||
// for every bit in the answer-
|
||||
set_module_sseg_raw(display_map);
|
||||
@ -111,13 +110,12 @@ void step2(void) {
|
||||
}
|
||||
} else {
|
||||
strike_time = xTaskGetTickCount();
|
||||
striked = true;
|
||||
strike("Incorrect Character!");
|
||||
}
|
||||
}
|
||||
|
||||
if (xTaskGetTickCount() - strike_time > pdMS_TO_TICKS(5000)) {
|
||||
striked = false;
|
||||
if (strike_time != 0 && xTaskGetTickCount() - strike_time > pdMS_TO_TICKS(5000)) {
|
||||
strike_time = 0;
|
||||
lcd_clear(&lcd);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
@ -386,8 +386,6 @@ void step5(void) {
|
||||
int buttons_pressed = 0;
|
||||
|
||||
ButtonKey button;
|
||||
KeypadKey key;
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
buttons_pressed++;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user