vibro.c 877 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <furi.h>
  2. #include <input/input.h>
  3. typedef struct {
  4. GpioPin* led;
  5. GpioPin* vibro;
  6. } Ctx;
  7. static void button_handler(const void* value, void* _ctx) {
  8. const InputEvent* event = value;
  9. Ctx* ctx = (Ctx*)_ctx;
  10. if(event->input == InputOk) {
  11. gpio_write(ctx->vibro, event->state);
  12. gpio_write(ctx->led, !event->state);
  13. }
  14. }
  15. void application_vibro(void* p) {
  16. Ctx ctx = {.led = (GpioPin*)&led_gpio[1], .vibro = (GpioPin*)&vibro_gpio};
  17. gpio_init(ctx.led, GpioModeOutputOpenDrain);
  18. gpio_init(ctx.vibro, GpioModeOutputPushPull);
  19. gpio_write(ctx.led, true);
  20. gpio_write(ctx.vibro, false);
  21. // subscribe on buttons
  22. PubSub* event_record = furi_record_open("input_events");
  23. furi_check(event_record);
  24. subscribe_pubsub(event_record, button_handler, &ctx);
  25. while(1) {
  26. osDelay(osWaitForever);
  27. }
  28. }