#include #include #include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_chip_info.h" #include "esp_flash.h" #include "esp_system.h" #include "blk_box.h" #include "blk_box_drivers/i2c.h" #include "blk_box_drivers/inputs.hpp" #include "blk_box_drivers/leds.hpp" #include "blk_box_drivers/char_lcd.hpp" #include "blk_box_drivers/ssegs.hpp" #include "blk_box_drivers/helpers.hpp" extern "C" void app_main(void) { BlkBoxInitConfig blk_box_cfg = {}; init_blk_box(blk_box_cfg); LCDController::set_backlight(true); lcd_do_splash(); LCDController::set_resting_cursor_mode(CursorMode::Show); LCDController::set_resting_cursor_pos(0, 0); SSegController::enable_game_timer(); SSegController::enable_module_timer(); uint32_t i = 0; while (1) { if (InputsController::has_button_press()) { Button b = InputsController::wait_button_press(); printf("Button pressed: %d\n", raw_value(b)); if (b == Button::GREEN) { LEDController::set_indicator(static_cast(i + LED_SHAPE_COUNT), LEDColor::GREEN); LEDController::flush(); } else if (b == Button::YELLOW) { LEDController::set_indicator(static_cast(i + LED_SHAPE_COUNT), LEDColor::YELLOW); LEDController::flush(); } else if (b == Button::RED) { i = (i + 1) % LED_INDICATOR_COUNT; LCDController::set_resting_cursor_pos(0, i % 20); } else if (b == Button::BLUE) { i = (i + LED_INDICATOR_COUNT - 1) % LED_INDICATOR_COUNT; LCDController::set_resting_cursor_pos(0, i % 20); } } if (InputsController::has_switch_flip()) { SwitchFlip flip = InputsController::wait_switch_flip(); printf("Switch flipped: %d, new state: %d\n", raw_value(flip.get_switch()), flip.is_up()); if (flip.get_switch() == Switch::S1) { SSegController::set_game_time(SSegController::get_game_time() + 10000); } if (flip.get_switch() == Switch::S2) { SSegController::set_module_time(SSegController::get_module_time() + 10000); } if (flip.get_switch() == Switch::S3) { SSegController::start_game_timer(); } if (flip.get_switch() == Switch::S4) { if (flip.is_up()) { SSegController::start_module_timer(); } else { SSegController::stop_module_timer(); } } } if (InputsController::has_keypad_press()) { KeypadKey k = InputsController::wait_keypad_press(); printf("Keypad key pressed: %c\n", keypad_key_to_char(k)); LEDController::flush(); } vTaskDelay(10 / portTICK_PERIOD_MS); } }