Broadcast button presses to CAN
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
|
||||
#include "hx8357d.h"
|
||||
#include "main.h"
|
||||
#include "vehicle.h"
|
||||
#include <stdint.h>
|
||||
|
||||
void ui_thread_entry(ULONG _) {
|
||||
@ -16,22 +17,24 @@ void ui_thread_entry(ULONG _) {
|
||||
uint16_t button_pins[NUM_BUTTONS] = {BTN1_Pin, BTN2_Pin, BTN3_Pin,
|
||||
BTN4_Pin, BTN5_Pin, BTN6_Pin};
|
||||
GPIO_PinState button_states[NUM_BUTTONS] = {GPIO_PIN_RESET};
|
||||
uint32_t button_change_times[NUM_BUTTONS] = {HAL_GetTick()};
|
||||
uint32_t button_press_times[NUM_BUTTONS] = {HAL_GetTick()};
|
||||
|
||||
while (1) {
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
GPIO_PinState state = HAL_GPIO_ReadPin(button_ports[i], button_pins[i]);
|
||||
if (state != button_states[i]) {
|
||||
uint32_t now = HAL_GetTick();
|
||||
if (state == GPIO_PIN_RESET && now - button_change_times[i]) {
|
||||
// Button release event!
|
||||
if (state == GPIO_PIN_SET &&
|
||||
now - button_press_times[i] >= BUTTON_MIN_INTERVAL) {
|
||||
// Button press event!
|
||||
button_press_times[i] = now;
|
||||
ButtonMessage msg = {.kind = UMK_BTN_RELEASED, .number = i};
|
||||
tx_queue_send(&gui_button_queue, &msg, TX_NO_WAIT);
|
||||
}
|
||||
button_change_times[i] = now;
|
||||
button_states[i] = state;
|
||||
}
|
||||
}
|
||||
vehicle_broadcast_buttons(button_states);
|
||||
// Release so other threads can get scheduled
|
||||
tx_thread_sleep(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user