gui-framework
Ondřej Hruška 5 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);
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<pos; i++) {
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() {
printf("Knob init\n");
gpio_config_t output = {
.pin_bit_mask = (1<<pushPin) | (1 << wheelPin1) | (1 << wheelPin2),
gpio_config_t cfgWheel = {
.pin_bit_mask = (1 << wheelPin1) | (1 << wheelPin2),
.mode = GPIO_MODE_INPUT,
.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_intr_enable(pushPin);
@ -96,6 +104,66 @@ const uint8_t switch_table[28] = {
};
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 uint8_t ab =
(((inputs >> 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();
}
}

Loading…
Cancel
Save