-
Notifications
You must be signed in to change notification settings - Fork 20
feat: Add capacitive touch controls for Tidbyt Gen 2 #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,9 @@ | |
| #include "sdkconfig.h" | ||
| #include "sntp.h" | ||
| #include "syslog.h" | ||
| #ifdef CONFIG_BOARD_TIDBYT_GEN2 | ||
| #include "touch_control.h" | ||
| #endif | ||
| #include "version.h" | ||
| #include "wifi.h" | ||
|
|
||
|
|
@@ -54,6 +57,13 @@ static bool button_boot = false; | |
| static bool first_ws_image_received = false; | ||
| static bool config_received = false; | ||
|
|
||
| #ifdef CONFIG_BOARD_TIDBYT_GEN2 | ||
| // Touch control state | ||
| static bool display_power_on = true; | ||
| static uint8_t saved_brightness = 30; | ||
| static void handle_touch_event(touch_event_t event); | ||
| #endif | ||
|
|
||
| static void config_saved_callback(void) { | ||
| config_received = true; | ||
| ESP_LOGI(TAG, "Configuration saved - signaling main task"); | ||
|
|
@@ -201,6 +211,11 @@ static void websocket_event_handler(void* handler_args, esp_event_base_t base, | |
| brightness_value = DISPLAY_MAX_BRIGHTNESS; | ||
| display_set_brightness((uint8_t)brightness_value); | ||
| ESP_LOGI(TAG, "Updated brightness to %d", brightness_value); | ||
| #ifdef CONFIG_BOARD_TIDBYT_GEN2 | ||
| // Sync touch control state - server brightness command means display is on | ||
| display_power_on = true; | ||
| saved_brightness = (uint8_t)brightness_value; | ||
| #endif | ||
| } | ||
|
|
||
| // Check for "ota_url" | ||
|
|
@@ -496,6 +511,19 @@ void app_main(void) { | |
| } | ||
| esp_register_shutdown_handler(&display_shutdown); | ||
|
|
||
| #ifdef CONFIG_BOARD_TIDBYT_GEN2 | ||
| // Initialize touch controls (GPIO33 on Tidbyt Gen2) | ||
| ESP_LOGI(TAG, "Initializing touch control..."); | ||
| esp_err_t touch_ret = touch_control_init(); | ||
| if (touch_ret == ESP_OK) { | ||
| ESP_LOGI(TAG, "Touch control ready on GPIO33"); | ||
| touch_control_debug_all_pads(); | ||
| } else { | ||
| ESP_LOGW(TAG, "Touch control init failed: %s (continuing without touch)", | ||
| esp_err_to_name(touch_ret)); | ||
| } | ||
| #endif | ||
|
|
||
| // Start the AP web server now that display memory is allocated | ||
| if (nvs_get_ap_mode()) { | ||
| ESP_LOGI(TAG, "Starting AP Web Server..."); | ||
|
|
@@ -692,7 +720,20 @@ void app_main(void) { | |
| } | ||
|
|
||
| wifi_health_check(); | ||
| vTaskDelay(pdMS_TO_TICKS(5000)); // check every 5s | ||
|
|
||
| #ifdef CONFIG_BOARD_TIDBYT_GEN2 | ||
| // Poll touch frequently for 5 seconds (50ms intervals = 100 checks) | ||
| // This allows proper gesture detection while keeping health checks at 5s | ||
| for (int i = 0; i < 100; i++) { | ||
| touch_event_t touch_event = touch_control_check(); | ||
| if (touch_event != TOUCH_EVENT_NONE) { | ||
| handle_touch_event(touch_event); | ||
| } | ||
| vTaskDelay(pdMS_TO_TICKS(50)); // 50ms = responsive touch | ||
| } | ||
| #else | ||
| vTaskDelay(pdMS_TO_TICKS(5000)); // 5 second health check interval | ||
| #endif | ||
| } | ||
| } else { | ||
| // normal http | ||
|
|
@@ -778,7 +819,62 @@ void app_main(void) { | |
| isAnimating = 1; | ||
| } | ||
| } | ||
|
|
||
| #ifdef CONFIG_BOARD_TIDBYT_GEN2 | ||
| // Check for touch events | ||
| touch_event_t touch_event = touch_control_check(); | ||
| if (touch_event != TOUCH_EVENT_NONE) { | ||
| handle_touch_event(touch_event); | ||
| } | ||
|
Comment on lines
+824
to
+828
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation only checks for touch events once per image cycle in the HTTP loop. This will lead to an unresponsive UI, as the loop can be blocked for |
||
| #endif | ||
|
|
||
| wifi_health_check(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #ifdef CONFIG_BOARD_TIDBYT_GEN2 | ||
| /** | ||
| * Handle touch events from the single touch pad | ||
| * TAP = skip to next app | ||
| * DOUBLE_TAP = (reserved for future use) | ||
| * HOLD = toggle display power on/off | ||
| */ | ||
| static void handle_touch_event(touch_event_t event) { | ||
| ESP_LOGI(TAG, "Touch event: %s", touch_event_to_string(event)); | ||
|
|
||
| switch (event) { | ||
| case TOUCH_EVENT_TAP: | ||
| if (display_power_on) { | ||
| ESP_LOGI(TAG, "TAP - skip to next app"); | ||
| isAnimating = -1; | ||
| } else { | ||
| ESP_LOGI(TAG, "TAP ignored - display is off (hold to turn on)"); | ||
| } | ||
| break; | ||
|
|
||
| case TOUCH_EVENT_DOUBLE_TAP: | ||
| // Reserved for future use | ||
| ESP_LOGI(TAG, "DOUBLE TAP - no action assigned"); | ||
| break; | ||
|
|
||
| case TOUCH_EVENT_HOLD: | ||
| display_power_on = !display_power_on; | ||
|
|
||
| if (display_power_on) { | ||
| ESP_LOGI(TAG, "HOLD - Display ON"); | ||
| display_set_brightness(saved_brightness); | ||
| isAnimating = 1; | ||
| } else { | ||
| ESP_LOGI(TAG, "HOLD - Display OFF"); | ||
| saved_brightness = 30; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When turning the display off, the current brightness level is not saved. Instead, |
||
| display_set_brightness(0); | ||
| isAnimating = 0; | ||
| } | ||
| break; | ||
|
|
||
| default: | ||
| break; | ||
| } | ||
| } | ||
| #endif | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number
30is used to initializesaved_brightness. To improve maintainability and consistency, please use theDISPLAY_DEFAULT_BRIGHTNESSconstant, which is defined indisplay.hand already included.