experiments with knob

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

@ -30,23 +30,30 @@ static void __attribute__((noreturn)) gui_thread(void *arg) {
if (value & 0b1000) { if (value & 0b1000) {
printf("PUSH "); printf("PUSH ");
} }
if (value & 0b100) { if (value & 0b100) {
printf("RELS "); printf("RELS ");
} }
if (value & 0b01) {
printf("FWD "); if ((value & 0b11) == 0b11) {
if (pos == NMAX) { printf("BNCE ");
pos = 0; } else {
} else { if (value & 0b01) {
pos += 1; printf("FWD ");
if (pos == NMAX) {
pos = 0;
}
else {
pos += 1;
}
} }
} if (value & 0b10) {
if (value & 0b10) { printf("BACK ");
printf("BACK "); if (pos == 0) {
if (pos == 0) { pos = NMAX;
pos = NMAX; }
} else { else {
pos--; pos--;
}
} }
} }

@ -69,7 +69,7 @@ const uint8_t switch_table[28] = {
/* -- S_FWD_1_01 -- */ /* -- S_FWD_1_01 -- */
S_FWD_2_00, /* 00 ADVANCE */ S_FWD_2_00, /* 00 ADVANCE */
S_FWD_1_01, /* 01 */ S_FWD_1_01, /* 01 */
S_ILLEGAL, /* 10 ILLEGAL */ S_FWD_3_10, /* 10 ILLEGAL */
S_11, /* 11 ABORT */ S_11, /* 11 ABORT */
/* -- S_FWD_2_00 -- */ /* -- S_FWD_2_00 -- */
@ -80,13 +80,13 @@ const uint8_t switch_table[28] = {
/* -- S_FWD_3_10 -- */ /* -- S_FWD_3_10 -- */
S_FWD_2_00, /* 00 ABORT */ S_FWD_2_00, /* 00 ABORT */
S_ILLEGAL, /* 01 ILLEGAL */ S_FWD_1_01, /* 01 ILLEGAL */
S_FWD_3_10, /* 10 */ S_FWD_3_10, /* 10 */
SW_FWD | S_11, /* 11 ADVANCE */ SW_FWD | S_11, /* 11 ADVANCE */
/* -- S_BCK_1_10 -- */ /* -- S_BCK_1_10 -- */
S_BCK_2_00, /* 00 ADVANCE */ S_BCK_2_00, /* 00 ADVANCE */
S_ILLEGAL, /* 01 ILLEGAL */ S_BCK_3_01, /* 01 ILLEGAL */
S_BCK_1_10, /* 10 */ S_BCK_1_10, /* 10 */
S_11, /* 11 ABORT */ S_11, /* 11 ABORT */
@ -99,14 +99,59 @@ const uint8_t switch_table[28] = {
/* -- S_BCK_3_01 -- */ /* -- S_BCK_3_01 -- */
S_BCK_2_00, /* 00 */ S_BCK_2_00, /* 00 */
S_BCK_3_01, /* 01 */ S_BCK_3_01, /* 01 */
S_ILLEGAL, /* 10 */ S_BCK_1_10, /* 10 */
SW_BCK | S_11, /* 11 */ SW_BCK | S_11, /* 11 */
}; };
static uint8_t OldEnc = 0b00;
static void handle_wheel(void *arg) { static void handle_wheel(void *arg) {
int dir = 0; int dir = 0;
#if 0 #if 0
const uint32_t inputs = gpio_input_get();
bool a = 0 == (inputs & (1 << wheelPin1)); // neg = active
bool b = 0 == (inputs & (1 << wheelPin2));
#define ENCODER_POS1 1
#define ENCODER_POS2 2
#define ENCODER_POS3 3
#define ENCODER_POS0 0
uint8_t NewEnc = a | (b<<1);
if (NewEnc ^ OldEnc) { // Encoder value changed???
switch(NewEnc) {
case ENCODER_POS1 : // 01
if (OldEnc == ENCODER_POS0) // 00
dir--;
else
dir++;
break;
case ENCODER_POS3 : // 11
if (OldEnc == ENCODER_POS1) // 01
dir--;
else
dir++;
break;
case ENCODER_POS2 : // 10
if (OldEnc == ENCODER_POS3) // 11
dir--;
else
dir++;
break;
case ENCODER_POS0 : // 00
if (OldEnc == ENCODER_POS2) // 10
dir--;
else
dir++;
break;
};
OldEnc = NewEnc;
}; // end if encoder value changed.
#endif
#if 1
// Omron version // Omron version
int which = (int)arg; int which = (int)arg;
@ -149,20 +194,20 @@ static void handle_wheel(void *arg) {
if (which == 0) { // itr from A if (which == 0) { // itr from A
if (b) { if (b) {
dir = -1; dir = -1;
} else { } /*else {
dir = 1; dir = 1;
} }*/
} }
else { // itr from B else { // itr from B
if (a) { if (a) {
dir = 1; dir = 1;
} else { } /*else {
dir = -1; dir = -1;
} }*/
} }
#endif #endif
#if 1 #if 0
// More complex version // 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 =

Loading…
Cancel
Save