mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Allow choosing fbdev and evdev names, load POSIX settings from config
This commit is contained in:
parent
a0c8fd49d4
commit
4c20d6a4b9
@ -23,6 +23,7 @@
|
||||
#include "display/monitor.h"
|
||||
#elif USE_FBDEV
|
||||
#include "display/fbdev.h"
|
||||
#include "drv/tft/tft_driver.h"
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
@ -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<std::string>()) {
|
||||
haspTft.fbdev_path = "/dev/" + settings["fbdev"].as<std::string>();
|
||||
}
|
||||
#if USE_EVDEV
|
||||
if(settings["evdev"].is<std::string>()) {
|
||||
haspTft.evdev_names.push_back(settings["evdev"].as<std::string>());
|
||||
}
|
||||
if(settings["evdevs"].is<JsonArray>()) {
|
||||
for(auto v : settings["evdevs"].as<JsonArray>()) {
|
||||
haspTft.evdev_names.push_back(v.as<std::string>());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if(settings["bldev"].is<std::string>()) {
|
||||
haspDevice.backlight_device = settings["bldev"].as<std::string>();
|
||||
}
|
||||
if(settings["blmax"].is<int>()) {
|
||||
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;
|
||||
|
@ -31,6 +31,8 @@ class PosixDevice : public BaseDevice {
|
||||
public:
|
||||
PosixDevice();
|
||||
|
||||
void set_config(const JsonObject& settings);
|
||||
|
||||
void reboot() override;
|
||||
void show_info() override;
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <algorithm>
|
||||
|
||||
#if USE_BSD_EVDEV
|
||||
#include <dev/evdev/input.h>
|
||||
@ -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/");
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
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<std::string> evdev_names;
|
||||
|
||||
private:
|
||||
int32_t _width, _height;
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -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++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user