vibro_test.c 2.3 KB

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