diff --git a/platformio.ini b/platformio.ini index b9a4abb..0d80a27 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,18 +20,14 @@ lib_deps = fbiego/ESP32Time@^2.0.6 electroniccats/MPU6050@^1.4.3 -; --- Hardware & Memory Topology --- board_build.arduino.psram = enabled board_upload.flash_size = 16MB board_build.partitions = default_16MB.csv - -; FIX 2: Explicitly matches the 'mode:DIO' your ROM is reporting board_build.flash_mode = dio board_build.arduino.memory_type = dio_opi build_flags = -DBOARD_HAS_PSRAM - ; FIX 1: Forces all Serial.print logs to stay on the hardware UART port -DARDUINO_USB_CDC_ON_BOOT=0 -DDEV_UNIT -DDEBUG @@ -44,20 +40,17 @@ platform = espressif32 board = esp32-s3-devkitc-1 framework = arduino -; Flash and PSRAM settings for 4MB Flash / 2MB PSRAM (Quad SPI) board_upload.flash_size = 4MB board_build.arduino.memory_type = qio_qspi board_build.flash_mode = qio board_build.psram_type = qio -; Required flag to enable PSRAM in code build_flags = -DBOARD_HAS_PSRAM -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MODE=1 -DDEV_UNIT -; Ensure partition table fits 4MB board_build.partitions = default.csv lib_deps = TFT_eSPI, fbiego/ESP32Time@^2.0.6, electroniccats/MPU6050@^1.4.3 upload_port = COM5 diff --git a/src/defs/background_data.h b/src/defs/background_data.h index 680af62..9367af4 100644 --- a/src/defs/background_data.h +++ b/src/defs/background_data.h @@ -3,6 +3,8 @@ #include +extern int currentBackground; + struct BackgroundData { uint8_t backgroundWidth; uint8_t backgroundHeight; diff --git a/src/main.cpp b/src/main.cpp index 604a8aa..c9990d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,6 +61,9 @@ uint32_t dayUnixTime = 0; Egg_t* eggSelection = NULL; uint8_t eggNumber = 0; +// Background stuff +int currentBackground = 0; + // Tasks TaskHandle_t secondLoop = NULL; @@ -92,7 +95,7 @@ void setup() { storage_readFile("/menu.bin", &menuElementsData); storage_readFile("/ui.bin", &uiElementsData); - storage_initBackground("/bg2.bin", bg); + storage_initBackground(currentBackground, bg); pinMode(K1_PIN, BUTTON_MODE); pinMode(K2_PIN, BUTTON_MODE); diff --git a/src/menu/change_background_screen.cpp b/src/menu/change_background_screen.cpp new file mode 100644 index 0000000..5e5a4c9 --- /dev/null +++ b/src/menu/change_background_screen.cpp @@ -0,0 +1,77 @@ +#include "menu.h" +#include "defs/sprite_data.h" +#include "buttons/buttons.h" +#include "draw/draw.h" +#include "storage/storage.h" +#include "display/display.h" +#include "defs/screen_defs.h" + +void menu_changeBackgroundScreen( + TFT_eSprite &bg, TFT_eSprite &sprite, struct SpriteData* uiSpriteData +) { + int8_t selectedBackground = currentBackground; + + fs::File bgFolder = SPIFFS.open("/bg"); + fs::File background = bgFolder.openNextFile(); + + uint8_t backgrounds = 0; + + uint64_t currentTime = esp_timer_get_time(); + + int8_t selectedPreviousBackground = 0; + + while (background) { + if (!background.isDirectory()) { + backgrounds++; + } + + background = background.openNextFile(); + } + + for (;;) { + uint8_t buttonsPressed = buttons_getPressedButtons(); + currentTime = esp_timer_get_time(); + + switch (buttonsPressed) { + case K1_PRESSED: + selectedBackground++; + if (selectedBackground > backgrounds) { + selectedBackground = 0; + } + storage_initBackground(selectedBackground, bg); + lastUpdateTime = currentTime; + break; + + case K2_PRESSED: + selectedBackground--; + if (selectedBackground < 0) { + selectedBackground = backgrounds - 1; + } + storage_initBackground(selectedBackground, bg); + lastUpdateTime = currentTime; + break; + + case K3_PRESSED: + currentBackground = selectedBackground; + lastUpdateTime = currentTime; + return; + + case K4_PRESSED: + storage_initBackground(currentBackground, bg); + lastUpdateTime = currentTime; + return; + } + + if (selectedPreviousBackground != selectedBackground) { + draw_drawBackground(bg, 90, 90, 3); + draw_drawSprite(sprite, 174, 96, uiSpriteData, ARROW_ICON); + tft_drawBuffer(); + } + + if (currentTime - lastUpdateTime > INACTIVITY_THRESHOLD_TIME_US) { + storage_initBackground(currentBackground, bg); + return; + } + } + +} \ No newline at end of file diff --git a/src/menu/menu.h b/src/menu/menu.h index fdf1194..bba3cec 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -53,11 +53,13 @@ void menu_drawAngryScreen( struct SpriteData* spriteData, struct SpriteData* smallUiElements ); void menu_drawFridgeScreen(TFT_eSprite &bg, TFT_eSprite& sprite, struct SpriteData* smallUiElements, struct SpriteData* bigUiElements); - void training_screenTraining2( TFT_eSprite &bg, TFT_eSprite &sprite, struct SpriteData* mainCharaData, struct SpriteData* attackSprites ); +void menu_changeBackgroundScreen( + TFT_eSprite &bg, TFT_eSprite &sprite, struct SpriteData* uiSpriteData +); void menu_sleepScreen_sleepAction(); void menu_sleepScreen_recalculateSleep(); diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index 745685c..fb92a9d 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -17,7 +17,11 @@ void storage_init() { } -void storage_initBackground(const char* path, TFT_eSprite& bg) { +void storage_initBackground(const int id, TFT_eSprite& bg) { + char path[15]; + + snprintf(path, 15, "/bg/%i.bin", id); + File file = SPIFFS.open(path, "r"); if (!file) { printf("%s Failed to open file for reading\n", TAG_S); diff --git a/src/storage/storage.h b/src/storage/storage.h index 7c73ce6..7573d71 100644 --- a/src/storage/storage.h +++ b/src/storage/storage.h @@ -9,7 +9,7 @@ void storage_init(); void storage_readFile(const char* path, struct SpriteData* spriteData); -void storage_initBackground(const char* path, TFT_eSprite &bg); +void storage_initBackground(const int id, TFT_eSprite &bg); void storage_saveState(); void storage_loadState();