|
@ -14,8 +14,6 @@ Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com> |
|
|
bool _haEnabled = false; |
|
|
bool _haEnabled = false; |
|
|
bool _haSendFlag = false; |
|
|
bool _haSendFlag = false; |
|
|
|
|
|
|
|
|
std::queue<uint32_t> _ha_send_config; |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// UTILS
|
|
|
// UTILS
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
@ -259,6 +257,8 @@ void _haConfigure() { |
|
|
|
|
|
|
|
|
#if WEB_SUPPORT
|
|
|
#if WEB_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
std::queue<uint32_t> _ha_send_config; |
|
|
|
|
|
|
|
|
bool _haWebSocketOnReceive(const char * key, JsonVariant& value) { |
|
|
bool _haWebSocketOnReceive(const char * key, JsonVariant& value) { |
|
|
return (strncmp(key, "ha", 2) == 0); |
|
|
return (strncmp(key, "ha", 2) == 0); |
|
|
} |
|
|
} |
|
@ -313,12 +313,16 @@ void _haInitCommands() { |
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#if WEB_SUPPORT
|
|
|
void _haLoop() { |
|
|
void _haLoop() { |
|
|
if (_ha_send_config.empty()) return; |
|
|
if (_ha_send_config.empty()) return; |
|
|
|
|
|
|
|
|
uint32_t client_id = _ha_send_config.front(); |
|
|
uint32_t client_id = _ha_send_config.front(); |
|
|
_ha_send_config.pop(); |
|
|
_ha_send_config.pop(); |
|
|
|
|
|
|
|
|
|
|
|
if (!wsConnected(client_id)) return; |
|
|
|
|
|
|
|
|
|
|
|
// TODO check wsConnected after each "printer" call?
|
|
|
_haDumpConfig([client_id](String& output) { |
|
|
_haDumpConfig([client_id](String& output) { |
|
|
output.replace(" ", " "); |
|
|
output.replace(" ", " "); |
|
|
output.replace("\n", "<br />"); |
|
|
output.replace("\n", "<br />"); |
|
@ -327,6 +331,7 @@ void _haLoop() { |
|
|
yield(); |
|
|
yield(); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
void haSetup() { |
|
|
void haSetup() { |
|
|
|
|
|
|
|
@ -336,6 +341,7 @@ void haSetup() { |
|
|
wsOnSendRegister(_haWebSocketOnSend); |
|
|
wsOnSendRegister(_haWebSocketOnSend); |
|
|
wsOnActionRegister(_haWebSocketOnAction); |
|
|
wsOnActionRegister(_haWebSocketOnAction); |
|
|
wsOnReceiveRegister(_haWebSocketOnReceive); |
|
|
wsOnReceiveRegister(_haWebSocketOnReceive); |
|
|
|
|
|
espurnaRegisterLoop(_haLoop); |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
#if TERMINAL_SUPPORT
|
|
|
#if TERMINAL_SUPPORT
|
|
@ -349,7 +355,6 @@ void haSetup() { |
|
|
|
|
|
|
|
|
// Main callbacks
|
|
|
// Main callbacks
|
|
|
espurnaRegisterReload(_haConfigure); |
|
|
espurnaRegisterReload(_haConfigure); |
|
|
espurnaRegisterLoop(_haLoop); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|