From 748fe573346491c459617be3003010354189c759 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:48:41 +0100 Subject: [PATCH] Update device drivers --- src/dev/device.cpp | 3 +++ src/dev/device.h | 18 ++++++++++++++---- src/dev/esp32/esp32.cpp | 10 ++++++++++ src/dev/esp32/esp32.h | 1 + src/dev/esp32/lanbonl8.cpp | 3 +++ src/dev/esp32/m5stackcore2.cpp | 3 +++ src/dev/esp8266/esp8266.cpp | 16 +++++++++++++--- src/dev/esp8266/esp8266.h | 9 +++++---- src/dev/win32/hasp_win32.cpp | 33 +++++++++++++++++++++++++++++++-- src/dev/win32/hasp_win32.h | 17 ++++++++++++++++- 10 files changed, 99 insertions(+), 14 deletions(-) diff --git a/src/dev/device.cpp b/src/dev/device.cpp index ce356046..7bee8627 100644 --- a/src/dev/device.cpp +++ b/src/dev/device.cpp @@ -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" #if defined(LANBONL8) diff --git a/src/dev/device.h b/src/dev/device.h index ac2524a3..13989e04 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -39,6 +39,8 @@ class BaseDevice { virtual void init() {} + virtual void show_info() + {} virtual void post_setup() {} virtual void loop() @@ -60,13 +62,21 @@ class BaseDevice { return true; } virtual size_t get_free_max_block() - {} + { + return 0; + } virtual size_t get_free_heap() - {} + { + return 0; + } virtual uint8_t get_heap_fragmentation() - {} + { + return 0; + } virtual uint16_t get_cpu_frequency() - {} + { + return 0; + } }; } // namespace dev diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index f9ef5ff1..bde329ea 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -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) #include "Arduino.h" @@ -23,6 +26,13 @@ void Esp32Device::reboot() 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() { return _hostname.c_str(); diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index d7627047..5cdb4f90 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -21,6 +21,7 @@ class Esp32Device : public BaseDevice { _backlight_level = 100; } void reboot() override; + void show_info() override; const char* get_hostname(); void set_hostname(const char*); diff --git a/src/dev/esp32/lanbonl8.cpp b/src/dev/esp32/lanbonl8.cpp index e72c21c5..39b7a182 100644 --- a/src/dev/esp32/lanbonl8.cpp +++ b/src/dev/esp32/lanbonl8.cpp @@ -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" #if defined(LANBONL8) diff --git a/src/dev/esp32/m5stackcore2.cpp b/src/dev/esp32/m5stackcore2.cpp index e86bb404..f4da47ab 100644 --- a/src/dev/esp32/m5stackcore2.cpp +++ b/src/dev/esp32/m5stackcore2.cpp @@ -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" #if defined(M5STACK) diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index 95a9c08a..a4ce90ad 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -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) #include "Arduino.h" @@ -17,6 +20,13 @@ void Esp8266Device::reboot() 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() { return _hostname.c_str(); @@ -32,7 +42,7 @@ void Esp8266Device::set_backlight_pin(uint8_t pin) /* Setup Backlight Control Pin */ if(pin >= 0) { LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); - pinMode(backlight_pin, OUTPUT); + pinMode(_backlight_pin, OUTPUT); update_backlight(); } } @@ -40,7 +50,7 @@ void Esp8266Device::set_backlight_pin(uint8_t pin) void Esp8266Device::set_backlight_level(uint8_t level) { _backlight_level = level >= 0 ? level : 0; - _backlight_level = _backlight_level <= 100 ? backlight_level : 100; + _backlight_level = _backlight_level <= 100 ? _backlight_level : 100; update_backlight(); } @@ -65,7 +75,7 @@ void Esp8266Device::update_backlight() { 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() diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index 4ef5421c..05a02e1a 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -16,13 +16,14 @@ class Esp8266Device : public BaseDevice { public: Esp8266Device() { - hostname = "plate"; - backlight_pin = TFT_BCKL; - backlight_power = 1; - backlight_level = 100; + _hostname = "plate"; + _backlight_pin = TFT_BCKL; + _backlight_power = 1; + _backlight_level = 100; } void reboot() override; + void show_info() override; const char* get_hostname(); void set_hostname(const char*); diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index c75f36dc..dd2c8906 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -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) #include @@ -6,16 +9,39 @@ #include "hasp_win32.h" #include "hasp_conf.h" -#include "hasp_debug.h" #include "hasp/hasp_utilities.h" +#include "hasp_debug.h" #include "display/monitor.h" 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::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() { return _hostname.c_str(); @@ -77,7 +103,10 @@ size_t Win32Device::get_free_max_block() 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() diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index 0788bd48..ae7015a0 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -20,13 +20,28 @@ class Win32Device : public BaseDevice { public: 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_power = 1; _backlight_level = 100; } void reboot() override; + void show_info() override; const char* get_hostname(); void set_hostname(const char*);