orgasmotron.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. typedef struct {
  7. FuriMutex* mutex;
  8. int mode;
  9. } PluginState;
  10. void vibro_test_draw_callback(Canvas* canvas, void* ctx) {
  11. UNUSED(ctx);
  12. canvas_clear(canvas);
  13. canvas_set_font(canvas, FontPrimary);
  14. canvas_draw_str(canvas, 2, 10, "Vibro Modes");
  15. canvas_set_font(canvas, FontSecondary);
  16. canvas_draw_str(canvas, 2, 22, "UP: Pulsed");
  17. canvas_draw_str(canvas, 2, 34, "LEFT: strong / RIGHT: Soft");
  18. canvas_draw_str(canvas, 2, 46, "DOWN: Pleasure combo");
  19. canvas_draw_str(canvas, 2, 58, "OK: Pause");
  20. }
  21. void vibro_test_input_callback(InputEvent* input_event, void* ctx) {
  22. furi_assert(ctx);
  23. FuriMessageQueue* event_queue = ctx;
  24. furi_message_queue_put(event_queue, input_event, FuriWaitForever);
  25. }
  26. void delay(int milliseconds) {
  27. furi_thread_flags_wait(0, FuriFlagWaitAny, milliseconds);
  28. }
  29. int32_t orgasmotron_app(void* p) {
  30. UNUSED(p);
  31. FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
  32. PluginState* plugin_state = malloc(sizeof(PluginState));
  33. plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
  34. if(!plugin_state->mutex) {
  35. FURI_LOG_E("Orgasmatron", "cannot create mutex\r\n");
  36. free(plugin_state);
  37. return 255;
  38. }
  39. // Configure view port
  40. ViewPort* view_port = view_port_alloc();
  41. view_port_draw_callback_set(view_port, vibro_test_draw_callback, NULL);
  42. view_port_input_callback_set(view_port, vibro_test_input_callback, event_queue);
  43. // Register view port in GUI
  44. Gui* gui = furi_record_open(RECORD_GUI);
  45. gui_add_view_port(gui, view_port, GuiLayerFullscreen);
  46. NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
  47. InputEvent event;
  48. bool processing = true;
  49. size_t i = 0;
  50. while(processing) {
  51. FuriStatus event_status = furi_message_queue_get(event_queue, &event, 50);
  52. furi_mutex_acquire(plugin_state->mutex, FuriWaitForever);
  53. if(event_status == FuriStatusOk) {
  54. if(event.key == InputKeyBack && event.type == InputTypeShort) {
  55. //Exit Application
  56. plugin_state->mode = 0;
  57. processing = false;
  58. }
  59. if(event.key == InputKeyOk &&
  60. (event.type == InputTypePress || event.type == InputTypeRelease)) {
  61. plugin_state->mode = 0;
  62. }
  63. if(event.key == InputKeyLeft &&
  64. (event.type == InputTypePress || event.type == InputTypeRelease)) {
  65. notification_message(notification, &sequence_set_green_255);
  66. plugin_state->mode = 1;
  67. }
  68. if(event.key == InputKeyRight &&
  69. (event.type == InputTypePress || event.type == InputTypeRelease)) {
  70. notification_message(notification, &sequence_set_green_255);
  71. plugin_state->mode = 3;
  72. }
  73. if(event.key == InputKeyUp &&
  74. (event.type == InputTypePress || event.type == InputTypeRelease)) {
  75. notification_message(notification, &sequence_set_green_255);
  76. plugin_state->mode = 2;
  77. }
  78. if(event.key == InputKeyDown &&
  79. (event.type == InputTypePress || event.type == InputTypeRelease)) {
  80. notification_message(notification, &sequence_set_green_255);
  81. plugin_state->mode = 4;
  82. }
  83. i = 0;
  84. }
  85. if(plugin_state->mode == 0) {
  86. //Stop Vibration
  87. if(i == 0) {
  88. notification_message(notification, &sequence_reset_vibro);
  89. notification_message(notification, &sequence_reset_green);
  90. i++;
  91. }
  92. } else if(plugin_state->mode == 1) {
  93. //Full power
  94. if(i == 0) {
  95. notification_message(notification, &sequence_set_vibro_on);
  96. i++;
  97. }
  98. } else if(plugin_state->mode == 2) {
  99. //Pulsed Vibration
  100. i++;
  101. if(i == 1) {
  102. notification_message(notification, &sequence_set_vibro_on);
  103. }
  104. if(i == 3) {
  105. notification_message(notification, &sequence_reset_vibro);
  106. }
  107. if(i == 4) {
  108. i = 0;
  109. }
  110. } else if(plugin_state->mode == 3) {
  111. //Soft power
  112. i++;
  113. if(i == 1) {
  114. notification_message(notification, &sequence_set_vibro_on);
  115. }
  116. if(i == 2) {
  117. notification_message(notification, &sequence_reset_vibro);
  118. i = 0;
  119. }
  120. } else if(plugin_state->mode == 4) {
  121. //Special Sequence
  122. i++;
  123. if(i < 23) {
  124. if(i % 2) {
  125. notification_message(notification, &sequence_set_vibro_on);
  126. } else {
  127. notification_message(notification, &sequence_reset_vibro);
  128. }
  129. } else if(i < 40) {
  130. if(i == 24 || i == 33) {
  131. notification_message(notification, &sequence_set_vibro_on);
  132. } else if(i == 32) {
  133. notification_message(notification, &sequence_reset_vibro);
  134. }
  135. } else if(i == 41) {
  136. notification_message(notification, &sequence_reset_vibro);
  137. i = 0;
  138. }
  139. }
  140. furi_mutex_release(plugin_state->mutex);
  141. }
  142. gui_remove_view_port(gui, view_port);
  143. view_port_free(view_port);
  144. furi_mutex_free(plugin_state->mutex);
  145. furi_message_queue_free(event_queue);
  146. furi_record_close(RECORD_NOTIFICATION);
  147. furi_record_close(RECORD_GUI);
  148. return 0;
  149. }