|
|
|
#include "gui.h"
|
|
|
|
#include "nokia.h"
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
#include <freertos/task.h>
|
|
|
|
|
|
|
|
static void gui_thread(void *arg);
|
|
|
|
|
|
|
|
TaskHandle_t hGuiThread = NULL;
|
|
|
|
|
|
|
|
void gui_init() {
|
|
|
|
printf("GUI init\n");
|
|
|
|
LCD_setup();
|
|
|
|
|
|
|
|
LCD_setContrast(60);
|
|
|
|
|
|
|
|
LCD_clearDisplay(0);
|
|
|
|
LCD_setStr("Hello World", 0, 0, 1);
|
|
|
|
LCD_updateDisplay();
|
|
|
|
|
|
|
|
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) {
|
|
|
|
uint32_t pos = 20;
|
|
|
|
bool btn = 0;
|
|
|
|
#define NMAX 60
|
|
|
|
while (1) {
|
|
|
|
uint32_t value = 0;
|
|
|
|
xTaskNotifyWait(0, ULONG_MAX, &value, portMAX_DELAY);
|
|
|
|
// printf("Knob event 0x%02x ", value);
|
|
|
|
|
|
|
|
if (value & 0b1000) {
|
|
|
|
// printf("PUSH ");
|
|
|
|
btn = 1;
|
|
|
|
} else if (value & 0b100) {
|
|
|
|
btn = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LCD_setRect(0, 15, 83, 35, 1, 1);
|
|
|
|
char buf[10];
|
|
|
|
sprintf(buf, "%3d %s", pos, btn?"BTN":"");
|
|
|
|
LCD_setStr(buf, 2, 17, 0);
|
|
|
|
LCD_updateDisplay();
|
|
|
|
|
|
|
|
// printf(">");
|
|
|
|
// for (int i=0; i<pos; i++) {
|
|
|
|
// printf(" ");
|
|
|
|
// }
|
|
|
|
// printf("#");
|
|
|
|
// for (int i=pos; i<NMAX; i++) {
|
|
|
|
// printf(" ");
|
|
|
|
// }
|
|
|
|
// printf("<\n");
|
|
|
|
}
|
|
|
|
}
|