#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_rom_gpio.h"

#include "drivers/all.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 = 90*60*1000;
uint32_t skip_to_step = 0;

extern "C" void app_main(void) {
    printf("app_main\n");

    init_drivers();
    init_tft();
    init_speaker();
    init_sseg();
    init_game_module_timer();
    init_leds();
    init_wires();
    init_bottom_half();
    
    init_power_board();

    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"));

    display_game_results();
}

