Add wires solver
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
set(SOURCES
|
||||
"TM1640/TM16xx.cpp"
|
||||
"TM1640/TM1640.cpp"
|
||||
"bottom_half.cpp"
|
||||
)
|
||||
|
||||
target_sources(${COMPONENT_LIB} PRIVATE ${SOURCES})
|
||||
@@ -17,6 +17,16 @@ static uint8_t touch_released;
|
||||
/// read buffer
|
||||
static uint8_t read_buf[8];
|
||||
|
||||
void clear_all_pressed_released(void) {
|
||||
keypad_pressed = 0;
|
||||
button_pressed = 0;
|
||||
touch_pressed = 0;
|
||||
|
||||
keypad_released = 0;
|
||||
button_released = 0;
|
||||
touch_released = 0;
|
||||
}
|
||||
|
||||
static bool _take_key(KeypadKey* kp, uint16_t* keypad_bitfield) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int bit_selector = (1 << i);
|
||||
@@ -76,6 +86,66 @@ char char_of_keypad_key(KeypadKey kp) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool _take_button(ButtonKey* button, uint16_t* button_bitfield) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int bit_selector = (1 << (i+8));
|
||||
if ((*button_bitfield) & bit_selector) {
|
||||
*button = (ButtonKey) i;
|
||||
// clear bit
|
||||
*button_bitfield &= ~bit_selector;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static bool _take_switch(SwitchKey* switch_, uint16_t* button_bitfield) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int bit_selector = (1 << i);
|
||||
if ((*button_bitfield) & bit_selector) {
|
||||
*switch_ = (SwitchKey) i;
|
||||
// clear bit
|
||||
*button_bitfield &= ~bit_selector;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_pressed_button(ButtonKey* button) {
|
||||
return _take_button(button, &button_pressed);
|
||||
}
|
||||
bool get_released_button(ButtonKey* button) {
|
||||
return _take_button(button, &button_released);
|
||||
}
|
||||
|
||||
uint8_t get_button_state() {
|
||||
return (uint8_t)((button_state >> 8) & 0xF);
|
||||
}
|
||||
|
||||
bool get_flipped_up_switch(SwitchKey* switch_) {
|
||||
return _take_switch(switch_, &button_released);
|
||||
}
|
||||
bool get_flipped_down_switch(SwitchKey* switch_) {
|
||||
return _take_switch(switch_, &button_released);
|
||||
}
|
||||
bool get_flipped_switch(SwitchKey* switch_) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int bit_selector = (1 << (i+4));
|
||||
if (button_pressed & bit_selector || button_released & bit_selector) {
|
||||
*switch_ = (SwitchKey) i;
|
||||
// clear bit
|
||||
button_pressed &= ~bit_selector;
|
||||
button_released &= ~bit_selector;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t get_switch_state(uint8_t* switch_flags) {
|
||||
return (uint8_t)(button_state && 0xF);
|
||||
}
|
||||
|
||||
static void poll_bottom_task(void *arg);
|
||||
|
||||
// static void IRAM_ATTR gpio_isr_handler(void* arg)
|
||||
@@ -144,6 +214,7 @@ static void receive_button(void) {
|
||||
read_buf[1] = 0;
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_device(BOTTOM_I2C_NUM, BOTTOM_I2C_ADDR, ®, 1, read_buf, 2, (100 / portTICK_PERIOD_MS)));
|
||||
uint16_t new_button_state = read_buf[0] | (read_buf[1] << 8);
|
||||
ESP_LOGI("jjj", "New Button State: %d", new_button_state);
|
||||
|
||||
uint16_t just_pressed = new_button_state & ~button_state;
|
||||
button_pressed |= just_pressed;
|
||||
|
||||
@@ -31,10 +31,35 @@ typedef enum {
|
||||
kd = 15,
|
||||
} KeypadKey;
|
||||
|
||||
typedef enum {
|
||||
b1 = 0,
|
||||
b2 = 1,
|
||||
b3 = 2,
|
||||
b4 = 3,
|
||||
} ButtonKey;
|
||||
|
||||
typedef enum {
|
||||
s1 = 0,
|
||||
s2 = 1,
|
||||
s3 = 2,
|
||||
s4 = 3,
|
||||
} SwitchKey;
|
||||
|
||||
void clear_all_pressed_released(void);
|
||||
|
||||
bool get_pressed_keypad(KeypadKey* kp);
|
||||
bool get_released_keypad(KeypadKey* kp);
|
||||
char char_of_keypad_key(KeypadKey kp);
|
||||
|
||||
bool get_pressed_button(ButtonKey* button);
|
||||
bool get_released_button(ButtonKey* button);
|
||||
uint8_t get_button_state();
|
||||
|
||||
bool get_flipped_up_switch(SwitchKey* switch_);
|
||||
bool get_flipped_down_switch(SwitchKey* switch_);
|
||||
bool get_flipped_switch(SwitchKey* switch_);
|
||||
uint8_t get_switch_state(uint8_t* switch_flags);
|
||||
|
||||
static void poll_bottom_task(void *arg);
|
||||
|
||||
void init_bottom_half();
|
||||
|
||||
Reference in New Issue
Block a user