vibro.c 851 B

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