mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Update device drivers
This commit is contained in:
parent
cc4cc54c22
commit
748fe57334
@ -1,3 +1,6 @@
|
|||||||
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
#if defined(LANBONL8)
|
#if defined(LANBONL8)
|
||||||
|
@ -39,6 +39,8 @@ class BaseDevice {
|
|||||||
|
|
||||||
virtual void init()
|
virtual void init()
|
||||||
{}
|
{}
|
||||||
|
virtual void show_info()
|
||||||
|
{}
|
||||||
virtual void post_setup()
|
virtual void post_setup()
|
||||||
{}
|
{}
|
||||||
virtual void loop()
|
virtual void loop()
|
||||||
@ -60,13 +62,21 @@ class BaseDevice {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
virtual size_t get_free_max_block()
|
virtual size_t get_free_max_block()
|
||||||
{}
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
virtual size_t get_free_heap()
|
virtual size_t get_free_heap()
|
||||||
{}
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
virtual uint8_t get_heap_fragmentation()
|
virtual uint8_t get_heap_fragmentation()
|
||||||
{}
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
virtual uint16_t get_cpu_frequency()
|
virtual uint16_t get_cpu_frequency()
|
||||||
{}
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dev
|
} // namespace dev
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
@ -23,6 +26,13 @@ void Esp32Device::reboot()
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Esp32Device::show_info()
|
||||||
|
{
|
||||||
|
LOG_VERBOSE(TAG_DEV, F("Processor : ESP32"));
|
||||||
|
LOG_VERBOSE(TAG_DEV, F("CPU freq. : %i MHz"), get_cpu_frequency());
|
||||||
|
// LOG_VERBOSE(TAG_DEV, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
|
||||||
|
}
|
||||||
|
|
||||||
const char* Esp32Device::get_hostname()
|
const char* Esp32Device::get_hostname()
|
||||||
{
|
{
|
||||||
return _hostname.c_str();
|
return _hostname.c_str();
|
||||||
|
@ -21,6 +21,7 @@ class Esp32Device : public BaseDevice {
|
|||||||
_backlight_level = 100;
|
_backlight_level = 100;
|
||||||
}
|
}
|
||||||
void reboot() override;
|
void reboot() override;
|
||||||
|
void show_info() override;
|
||||||
|
|
||||||
const char* get_hostname();
|
const char* get_hostname();
|
||||||
void set_hostname(const char*);
|
void set_hostname(const char*);
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
#include "lanbonl8.h"
|
#include "lanbonl8.h"
|
||||||
|
|
||||||
#if defined(LANBONL8)
|
#if defined(LANBONL8)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
#include "m5stackcore2.h"
|
#include "m5stackcore2.h"
|
||||||
|
|
||||||
#if defined(M5STACK)
|
#if defined(M5STACK)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
@ -17,6 +20,13 @@ void Esp8266Device::reboot()
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Esp8266Device::show_info()
|
||||||
|
{
|
||||||
|
LOG_VERBOSE(TAG_DEV, F("Processor : ESP8266"));
|
||||||
|
LOG_VERBOSE(TAG_DEV, F("CPU freq. : %i MHz"), get_cpu_frequency());
|
||||||
|
LOG_VERBOSE(TAG_DEV, F("Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined
|
||||||
|
}
|
||||||
|
|
||||||
const char* Esp8266Device::get_hostname()
|
const char* Esp8266Device::get_hostname()
|
||||||
{
|
{
|
||||||
return _hostname.c_str();
|
return _hostname.c_str();
|
||||||
@ -32,7 +42,7 @@ void Esp8266Device::set_backlight_pin(uint8_t pin)
|
|||||||
/* Setup Backlight Control Pin */
|
/* Setup Backlight Control Pin */
|
||||||
if(pin >= 0) {
|
if(pin >= 0) {
|
||||||
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
|
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
|
||||||
pinMode(backlight_pin, OUTPUT);
|
pinMode(_backlight_pin, OUTPUT);
|
||||||
update_backlight();
|
update_backlight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,7 +50,7 @@ void Esp8266Device::set_backlight_pin(uint8_t pin)
|
|||||||
void Esp8266Device::set_backlight_level(uint8_t level)
|
void Esp8266Device::set_backlight_level(uint8_t level)
|
||||||
{
|
{
|
||||||
_backlight_level = level >= 0 ? level : 0;
|
_backlight_level = level >= 0 ? level : 0;
|
||||||
_backlight_level = _backlight_level <= 100 ? backlight_level : 100;
|
_backlight_level = _backlight_level <= 100 ? _backlight_level : 100;
|
||||||
|
|
||||||
update_backlight();
|
update_backlight();
|
||||||
}
|
}
|
||||||
@ -65,7 +75,7 @@ void Esp8266Device::update_backlight()
|
|||||||
{
|
{
|
||||||
if(_backlight_pin == -1) return;
|
if(_backlight_pin == -1) return;
|
||||||
|
|
||||||
analogWrite(backlight_pin, _backlight_power ? map(_backlight_level, 0, 100, 0, 1023) : 0);
|
analogWrite(_backlight_pin, _backlight_power ? map(_backlight_level, 0, 100, 0, 1023) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Esp8266Device::get_free_max_block()
|
size_t Esp8266Device::get_free_max_block()
|
||||||
|
@ -16,13 +16,14 @@ class Esp8266Device : public BaseDevice {
|
|||||||
public:
|
public:
|
||||||
Esp8266Device()
|
Esp8266Device()
|
||||||
{
|
{
|
||||||
hostname = "plate";
|
_hostname = "plate";
|
||||||
backlight_pin = TFT_BCKL;
|
_backlight_pin = TFT_BCKL;
|
||||||
backlight_power = 1;
|
_backlight_power = 1;
|
||||||
backlight_level = 100;
|
_backlight_level = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reboot() override;
|
void reboot() override;
|
||||||
|
void show_info() override;
|
||||||
|
|
||||||
const char* get_hostname();
|
const char* get_hostname();
|
||||||
void set_hostname(const char*);
|
void set_hostname(const char*);
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
#if defined(WINDOWS)
|
#if defined(WINDOWS)
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@ -6,16 +9,39 @@
|
|||||||
#include "hasp_win32.h"
|
#include "hasp_win32.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
#include "hasp_debug.h"
|
|
||||||
#include "hasp/hasp_utilities.h"
|
#include "hasp/hasp_utilities.h"
|
||||||
|
#include "hasp_debug.h"
|
||||||
|
|
||||||
#include "display/monitor.h"
|
#include "display/monitor.h"
|
||||||
|
|
||||||
namespace dev {
|
namespace dev {
|
||||||
|
|
||||||
|
static inline void native_cpuid(unsigned int* eax, unsigned int* ebx, unsigned int* ecx, unsigned int* edx)
|
||||||
|
{
|
||||||
|
/* ecx is often an input as well as an output. */
|
||||||
|
asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "0"(*eax), "2"(*ecx) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
void Win32Device::reboot()
|
void Win32Device::reboot()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void Win32Device::show_info()
|
||||||
|
{
|
||||||
|
|
||||||
|
unsigned int eax, ebx, ecx, edx;
|
||||||
|
eax = 0;
|
||||||
|
native_cpuid(&eax, &ebx, &ecx, &edx);
|
||||||
|
printf("EAX: %08X EBX: %08X ECX: %08X EDX: %08X\n", eax, ebx, ecx, edx);
|
||||||
|
char vendor[13];
|
||||||
|
memcpy(vendor, &ebx, 4);
|
||||||
|
memcpy(vendor + 4, &edx, 4);
|
||||||
|
memcpy(vendor + 8, &ecx, 4);
|
||||||
|
vendor[12] = '\0';
|
||||||
|
|
||||||
|
LOG_VERBOSE(0, F("Processor : %s"), vendor);
|
||||||
|
LOG_VERBOSE(0, F("CPU freq. : %i MHz"), get_cpu_frequency());
|
||||||
|
}
|
||||||
|
|
||||||
const char* Win32Device::get_hostname()
|
const char* Win32Device::get_hostname()
|
||||||
{
|
{
|
||||||
return _hostname.c_str();
|
return _hostname.c_str();
|
||||||
@ -77,7 +103,10 @@ size_t Win32Device::get_free_max_block()
|
|||||||
|
|
||||||
size_t Win32Device::get_free_heap(void)
|
size_t Win32Device::get_free_heap(void)
|
||||||
{
|
{
|
||||||
return 0;
|
MEMORYSTATUSEX status;
|
||||||
|
status.dwLength = sizeof(status);
|
||||||
|
GlobalMemoryStatusEx(&status);
|
||||||
|
return status.ullAvailPhys;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Win32Device::get_heap_fragmentation()
|
uint8_t Win32Device::get_heap_fragmentation()
|
||||||
|
@ -20,13 +20,28 @@ class Win32Device : public BaseDevice {
|
|||||||
public:
|
public:
|
||||||
Win32Device()
|
Win32Device()
|
||||||
{
|
{
|
||||||
_hostname = "winplate";
|
char buffer[MAX_COMPUTERNAME_LENGTH + 1];
|
||||||
|
DWORD length = sizeof(buffer);
|
||||||
|
|
||||||
|
if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNameNetBIOS, buffer, &length)) {
|
||||||
|
_hostname = buffer;
|
||||||
|
} else if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNameDnsHostname, buffer, &length)) {
|
||||||
|
_hostname = buffer;
|
||||||
|
} else if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNamePhysicalDnsHostname, buffer, &length)) {
|
||||||
|
_hostname = buffer;
|
||||||
|
} else if(GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNamePhysicalDnsDomain, buffer, &length)) {
|
||||||
|
_hostname = buffer;
|
||||||
|
} else {
|
||||||
|
_hostname = "localhost";
|
||||||
|
}
|
||||||
|
|
||||||
// _backlight_pin = -1;
|
// _backlight_pin = -1;
|
||||||
_backlight_power = 1;
|
_backlight_power = 1;
|
||||||
_backlight_level = 100;
|
_backlight_level = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reboot() override;
|
void reboot() override;
|
||||||
|
void show_info() override;
|
||||||
|
|
||||||
const char* get_hostname();
|
const char* get_hostname();
|
||||||
void set_hostname(const char*);
|
void set_hostname(const char*);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user