added a 20 ms delay before sending WS update, improves performance when user repains entire screen quickly - just 1 update

pull/30/head
Ondřej Hruška 8 years ago
parent f7edbf19b0
commit 1d891dd313
  1. 30
      user/cgi_sockets.c

@ -6,18 +6,15 @@
#include "uart_driver.h"
#include "screen.h"
/**
* Broadcast screen state to sockets.
* This is a callback for the Screen module,
* called after each visible screen modification.
*/
void ICACHE_FLASH_ATTR screen_notifyChange()
{
// TODO cooldown / buffering to reduce nr of such events
static volatile bool timer_running = false;
static ETSTimer notifyTim;
static void notifyTimCb(void *arg) {
timer_running = false;
void *data = NULL;
const int bufsiz = 512;
const int bufsiz = 1024;
char buff[bufsiz];
for (int i = 0; i < 20; i++) {
httpd_cgi_state cont = screenSerializeToBuffer(buff, bufsiz, &data);
@ -31,6 +28,21 @@ void ICACHE_FLASH_ATTR screen_notifyChange()
screenSerializeToBuffer(NULL, bufsiz, &data);
}
/**
* Broadcast screen state to sockets.
* This is a callback for the Screen module,
* called after each visible screen modification.
*/
void ICACHE_FLASH_ATTR screen_notifyChange(void)
{
if (timer_running) return;
timer_running = true;
os_timer_disarm(&notifyTim);
os_timer_setfn(&notifyTim, notifyTimCb, NULL);
os_timer_arm(&notifyTim, 20, 0);
}
/** Socket received a message */
void ICACHE_FLASH_ATTR updateSockRx(Websock *ws, char *data, int len, int flags)
{

Loading…
Cancel
Save