File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
src/eloquent_esp32cam/viz Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ namespace Eloquent {
3131 server (" Mjpeg" , MJPEG_HTTP_PORT),
3232 _paused (false ),
3333 _stopped (false ),
34+ _delay (50 ),
3435 _onFrame (NULL ) {
3536
3637 }
@@ -42,6 +43,17 @@ namespace Eloquent {
4243 return String (" MJPEG stream is available at http://" ) + wifi.ip () + " :" + String (MJPEG_HTTP_PORT);
4344 }
4445
46+ /* *
47+ * Limit FPS
48+ * @param fps
49+ */
50+ void maxFPS (uint8_t fps) {
51+ _delay = 1000 .0f / fps;
52+
53+ if (_delay < 1 )
54+ _delay = 1 ;
55+ }
56+
4557 /* *
4658 * Start server
4759 */
@@ -92,6 +104,7 @@ namespace Eloquent {
92104 protected:
93105 bool _paused;
94106 bool _stopped;
107+ uint16_t _delay;
95108 OnFrameCallback _onFrame;
96109
97110 /* *
@@ -111,8 +124,12 @@ namespace Eloquent {
111124 client.println (F (" Access-Control-Allow-Origin: *" ));
112125 client.println (F (" \r\n --frame" ));
113126
127+ size_t last = millis ();
128+
114129 while (true ) {
115- delay (1 );
130+ while (millis () - last < _delay)
131+ delay (1 );
132+
116133 yield ();
117134
118135 if (_paused)
@@ -137,6 +154,7 @@ namespace Eloquent {
137154 client.write ((const char *) camera.frame ->buf , camera.frame ->len );
138155 client.println (F (" \r\n --frame" ));
139156 client.flush ();
157+ last = millis ();
140158 }
141159 });
142160 }
You can’t perform that action at this time.
0 commit comments