update: fixed shake animation

The shake animation figures have been fixed. However, the petting emotion working with touch remains an issue. The Lottie JSON for the emotion is unable not parsable for some reason and my next step is to fix that for tomorrow's meeting.
This commit is contained in:
2026-01-27 00:30:12 +05:30
parent 90031cd16e
commit 22bd5a6f70
13 changed files with 814 additions and 5 deletions

View File

@@ -25,7 +25,9 @@
#include "drivers/touch_driver.h"
#include "emotion-engine/emotion_manager.h"
#include "emotion-engine/shake/shake_emotion.h"
#include "emotion-engine/shy/shy_emotion.h"
#include "sensors/shake_detector.h"
#include "sensors/glide_detector.h"
#include "ui/calibration_screen.h"
#include "ui/loading_anim.h"
#include "ui/splash_screen.h"
@@ -37,6 +39,106 @@
static const char *TAG = "main";
// Track touch initialization status
static bool touchInitialized = false;
// ----------------------------------------------------------------------------
// Glide Detection Callback
// Triggers shy emotion when a glide gesture is detected.
// Only triggers if currently in idle state for calm, subtle interactions.
// ----------------------------------------------------------------------------
static void onGlideDetected(const GlideEvent *event, void *user_data) {
(void)event; // Unused parameter
(void)user_data; // Unused parameter
// Only trigger shy emotion if currently in idle state
if (emotionManagerGetCurrent() == EMOTION_IDLE) {
ESP_LOGI(TAG, "Glide gesture detected, triggering shy emotion");
if (displayDriverLock(500)) {
emotionManagerSetEmotion(EMOTION_SHY);
displayDriverUnlock();
} else {
ESP_LOGW(TAG, "Failed to acquire lock for SHY emotion");
}
}
}
// ----------------------------------------------------------------------------
// Glide Detection Task
// Polls the touch controller for glide gestures and triggers shy emotion.
// Only triggers shy emotion when currently in idle state.
// ----------------------------------------------------------------------------
static void glideTask(void *arg) {
ESP_LOGI(TAG, "Glide detection task started");
// Check if touch was initialized successfully
if (!touchInitialized) {
ESP_LOGW(TAG, "Touch controller not initialized, glide detection disabled");
vTaskDelete(NULL);
return;
}
esp_lcd_touch_handle_t touchHandle = touchDriverGetHandle();
if (touchHandle == NULL) {
ESP_LOGE(TAG, "Touch handle is NULL even though initialization succeeded, disabling glide detection");
vTaskDelete(NULL);
return;
}
ESP_LOGI(TAG, "Glide detection task running with touch handle %p", (void*)touchHandle);
while (1) {
uint16_t x, y;
uint8_t count = 0;
// Read touch data from controller
esp_lcd_touch_read_data(touchHandle);
bool pressed = esp_lcd_touch_get_coordinates(touchHandle, &x, &y, NULL, &count, 1);
// Feed touch events to glide detector
glideDetectorUpdate(x, y, pressed && count > 0);
// Poll at 60Hz for responsive touch detection
vTaskDelay(pdMS_TO_TICKS(16));
}
}
// ----------------------------------------------------------------------------
// Shy Emotion Task
// Monitors shy emotion state and transitions back to idle when complete.
// The shy emotion is a one-shot animation that plays once then returns to idle.
// ----------------------------------------------------------------------------
static void shyTask(void *arg) {
ESP_LOGI(TAG, "Shy emotion task started");
while (1) {
// Check if shy emotion is currently playing
if (shyEmotionIsPlaying()) {
// Update shy emotion state
bool animationComplete = false;
if (displayDriverLock(100)) {
animationComplete = shyEmotionUpdate();
displayDriverUnlock();
}
// Transition back to idle when animation completes
if (animationComplete) {
ESP_LOGI(TAG, "Shy animation complete, returning to idle");
if (displayDriverLock(500)) {
emotionManagerSetEmotion(EMOTION_IDLE);
displayDriverUnlock();
}
}
}
// Poll at 20Hz for emotion state updates
vTaskDelay(pdMS_TO_TICKS(50));
}
}
// ----------------------------------------------------------------------------
// Shake Detection Task
// Polls the accelerometer for shake events and triggers emotions.
@@ -138,6 +240,10 @@ static void ui_entry_task(void *arg) {
// Initialize touch controller
if (!touchDriverInit()) {
ESP_LOGW(TAG, "Touch initialization failed (continuing)");
touchInitialized = false;
} else {
touchInitialized = true;
ESP_LOGI(TAG, "Touch controller initialized successfully");
}
// Initialize shake detector
@@ -145,6 +251,14 @@ static void ui_entry_task(void *arg) {
ESP_LOGW(TAG, "Shake detector initialization failed (continuing)");
}
// Initialize glide detector
if (!glideDetectorInit()) {
ESP_LOGW(TAG, "Glide detector initialization failed (continuing)");
} else {
// Register callback to trigger shy emotion on glide detection
glideDetectorRegisterCallback(onGlideDetected, NULL);
}
// Initialize NVS (Critical for first boot check)
nvsDriverInit();
@@ -210,6 +324,18 @@ static void ui_entry_task(void *arg) {
// Start shake detection task
xTaskCreate(shakeTask, "shake_task", 4096, NULL, 5, NULL);
// Start glide detection task only if touch controller is initialized
if (touchInitialized) {
xTaskCreate(glideTask, "glide_task", 4096, NULL, 5, NULL);
} else {
ESP_LOGW(TAG, "Skipping glide detection task - touch controller not initialized");
}
// Start shy emotion task
// Use 8KB stack (same as ui_entry_task) to handle complex shy animation
// Shy emotion has large JSON (~3KB) and 300 frames requiring more stack
xTaskCreate(shyTask, "shy_task", 8192, NULL, 5, NULL);
ESP_LOGI(TAG, "iroBot Display System initialized successfully");
vTaskDelete(NULL);
}