#include #include #include "nokia.h" #include "liquid.h" #include "drawing.h" static void gui_thread(void *arg); TaskHandle_t hGuiThread = NULL; void gui_init() { printf("GUI init\n"); LCD_setup(); LCD_setContrast(57); int rv = xTaskCreate(gui_thread, "gui", 4096, NULL, 6, &hGuiThread); assert (rv == pdPASS); } /** * Notification API: * * 0b1 - knob CW * 0b10 - knowb CCW * 0b100 - button released * 0b1000 - button pressed * * @param arg */ static void __attribute__((noreturn)) gui_thread(void *arg) { struct Liquid *liquid = Liquid_start(); uint32_t last_wheel_time = 0; uint32_t last_time = xTaskGetTickCount(); while (1) { bool want_repaint = false; uint32_t value = 0; xTaskNotifyWait(0, ULONG_MAX, &value, pdMS_TO_TICKS(10)); uint32_t time = xTaskGetTickCount(); if (time - last_time >= pdMS_TO_TICKS(2)) { want_repaint |= Liquid_handleTick(liquid, time - last_time); last_time = time; } if (value & 0b1000) { want_repaint |= Liquid_handleInput(liquid, InputEvent_Button(1)); } else if (value & 0b100) { want_repaint |= Liquid_handleInput(liquid, InputEvent_Button(0)); } if (value & 0b11) { uint32_t increment = 1; // wheel delta changes with speed if (last_wheel_time != 0) { uint32_t ela = time - last_wheel_time; if (ela < pdMS_TO_TICKS(20)) { increment = 25; } else if (ela < pdMS_TO_TICKS(35)) { increment = 10; } else if (ela < pdMS_TO_TICKS(75)) { increment = 5; } } last_wheel_time = time; if (value & 0b01) { want_repaint |= Liquid_handleInput(liquid, InputEvent_Wheel(increment)); } if (value & 0b10) { want_repaint |= Liquid_handleInput(liquid, InputEvent_Wheel(-increment)); } } if (want_repaint) { Liquid_paint(liquid); } } }