|
|
@ -11,25 +11,36 @@ |
|
|
|
static char sock_buff[SOCK_BUF_LEN]; |
|
|
|
static char sock_buff[SOCK_BUF_LEN]; |
|
|
|
|
|
|
|
|
|
|
|
volatile bool notify_available = true; |
|
|
|
volatile bool notify_available = true; |
|
|
|
|
|
|
|
volatile bool notify_cooldown = false; |
|
|
|
|
|
|
|
|
|
|
|
static ETSTimer notifyTim; |
|
|
|
static ETSTimer notifyContentTim; |
|
|
|
static ETSTimer notifyTim2; |
|
|
|
static ETSTimer notifyLabelsTim; |
|
|
|
|
|
|
|
static ETSTimer notifyCooldownTim; |
|
|
|
|
|
|
|
|
|
|
|
// we're trying to do a kind of mutex here, without the actual primitives
|
|
|
|
// we're trying to do a kind of mutex here, without the actual primitives
|
|
|
|
// this might glitch, very rarely.
|
|
|
|
// this might glitch, very rarely.
|
|
|
|
// it's recommended to put some delay between setting labels and updating the screen.
|
|
|
|
// it's recommended to put some delay between setting labels and updating the screen.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Cooldown delay is over |
|
|
|
|
|
|
|
* @param arg |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
|
|
|
|
notifyCooldownTimCb(void *arg) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
notify_cooldown = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
notifyTimCb(void *arg) { |
|
|
|
notifyContentTimCb(void *arg) |
|
|
|
|
|
|
|
{ |
|
|
|
void *data = NULL; |
|
|
|
void *data = NULL; |
|
|
|
int max_bl, total_bl; |
|
|
|
int max_bl, total_bl; |
|
|
|
cgiWebsockMeasureBacklog(URL_WS_UPDATE, &max_bl, &total_bl); |
|
|
|
cgiWebsockMeasureBacklog(URL_WS_UPDATE, &max_bl, &total_bl); |
|
|
|
|
|
|
|
|
|
|
|
if (!notify_available || (max_bl > 2048)) { // do not send if we have anything significant backlogged
|
|
|
|
if (!notify_available || notify_cooldown || (max_bl > 2048)) { // do not send if we have anything significant backlogged
|
|
|
|
// postpone a little
|
|
|
|
// postpone a little
|
|
|
|
os_timer_disarm(¬ifyTim); |
|
|
|
TIMER_START(¬ifyContentTim, notifyContentTimCb, 5, 0); |
|
|
|
os_timer_setfn(¬ifyTim, notifyTimCb, NULL); |
|
|
|
|
|
|
|
os_timer_arm(¬ifyTim, 5, 0); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
notify_available = false; |
|
|
|
notify_available = false; |
|
|
@ -46,17 +57,18 @@ notifyTimCb(void *arg) { |
|
|
|
// cleanup
|
|
|
|
// cleanup
|
|
|
|
screenSerializeToBuffer(NULL, SOCK_BUF_LEN, &data); |
|
|
|
screenSerializeToBuffer(NULL, SOCK_BUF_LEN, &data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notify_cooldown = true; |
|
|
|
notify_available = true; |
|
|
|
notify_available = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TIMER_START(¬ifyCooldownTim, notifyCooldownTimCb, termconf->display_cooldown_ms, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
notifyLabelsTimCb(void *arg) |
|
|
|
notifyLabelsTimCb(void *arg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!notify_available) { |
|
|
|
if (!notify_available || notify_cooldown) { |
|
|
|
// postpone a little
|
|
|
|
// postpone a little
|
|
|
|
os_timer_disarm(¬ifyTim2); |
|
|
|
TIMER_START(¬ifyLabelsTim, notifyLabelsTimCb, 1, 0); |
|
|
|
os_timer_setfn(¬ifyTim2, notifyLabelsTimCb, NULL); |
|
|
|
|
|
|
|
os_timer_arm(¬ifyTim2, 1, 0); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
notify_available = false; |
|
|
|
notify_available = false; |
|
|
@ -64,7 +76,10 @@ notifyLabelsTimCb(void *arg) |
|
|
|
screenSerializeLabelsToBuffer(sock_buff, SOCK_BUF_LEN); |
|
|
|
screenSerializeLabelsToBuffer(sock_buff, SOCK_BUF_LEN); |
|
|
|
cgiWebsockBroadcast(URL_WS_UPDATE, sock_buff, (int) strlen(sock_buff), 0); |
|
|
|
cgiWebsockBroadcast(URL_WS_UPDATE, sock_buff, (int) strlen(sock_buff), 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notify_cooldown = true; |
|
|
|
notify_available = true; |
|
|
|
notify_available = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TIMER_START(¬ifyCooldownTim, notifyCooldownTimCb, termconf->display_cooldown_ms, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Beep */ |
|
|
|
/** Beep */ |
|
|
@ -87,17 +102,15 @@ void ICACHE_FLASH_ATTR screen_notifyChange(ScreenNotifyChangeTopic topic) |
|
|
|
// PRs are welcome for a nicer update "queue" solution
|
|
|
|
// PRs are welcome for a nicer update "queue" solution
|
|
|
|
if (termconf->display_tout_ms == 0) termconf->display_tout_ms = SCR_DEF_DISPLAY_TOUT_MS; |
|
|
|
if (termconf->display_tout_ms == 0) termconf->display_tout_ms = SCR_DEF_DISPLAY_TOUT_MS; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: the timers are restarted if already running
|
|
|
|
|
|
|
|
|
|
|
|
if (topic == CHANGE_LABELS) { |
|
|
|
if (topic == CHANGE_LABELS) { |
|
|
|
// separate timer from content change timer, to avoid losing that update
|
|
|
|
// separate timer from content change timer, to avoid losing that update
|
|
|
|
os_timer_disarm(¬ifyTim2); |
|
|
|
TIMER_START(¬ifyLabelsTim, notifyLabelsTimCb, termconf->display_tout_ms, 0); |
|
|
|
os_timer_setfn(¬ifyTim2, notifyLabelsTimCb, NULL); |
|
|
|
|
|
|
|
os_timer_arm(¬ifyTim2, termconf->display_tout_ms, 0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if (topic == CHANGE_CONTENT) { |
|
|
|
else if (topic == CHANGE_CONTENT) { |
|
|
|
// throttle delay
|
|
|
|
// throttle delay
|
|
|
|
os_timer_disarm(¬ifyTim); |
|
|
|
TIMER_START(¬ifyContentTim, notifyContentTimCb, termconf->display_tout_ms, 0); |
|
|
|
os_timer_setfn(¬ifyTim, notifyTimCb, NULL); |
|
|
|
|
|
|
|
os_timer_arm(¬ifyTim, termconf->display_tout_ms, 0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|