gui-framework
Ondřej Hruška 4 years ago
parent 0353b96303
commit 10a2779ec2
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 50
      main/gui.c
  2. 98
      main/knob.c

@ -27,33 +27,37 @@ static void __attribute__((noreturn)) gui_thread(void *arg) {
xTaskNotifyWait(0, ULONG_MAX, &value, portMAX_DELAY); xTaskNotifyWait(0, ULONG_MAX, &value, portMAX_DELAY);
printf("Knob event 0x%02x ", value); printf("Knob event 0x%02x ", value);
switch (value) { if (value & 0b1000) {
case 0b100: printf("PUSH ");
printf("PUSH |"); }
break; if (value & 0b100) {
printf("RELS ");
case 0b010: }
printf("BACK |"); if (value & 0b01) {
if (pos == 0) { printf("FWD ");
pos = NMAX; if (pos == NMAX) {
} else { pos = 0;
pos--; } else {
} pos += 1;
break; }
}
case 0b001: if (value & 0b10) {
printf("FWD |"); printf("BACK ");
if (pos == NMAX) { if (pos == 0) {
pos = 0; pos = NMAX;
} else { } else {
pos += 1; pos--;
} }
break;
} }
printf(">");
for (int i=0; i<pos; i++) { for (int i=0; i<pos; i++) {
printf(" "); printf(" ");
} }
printf("#\n"); printf("#");
for (int i=pos; i<NMAX; i++) {
printf(" ");
}
printf("<\n");
} }
} }

@ -14,13 +14,21 @@ static void handle_wheel(void *arg);
void knob_init() { void knob_init() {
printf("Knob init\n"); printf("Knob init\n");
gpio_config_t output = { gpio_config_t cfgWheel = {
.pin_bit_mask = (1<<pushPin) | (1 << wheelPin1) | (1 << wheelPin2), .pin_bit_mask = (1 << wheelPin1) | (1 << wheelPin2),
.mode = GPIO_MODE_INPUT, .mode = GPIO_MODE_INPUT,
.pull_up_en = 1, .pull_up_en = 1,
.intr_type = GPIO_INTR_ANYEDGE, .intr_type = GPIO_INTR_NEGEDGE, // neg means active
}; };
gpio_config(&output); gpio_config(&cfgWheel);
gpio_config_t cfgPush = {
.pin_bit_mask = (1 << pushPin),
.mode = GPIO_MODE_INPUT,
.pull_up_en = 1,
.intr_type = GPIO_INTR_ANYEDGE, // neg means active
};
gpio_config(&cfgPush);
gpio_install_isr_service(0); gpio_install_isr_service(0);
gpio_intr_enable(pushPin); gpio_intr_enable(pushPin);
@ -96,6 +104,66 @@ const uint8_t switch_table[28] = {
}; };
static void handle_wheel(void *arg) { static void handle_wheel(void *arg) {
int dir = 0;
#if 0
// Omron version
int which = (int)arg;
const uint32_t inputs = gpio_input_get();
bool a = 0 == (inputs & (1 << wheelPin1)); // neg = active
bool b = 0 == (inputs & (1 << wheelPin2));
if (which == 0) { // itr from A
if (a) {
if (b) {
dir = -1;
}
else {
dir = 1;
}
}
}
else { // itr from B
if (b) {
if (a) {
dir = 1;
}
else {
dir = -1;
}
}
}
#endif
#if 0
// Naive version
int which = arg;
const uint32_t inputs = gpio_input_get();
bool a = 0 == (inputs & (1 << wheelPin1)); // neg = active
bool b = 0 == (inputs & (1 << wheelPin2));
if (which == 0) { // itr from A
if (b) {
dir = -1;
} else {
dir = 1;
}
}
else { // itr from B
if (a) {
dir = 1;
} else {
dir = -1;
}
}
#endif
#if 1
// More complex version
const uint32_t inputs = gpio_input_get(); const uint32_t inputs = gpio_input_get();
const uint8_t ab = const uint8_t ab =
(((inputs >> wheelPin2) & 1) << 1) | (((inputs >> wheelPin2) & 1) << 1) |
@ -109,15 +177,16 @@ static void handle_wheel(void *arg) {
uint8_t next = switch_table[wheelState*4 + ab]; uint8_t next = switch_table[wheelState*4 + ab];
const bool forward = next & SW_FWD; if (next & SW_FWD) dir = 1;
const bool backward = next & SW_BCK; if (next & SW_BCK) dir = -1;
next &= ~(SW_FWD | SW_BCK); next &= ~(SW_FWD | SW_BCK);
wheelState = next; wheelState = next;
#endif
if (forward || backward) { if (dir != 0) {
BaseType_t higherWoken = 0; BaseType_t higherWoken = 0;
xTaskNotifyFromISR(hGuiThread, forward | (backward << 1), eSetValueWithOverwrite, &higherWoken); xTaskNotifyFromISR(hGuiThread, dir == 1 ? 0b10 : 0b01, eSetBits, &higherWoken);
if (higherWoken) { if (higherWoken) {
portYIELD_FROM_ISR(); portYIELD_FROM_ISR();
} }
@ -126,11 +195,12 @@ static void handle_wheel(void *arg) {
static void handle_pushbtn(void *arg) { static void handle_pushbtn(void *arg) {
const uint32_t inputs = gpio_input_get(); const uint32_t inputs = gpio_input_get();
if ((inputs & (1 << pushPin)) == 0) { BaseType_t higherWoken = 0;
BaseType_t higherWoken = 0;
xTaskNotifyFromISR(hGuiThread, 0b100, eSetValueWithOverwrite, &higherWoken); bool pushed = (inputs & (1 << pushPin)) == 0;
if (higherWoken) { xTaskNotifyFromISR(hGuiThread, pushed ? 0b1000 : 0b0100, eSetBits, &higherWoken);
portYIELD_FROM_ISR();
} if (higherWoken) {
portYIELD_FROM_ISR();
} }
} }

Loading…
Cancel
Save