mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +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"
|
#include "display/monitor.h"
|
||||||
#elif USE_FBDEV
|
#elif USE_FBDEV
|
||||||
#include "display/fbdev.h"
|
#include "display/fbdev.h"
|
||||||
|
#include "drv/tft/tft_driver.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -54,6 +55,32 @@ PosixDevice::PosixDevice()
|
|||||||
_backlight_level = 255;
|
_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::reboot()
|
||||||
{}
|
{}
|
||||||
void PosixDevice::show_info()
|
void PosixDevice::show_info()
|
||||||
|
@ -31,6 +31,8 @@ class PosixDevice : public BaseDevice {
|
|||||||
public:
|
public:
|
||||||
PosixDevice();
|
PosixDevice();
|
||||||
|
|
||||||
|
void set_config(const JsonObject& settings);
|
||||||
|
|
||||||
void reboot() override;
|
void reboot() override;
|
||||||
void show_info() override;
|
void show_info() override;
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#if USE_BSD_EVDEV
|
#if USE_BSD_EVDEV
|
||||||
#include <dev/evdev/input.h>
|
#include <dev/evdev/input.h>
|
||||||
@ -83,7 +84,7 @@ void TftFbdevDrv::init(int32_t w, int h)
|
|||||||
/* Add a display
|
/* Add a display
|
||||||
* Use the 'fbdev' driver which uses POSIX framebuffer device as a display
|
* Use the 'fbdev' driver which uses POSIX framebuffer device as a display
|
||||||
* The following input devices are handled: mouse, keyboard, mousewheel */
|
* 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);
|
fbdev_get_sizes((uint32_t*)&_width, (uint32_t*)&_height);
|
||||||
|
|
||||||
// show the splashscreen early
|
// 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*
|
// 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(strncmp(dirent->d_name, "event", 5) != 0 || strlen(dirent->d_name) <= 5) continue;
|
||||||
if(dirent->d_type != DT_CHR) 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
|
// get full path
|
||||||
char dev_path[64];
|
char dev_path[64];
|
||||||
strcpy(dev_path, "/dev/input/");
|
strcpy(dev_path, "/dev/input/");
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace dev {
|
namespace dev {
|
||||||
|
|
||||||
class TftFbdevDrv : BaseTft {
|
class TftFbdevDrv : BaseTft {
|
||||||
@ -30,6 +32,10 @@ class TftFbdevDrv : BaseTft {
|
|||||||
int32_t width();
|
int32_t width();
|
||||||
int32_t height();
|
int32_t height();
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string fbdev_path;
|
||||||
|
std::vector<std::string> evdev_names;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32_t _width, _height;
|
int32_t _width, _height;
|
||||||
};
|
};
|
||||||
|
@ -636,6 +636,12 @@ void configSetup()
|
|||||||
gpioSetConfig(settings[FPSTR(FP_GPIO)]);
|
gpioSetConfig(settings[FPSTR(FP_GPIO)]);
|
||||||
#endif
|
#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));
|
LOG_INFO(TAG_CONF, F(D_CONFIG_LOADED));
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
@ -112,17 +112,15 @@ void usage(const char* progName, const char* version)
|
|||||||
<< std::endl
|
<< std::endl
|
||||||
<< "Options:" << std::endl
|
<< "Options:" << std::endl
|
||||||
<< " -h | --help Print this help" << std::endl
|
<< " -h | --help Print this help" << std::endl
|
||||||
|
#if !USE_FBDEV
|
||||||
<< " -W | --width Width of the window" << std::endl
|
<< " -W | --width Width of the window" << std::endl
|
||||||
<< " -H | --height Height 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)
|
#if defined(WINDOWS)
|
||||||
<< " (default: 'AppData\\hasp\\hasp')" << std::endl
|
<< " (default: 'AppData\\hasp\\hasp')" << std::endl
|
||||||
#elif defined(POSIX)
|
#elif defined(POSIX)
|
||||||
<< " (default: '~/.local/share/hasp/hasp')" << std::endl
|
<< " (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
|
#endif
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -142,25 +140,7 @@ int main(int argc, char* argv[])
|
|||||||
for(int arg = 1; arg < argc; arg++) {
|
for(int arg = 1; arg < argc; arg++) {
|
||||||
if(strncmp(argv[arg], "--help", 6) == 0 || strncmp(argv[arg], "-h", 2) == 0) {
|
if(strncmp(argv[arg], "--help", 6) == 0 || strncmp(argv[arg], "-h", 2) == 0) {
|
||||||
showhelp = true;
|
showhelp = true;
|
||||||
#if USE_FBDEV && defined(POSIX)
|
#if !USE_FBDEV
|
||||||
} 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
|
|
||||||
} else if(strncmp(argv[arg], "--width", 7) == 0 || strncmp(argv[arg], "-W", 2) == 0) {
|
} else if(strncmp(argv[arg], "--width", 7) == 0 || strncmp(argv[arg], "-W", 2) == 0) {
|
||||||
if(arg + 1 < argc) {
|
if(arg + 1 < argc) {
|
||||||
int w = atoi(argv[arg + 1]);
|
int w = atoi(argv[arg + 1]);
|
||||||
@ -179,7 +159,8 @@ int main(int argc, char* argv[])
|
|||||||
std::cout << "Missing height value" << std::endl;
|
std::cout << "Missing height value" << std::endl;
|
||||||
showhelp = true;
|
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) {
|
if(arg + 1 < argc) {
|
||||||
strcpy(config, argv[arg + 1]);
|
strcpy(config, argv[arg + 1]);
|
||||||
arg++;
|
arg++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user