b835d7a451
* Furi: replace obsolete furiac_exit with osThreadExit, drop obsolete apis and test. Rename systemd to flipper and move to separate file, cleanup. ApiHal: Rename timebase to os and move freertos hooks there, move insomnia api to power module. * Furi: new thread helper * Furi: cleanup thread documentation * Flipper, AppLoader: update to use FuriThread. Update tasks signatures to match FuriThreadCallback signature. * F4: rename API_HAL_TIMEBASE_DEBUG to API_HAL_OS_DEBUG * Applications: rename FuriApplication to FlipperApplication, use FuriThreadCallback signature for apps. * C++ app template sample, new exit method
42 lines
1.0 KiB
C
42 lines
1.0 KiB
C
#include <furi.h>
|
|
#include <input/input.h>
|
|
|
|
typedef struct {
|
|
GpioPin* led;
|
|
GpioPin* vibro;
|
|
} Ctx;
|
|
|
|
static void button_handler(const void* value, void* _ctx) {
|
|
const InputEvent* event = value;
|
|
Ctx* ctx = (Ctx*)_ctx;
|
|
|
|
if(event->key != InputKeyOk) return;
|
|
|
|
if(event->type == InputTypePress) {
|
|
gpio_write(ctx->led, false);
|
|
gpio_write(ctx->vibro, true);
|
|
} else if(event->type == InputTypeRelease) {
|
|
gpio_write(ctx->led, true);
|
|
gpio_write(ctx->vibro, false);
|
|
}
|
|
}
|
|
|
|
int32_t application_vibro(void* p) {
|
|
Ctx ctx = {.led = (GpioPin*)&led_gpio[1], .vibro = (GpioPin*)&vibro_gpio};
|
|
|
|
gpio_init(ctx.led, GpioModeOutputOpenDrain);
|
|
gpio_init(ctx.vibro, GpioModeOutputPushPull);
|
|
gpio_write(ctx.led, true);
|
|
gpio_write(ctx.vibro, false);
|
|
|
|
// subscribe on buttons
|
|
PubSub* event_record = furi_record_open("input_events");
|
|
furi_check(event_record);
|
|
subscribe_pubsub(event_record, button_handler, &ctx);
|
|
|
|
while(1) {
|
|
osDelay(osWaitForever);
|
|
}
|
|
|
|
return 0;
|
|
} |