virtual_portal.h 2.4 KB

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