100 lines
2.4 KiB
C++
Executable File
100 lines
2.4 KiB
C++
Executable File
#include <stdio.h>
|
|
#include "sdkconfig.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "driver/uart.h"
|
|
#include "driver/i2c.h"
|
|
#include "drivers/tft.h"
|
|
#include "drivers/wires.h"
|
|
#include "drivers/bottom_half.h"
|
|
#include "drivers/sd.h"
|
|
#include "drivers/game_timer.h"
|
|
#include "drivers/speaker.h"
|
|
#include "drivers/char_lcd.h"
|
|
#include "esp_rom_gpio.h"
|
|
#include "drivers/leds.h"
|
|
|
|
#include "helper.h"
|
|
|
|
#include "steps/step0.h"
|
|
#include "steps/step1.h"
|
|
#include "steps/step2.h"
|
|
#include "steps/step3.h"
|
|
#include "steps/step4.h"
|
|
#include "steps/step5.h"
|
|
#include "steps/step6.h"
|
|
|
|
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");
|
|
|
|
init_sd();
|
|
init_tft();
|
|
init_speaker();
|
|
init_sseg();
|
|
init_game_module_timer();
|
|
init_leds();
|
|
init_wires();
|
|
|
|
init_bottom_half();
|
|
init_char_lcd();
|
|
|
|
clean_bomb();
|
|
step0();
|
|
set_game_time(initial_game_time + 1000);
|
|
start_game_timer();
|
|
clean_bomb();
|
|
if (skip_to_step <= 1) step1();
|
|
clean_bomb();
|
|
if (skip_to_step <= 2) step2();
|
|
clean_bomb();
|
|
if (skip_to_step <= 3) step3();
|
|
clean_bomb();
|
|
if (skip_to_step <= 4) step4();
|
|
clean_bomb();
|
|
if (skip_to_step <= 5) step5();
|
|
clean_bomb();
|
|
if (skip_to_step <= 6) step6();
|
|
clean_bomb();
|
|
|
|
stop_game_timer();
|
|
ESP_LOGI(TAG, "Bomb has been diffused. Counter-Terrorists win.");
|
|
ESP_ERROR_CHECK_WITHOUT_ABORT(play_raw("/sdcard/diffused.pcm"));
|
|
}
|
|
|