vibro.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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->key != InputKeyOk) return;
  11. if(event->type == InputTypePress) {
  12. gpio_write(ctx->led, false);
  13. gpio_write(ctx->vibro, true);
  14. } else if(event->type == InputTypeRelease) {
  15. gpio_write(ctx->led, true);
  16. gpio_write(ctx->vibro, false);
  17. }
  18. }
  19. void application_vibro(void* p) {
  20. Ctx ctx = {.led = (GpioPin*)&led_gpio[1], .vibro = (GpioPin*)&vibro_gpio};
  21. gpio_init(ctx.led, GpioModeOutputOpenDrain);
  22. gpio_init(ctx.vibro, GpioModeOutputPushPull);
  23. gpio_write(ctx.led, true);
  24. gpio_write(ctx.vibro, false);
  25. // subscribe on buttons
  26. PubSub* event_record = furi_record_open("input_events");
  27. furi_check(event_record);
  28. subscribe_pubsub(event_record, button_handler, &ctx);
  29. while(1) {
  30. osDelay(osWaitForever);
  31. }
  32. }