Files
t-embed-insecam-widget/main/input.c
T
Juli 65a391940b insecam desk widget for the LilyGO T-Embed
ESP-IDF 5.5 + LVGL 9 firmware that plays random public cameras from
insecam.org on the T-Embed's 320x170 screen, live MJPEG where available,
a new camera every 20 seconds. Knob steps through cameras, LED ring shows
the countdown. Auto-detects the original vs CC1101 board, reuses Wi-Fi
credentials from NVS and falls back to a captive-portal setup hotspot.
2026-09-17 00:38:09 +02:00

59 lines
2.1 KiB
C

#include "input.h"
#include "board.h"
#include "iot_knob.h"
#include "iot_button.h"
#include "button_gpio.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
static const char *TAG = "input";
static QueueHandle_t queue;
static void post(input_event_t ev)
{
xQueueSend(queue, &ev, 0);
}
static void knob_cb(void *arg, void *data) { post((input_event_t)(intptr_t)data); }
static void button_cb(void *arg, void *data) { post((input_event_t)(intptr_t)data); }
void input_init(void)
{
queue = xQueueCreate(8, sizeof(input_event_t));
knob_config_t kcfg = {.default_direction = 0, .gpio_encoder_a = board->enc_a, .gpio_encoder_b = board->enc_b};
knob_handle_t knob = iot_knob_create(&kcfg);
if (!knob) { ESP_LOGE(TAG, "knob init failed"); return; }
iot_knob_register_cb(knob, KNOB_RIGHT, knob_cb, (void *)INPUT_CW);
iot_knob_register_cb(knob, KNOB_LEFT, knob_cb, (void *)INPUT_CCW);
button_config_t bcfg = {.long_press_time = 800, .short_press_time = 180};
button_gpio_config_t gcfg = {.gpio_num = board->enc_btn, .active_level = 0};
button_handle_t btn = NULL;
ESP_ERROR_CHECK(iot_button_new_gpio_device(&bcfg, &gcfg, &btn));
iot_button_register_cb(btn, BUTTON_SINGLE_CLICK, NULL, button_cb, (void *)INPUT_CLICK);
iot_button_register_cb(btn, BUTTON_DOUBLE_CLICK, NULL, button_cb, (void *)INPUT_DOUBLE);
iot_button_register_cb(btn, BUTTON_LONG_PRESS_START, NULL, button_cb, (void *)INPUT_LONG);
if (board->user_key >= 0) {
button_gpio_config_t ucfg = {.gpio_num = board->user_key, .active_level = 0};
button_handle_t ukey = NULL;
if (iot_button_new_gpio_device(&bcfg, &ucfg, &ukey) == ESP_OK)
iot_button_register_cb(ukey, BUTTON_SINGLE_CLICK, NULL, button_cb, (void *)INPUT_KEY);
}
ESP_LOGI(TAG, "encoder A%d/B%d, button GPIO%d", board->enc_a, board->enc_b, board->enc_btn);
}
input_event_t input_poll(void)
{
input_event_t ev;
return xQueueReceive(queue, &ev, 0) == pdTRUE ? ev : INPUT_NONE;
}
input_event_t input_wait(int timeout_ms)
{
input_event_t ev;
return xQueueReceive(queue, &ev, pdMS_TO_TICKS(timeout_ms)) == pdTRUE ? ev : INPUT_NONE;
}