vibro.c 961 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <furi.h>
  2. #include <api-hal.h>
  3. #include <input/input.h>
  4. typedef struct {
  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. api_hal_light_set(LightGreen, 0xFF);
  13. gpio_write(ctx->vibro, true);
  14. } else if(event->type == InputTypeRelease) {
  15. api_hal_light_set(LightGreen, 0x00);
  16. gpio_write(ctx->vibro, false);
  17. }
  18. }
  19. int32_t application_vibro(void* p) {
  20. Ctx ctx = {.vibro = (GpioPin*)&vibro_gpio};
  21. gpio_init(ctx.vibro, GpioModeOutputPushPull);
  22. gpio_write(ctx.vibro, false);
  23. // subscribe on buttons
  24. PubSub* event_record = furi_record_open("input_events");
  25. furi_check(event_record);
  26. subscribe_pubsub(event_record, button_handler, &ctx);
  27. while(1) {
  28. osDelay(osWaitForever);
  29. }
  30. return 0;
  31. }