/** * @file main.c * @brief Application entry point for iroBot display system * * This is the main entry point for the iroBot display firmware. * It initializes all subsystems in the proper order and starts * the main application loop. * * Architecture Overview: * - drivers/: Hardware abstraction (display, touch) * - sensors/: Motion detection (shake detector) * - ui/: Visual components (splash screen, lottie player) * - emotion-engine/: Emotion management and animations * * Startup Sequence: * 1. Initialize display driver (I2C, SPI, LCD, LVGL) * 2. Initialize touch driver * 3. Initialize shake detector sensor * 4. Show splash screen * 5. Initialize and start emotion engine */ #include "drivers/display_driver.h" #include "drivers/touch_driver.h" #include "emotion-engine/emotion_manager.h" #include "sensors/shake_detector.h" #include "ui/splash_screen.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" static const char *TAG = "main"; // ---------------------------------------------------------------------------- // Shake Detection Task // Polls the accelerometer for shake events and triggers emotions. // ---------------------------------------------------------------------------- static void shakeTask(void *arg) { ESP_LOGI(TAG, "Shake detection task started"); while (1) { ShakeEvent event = shakeDetectorUpdate(); if (event != SHAKE_NONE) { // Map shake events to emotions EmotionType emotion = EMOTION_IDLE; switch (event) { case SHAKE_SURPRISED: emotion = EMOTION_SURPRISED; break; case SHAKE_SAD: emotion = EMOTION_SAD; break; case SHAKE_ANGRY: emotion = EMOTION_ANGRY; break; default: break; } if (emotion != EMOTION_IDLE) { // Acquire LVGL lock before modifying emotions if (displayDriverLock(100)) { emotionManagerSetEmotion(emotion); displayDriverUnlock(); } } } // Poll at 20Hz for responsive shake detection vTaskDelay(pdMS_TO_TICKS(50)); } } // ---------------------------------------------------------------------------- // Application Entry Point // ---------------------------------------------------------------------------- void app_main(void) { ESP_LOGI(TAG, "Starting iroBot Display System"); // Initialize display subsystem (I2C, SPI, LCD, LVGL) if (!displayDriverInit()) { ESP_LOGE(TAG, "Display initialization failed"); return; } // Initialize touch controller if (!touchDriverInit()) { ESP_LOGW(TAG, "Touch initialization failed (continuing)"); } // Initialize shake detector if (!shakeDetectorInit()) { ESP_LOGW(TAG, "Shake detector initialization failed (continuing)"); } // Show splash screen (blocks for SPLASH_SCREEN_DURATION_MS) if (displayDriverLock(-1)) { ESP_LOGI(TAG, "Showing splash screen"); splashScreenShow(); displayDriverUnlock(); } // Initialize emotion engine if (!emotionManagerInit()) { ESP_LOGE(TAG, "Emotion manager initialization failed"); return; } // Start emotion engine (begins idle animation with natural blink) if (displayDriverLock(-1)) { ESP_LOGI(TAG, "Starting emotion engine"); emotionManagerStart(); displayDriverUnlock(); } // Start shake detection task xTaskCreate(shakeTask, "shake_task", 4096, NULL, 5, NULL); ESP_LOGI(TAG, "iroBot Display System initialized successfully"); }