vibro_test.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <furi.h>
  2. #include <api-hal.h>
  3. #include <gui/gui.h>
  4. #include <input/input.h>
  5. #include <notification/notification-messages.h>
  6. typedef struct {
  7. InputEvent input;
  8. } VibroEvent;
  9. void vibro_test_draw_callback(Canvas* canvas, void* ctx) {
  10. canvas_clear(canvas);
  11. canvas_set_font(canvas, FontPrimary);
  12. canvas_draw_str(canvas, 2, 10, "Vibro application");
  13. canvas_set_font(canvas, FontSecondary);
  14. canvas_draw_str(canvas, 2, 22, "Press OK turns on vibro");
  15. canvas_set_font(canvas, FontSecondary);
  16. canvas_draw_str(canvas, 2, 34, "Release OK turns off vibro");
  17. }
  18. void vibro_test_input_callback(InputEvent* input_event, void* ctx) {
  19. furi_assert(ctx);
  20. osMessageQueueId_t event_queue = ctx;
  21. VibroEvent event = {.input = *input_event};
  22. osMessageQueuePut(event_queue, &event, 0, 0);
  23. }
  24. int32_t vibro_test_app(void* p) {
  25. osMessageQueueId_t event_queue = osMessageQueueNew(8, sizeof(VibroEvent), NULL);
  26. // Configure view port
  27. ViewPort* view_port = view_port_alloc();
  28. furi_check(view_port);
  29. view_port_draw_callback_set(view_port, vibro_test_draw_callback, NULL);
  30. view_port_input_callback_set(view_port, vibro_test_input_callback, event_queue);
  31. // Register view port in GUI
  32. Gui* gui = furi_record_open("gui");
  33. gui_add_view_port(gui, view_port, GuiLayerFullscreen);
  34. NotificationApp* notification = furi_record_open("notification");
  35. VibroEvent event;
  36. while(1) {
  37. furi_check(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK);
  38. if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) {
  39. notification_message(notification, &sequence_reset_vibro);
  40. notification_message(notification, &sequence_reset_green);
  41. furi_record_close("notification");
  42. view_port_enabled_set(view_port, false);
  43. gui_remove_view_port(gui, view_port);
  44. view_port_free(view_port);
  45. osMessageQueueDelete(event_queue);
  46. return 0;
  47. }
  48. if(event.input.key == InputKeyOk) {
  49. if(event.input.type == InputTypePress) {
  50. notification_message(notification, &sequence_set_vibro_on);
  51. notification_message(notification, &sequence_set_green_255);
  52. } else if(event.input.type == InputTypeRelease) {
  53. notification_message(notification, &sequence_reset_vibro);
  54. notification_message(notification, &sequence_reset_green);
  55. }
  56. }
  57. }
  58. return 0;
  59. }