virtual_portal.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include <furi_hal_light.h>
  3. #include <notification/notification_messages.h>
  4. #include "pof_token.h"
  5. #define POF_TOKEN_LIMIT 16
  6. #define SAMPLES_COUNT 1024
  7. #define SAMPLES_COUNT_BUFFERED SAMPLES_COUNT * 4
  8. typedef enum {
  9. PoFHid,
  10. PoFXbox360
  11. } PoFType;
  12. typedef enum {
  13. EventExit = (1 << 0),
  14. EventReset = (1 << 1),
  15. EventRx = (1 << 2),
  16. EventTx = (1 << 3),
  17. EventTxComplete = (1 << 4),
  18. EventResetSio = (1 << 5),
  19. EventTxImmediate = (1 << 6),
  20. EventAll = EventExit | EventReset | EventRx | EventTx | EventTxComplete | EventResetSio |
  21. EventTxImmediate,
  22. } PoFEvent;
  23. typedef struct {
  24. uint8_t r;
  25. uint8_t g;
  26. uint8_t b;
  27. uint8_t target_r;
  28. uint8_t target_g;
  29. uint8_t target_b;
  30. uint8_t last_r;
  31. uint8_t last_g;
  32. uint8_t last_b;
  33. uint16_t delay;
  34. uint32_t start_time;
  35. bool two_phase;
  36. bool running;
  37. int current_phase;
  38. } VirtualPortalLed;
  39. typedef struct {
  40. PoFToken* tokens[POF_TOKEN_LIMIT];
  41. uint8_t sequence_number;
  42. float volume;
  43. bool playing_audio;
  44. uint8_t audio_buffer[SAMPLES_COUNT];
  45. uint8_t current_audio_buffer[SAMPLES_COUNT_BUFFERED];
  46. uint8_t* head;
  47. uint8_t* tail;
  48. uint8_t* end;
  49. uint16_t count;
  50. bool active;
  51. bool speaker;
  52. bool got_speaker;
  53. NotificationApp* notifications;
  54. PoFType type;
  55. VirtualPortalLed left;
  56. VirtualPortalLed right;
  57. VirtualPortalLed trap;
  58. FuriTimer* led_timer;
  59. } VirtualPortal;
  60. VirtualPortal* virtual_portal_alloc(NotificationApp* notifications);
  61. void virtual_portal_free(VirtualPortal* virtual_portal);
  62. void virtual_portal_cleanup(VirtualPortal* virtual_portal);
  63. void virtual_portal_load_token(VirtualPortal* virtual_portal, PoFToken* pof_token);
  64. void virtual_portal_tick();
  65. int virtual_portal_process_message(
  66. VirtualPortal* virtual_portal,
  67. uint8_t* message,
  68. uint8_t* response);
  69. void virtual_portal_process_audio(VirtualPortal* virtual_portal,
  70. uint8_t* message, uint8_t len);
  71. int virtual_portal_send_status(VirtualPortal* virtual_portal, uint8_t* response);