mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Add get_hardware_id
This commit is contained in:
parent
079d0630e6
commit
074ad55604
@ -41,8 +41,11 @@ class BaseDevice {
|
||||
{
|
||||
return "";
|
||||
}
|
||||
const char* get_model();
|
||||
|
||||
virtual const char* get_model();
|
||||
virtual const char* get_hardware_id()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual void init()
|
||||
{}
|
||||
virtual void show_info()
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Esp.h>
|
||||
#include <WiFi.h>
|
||||
#include "esp_system.h"
|
||||
|
||||
#include "hasp_conf.h"
|
||||
@ -21,6 +22,24 @@
|
||||
|
||||
namespace dev {
|
||||
|
||||
Esp32Device::Esp32Device()
|
||||
{
|
||||
_hostname = MQTT_NODENAME;
|
||||
_backlight_invert = (TFT_BACKLIGHT_ON == LOW);
|
||||
_backlight_power = 1;
|
||||
_backlight_level = 255;
|
||||
_backlight_pin = TFT_BCKL;
|
||||
|
||||
/* fill unique identifier with wifi mac */
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
_hardware_id.reserve(13);
|
||||
for(int i = 0; i < 6; ++i) {
|
||||
if(mac[i] < 0x10) _hardware_id += "0";
|
||||
_hardware_id += String(mac[i], HEX).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
void Esp32Device::reboot()
|
||||
{
|
||||
ESP.restart();
|
||||
@ -76,6 +95,11 @@ const char* Esp32Device::get_chip_model()
|
||||
// model += chip_info.revision;
|
||||
}
|
||||
|
||||
const char* Esp32Device::get_hardware_id()
|
||||
{
|
||||
return _hardware_id.c_str();
|
||||
}
|
||||
|
||||
void Esp32Device::set_backlight_pin(uint8_t pin)
|
||||
{
|
||||
_backlight_pin = pin;
|
||||
|
@ -14,14 +14,8 @@ namespace dev {
|
||||
class Esp32Device : public BaseDevice {
|
||||
|
||||
public:
|
||||
Esp32Device()
|
||||
{
|
||||
_hostname = MQTT_NODENAME;
|
||||
_backlight_invert = (TFT_BACKLIGHT_ON == LOW);
|
||||
_backlight_power = 1;
|
||||
_backlight_level = 255;
|
||||
_backlight_pin = TFT_BCKL;
|
||||
}
|
||||
Esp32Device();
|
||||
|
||||
void reboot() override;
|
||||
void show_info() override;
|
||||
|
||||
@ -29,6 +23,7 @@ class Esp32Device : public BaseDevice {
|
||||
void set_hostname(const char*);
|
||||
const char* get_core_version();
|
||||
const char* get_chip_model();
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin) override;
|
||||
void set_backlight_level(uint8_t val) override;
|
||||
@ -45,6 +40,7 @@ class Esp32Device : public BaseDevice {
|
||||
|
||||
private:
|
||||
std::string _hostname;
|
||||
std::string _hardware_id;
|
||||
|
||||
uint8_t _backlight_pin;
|
||||
uint8_t _backlight_level;
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Esp.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
#include "esp8266.h"
|
||||
|
||||
@ -15,6 +16,25 @@
|
||||
|
||||
namespace dev {
|
||||
|
||||
Esp8266Device::Esp8266Device()
|
||||
{
|
||||
_hostname = MQTT_NODENAME;
|
||||
_backlight_invert = (TFT_BACKLIGHT_ON == LOW);
|
||||
_backlight_power = 1;
|
||||
_backlight_level = 255;
|
||||
_core_version = ESP.getCoreVersion().c_str();
|
||||
_backlight_pin = TFT_BCKL;
|
||||
|
||||
/* fill unique identifier with wifi mac */
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
_hardware_id.reserve(13);
|
||||
for(int i = 0; i < 6; ++i) {
|
||||
if(mac[i] < 0x10) _hardware_id += "0";
|
||||
_hardware_id += String(mac[i], HEX).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
void Esp8266Device::reboot()
|
||||
{
|
||||
ESP.restart();
|
||||
@ -46,6 +66,11 @@ const char* Esp8266Device::get_chip_model()
|
||||
return "ESP8266";
|
||||
}
|
||||
|
||||
const char* Esp8266Device::get_hardware_id()
|
||||
{
|
||||
return _hardware_id.c_str();
|
||||
}
|
||||
|
||||
void Esp8266Device::set_backlight_pin(uint8_t pin)
|
||||
{
|
||||
_backlight_pin = pin;
|
||||
|
@ -14,15 +14,7 @@ namespace dev {
|
||||
class Esp8266Device : public BaseDevice {
|
||||
|
||||
public:
|
||||
Esp8266Device()
|
||||
{
|
||||
_hostname = MQTT_NODENAME;
|
||||
_backlight_invert = (TFT_BACKLIGHT_ON == LOW);
|
||||
_backlight_power = 1;
|
||||
_backlight_level = 255;
|
||||
_core_version = ESP.getCoreVersion().c_str();
|
||||
_backlight_pin = TFT_BCKL;
|
||||
}
|
||||
Esp8266Device();
|
||||
|
||||
void reboot() override;
|
||||
void show_info() override;
|
||||
@ -31,6 +23,7 @@ class Esp8266Device : public BaseDevice {
|
||||
void set_hostname(const char*);
|
||||
const char* get_core_version();
|
||||
const char* get_chip_model();
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin) override;
|
||||
void set_backlight_level(uint8_t val) override;
|
||||
@ -47,6 +40,7 @@ class Esp8266Device : public BaseDevice {
|
||||
|
||||
private:
|
||||
std::string _hostname;
|
||||
std::string _hardware_id;
|
||||
std::string _core_version;
|
||||
|
||||
uint8_t _backlight_pin;
|
||||
|
@ -66,21 +66,29 @@ const char* PosixDevice::get_hostname()
|
||||
{
|
||||
return _hostname.c_str();
|
||||
}
|
||||
|
||||
void PosixDevice::set_hostname(const char* hostname)
|
||||
{
|
||||
_hostname = hostname;
|
||||
monitor_title(hostname);
|
||||
// SDL_SetWindowTitle(monitor.window, hostname);
|
||||
}
|
||||
|
||||
const char* PosixDevice::get_core_version()
|
||||
{
|
||||
return _core_version.c_str();
|
||||
}
|
||||
|
||||
const char* PosixDevice::get_chip_model()
|
||||
{
|
||||
return _chip_model.c_str();
|
||||
}
|
||||
|
||||
const char* PosixDevice::get_hardware_id()
|
||||
{
|
||||
return "223344556677";
|
||||
}
|
||||
|
||||
void PosixDevice::set_backlight_pin(uint8_t pin)
|
||||
{
|
||||
// PosixDevice::backlight_pin = pin;
|
||||
|
@ -38,6 +38,7 @@ class PosixDevice : public BaseDevice {
|
||||
void set_hostname(const char*);
|
||||
const char* get_core_version();
|
||||
const char* get_chip_model();
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin);
|
||||
void set_backlight_level(uint8_t val);
|
||||
|
@ -30,6 +30,7 @@ const char* Stm32f4Device::get_hostname()
|
||||
{
|
||||
return _hostname.c_str();
|
||||
}
|
||||
|
||||
void Stm32f4Device::set_hostname(const char* hostname)
|
||||
{
|
||||
_hostname = hostname;
|
||||
@ -40,6 +41,14 @@ const char* Stm32f4Device::get_core_version()
|
||||
// return ESP.getCoreVersion().c_str();
|
||||
}
|
||||
|
||||
const char* Stm32f4Device::get_hardware_id()
|
||||
{
|
||||
// https://stm32duinoforum.com/forum/viewtopic_f_29_t_2909_start_10.html
|
||||
// Serial.println("UID [HEX] : "+String(*(uint32_t*)(UID_BASE), HEX)+" "+String(*(uint32_t*)(UID_BASE+0x04),
|
||||
// HEX)+" "+String(*(uint32_t*)(UID_BASE+0x08), HEX));
|
||||
return _hardware_id.c_str();
|
||||
}
|
||||
|
||||
void Stm32f4Device::set_backlight_pin(uint8_t pin)
|
||||
{
|
||||
_backlight_pin = pin;
|
||||
|
@ -30,6 +30,7 @@ class Stm32f4Device : public BaseDevice {
|
||||
void set_hostname(const char*);
|
||||
const char* get_core_version();
|
||||
const char* get_chip_model();
|
||||
const char* get_chip_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin) override;
|
||||
void set_backlight_level(uint8_t val) override;
|
||||
@ -46,6 +47,7 @@ class Stm32f4Device : public BaseDevice {
|
||||
|
||||
private:
|
||||
std::string _hostname;
|
||||
std::string _hardware_id;
|
||||
|
||||
uint8_t _backlight_pin;
|
||||
uint8_t _backlight_level;
|
||||
|
@ -55,11 +55,17 @@ const char* Win32Device::get_core_version()
|
||||
{
|
||||
return _core_version.c_str();
|
||||
}
|
||||
|
||||
const char* Win32Device::get_chip_model()
|
||||
{
|
||||
return "SDL2";
|
||||
}
|
||||
|
||||
const char* Win32Device::get_hardware_id()
|
||||
{
|
||||
return "112233445566";
|
||||
}
|
||||
|
||||
void Win32Device::set_backlight_pin(uint8_t pin)
|
||||
{
|
||||
// Win32Device::_backlight_pin = pin;
|
||||
|
@ -59,6 +59,7 @@ class Win32Device : public BaseDevice {
|
||||
void set_hostname(const char*);
|
||||
const char* get_core_version();
|
||||
const char* get_chip_model();
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin);
|
||||
void set_backlight_level(uint8_t val);
|
||||
|
Loading…
x
Reference in New Issue
Block a user