From 10a2779ec2e2b2662441f17052673d8a3ab1e4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Fri, 3 Jan 2020 01:07:14 +0100 Subject: [PATCH] v2 and v3 --- main/gui.c | 50 ++++++++++++++------------- main/knob.c | 98 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 111 insertions(+), 37 deletions(-) diff --git a/main/gui.c b/main/gui.c index ae86fe6..af39401 100644 --- a/main/gui.c +++ b/main/gui.c @@ -27,33 +27,37 @@ static void __attribute__((noreturn)) gui_thread(void *arg) { xTaskNotifyWait(0, ULONG_MAX, &value, portMAX_DELAY); printf("Knob event 0x%02x ", value); - switch (value) { - case 0b100: - printf("PUSH |"); - break; - - case 0b010: - printf("BACK |"); - if (pos == 0) { - pos = NMAX; - } else { - pos--; - } - break; - - case 0b001: - printf("FWD |"); - if (pos == NMAX) { - pos = 0; - } else { - pos += 1; - } - break; + if (value & 0b1000) { + printf("PUSH "); + } + if (value & 0b100) { + printf("RELS "); + } + if (value & 0b01) { + printf("FWD "); + if (pos == NMAX) { + pos = 0; + } else { + pos += 1; + } + } + if (value & 0b10) { + printf("BACK "); + if (pos == 0) { + pos = NMAX; + } else { + pos--; + } } + printf(">"); for (int i=0; i> wheelPin2) & 1) << 1) | @@ -109,15 +177,16 @@ static void handle_wheel(void *arg) { uint8_t next = switch_table[wheelState*4 + ab]; - const bool forward = next & SW_FWD; - const bool backward = next & SW_BCK; + if (next & SW_FWD) dir = 1; + if (next & SW_BCK) dir = -1; next &= ~(SW_FWD | SW_BCK); wheelState = next; +#endif - if (forward || backward) { + if (dir != 0) { BaseType_t higherWoken = 0; - xTaskNotifyFromISR(hGuiThread, forward | (backward << 1), eSetValueWithOverwrite, &higherWoken); + xTaskNotifyFromISR(hGuiThread, dir == 1 ? 0b10 : 0b01, eSetBits, &higherWoken); if (higherWoken) { portYIELD_FROM_ISR(); } @@ -126,11 +195,12 @@ static void handle_wheel(void *arg) { static void handle_pushbtn(void *arg) { const uint32_t inputs = gpio_input_get(); - if ((inputs & (1 << pushPin)) == 0) { - BaseType_t higherWoken = 0; - xTaskNotifyFromISR(hGuiThread, 0b100, eSetValueWithOverwrite, &higherWoken); - if (higherWoken) { - portYIELD_FROM_ISR(); - } + BaseType_t higherWoken = 0; + + bool pushed = (inputs & (1 << pushPin)) == 0; + xTaskNotifyFromISR(hGuiThread, pushed ? 0b1000 : 0b0100, eSetBits, &higherWoken); + + if (higherWoken) { + portYIELD_FROM_ISR(); } }