"
"%s | " // name
"%s | " // sbatt (Battery Indicator)
"" // slqi
), name, sbatt, slqi);
if(device.validLqi()) {
for(uint32_t j = 0; j < 4; ++j) {
WSContentSend_PD(PSTR(""), j, (num_bars < j) ? PSTR(" o30") : PSTR(""));
}
}
char dhm[16]; // len("🕗" + "49710d" + '\0') == 16
snprintf_P(dhm, sizeof(dhm), PSTR(" "));
if(device.validLastSeen()){
snprintf_P(dhm, sizeof(dhm), PSTR("🕗"));
convert_seconds_to_dhm(now - device.last_seen, &dhm[9], 7);
}
WSContentSend_PD(PSTR(
" | " // Close LQI
"%s{e}" // dhm (Last Seen)
), dhm );
// Sensors
bool temperature_ok = device.validTemperature();
bool humidity_ok = device.validHumidity();
bool pressure_ok = device.validPressure();
if (temperature_ok || humidity_ok || pressure_ok) {
WSContentSend_P(PSTR(" |
┆"));
if (temperature_ok) {
char buf[12];
dtostrf(device.temperature / 10.0f, 3, 1, buf);
WSContentSend_PD(PSTR(" ☀️ %s°C"), buf);
}
if (humidity_ok) {
WSContentSend_P(PSTR(" 💧 %d%%"), device.humidity);
}
if (pressure_ok) {
WSContentSend_P(PSTR(" ⛅ %d hPa"), device.pressure);
}
WSContentSend_P(PSTR("{e}"));
}
// Light, switches and plugs
bool power_ok = device.validPower();
if (power_ok) {
uint8_t channels = device.getLightChannels();
if (0xFF == channels) { channels = 5; } // if number of channel is unknown, display all known attributes
WSContentSend_P(PSTR(" |
┆ %s"), device.getPower() ? PSTR(D_ON) : PSTR(D_OFF));
if (device.validDimmer() && (channels >= 1)) {
WSContentSend_P(PSTR(" 🔅 %d%%"), changeUIntScale(device.dimmer,0,254,0,100));
}
if (device.validCT() && ((channels == 2) || (channels == 5))) {
uint32_t ct_k = (((1000000 / device.ct) + 25) / 50) * 50;
WSContentSend_P(PSTR(" ⚪ %dK"), device.ct, ct_k);
}
if (device.validHue() && device.validSat() && (channels >= 3)) {
uint8_t r,g,b;
uint8_t sat = changeUIntScale(device.sat, 0, 254, 0, 255); // scale to 0..255
LightStateClass::HsToRgb(device.hue, sat, &r, &g, &b);
WSContentSend_P(PSTR(" #%02X%02X%02X"), r,g,b,r,g,b);
} else if (device.validX() && device.validY() && (channels >= 3)) {
uint8_t r,g,b;
LightStateClass::XyToRgb(device.x / 65535.0f, device.y / 65535.0f, &r, &g, &b);
WSContentSend_P(PSTR(" #%02X%02X%02X"), r,g,b,r,g,b);
}
if (device.validMainsPower() || device.validMainsVoltage()) {
WSContentSend_P(PSTR(" ⚡ "));
if (device.validMainsVoltage()) {
WSContentSend_P(PSTR(" %dV"), device.mains_voltage);
}
if (device.validMainsPower()) {
WSContentSend_P(PSTR(" %dW"), device.mains_power);
}
}
WSContentSend_P(PSTR("{e}"));
}
}
WSContentSend_P(PSTR("{t}")); // Terminate current multi column table and open new table
#endif
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xdrv23(uint8_t function)
{
bool result = false;
if (zigbee.active) {
switch (function) {
case FUNC_EVERY_50_MSECOND:
if (!zigbee.init_phase) {
zigbee_devices.runTimer();
}
break;
case FUNC_LOOP:
#ifdef USE_ZIGBEE_EZSP
if (ZigbeeUploadXmodem()) {
return false;
}
#endif
if (ZigbeeSerial) {
ZigbeeInputLoop();
ZigbeeOutputLoop(); // send any outstanding data
}
if (zigbee.state_machine) {
ZigbeeStateMachine_Run();
}
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
ZigbeeShow(false);
break;
#ifdef USE_ZIGBEE_EZSP
// GUI xmodem
case FUNC_WEB_ADD_HANDLER:
Webserver->on("/" WEB_HANDLE_ZIGBEE_XFER, HandleZigbeeXfer);
break;
#endif // USE_ZIGBEE_EZSP
#endif // USE_WEBSERVER
case FUNC_PRE_INIT:
ZigbeeInit();
break;
case FUNC_COMMAND:
result = DecodeCommand(kZbCommands, ZigbeeCommand);
break;
}
}
return result;
}
#endif // USE_ZIGBEE
|