vibro_test.c 2.3 KB

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