virtual_portal.h 2.4 KB

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