mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Replace haspGetVersion() with haspDevice.get_version()
This commit is contained in:
parent
af9e45645e
commit
798cf8bd5e
@ -16,4 +16,24 @@ const char* BaseDevice::get_model()
|
||||
return PIOENV;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
const char* BaseDevice::get_version()
|
||||
{
|
||||
#ifdef HASP_MODEL
|
||||
return (QUOTE(HASP_VER_MAJ) "." QUOTE(HASP_VER_MIN) "." QUOTE(HASP_VER_REV));
|
||||
#else
|
||||
return PIOENV;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* BaseDevice::get_hostname()
|
||||
{
|
||||
return _hostname; //.c_str();
|
||||
}
|
||||
|
||||
void BaseDevice::set_hostname(const char* hostname)
|
||||
{
|
||||
strncpy(_hostname, hostname, STR_LEN_HOSTNAME);
|
||||
}
|
||||
|
||||
} // namespace dev
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
#define STR_LEN_HOSTNAME 64
|
||||
|
||||
namespace dev {
|
||||
|
||||
class BaseDevice {
|
||||
@ -29,13 +31,9 @@ class BaseDevice {
|
||||
|
||||
virtual void reboot()
|
||||
{}
|
||||
virtual const char* get_hostname()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual void set_hostname(const char*)
|
||||
{}
|
||||
virtual const char* get_core_version()
|
||||
const char* get_hostname();
|
||||
void set_hostname(const char*);
|
||||
const char* get_core_version()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
@ -44,6 +42,7 @@ class BaseDevice {
|
||||
return "";
|
||||
}
|
||||
virtual const char* get_model();
|
||||
virtual const char* get_version();
|
||||
virtual const char* get_hardware_id()
|
||||
{
|
||||
return "";
|
||||
@ -100,6 +99,10 @@ class BaseDevice {
|
||||
snprintf(buffer, sizeof(buffer), "%d", pin);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
// std::string _hostname;
|
||||
char _hostname[STR_LEN_HOSTNAME];
|
||||
};
|
||||
|
||||
} // namespace dev
|
||||
|
@ -97,7 +97,7 @@ static void halGetResetInfo(String& resetReason)
|
||||
|
||||
Esp32Device::Esp32Device()
|
||||
{
|
||||
_hostname = MQTT_NODENAME;
|
||||
BaseDevice::set_hostname(MQTT_NODENAME);
|
||||
_backlight_invert = (TFT_BACKLIGHT_ON == LOW);
|
||||
_backlight_power = 1;
|
||||
_backlight_level = 255;
|
||||
@ -129,14 +129,6 @@ void Esp32Device::show_info()
|
||||
if(_sketch_size == 0) _sketch_size = ESP.getSketchSize(); // slow: takes ~1 second
|
||||
}
|
||||
|
||||
const char* Esp32Device::get_hostname()
|
||||
{
|
||||
return _hostname.c_str();
|
||||
}
|
||||
void Esp32Device::set_hostname(const char* hostname)
|
||||
{
|
||||
_hostname = hostname;
|
||||
}
|
||||
const char* Esp32Device::get_core_version()
|
||||
{
|
||||
return esp_get_idf_version(); // == ESP.getSdkVersion();
|
||||
|
@ -19,8 +19,6 @@ class Esp32Device : public BaseDevice {
|
||||
void reboot() override;
|
||||
void show_info() override;
|
||||
|
||||
const char* get_hostname();
|
||||
void set_hostname(const char*);
|
||||
const char* get_core_version();
|
||||
const char* get_chip_model();
|
||||
const char* get_hardware_id();
|
||||
@ -40,7 +38,6 @@ class Esp32Device : public BaseDevice {
|
||||
bool is_system_pin(uint8_t pin) override;
|
||||
|
||||
private:
|
||||
std::string _hostname;
|
||||
std::string _hardware_id;
|
||||
uint32_t _sketch_size; // cached because function is slow
|
||||
|
||||
|
@ -534,10 +534,10 @@ void hasp_background(uint16_t pageid, uint16_t imageid)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void haspGetVersion(char* version, size_t len)
|
||||
{
|
||||
snprintf_P(version, len, PSTR("%u.%u.%u"), HASP_VER_MAJ, HASP_VER_MIN, HASP_VER_REV);
|
||||
}
|
||||
// void haspGetVersion(char* version, size_t len)
|
||||
// {
|
||||
// snprintf_P(version, len, PSTR("%u.%u.%u"), HASP_VER_MAJ, HASP_VER_MIN, HASP_VER_REV);
|
||||
// }
|
||||
|
||||
void haspClearPage(uint16_t pageid)
|
||||
{
|
||||
@ -577,8 +577,7 @@ void hasp_get_info(JsonDocument& doc)
|
||||
char size_buf[32];
|
||||
JsonObject info = doc.createNestedObject(F(D_MANUFACTURER));
|
||||
|
||||
haspGetVersion(size_buf, sizeof(size_buf));
|
||||
info[F(D_INFO_VERSION)] = size_buf;
|
||||
info[F(D_INFO_VERSION)] = haspDevice.get_version();
|
||||
|
||||
buffer = __DATE__;
|
||||
buffer += (" ");
|
||||
|
@ -50,7 +50,7 @@ void haspEverySecond(void);
|
||||
void haspReconnect(void);
|
||||
void haspDisconnect(void);
|
||||
|
||||
void haspGetVersion(char* version, size_t len);
|
||||
// void haspGetVersion(char* version, size_t len);
|
||||
// void haspBackground(uint16_t pageid, uint16_t imageid);
|
||||
|
||||
// void haspNewObject(const JsonObject & config, uint8_t & saved_page_id);
|
||||
|
@ -810,6 +810,7 @@ void dispatch_send_discovery(const char*, const char*)
|
||||
doc[F("mf")] = F(D_MANUFACTURER);
|
||||
doc[F("hwid")] = haspDevice.get_hardware_id();
|
||||
doc[F("pages")] = haspPages.count();
|
||||
doc[F("sw")] = haspDevice.get_version();
|
||||
|
||||
JsonObject input = doc.createNestedObject(F("input"));
|
||||
JsonArray relay = doc.createNestedArray(F("power"));
|
||||
@ -821,10 +822,8 @@ void dispatch_send_discovery(const char*, const char*)
|
||||
#endif
|
||||
|
||||
char data[1024];
|
||||
haspGetVersion(data, sizeof(data));
|
||||
doc[F("sw")] = data;
|
||||
|
||||
size_t len = serializeJson(doc, data);
|
||||
|
||||
switch(mqtt_send_discovery(data, len)) {
|
||||
case MQTT_ERR_OK:
|
||||
LOG_TRACE(TAG_MQTT_PUB, F(MQTT_TOPIC_DISCOVERY " => %s"), data);
|
||||
@ -854,9 +853,9 @@ void dispatch_statusupdate(const char*, const char*)
|
||||
char buffer[128];
|
||||
|
||||
hasp_get_sleep_state(topic);
|
||||
haspGetVersion(buffer, sizeof(buffer));
|
||||
snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||
haspDevice.get_hostname(), topic, buffer, long(millis() / 1000)); // \"status\":\"available\",
|
||||
haspDevice.get_hostname(), topic, haspDevice.get_version(),
|
||||
long(millis() / 1000)); // \"status\":\"available\",
|
||||
|
||||
#if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0
|
||||
network_get_statusupdate(buffer, sizeof(buffer));
|
||||
|
@ -177,9 +177,6 @@ void debugLvglLogEvent(lv_log_level_t level, const char* file, uint32_t line, co
|
||||
// Send the HASP header and version to the output device specified
|
||||
void debugPrintHaspHeader(Print* output)
|
||||
{
|
||||
char buffer[16];
|
||||
haspGetVersion(buffer, sizeof(buffer));
|
||||
|
||||
#ifdef ARDUINO
|
||||
if(debugAnsiCodes) output->print(TERM_COLOR_YELLOW);
|
||||
output->println();
|
||||
@ -190,7 +187,7 @@ void debugPrintHaspHeader(Print* output)
|
||||
" |__|__|__|__|_____|__|\r\n"
|
||||
" Home Automation Switch Plate\r\n"
|
||||
" Open Hardware edition v"));
|
||||
output->println(buffer);
|
||||
output->println(haspDevice.get_version());
|
||||
output->println();
|
||||
#else
|
||||
if(debugAnsiCodes) debug_print(output, TERM_COLOR_YELLOW);
|
||||
@ -201,7 +198,7 @@ void debugPrintHaspHeader(Print* output)
|
||||
" |__|__|__|__|_____|__|\r\n"
|
||||
" Home Automation Switch Plate\r\n"
|
||||
" Open Hardware edition v"));
|
||||
debug_print(output, buffer);
|
||||
debug_print(output, haspDevice.get_version());
|
||||
debug_newline(output);
|
||||
debug_newline(output);
|
||||
#endif
|
||||
|
@ -75,10 +75,7 @@ void mqtt_ha_add_device_ids(JsonDocument& doc)
|
||||
ids.add(haspDevice.get_hostname());
|
||||
ids.add(HASP_MAC_ADDRESS_STR);
|
||||
|
||||
char buffer[32];
|
||||
haspGetVersion(buffer, sizeof(buffer));
|
||||
device[F("sw")] = buffer;
|
||||
|
||||
device[F("sw")] = haspDevice.get_version();
|
||||
device[FPSTR(FP_MQTT_HA_NAME)] = haspDevice.get_hostname();
|
||||
device[FPSTR(FP_MQTT_HA_MODEL)] = F(PIOENV);
|
||||
device[FPSTR(FP_MQTT_HA_MANUFACTURER)] = F(D_MANUFACTURER);
|
||||
|
@ -250,16 +250,13 @@ bool httpIsAuthenticated(const __FlashStringHelper* notused)
|
||||
|
||||
void webSendFooter()
|
||||
{
|
||||
char buffer[16];
|
||||
haspGetVersion(buffer, sizeof(buffer));
|
||||
|
||||
#if defined(STM32F4xx)
|
||||
webServer.sendContent(HTTP_END);
|
||||
webServer.sendContent(buffer);
|
||||
webServer.sendContent(haspDevice.get_version());
|
||||
webServer.sendContent(HTTP_FOOTER);
|
||||
#else
|
||||
webServer.sendContent_P(HTTP_END);
|
||||
webServer.sendContent(buffer);
|
||||
webServer.sendContent(haspDevice.get_version());
|
||||
webServer.sendContent_P(HTTP_FOOTER);
|
||||
#endif
|
||||
}
|
||||
@ -279,10 +276,9 @@ void webSendPage(const char* nodename, uint32_t httpdatalength, bool gohome = fa
|
||||
{
|
||||
{
|
||||
char buffer[64];
|
||||
haspGetVersion(buffer, sizeof(buffer));
|
||||
|
||||
/* Calculate Content Length upfront */
|
||||
uint32_t contentLength = strlen(buffer); // version length
|
||||
uint32_t contentLength = strlen(haspDevice.get_version()); // version length
|
||||
contentLength += sizeof(HTTP_DOCTYPE) - 1;
|
||||
contentLength += sizeof(HTTP_HEADER) - 1 - 2 + strlen(nodename); // -2 for %s
|
||||
contentLength += sizeof(HTTP_SCRIPT) - 1;
|
||||
@ -624,11 +620,7 @@ void webHandleInfo()
|
||||
|
||||
/* HASP Stats */
|
||||
httpMessage += F("<b>HASP Version: </b>");
|
||||
{
|
||||
char version[32];
|
||||
haspGetVersion(version, sizeof(version));
|
||||
httpMessage += version;
|
||||
}
|
||||
httpMessage += haspDevice.get_version();
|
||||
httpMessage += F("<br/><b>Build DateTime: </b>");
|
||||
httpMessage += __DATE__;
|
||||
httpMessage += F(" ");
|
||||
|
@ -60,8 +60,7 @@ void mdnsStart()
|
||||
MDNS.addService(service, proto, 80);
|
||||
|
||||
strcpy_P(key, PSTR("app_version"));
|
||||
haspGetVersion(value, sizeof(value));
|
||||
MDNS.addServiceTxt(service, proto, key, value);
|
||||
MDNS.addServiceTxt(service, proto, key, haspDevice.get_version());
|
||||
|
||||
strcpy_P(key, PSTR("app_name"));
|
||||
strcpy_P(value, PSTR(D_MANUFACTURER));
|
||||
|
@ -70,10 +70,9 @@ void TASMO_TELE_JSON()
|
||||
char data[3 * 128];
|
||||
{
|
||||
char buffer[128];
|
||||
haspGetVersion(buffer, sizeof(buffer));
|
||||
|
||||
snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), buffer,
|
||||
long(millis() / 1000));
|
||||
snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||
haspDevice.get_version(), long(millis() / 1000));
|
||||
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"),
|
||||
haspGetPage(), (HASP_NUM_PAGES));
|
||||
|
Loading…
x
Reference in New Issue
Block a user