experiments with knob
This commit is contained in:
+9
-2
@@ -33,11 +33,16 @@ static void __attribute__((noreturn)) gui_thread(void *arg) {
|
|||||||
if (value & 0b100) {
|
if (value & 0b100) {
|
||||||
printf("RELS ");
|
printf("RELS ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((value & 0b11) == 0b11) {
|
||||||
|
printf("BNCE ");
|
||||||
|
} else {
|
||||||
if (value & 0b01) {
|
if (value & 0b01) {
|
||||||
printf("FWD ");
|
printf("FWD ");
|
||||||
if (pos == NMAX) {
|
if (pos == NMAX) {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
pos += 1;
|
pos += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,10 +50,12 @@ static void __attribute__((noreturn)) gui_thread(void *arg) {
|
|||||||
printf("BACK ");
|
printf("BACK ");
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
pos = NMAX;
|
pos = NMAX;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
pos--;
|
pos--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
printf(">");
|
printf(">");
|
||||||
for (int i=0; i<pos; i++) {
|
for (int i=0; i<pos; i++) {
|
||||||
|
|||||||
+54
-9
@@ -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 =
|
||||||
|
|||||||
Reference in New Issue
Block a user