virtual_portal.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 1024
  9. #define SAMPLES_COUNT_BUFFERED SAMPLES_COUNT * 16
  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. bool audio_in_buffer;
  49. uint8_t audio_buffer[SAMPLES_COUNT];
  50. uint8_t current_audio_buffer[SAMPLES_COUNT_BUFFERED];
  51. uint8_t* head;
  52. uint8_t* tail;
  53. uint8_t* end;
  54. uint16_t count;
  55. uint8_t m;
  56. bool active;
  57. bool speaker;
  58. NotificationApp* notifications;
  59. PoFType type;
  60. VirtualPortalLed left;
  61. VirtualPortalLed right;
  62. VirtualPortalLed trap;
  63. FuriTimer* led_timer;
  64. FuriThread* thread;
  65. struct g72x_state state;
  66. } VirtualPortal;
  67. VirtualPortal* virtual_portal_alloc(NotificationApp* notifications);
  68. void virtual_portal_set_type(VirtualPortal* virtual_portal, PoFType type);
  69. void virtual_portal_free(VirtualPortal* virtual_portal);
  70. void virtual_portal_cleanup(VirtualPortal* virtual_portal);
  71. void virtual_portal_load_token(VirtualPortal* virtual_portal, PoFToken* pof_token);
  72. void virtual_portal_tick();
  73. int virtual_portal_process_message(
  74. VirtualPortal* virtual_portal,
  75. uint8_t* message,
  76. uint8_t* response);
  77. void virtual_portal_process_audio(VirtualPortal* virtual_portal,
  78. uint8_t* message, uint8_t len);
  79. void virtual_portal_process_audio_360(VirtualPortal* virtual_portal,
  80. uint8_t* message, uint8_t len);
  81. int virtual_portal_send_status(VirtualPortal* virtual_portal, uint8_t* response);