Skip to content

Instantly share code, notes, and snippets.

@daisyUniverse
Created March 20, 2025 01:25
Show Gist options
  • Save daisyUniverse/a03c3be48fe00673c25a91f0e9754969 to your computer and use it in GitHub Desktop.
Save daisyUniverse/a03c3be48fe00673c25a91f0e9754969 to your computer and use it in GitHub Desktop.
#include <furi.h>
#include <input/input.h>
#include <furi_hal_gpio.h>
#include <furi/core/log.h>
#define GPIO_BUTTON_UP &gpio_ext_pa7
#define GPIO_BUTTON_DOWN &gpio_ext_pa6
#define GPIO_BUTTON_LEFT &gpio_ext_pa4
#define GPIO_BUTTON_RIGHT &gpio_ext_pb3
#define GPIO_BUTTON_OK &gpio_ext_pb2
#define GPIO_BUTTON_BACK &gpio_ext_pc3
static int32_t gpio_input_worker(void* context) {
UNUSED(context);
bool last_state_up = true ;
bool last_state_down = true ;
bool last_state_left = true ;
bool last_state_right = true ;
bool last_state_ok = true ;
bool last_state_back = true ;
furi_hal_gpio_init(GPIO_BUTTON_UP, GpioModeInterruptFall, GpioPullUp, GpioSpeedLow) ;
furi_hal_gpio_init(GPIO_BUTTON_DOWN, GpioModeInterruptFall, GpioPullUp, GpioSpeedLow) ;
furi_hal_gpio_init(GPIO_BUTTON_LEFT, GpioModeInterruptFall, GpioPullUp, GpioSpeedLow) ;
furi_hal_gpio_init(GPIO_BUTTON_RIGHT, GpioModeInterruptFall, GpioPullUp, GpioSpeedLow) ;
furi_hal_gpio_init(GPIO_BUTTON_OK, GpioModeInterruptFall, GpioPullUp, GpioSpeedLow) ;
furi_hal_gpio_init(GPIO_BUTTON_BACK, GpioModeInterruptFall, GpioPullUp, GpioSpeedLow) ;
while (true) {
bool state_up = furi_hal_gpio_read(GPIO_BUTTON_UP) ;
bool state_down = furi_hal_gpio_read(GPIO_BUTTON_DOWN) ;
bool state_left = furi_hal_gpio_read(GPIO_BUTTON_LEFT) ;
bool state_right = furi_hal_gpio_read(GPIO_BUTTON_RIGHT) ;
bool state_ok = furi_hal_gpio_read(GPIO_BUTTON_OK) ;
bool state_back = furi_hal_gpio_read(GPIO_BUTTON_BACK) ;
if (!state_up && last_state_up) {
FURI_LOG_E("PowerGlove", "UP");
} else if (!state_down && last_state_down) {
FURI_LOG_E("PowerGlove", "DOWN");
} else if (!state_left && last_state_left) {
FURI_LOG_E("PowerGlove", "LEFT");
} else if (!state_right && last_state_right) {
FURI_LOG_E("PowerGlove", "RIGHT");
} else if (!state_ok && last_state_ok) {
FURI_LOG_E("PowerGlove", "OK");
} else if (!state_back && last_state_back) {
FURI_LOG_E("PowerGlove", "BACK");
}
last_state_up = state_up ;
last_state_down = state_down ;
last_state_left = state_left ;
last_state_right = state_right ;
last_state_ok = state_ok ;
last_state_back = state_back ;
furi_delay_ms(10) ;
}
return 0 ;
}
int32_t powerglove_app_app(void* p) {
UNUSED(p) ;
// Create the background worker thread
FuriThread* gpio_thread = furi_thread_alloc();
furi_thread_set_name(gpio_thread, "GPIO_worker");
furi_thread_set_stack_size(gpio_thread, 4096);
furi_thread_set_callback(gpio_thread, gpio_input_worker);
furi_thread_start(gpio_thread);
// Keep the service alive
while (1) {
furi_delay_ms(1000);
}
// Cleanup (though it will never reach here)
furi_thread_free(gpio_thread);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment