Repository navigation
Expand file tree
/
Copy pathPanelStreamer.hpp
More file actions
97 lines (80 loc) · 2.55 KB
/
Copy pathPanelStreamer.hpp
File metadata and controls
97 lines (80 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef PANEL_STREAMER_HPP
#define PANEL_STREAMER_HPP
#include <Arduino.h>
#include <WebSocketsServer.h>
#include "PanelManager.hpp"
#include "MultiLogger.hpp"
#include "PsramUtils.hpp"
/**
* @brief Manages WebSocket streaming of panel data and log messages
*
* This class runs a FreeRTOS task on the non-Arduino core that:
* 1. Streams compressed panel snapshots at ~2 FPS
* 2. Streams log messages as they arrive
* 3. Handles WebSocket client connections (max 2 clients)
*
* RGB888 Compatibility Note:
* Currently uses RGB565 (16-bit) format matching GFXcanvas16.
* For RGB888 canvas support, modify:
* - _panelBuffer type from uint16_t* to uint32_t* or use template
* - compressRLE to handle 24/32-bit pixels
* - Client-side decoder to handle RGB888 format
*/
class PanelStreamer {
public:
/**
* @brief Constructor
* @param panelManager Pointer to the PanelManager for accessing panel data
*/
PanelStreamer(PanelManager* panelManager);
/**
* @brief Destructor
*/
~PanelStreamer();
/**
* @brief Start the streamer task
* Must be called after WiFi is connected
*/
void begin();
/**
* @brief Stop the streamer task
*/
void stop();
/**
* @brief Check if any clients are connected
* @return Number of connected clients
*/
uint8_t getClientCount();
/**
* @brief Get the WebSocket server instance
* @return Pointer to the WebSocketsServer
*/
WebSocketsServer* getWebSocketServer() { return _wsServer; }
private:
// Panel manager reference
PanelManager* _panelManager;
// WebSocket server (port 81 for /stream endpoint)
WebSocketsServer* _wsServer;
// FreeRTOS task handle
TaskHandle_t _taskHandle;
// Control flags
bool _running;
SemaphoreHandle_t _controlMutex;
// Panel buffer for copying (in PSRAM)
uint16_t* _panelBuffer;
size_t _panelBufferSize;
// Compressed data buffer (in PSRAM)
uint8_t* _compressedBuffer;
size_t _compressedBufferSize;
// Task function
static void streamerTaskWrapper(void* param);
void streamerTask();
// Helper functions
size_t compressRLE(const uint16_t* input, size_t inputSize, uint8_t* output, size_t outputMaxSize);
void sendPanelSnapshot();
void sendLogMessages();
// WebSocket event handler
static void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length);
static PanelStreamer* _instance; // For static callback
};
#endif // PANEL_STREAMER_HPP