Initialize default device info

This commit is contained in:
fvanroie 2021-03-09 22:19:27 +01:00
parent 51981a56db
commit 5b21c715ff
3 changed files with 31 additions and 32 deletions

View File

@ -15,11 +15,34 @@
namespace dev {
PosixDevice::PosixDevice() {
struct utsname uts;
if (uname(&uts) < 0) {
LOG_ERROR(0,"uname() error");
_hostname = "localhost";
_core_version = "unknown";
} else {
// LOG_VERBOSE(0,"Sysname: %s", uts.sysname);
// LOG_VERBOSE(0,"Nodename: %s", uts.nodename);
// LOG_VERBOSE(0,"Release: %s", uts.release);
// LOG_VERBOSE(0,"Version: %s", uts.version);
// LOG_VERBOSE(0,"Machine: %s", uts.machine);
char version[128];
snprintf(version, sizeof(version), "%s %s", uts.sysname, uts.release);
_core_version = version;
_hostname = uts.nodename;
}
_backlight_power = 1;
_backlight_level = 100;
}
void PosixDevice::reboot()
{}
void PosixDevice::show_info()
{
struct utsname uts;
if (uname(&uts) < 0) {
@ -49,7 +72,7 @@ void PosixDevice::set_hostname(const char* hostname)
}
const char* PosixDevice::get_core_version()
{
return "posix";
return _core_version.c_str();
}
const char* PosixDevice::get_display_driver()
{

View File

@ -6,11 +6,13 @@
#include <cstdint>
#include <cstddef>
extern "C"
{
#include <inttypes.h>
#include <stdlib.h>
#include <stddef.h>
#include <sys/utsname.h>
}
#include "hasp_conf.h"
@ -28,12 +30,7 @@ namespace dev {
class PosixDevice : public BaseDevice {
public:
PosixDevice()
{
_hostname = "localhost";
_backlight_power = 1;
_backlight_level = 100;
}
PosixDevice();
void reboot() override;
void show_info() override;
@ -58,6 +55,7 @@ class PosixDevice : public BaseDevice {
private:
std::string _hostname;
std::string _core_version;
uint8_t _backlight_pin;
uint8_t _backlight_level;

View File

@ -112,7 +112,8 @@ void setup()
lv_log_register_print_cb(debugLvglLogEvent);
lv_init();
haspDevice.init(); // hardware setup
haspDevice.init(); // hardware setup
haspDevice.show_info(); // debug info
// hal_setup();
guiSetup();
@ -204,29 +205,6 @@ int main(int argc, char* argv[])
InitializeConsoleOutput();
#endif
haspDevice.show_info();
char hostbuffer[256];
char* IPbuffer;
struct hostent* host_entry;
int hostname;
// To retrieve hostname
hostname = gethostname(hostbuffer, sizeof(hostbuffer));
// checkHostName(hostname);
// To retrieve host information
host_entry = gethostbyname(hostbuffer);
// checkHostEntry(host_entry);
haspDevice.set_hostname(hostbuffer);
// To convert an Internet network
// address into ASCII string
// IPbuffer = inet_ntoa(*((struct in_addr*)host_entry->h_addr_list[0]));
printf("Hostname: %s", hostbuffer);
// printf("Host IP: %s", IPbuffer);
// Display each command-line argument.
std::cout << "\nCommand-line arguments:\n";
for(count = 0; count < argc; count++)