diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index e19e3c2e..8d864cf7 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -23,6 +23,7 @@ #include "display/monitor.h" #elif USE_FBDEV #include "display/fbdev.h" +#include "drv/tft/tft_driver.h" #endif #include @@ -54,6 +55,32 @@ PosixDevice::PosixDevice() _backlight_level = 255; } +void PosixDevice::set_config(const JsonObject& settings) +{ + configOutput(settings, 0); +#if USE_FBDEV + if(settings["fbdev"].is()) { + haspTft.fbdev_path = "/dev/" + settings["fbdev"].as(); + } +#if USE_EVDEV + if(settings["evdev"].is()) { + haspTft.evdev_names.push_back(settings["evdev"].as()); + } + if(settings["evdevs"].is()) { + for(auto v : settings["evdevs"].as()) { + haspTft.evdev_names.push_back(v.as()); + } + } +#endif + if(settings["bldev"].is()) { + haspDevice.backlight_device = settings["bldev"].as(); + } + if(settings["blmax"].is()) { + haspDevice.backlight_max = settings["blmax"]; + } +#endif +} + void PosixDevice::reboot() {} void PosixDevice::show_info() @@ -254,8 +281,8 @@ unsigned long PosixMillis() { struct timespec spec; clock_gettime(CLOCK_REALTIME, &spec); - if (tv_sec_start == 0) { - tv_sec_start = spec.tv_sec; + if(tv_sec_start == 0) { + tv_sec_start = spec.tv_sec; } unsigned long msec1 = (spec.tv_sec - tv_sec_start) * 1000; unsigned long msec2 = spec.tv_nsec / 1e6; diff --git a/src/dev/posix/hasp_posix.h b/src/dev/posix/hasp_posix.h index 7e7d6275..439d4c12 100644 --- a/src/dev/posix/hasp_posix.h +++ b/src/dev/posix/hasp_posix.h @@ -31,6 +31,8 @@ class PosixDevice : public BaseDevice { public: PosixDevice(); + void set_config(const JsonObject& settings); + void reboot() override; void show_info() override; diff --git a/src/drv/tft/tft_driver_posix_fbdev.cpp b/src/drv/tft/tft_driver_posix_fbdev.cpp index 79706c49..955903f8 100644 --- a/src/drv/tft/tft_driver_posix_fbdev.cpp +++ b/src/drv/tft/tft_driver_posix_fbdev.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #if USE_BSD_EVDEV #include @@ -83,7 +84,7 @@ void TftFbdevDrv::init(int32_t w, int h) /* Add a display * Use the 'fbdev' driver which uses POSIX framebuffer device as a display * The following input devices are handled: mouse, keyboard, mousewheel */ - fbdev_init(); + fbdev_init(fbdev_path.empty() ? NULL : fbdev_path.c_str()); fbdev_get_sizes((uint32_t*)&_width, (uint32_t*)&_height); // show the splashscreen early @@ -104,6 +105,10 @@ void TftFbdevDrv::init(int32_t w, int h) // make sure it's a block device matching /dev/input/event* if(strncmp(dirent->d_name, "event", 5) != 0 || strlen(dirent->d_name) <= 5) continue; if(dirent->d_type != DT_CHR) continue; + // skip device if not specified on command line + if(!evdev_names.empty() && + std::find(evdev_names.begin(), evdev_names.end(), std::string(dirent->d_name)) == evdev_names.end()) + continue; // get full path char dev_path[64]; strcpy(dev_path, "/dev/input/"); diff --git a/src/drv/tft/tft_driver_posix_fbdev.h b/src/drv/tft/tft_driver_posix_fbdev.h index 5856f892..643126bf 100644 --- a/src/drv/tft/tft_driver_posix_fbdev.h +++ b/src/drv/tft/tft_driver_posix_fbdev.h @@ -11,6 +11,8 @@ #include "lvgl.h" +#include + namespace dev { class TftFbdevDrv : BaseTft { @@ -30,6 +32,10 @@ class TftFbdevDrv : BaseTft { int32_t width(); int32_t height(); + public: + std::string fbdev_path; + std::vector evdev_names; + private: int32_t _width, _height; }; diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 559c3f0a..4bdb7c80 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -636,6 +636,12 @@ void configSetup() gpioSetConfig(settings[FPSTR(FP_GPIO)]); #endif + // target-specific config +#if defined(POSIX) + LOG_INFO(TAG_CONF, F("Loading POSIX-specific settings")); + haspDevice.set_config(settings[F("posix")]); +#endif + LOG_INFO(TAG_CONF, F(D_CONFIG_LOADED)); } // #endif diff --git a/src/main_pc.cpp b/src/main_pc.cpp index ad851d1b..63d3d2bb 100644 --- a/src/main_pc.cpp +++ b/src/main_pc.cpp @@ -112,17 +112,15 @@ void usage(const char* progName, const char* version) << std::endl << "Options:" << std::endl << " -h | --help Print this help" << std::endl +#if !USE_FBDEV << " -W | --width Width of the window" << std::endl << " -H | --height Height of the window" << std::endl - << " -C | --config Configuration directory" << std::endl +#endif + << " -c | --config Configuration/storage directory" << std::endl #if defined(WINDOWS) << " (default: 'AppData\\hasp\\hasp')" << std::endl #elif defined(POSIX) << " (default: '~/.local/share/hasp/hasp')" << std::endl -#endif -#if USE_FBDEV && defined(POSIX) - << " -b | --backlight Backlight device name (in /sys/class/backlight/)" << std::endl - << " -B | --bl-max Backlight brightness limit (default: max_brightness)" << std::endl #endif << std::endl; fflush(stdout); @@ -142,25 +140,7 @@ int main(int argc, char* argv[]) for(int arg = 1; arg < argc; arg++) { if(strncmp(argv[arg], "--help", 6) == 0 || strncmp(argv[arg], "-h", 2) == 0) { showhelp = true; -#if USE_FBDEV && defined(POSIX) - } else if(strncmp(argv[arg], "--backlight", 11) == 0 || strncmp(argv[arg], "-b", 2) == 0) { - if(arg + 1 < argc) { - haspDevice.backlight_device = argv[arg + 1]; - arg++; - } else { - std::cout << "Missing device name" << std::endl; - showhelp = true; - } - } else if(strncmp(argv[arg], "--bl-max", 9) == 0 || strncmp(argv[arg], "-B", 2) == 0) { - if(arg + 1 < argc) { - int bl_max = atoi(argv[arg + 1]); - if(bl_max > 0) haspDevice.backlight_max = bl_max; - arg++; - } else { - std::cout << "Missing backlight level" << std::endl; - showhelp = true; - } -#endif +#if !USE_FBDEV } else if(strncmp(argv[arg], "--width", 7) == 0 || strncmp(argv[arg], "-W", 2) == 0) { if(arg + 1 < argc) { int w = atoi(argv[arg + 1]); @@ -179,7 +159,8 @@ int main(int argc, char* argv[]) std::cout << "Missing height value" << std::endl; showhelp = true; } - } else if(strncmp(argv[arg], "--config", 8) == 0 || strncmp(argv[arg], "-C", 2) == 0) { +#endif + } else if(strncmp(argv[arg], "--config", 8) == 0 || strncmp(argv[arg], "-c", 2) == 0) { if(arg + 1 < argc) { strcpy(config, argv[arg + 1]); arg++;