mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-23 11:10:52 +00:00
Portduino config refactor (#7796)
* Start portduino_config refactor * refactor GPIOs to new portduino_config * More portduino_config work * More conversion to portduino_config * Finish portduino_config transition * trunk * yaml output work * Simplify the GPIO config * Trunk
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include "api/ServerAPI.h"
|
||||
#include "linux/gpio/LinuxGPIOPin.h"
|
||||
#include "meshUtils.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include <ErriezCRC32.h>
|
||||
#include <Utility.h>
|
||||
#include <assert.h>
|
||||
@@ -28,14 +27,13 @@
|
||||
|
||||
#include "platform/portduino/USBHal.h"
|
||||
|
||||
std::map<configNames, int> settingsMap;
|
||||
std::map<configNames, std::string> settingsStrings;
|
||||
portduino_config_struct portduino_config;
|
||||
std::ofstream traceFile;
|
||||
Ch341Hal *ch341Hal = nullptr;
|
||||
char *configPath = nullptr;
|
||||
char *optionMac = nullptr;
|
||||
bool verboseEnabled = false;
|
||||
bool yamlOnly = false;
|
||||
|
||||
const char *argp_program_version = optstr(APP_VERSION);
|
||||
|
||||
@@ -75,6 +73,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
||||
case 'v':
|
||||
verboseEnabled = true;
|
||||
break;
|
||||
case 'y':
|
||||
yamlOnly = true;
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
return 0;
|
||||
default:
|
||||
@@ -90,6 +91,7 @@ void portduinoCustomInit()
|
||||
{"hwid", 'h', "HWID", 0, "The mac address to assign to this virtual machine"},
|
||||
{"sim", 's', 0, 0, "Run in Simulated radio mode"},
|
||||
{"verbose", 'v', 0, 0, "Set log level to full debug"},
|
||||
{"output-yaml", 'y', 0, 0, "Output config yaml and exit"},
|
||||
{0}};
|
||||
static void *childArguments;
|
||||
static char doc[] = "Meshtastic native build.";
|
||||
@@ -115,8 +117,8 @@ void getMacAddr(uint8_t *dmac)
|
||||
dmac[4] = hwId >> 8;
|
||||
dmac[5] = hwId & 0xff;
|
||||
}
|
||||
} else if (settingsStrings[mac_address].length() > 11) {
|
||||
MAC_from_string(settingsStrings[mac_address], dmac);
|
||||
} else if (portduino_config.mac_address.length() > 11) {
|
||||
MAC_from_string(portduino_config.mac_address, dmac);
|
||||
exit;
|
||||
} else {
|
||||
|
||||
@@ -148,89 +150,46 @@ void getMacAddr(uint8_t *dmac)
|
||||
*/
|
||||
void portduinoSetup()
|
||||
{
|
||||
printf("Set up Meshtastic on Portduino...\n");
|
||||
int max_GPIO = 0;
|
||||
const configNames GPIO_lines[] = {cs_pin,
|
||||
irq_pin,
|
||||
busy_pin,
|
||||
reset_pin,
|
||||
sx126x_ant_sw_pin,
|
||||
txen_pin,
|
||||
rxen_pin,
|
||||
displayDC,
|
||||
displayCS,
|
||||
displayBacklight,
|
||||
displayBacklightPWMChannel,
|
||||
displayReset,
|
||||
touchscreenCS,
|
||||
touchscreenIRQ,
|
||||
userButtonPin,
|
||||
tbUpPin,
|
||||
tbDownPin,
|
||||
tbLeftPin,
|
||||
tbRightPin,
|
||||
tbPressPin};
|
||||
|
||||
std::string gpioChipName = "gpiochip";
|
||||
settingsStrings[i2cdev] = "";
|
||||
settingsStrings[keyboardDevice] = "";
|
||||
settingsStrings[pointerDevice] = "";
|
||||
settingsStrings[webserverrootpath] = "";
|
||||
settingsStrings[spidev] = "";
|
||||
settingsStrings[displayspidev] = "";
|
||||
settingsMap[spiSpeed] = 2000000;
|
||||
settingsMap[ascii_logs] = !isatty(1);
|
||||
settingsMap[displayPanel] = no_screen;
|
||||
settingsMap[touchscreenModule] = no_touchscreen;
|
||||
settingsMap[tbUpPin] = RADIOLIB_NC;
|
||||
settingsMap[tbDownPin] = RADIOLIB_NC;
|
||||
settingsMap[tbLeftPin] = RADIOLIB_NC;
|
||||
settingsMap[tbRightPin] = RADIOLIB_NC;
|
||||
settingsMap[tbPressPin] = RADIOLIB_NC;
|
||||
|
||||
YAML::Node yamlConfig;
|
||||
portduino_config.displayPanel = no_screen;
|
||||
|
||||
if (portduino_config.force_simradio == true) {
|
||||
settingsMap[use_simradio] = true;
|
||||
portduino_config.lora_module = use_simradio;
|
||||
} else if (configPath != nullptr) {
|
||||
if (loadConfig(configPath)) {
|
||||
std::cout << "Using " << configPath << " as config file" << std::endl;
|
||||
if (!yamlOnly)
|
||||
std::cout << "Using " << configPath << " as config file" << std::endl;
|
||||
} else {
|
||||
std::cout << "Unable to use " << configPath << " as config file" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else if (access("config.yaml", R_OK) == 0) {
|
||||
if (loadConfig("config.yaml")) {
|
||||
std::cout << "Using local config.yaml as config file" << std::endl;
|
||||
if (!yamlOnly)
|
||||
std::cout << "Using local config.yaml as config file" << std::endl;
|
||||
} else {
|
||||
std::cout << "Unable to use local config.yaml as config file" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else if (access("/etc/meshtasticd/config.yaml", R_OK) == 0) {
|
||||
if (loadConfig("/etc/meshtasticd/config.yaml")) {
|
||||
std::cout << "Using /etc/meshtasticd/config.yaml as config file" << std::endl;
|
||||
if (!yamlOnly)
|
||||
std::cout << "Using /etc/meshtasticd/config.yaml as config file" << std::endl;
|
||||
} else {
|
||||
std::cout << "Unable to use /etc/meshtasticd/config.yaml as config file" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
std::cout << "No 'config.yaml' found..." << std::endl;
|
||||
settingsMap[use_simradio] = true;
|
||||
if (!yamlOnly)
|
||||
std::cout << "No 'config.yaml' found..." << std::endl;
|
||||
portduino_config.lora_module = use_simradio;
|
||||
}
|
||||
|
||||
if (settingsMap[use_simradio] == true) {
|
||||
std::cout << "Running in simulated mode." << std::endl;
|
||||
settingsMap[maxnodes] = 200; // Default to 200 nodes
|
||||
settingsMap[logoutputlevel] = level_debug; // Default to debug
|
||||
// Set the random seed equal to TCPPort to have a different seed per instance
|
||||
randomSeed(TCPPort);
|
||||
return;
|
||||
}
|
||||
|
||||
if (settingsStrings[config_directory] != "") {
|
||||
if (portduino_config.config_directory != "") {
|
||||
std::string filetype = ".yaml";
|
||||
for (const std::filesystem::directory_entry &entry :
|
||||
std::filesystem::directory_iterator{settingsStrings[config_directory]}) {
|
||||
std::filesystem::directory_iterator{portduino_config.config_directory}) {
|
||||
if (ends_with(entry.path().string(), ".yaml")) {
|
||||
std::cout << "Also using " << entry << " as additional config file" << std::endl;
|
||||
loadConfig(entry.path().c_str());
|
||||
@@ -238,15 +197,28 @@ void portduinoSetup()
|
||||
}
|
||||
}
|
||||
|
||||
if (yamlOnly) {
|
||||
std::cout << portduino_config.emit_yaml() << std::endl;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (portduino_config.lora_module == use_simradio) {
|
||||
std::cout << "Running in simulated mode." << std::endl;
|
||||
portduino_config.MaxNodes = 200; // Default to 200 nodes
|
||||
// Set the random seed equal to TCPPort to have a different seed per instance
|
||||
randomSeed(TCPPort);
|
||||
return;
|
||||
}
|
||||
|
||||
// If LoRa `Module: auto` (default in config.yaml),
|
||||
// attempt to auto config based on Product Strings
|
||||
if (settingsMap[use_autoconf] == true) {
|
||||
if (portduino_config.lora_module == use_autoconf) {
|
||||
char autoconf_product[96] = {0};
|
||||
// Try CH341
|
||||
try {
|
||||
std::cout << "autoconf: Looking for CH341 device..." << std::endl;
|
||||
ch341Hal =
|
||||
new Ch341Hal(0, settingsStrings[lora_usb_serial_num], settingsMap[lora_usb_vid], settingsMap[lora_usb_pid]);
|
||||
ch341Hal = new Ch341Hal(0, portduino_config.lora_usb_serial_num, portduino_config.lora_usb_vid,
|
||||
portduino_config.lora_usb_pid);
|
||||
ch341Hal->getProductString(autoconf_product, 95);
|
||||
delete ch341Hal;
|
||||
std::cout << "autoconf: Found CH341 device " << autoconf_product << std::endl;
|
||||
@@ -323,7 +295,7 @@ void portduinoSetup()
|
||||
if (mac_start != nullptr) {
|
||||
std::cout << "autoconf: Found mac data " << mac_start << std::endl;
|
||||
if (strlen(mac_start) == 12)
|
||||
settingsStrings[mac_address] = std::string(mac_start);
|
||||
portduino_config.mac_address = std::string(mac_start);
|
||||
}
|
||||
if (devID_start != nullptr) {
|
||||
std::cout << "autoconf: Found deviceid data " << devID_start << std::endl;
|
||||
@@ -354,7 +326,7 @@ void portduinoSetup()
|
||||
std::cerr << "autoconf: Unable to find config for " << autoconf_product << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (loadConfig((settingsStrings[available_directory] + product_config).c_str())) {
|
||||
if (loadConfig((portduino_config.available_directory + product_config).c_str())) {
|
||||
std::cout << "autoconf: Using " << product_config << " as config file for " << autoconf_product << std::endl;
|
||||
} else {
|
||||
std::cerr << "autoconf: Unable to use " << product_config << " as config file for " << autoconf_product
|
||||
@@ -363,15 +335,16 @@ void portduinoSetup()
|
||||
}
|
||||
} else {
|
||||
std::cerr << "autoconf: Could not locate any devices" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// if we're using a usermode driver, we need to initialize it here, to get a serial number back for mac address
|
||||
uint8_t dmac[6] = {0};
|
||||
if (settingsStrings[spidev] == "ch341") {
|
||||
if (portduino_config.lora_spi_dev == "ch341") {
|
||||
try {
|
||||
ch341Hal =
|
||||
new Ch341Hal(0, settingsStrings[lora_usb_serial_num], settingsMap[lora_usb_vid], settingsMap[lora_usb_pid]);
|
||||
ch341Hal = new Ch341Hal(0, portduino_config.lora_usb_serial_num, portduino_config.lora_usb_vid,
|
||||
portduino_config.lora_usb_pid);
|
||||
} catch (std::exception &e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cerr << "Could not initialize CH341 device!" << std::endl;
|
||||
@@ -383,7 +356,7 @@ void portduinoSetup()
|
||||
char product_string[96] = {0};
|
||||
ch341Hal->getProductString(product_string, 95);
|
||||
std::cout << "CH341 Product " << product_string << std::endl;
|
||||
if (strlen(serial) == 8 && settingsStrings[mac_address].length() < 12) {
|
||||
if (strlen(serial) == 8 && portduino_config.mac_address.length() < 12) {
|
||||
uint8_t hash[32] = {0};
|
||||
memcpy(hash, serial, 8);
|
||||
crypto->hash(hash, 8);
|
||||
@@ -395,7 +368,7 @@ void portduinoSetup()
|
||||
dmac[5] = hash[5];
|
||||
char macBuf[13] = {0};
|
||||
sprintf(macBuf, "%02X%02X%02X%02X%02X%02X", dmac[0], dmac[1], dmac[2], dmac[3], dmac[4], dmac[5]);
|
||||
settingsStrings[mac_address] = macBuf;
|
||||
portduino_config.mac_address = macBuf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,100 +382,38 @@ void portduinoSetup()
|
||||
// Rather important to set this, if not running simulated.
|
||||
randomSeed(time(NULL));
|
||||
|
||||
std::string defaultGpioChipName = gpioChipName + std::to_string(settingsMap[default_gpiochip]);
|
||||
|
||||
for (configNames i : GPIO_lines) {
|
||||
if (settingsMap.count(i) && settingsMap[i] > max_GPIO)
|
||||
max_GPIO = settingsMap[i];
|
||||
std::string defaultGpioChipName = gpioChipName + std::to_string(portduino_config.lora_default_gpiochip);
|
||||
for (auto i : portduino_config.all_pins) {
|
||||
if (i->enabled && i->pin > max_GPIO)
|
||||
max_GPIO = i->pin;
|
||||
}
|
||||
|
||||
gpioInit(max_GPIO + 1); // Done here so we can inform Portduino how many GPIOs we need.
|
||||
|
||||
// Need to bind all the configured GPIO pins so they're not simulated
|
||||
// TODO: If one of these fails, we should log and terminate
|
||||
if (settingsMap.count(userButtonPin) > 0 && settingsMap[userButtonPin] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[userButtonPin], defaultGpioChipName, settingsMap[userButtonPin]) != ERRNO_OK) {
|
||||
settingsMap[userButtonPin] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap.count(tbUpPin) > 0 && settingsMap[tbUpPin] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[tbUpPin], defaultGpioChipName, settingsMap[tbUpPin]) != ERRNO_OK) {
|
||||
settingsMap[tbUpPin] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap.count(tbDownPin) > 0 && settingsMap[tbDownPin] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[tbDownPin], defaultGpioChipName, settingsMap[tbDownPin]) != ERRNO_OK) {
|
||||
settingsMap[tbDownPin] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap.count(tbLeftPin) > 0 && settingsMap[tbLeftPin] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[tbLeftPin], defaultGpioChipName, settingsMap[tbLeftPin]) != ERRNO_OK) {
|
||||
settingsMap[tbLeftPin] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap.count(tbRightPin) > 0 && settingsMap[tbRightPin] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[tbRightPin], defaultGpioChipName, settingsMap[tbRightPin]) != ERRNO_OK) {
|
||||
settingsMap[tbRightPin] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap.count(tbPressPin) > 0 && settingsMap[tbPressPin] != RADIOLIB_NC) {
|
||||
if (initGPIOPin(settingsMap[tbPressPin], defaultGpioChipName, settingsMap[tbPressPin]) != ERRNO_OK) {
|
||||
settingsMap[tbPressPin] = RADIOLIB_NC;
|
||||
}
|
||||
}
|
||||
if (settingsMap[displayPanel] != no_screen) {
|
||||
if (settingsMap[displayCS] > 0)
|
||||
initGPIOPin(settingsMap[displayCS], defaultGpioChipName, settingsMap[displayCS]);
|
||||
if (settingsMap[displayDC] > 0)
|
||||
initGPIOPin(settingsMap[displayDC], defaultGpioChipName, settingsMap[displayDC]);
|
||||
if (settingsMap[displayBacklight] > 0)
|
||||
initGPIOPin(settingsMap[displayBacklight], defaultGpioChipName, settingsMap[displayBacklight]);
|
||||
if (settingsMap[displayReset] > 0)
|
||||
initGPIOPin(settingsMap[displayReset], defaultGpioChipName, settingsMap[displayReset]);
|
||||
}
|
||||
if (settingsMap[touchscreenModule] != no_touchscreen) {
|
||||
if (settingsMap[touchscreenCS] > 0)
|
||||
initGPIOPin(settingsMap[touchscreenCS], defaultGpioChipName, settingsMap[touchscreenCS]);
|
||||
if (settingsMap[touchscreenIRQ] > 0)
|
||||
initGPIOPin(settingsMap[touchscreenIRQ], defaultGpioChipName, settingsMap[touchscreenIRQ]);
|
||||
for (auto i : portduino_config.all_pins) {
|
||||
if (i->enabled)
|
||||
if (initGPIOPin(i->pin, gpioChipName + std::to_string(i->gpiochip), i->line) != ERRNO_OK) {
|
||||
printf("Error setting pin number %d. It may not exist, or may already be in use.\n", i->line);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// Only initialize the radio pins when dealing with real, kernel controlled SPI hardware
|
||||
if (settingsStrings[spidev] != "" && settingsStrings[spidev] != "ch341") {
|
||||
const struct {
|
||||
configNames pin;
|
||||
configNames gpiochip;
|
||||
configNames line;
|
||||
} pinMappings[] = {{cs_pin, cs_gpiochip, cs_line},
|
||||
{irq_pin, irq_gpiochip, irq_line},
|
||||
{busy_pin, busy_gpiochip, busy_line},
|
||||
{reset_pin, reset_gpiochip, reset_line},
|
||||
{rxen_pin, rxen_gpiochip, rxen_line},
|
||||
{txen_pin, txen_gpiochip, txen_line},
|
||||
{sx126x_ant_sw_pin, sx126x_ant_sw_gpiochip, sx126x_ant_sw_line}};
|
||||
for (auto &pinMap : pinMappings) {
|
||||
auto setMapIter = settingsMap.find(pinMap.pin);
|
||||
if (setMapIter != settingsMap.end() && setMapIter->second != RADIOLIB_NC) {
|
||||
if (initGPIOPin(setMapIter->second, gpioChipName + std::to_string(settingsMap[pinMap.gpiochip]),
|
||||
settingsMap[pinMap.line]) != ERRNO_OK) {
|
||||
printf("Error setting pin number %d. It may not exist, or may already be in use.\n",
|
||||
settingsMap[pinMap.line]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
SPI.begin(settingsStrings[spidev].c_str());
|
||||
if (portduino_config.lora_spi_dev != "" && portduino_config.lora_spi_dev != "ch341") {
|
||||
SPI.begin(portduino_config.lora_spi_dev.c_str());
|
||||
}
|
||||
if (settingsStrings[traceFilename] != "") {
|
||||
if (portduino_config.traceFilename != "") {
|
||||
try {
|
||||
traceFile.open(settingsStrings[traceFilename], std::ios::out | std::ios::app);
|
||||
traceFile.open(portduino_config.traceFilename, std::ios::out | std::ios::app);
|
||||
} catch (std::ofstream::failure &e) {
|
||||
std::cout << "*** traceFile Exception " << e.what() << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
if (verboseEnabled && settingsMap[logoutputlevel] != level_trace) {
|
||||
settingsMap[logoutputlevel] = level_debug;
|
||||
if (verboseEnabled && portduino_config.logoutputlevel != level_trace) {
|
||||
portduino_config.logoutputlevel = level_debug;
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -537,99 +448,78 @@ bool loadConfig(const char *configPath)
|
||||
yamlConfig = YAML::LoadFile(configPath);
|
||||
if (yamlConfig["Logging"]) {
|
||||
if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "trace") {
|
||||
settingsMap[logoutputlevel] = level_trace;
|
||||
portduino_config.logoutputlevel = level_trace;
|
||||
} else if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "debug") {
|
||||
settingsMap[logoutputlevel] = level_debug;
|
||||
portduino_config.logoutputlevel = level_debug;
|
||||
} else if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "info") {
|
||||
settingsMap[logoutputlevel] = level_info;
|
||||
portduino_config.logoutputlevel = level_info;
|
||||
} else if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "warn") {
|
||||
settingsMap[logoutputlevel] = level_warn;
|
||||
portduino_config.logoutputlevel = level_warn;
|
||||
} else if (yamlConfig["Logging"]["LogLevel"].as<std::string>("info") == "error") {
|
||||
settingsMap[logoutputlevel] = level_error;
|
||||
portduino_config.logoutputlevel = level_error;
|
||||
}
|
||||
settingsStrings[traceFilename] = yamlConfig["Logging"]["TraceFile"].as<std::string>("");
|
||||
portduino_config.traceFilename = yamlConfig["Logging"]["TraceFile"].as<std::string>("");
|
||||
if (yamlConfig["Logging"]["AsciiLogs"]) {
|
||||
// Default is !isatty(1) but can be set explicitly in config.yaml
|
||||
settingsMap[ascii_logs] = yamlConfig["Logging"]["AsciiLogs"].as<bool>();
|
||||
portduino_config.ascii_logs = yamlConfig["Logging"]["AsciiLogs"].as<bool>();
|
||||
portduino_config.ascii_logs_explicit = true;
|
||||
}
|
||||
}
|
||||
if (yamlConfig["Lora"]) {
|
||||
const struct {
|
||||
configNames cfgName;
|
||||
std::string strName;
|
||||
} loraModules[] = {{use_simradio, "sim"}, {use_autoconf, "auto"}, {use_rf95, "RF95"}, {use_sx1262, "sx1262"},
|
||||
{use_sx1268, "sx1268"}, {use_sx1280, "sx1280"}, {use_lr1110, "lr1110"}, {use_lr1120, "lr1120"},
|
||||
{use_lr1121, "lr1121"}, {use_llcc68, "LLCC68"}};
|
||||
for (auto &loraModule : loraModules) {
|
||||
settingsMap[loraModule.cfgName] = false;
|
||||
}
|
||||
|
||||
if (yamlConfig["Lora"]["Module"]) {
|
||||
for (auto &loraModule : loraModules) {
|
||||
if (yamlConfig["Lora"]["Module"].as<std::string>("") == loraModule.strName) {
|
||||
settingsMap[loraModule.cfgName] = true;
|
||||
for (auto &loraModule : portduino_config.loraModules) {
|
||||
if (yamlConfig["Lora"]["Module"].as<std::string>("") == loraModule.second) {
|
||||
portduino_config.lora_module = loraModule.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (yamlConfig["Lora"]["SX126X_MAX_POWER"])
|
||||
portduino_config.sx126x_max_power = yamlConfig["Lora"]["SX126X_MAX_POWER"].as<int>(22);
|
||||
if (yamlConfig["Lora"]["SX128X_MAX_POWER"])
|
||||
portduino_config.sx128x_max_power = yamlConfig["Lora"]["SX128X_MAX_POWER"].as<int>(13);
|
||||
if (yamlConfig["Lora"]["LR1110_MAX_POWER"])
|
||||
portduino_config.lr1110_max_power = yamlConfig["Lora"]["LR1110_MAX_POWER"].as<int>(22);
|
||||
if (yamlConfig["Lora"]["LR1120_MAX_POWER"])
|
||||
portduino_config.lr1120_max_power = yamlConfig["Lora"]["LR1120_MAX_POWER"].as<int>(13);
|
||||
if (yamlConfig["Lora"]["RF95_MAX_POWER"])
|
||||
portduino_config.rf95_max_power = yamlConfig["Lora"]["RF95_MAX_POWER"].as<int>(20);
|
||||
|
||||
settingsMap[sx126x_max_power] = yamlConfig["Lora"]["SX126X_MAX_POWER"].as<int>(22);
|
||||
settingsMap[sx128x_max_power] = yamlConfig["Lora"]["SX128X_MAX_POWER"].as<int>(13);
|
||||
settingsMap[lr1110_max_power] = yamlConfig["Lora"]["LR1110_MAX_POWER"].as<int>(22);
|
||||
settingsMap[lr1120_max_power] = yamlConfig["Lora"]["LR1120_MAX_POWER"].as<int>(13);
|
||||
settingsMap[rf95_max_power] = yamlConfig["Lora"]["RF95_MAX_POWER"].as<int>(20);
|
||||
if (portduino_config.lora_module != use_autoconf && portduino_config.lora_module != use_simradio &&
|
||||
!portduino_config.force_simradio) {
|
||||
portduino_config.dio2_as_rf_switch = yamlConfig["Lora"]["DIO2_AS_RF_SWITCH"].as<bool>(false);
|
||||
portduino_config.dio3_tcxo_voltage = yamlConfig["Lora"]["DIO3_TCXO_VOLTAGE"].as<float>(0) * 1000;
|
||||
if (portduino_config.dio3_tcxo_voltage == 0 && yamlConfig["Lora"]["DIO3_TCXO_VOLTAGE"].as<bool>(false)) {
|
||||
portduino_config.dio3_tcxo_voltage = 1800; // default millivolts for "true"
|
||||
}
|
||||
|
||||
settingsMap[dio2_as_rf_switch] = yamlConfig["Lora"]["DIO2_AS_RF_SWITCH"].as<bool>(false);
|
||||
settingsMap[dio3_tcxo_voltage] = yamlConfig["Lora"]["DIO3_TCXO_VOLTAGE"].as<float>(0) * 1000;
|
||||
if (settingsMap[dio3_tcxo_voltage] == 0 && yamlConfig["Lora"]["DIO3_TCXO_VOLTAGE"].as<bool>(false)) {
|
||||
settingsMap[dio3_tcxo_voltage] = 1800; // default millivolts for "true"
|
||||
}
|
||||
|
||||
// backwards API compatibility and to globally set gpiochip once
|
||||
int defaultGpioChip = settingsMap[default_gpiochip] = yamlConfig["Lora"]["gpiochip"].as<int>(0);
|
||||
|
||||
const struct {
|
||||
configNames pin;
|
||||
configNames gpiochip;
|
||||
configNames line;
|
||||
std::string strName;
|
||||
} pinMappings[] = {
|
||||
{cs_pin, cs_gpiochip, cs_line, "CS"},
|
||||
{irq_pin, irq_gpiochip, irq_line, "IRQ"},
|
||||
{busy_pin, busy_gpiochip, busy_line, "Busy"},
|
||||
{reset_pin, reset_gpiochip, reset_line, "Reset"},
|
||||
{txen_pin, txen_gpiochip, txen_line, "TXen"},
|
||||
{rxen_pin, rxen_gpiochip, rxen_line, "RXen"},
|
||||
{sx126x_ant_sw_pin, sx126x_ant_sw_gpiochip, sx126x_ant_sw_line, "SX126X_ANT_SW"},
|
||||
};
|
||||
for (auto &pinMap : pinMappings) {
|
||||
if (yamlConfig["Lora"][pinMap.strName].IsMap()) {
|
||||
settingsMap[pinMap.pin] = yamlConfig["Lora"][pinMap.strName]["pin"].as<int>(RADIOLIB_NC);
|
||||
settingsMap[pinMap.line] = yamlConfig["Lora"][pinMap.strName]["line"].as<int>(settingsMap[pinMap.pin]);
|
||||
settingsMap[pinMap.gpiochip] = yamlConfig["Lora"][pinMap.strName]["gpiochip"].as<int>(defaultGpioChip);
|
||||
} else { // backwards API compatibility
|
||||
settingsMap[pinMap.pin] = yamlConfig["Lora"][pinMap.strName].as<int>(RADIOLIB_NC);
|
||||
settingsMap[pinMap.line] = settingsMap[pinMap.pin];
|
||||
settingsMap[pinMap.gpiochip] = defaultGpioChip;
|
||||
// backwards API compatibility and to globally set gpiochip once
|
||||
portduino_config.lora_default_gpiochip = yamlConfig["Lora"]["gpiochip"].as<int>(0);
|
||||
for (auto this_pin : portduino_config.all_pins) {
|
||||
if (this_pin->config_section == "Lora") {
|
||||
readGPIOFromYaml(yamlConfig["Lora"][this_pin->config_name], *this_pin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
settingsMap[spiSpeed] = yamlConfig["Lora"]["spiSpeed"].as<int>(2000000);
|
||||
settingsStrings[lora_usb_serial_num] = yamlConfig["Lora"]["USB_Serialnum"].as<std::string>("");
|
||||
settingsMap[lora_usb_pid] = yamlConfig["Lora"]["USB_PID"].as<int>(0x5512);
|
||||
settingsMap[lora_usb_vid] = yamlConfig["Lora"]["USB_VID"].as<int>(0x1A86);
|
||||
portduino_config.spiSpeed = yamlConfig["Lora"]["spiSpeed"].as<int>(2000000);
|
||||
portduino_config.lora_usb_serial_num = yamlConfig["Lora"]["USB_Serialnum"].as<std::string>("");
|
||||
portduino_config.lora_usb_pid = yamlConfig["Lora"]["USB_PID"].as<int>(0x5512);
|
||||
portduino_config.lora_usb_vid = yamlConfig["Lora"]["USB_VID"].as<int>(0x1A86);
|
||||
|
||||
settingsStrings[spidev] = yamlConfig["Lora"]["spidev"].as<std::string>("spidev0.0");
|
||||
if (settingsStrings[spidev] != "ch341") {
|
||||
settingsStrings[spidev] = "/dev/" + settingsStrings[spidev];
|
||||
if (settingsStrings[spidev].length() == 14) {
|
||||
int x = settingsStrings[spidev].at(11) - '0';
|
||||
int y = settingsStrings[spidev].at(13) - '0';
|
||||
portduino_config.lora_spi_dev = yamlConfig["Lora"]["spidev"].as<std::string>("spidev0.0");
|
||||
if (portduino_config.lora_spi_dev != "ch341") {
|
||||
portduino_config.lora_spi_dev = "/dev/" + portduino_config.lora_spi_dev;
|
||||
if (portduino_config.lora_spi_dev.length() == 14) {
|
||||
int x = portduino_config.lora_spi_dev.at(11) - '0';
|
||||
int y = portduino_config.lora_spi_dev.at(13) - '0';
|
||||
// Pretty sure this is always true
|
||||
if (x >= 0 && x < 10 && y >= 0 && y < 10) {
|
||||
// I believe this bit of weirdness is specifically for the new GUI
|
||||
settingsMap[spidev] = x + y << 4;
|
||||
settingsMap[displayspidev] = settingsMap[spidev];
|
||||
settingsMap[touchscreenspidev] = settingsMap[spidev];
|
||||
portduino_config.lora_spi_dev_int = x + y << 4;
|
||||
portduino_config.display_spi_dev_int = portduino_config.lora_spi_dev_int;
|
||||
portduino_config.touchscreen_spi_dev_int = portduino_config.lora_spi_dev_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,163 +566,152 @@ bool loadConfig(const char *configPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (yamlConfig["GPIO"]) {
|
||||
settingsMap[userButtonPin] = yamlConfig["GPIO"]["User"].as<int>(RADIOLIB_NC);
|
||||
}
|
||||
readGPIOFromYaml(yamlConfig["GPIO"]["User"], portduino_config.userButtonPin);
|
||||
if (yamlConfig["GPS"]) {
|
||||
std::string serialPath = yamlConfig["GPS"]["SerialPath"].as<std::string>("");
|
||||
if (serialPath != "") {
|
||||
Serial1.setPath(serialPath);
|
||||
settingsMap[has_gps] = 1;
|
||||
portduino_config.has_gps = 1;
|
||||
}
|
||||
}
|
||||
if (yamlConfig["I2C"]) {
|
||||
settingsStrings[i2cdev] = yamlConfig["I2C"]["I2CDevice"].as<std::string>("");
|
||||
portduino_config.i2cdev = yamlConfig["I2C"]["I2CDevice"].as<std::string>("");
|
||||
}
|
||||
if (yamlConfig["Display"]) {
|
||||
if (yamlConfig["Display"]["Panel"].as<std::string>("") == "ST7789")
|
||||
settingsMap[displayPanel] = st7789;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "ST7735")
|
||||
settingsMap[displayPanel] = st7735;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "ST7735S")
|
||||
settingsMap[displayPanel] = st7735s;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "ST7796")
|
||||
settingsMap[displayPanel] = st7796;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "ILI9341")
|
||||
settingsMap[displayPanel] = ili9341;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "ILI9342")
|
||||
settingsMap[displayPanel] = ili9342;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "ILI9486")
|
||||
settingsMap[displayPanel] = ili9486;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "ILI9488")
|
||||
settingsMap[displayPanel] = ili9488;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "HX8357D")
|
||||
settingsMap[displayPanel] = hx8357d;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "X11")
|
||||
settingsMap[displayPanel] = x11;
|
||||
else if (yamlConfig["Display"]["Panel"].as<std::string>("") == "FB")
|
||||
settingsMap[displayPanel] = fb;
|
||||
settingsMap[displayHeight] = yamlConfig["Display"]["Height"].as<int>(0);
|
||||
settingsMap[displayWidth] = yamlConfig["Display"]["Width"].as<int>(0);
|
||||
settingsMap[displayDC] = yamlConfig["Display"]["DC"].as<int>(-1);
|
||||
settingsMap[displayCS] = yamlConfig["Display"]["CS"].as<int>(-1);
|
||||
settingsMap[displayRGBOrder] = yamlConfig["Display"]["RGBOrder"].as<bool>(false);
|
||||
settingsMap[displayBacklight] = yamlConfig["Display"]["Backlight"].as<int>(-1);
|
||||
settingsMap[displayBacklightInvert] = yamlConfig["Display"]["BacklightInvert"].as<bool>(false);
|
||||
settingsMap[displayBacklightPWMChannel] = yamlConfig["Display"]["BacklightPWMChannel"].as<int>(-1);
|
||||
settingsMap[displayReset] = yamlConfig["Display"]["Reset"].as<int>(-1);
|
||||
settingsMap[displayOffsetX] = yamlConfig["Display"]["OffsetX"].as<int>(0);
|
||||
settingsMap[displayOffsetY] = yamlConfig["Display"]["OffsetY"].as<int>(0);
|
||||
settingsMap[displayRotate] = yamlConfig["Display"]["Rotate"].as<bool>(false);
|
||||
settingsMap[displayOffsetRotate] = yamlConfig["Display"]["OffsetRotate"].as<int>(1);
|
||||
settingsMap[displayInvert] = yamlConfig["Display"]["Invert"].as<bool>(false);
|
||||
settingsMap[displayBusFrequency] = yamlConfig["Display"]["BusFrequency"].as<int>(40000000);
|
||||
|
||||
for (auto &screen_name : portduino_config.screen_names) {
|
||||
if (yamlConfig["Display"]["Panel"].as<std::string>("") == screen_name.second)
|
||||
portduino_config.displayPanel = screen_name.first;
|
||||
}
|
||||
portduino_config.displayHeight = yamlConfig["Display"]["Height"].as<int>(0);
|
||||
portduino_config.displayWidth = yamlConfig["Display"]["Width"].as<int>(0);
|
||||
|
||||
readGPIOFromYaml(yamlConfig["Display"]["DC"], portduino_config.displayDC, -1);
|
||||
readGPIOFromYaml(yamlConfig["Display"]["CS"], portduino_config.displayCS, -1);
|
||||
readGPIOFromYaml(yamlConfig["Display"]["Backlight"], portduino_config.displayBacklight, -1);
|
||||
readGPIOFromYaml(yamlConfig["Display"]["BacklightPWMChannel"], portduino_config.displayBacklightPWMChannel, -1);
|
||||
readGPIOFromYaml(yamlConfig["Display"]["Reset"], portduino_config.displayReset, -1);
|
||||
|
||||
portduino_config.displayBacklightInvert = yamlConfig["Display"]["BacklightInvert"].as<bool>(false);
|
||||
portduino_config.displayRGBOrder = yamlConfig["Display"]["RGBOrder"].as<bool>(false);
|
||||
portduino_config.displayOffsetX = yamlConfig["Display"]["OffsetX"].as<int>(0);
|
||||
portduino_config.displayOffsetY = yamlConfig["Display"]["OffsetY"].as<int>(0);
|
||||
portduino_config.displayRotate = yamlConfig["Display"]["Rotate"].as<bool>(false);
|
||||
portduino_config.displayOffsetRotate = yamlConfig["Display"]["OffsetRotate"].as<int>(1);
|
||||
portduino_config.displayInvert = yamlConfig["Display"]["Invert"].as<bool>(false);
|
||||
portduino_config.displayBusFrequency = yamlConfig["Display"]["BusFrequency"].as<int>(40000000);
|
||||
if (yamlConfig["Display"]["spidev"]) {
|
||||
settingsStrings[displayspidev] = "/dev/" + yamlConfig["Display"]["spidev"].as<std::string>("spidev0.1");
|
||||
if (settingsStrings[displayspidev].length() == 14) {
|
||||
int x = settingsStrings[displayspidev].at(11) - '0';
|
||||
int y = settingsStrings[displayspidev].at(13) - '0';
|
||||
portduino_config.display_spi_dev = "/dev/" + yamlConfig["Display"]["spidev"].as<std::string>("spidev0.1");
|
||||
if (portduino_config.display_spi_dev.length() == 14) {
|
||||
int x = portduino_config.display_spi_dev.at(11) - '0';
|
||||
int y = portduino_config.display_spi_dev.at(13) - '0';
|
||||
if (x >= 0 && x < 10 && y >= 0 && y < 10) {
|
||||
settingsMap[displayspidev] = x + y << 4;
|
||||
settingsMap[touchscreenspidev] = settingsMap[displayspidev];
|
||||
portduino_config.display_spi_dev_int = x + y << 4;
|
||||
portduino_config.touchscreen_spi_dev_int = portduino_config.display_spi_dev_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (yamlConfig["Touchscreen"]) {
|
||||
if (yamlConfig["Touchscreen"]["Module"].as<std::string>("") == "XPT2046")
|
||||
settingsMap[touchscreenModule] = xpt2046;
|
||||
portduino_config.touchscreenModule = xpt2046;
|
||||
else if (yamlConfig["Touchscreen"]["Module"].as<std::string>("") == "STMPE610")
|
||||
settingsMap[touchscreenModule] = stmpe610;
|
||||
portduino_config.touchscreenModule = stmpe610;
|
||||
else if (yamlConfig["Touchscreen"]["Module"].as<std::string>("") == "GT911")
|
||||
settingsMap[touchscreenModule] = gt911;
|
||||
portduino_config.touchscreenModule = gt911;
|
||||
else if (yamlConfig["Touchscreen"]["Module"].as<std::string>("") == "FT5x06")
|
||||
settingsMap[touchscreenModule] = ft5x06;
|
||||
settingsMap[touchscreenCS] = yamlConfig["Touchscreen"]["CS"].as<int>(-1);
|
||||
settingsMap[touchscreenIRQ] = yamlConfig["Touchscreen"]["IRQ"].as<int>(-1);
|
||||
settingsMap[touchscreenBusFrequency] = yamlConfig["Touchscreen"]["BusFrequency"].as<int>(1000000);
|
||||
settingsMap[touchscreenRotate] = yamlConfig["Touchscreen"]["Rotate"].as<int>(-1);
|
||||
settingsMap[touchscreenI2CAddr] = yamlConfig["Touchscreen"]["I2CAddr"].as<int>(-1);
|
||||
portduino_config.touchscreenModule = ft5x06;
|
||||
|
||||
readGPIOFromYaml(yamlConfig["Touchscreen"]["CS"], portduino_config.touchscreenCS, -1);
|
||||
readGPIOFromYaml(yamlConfig["Touchscreen"]["IRQ"], portduino_config.touchscreenIRQ, -1);
|
||||
|
||||
portduino_config.touchscreenBusFrequency = yamlConfig["Touchscreen"]["BusFrequency"].as<int>(1000000);
|
||||
portduino_config.touchscreenRotate = yamlConfig["Touchscreen"]["Rotate"].as<int>(-1);
|
||||
portduino_config.touchscreenI2CAddr = yamlConfig["Touchscreen"]["I2CAddr"].as<int>(-1);
|
||||
if (yamlConfig["Touchscreen"]["spidev"]) {
|
||||
settingsStrings[touchscreenspidev] = "/dev/" + yamlConfig["Touchscreen"]["spidev"].as<std::string>("");
|
||||
if (settingsStrings[touchscreenspidev].length() == 14) {
|
||||
int x = settingsStrings[touchscreenspidev].at(11) - '0';
|
||||
int y = settingsStrings[touchscreenspidev].at(13) - '0';
|
||||
portduino_config.touchscreen_spi_dev = "/dev/" + yamlConfig["Touchscreen"]["spidev"].as<std::string>("");
|
||||
if (portduino_config.touchscreen_spi_dev.length() == 14) {
|
||||
int x = portduino_config.touchscreen_spi_dev.at(11) - '0';
|
||||
int y = portduino_config.touchscreen_spi_dev.at(13) - '0';
|
||||
if (x >= 0 && x < 10 && y >= 0 && y < 10) {
|
||||
settingsMap[touchscreenspidev] = x + y << 4;
|
||||
portduino_config.touchscreen_spi_dev_int = x + y << 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (yamlConfig["Input"]) {
|
||||
settingsStrings[keyboardDevice] = (yamlConfig["Input"]["KeyboardDevice"]).as<std::string>("");
|
||||
settingsStrings[pointerDevice] = (yamlConfig["Input"]["PointerDevice"]).as<std::string>("");
|
||||
settingsMap[userButtonPin] = yamlConfig["Input"]["User"].as<int>(RADIOLIB_NC);
|
||||
settingsMap[tbUpPin] = yamlConfig["Input"]["TrackballUp"].as<int>(RADIOLIB_NC);
|
||||
settingsMap[tbDownPin] = yamlConfig["Input"]["TrackballDown"].as<int>(RADIOLIB_NC);
|
||||
settingsMap[tbLeftPin] = yamlConfig["Input"]["TrackballLeft"].as<int>(RADIOLIB_NC);
|
||||
settingsMap[tbRightPin] = yamlConfig["Input"]["TrackballRight"].as<int>(RADIOLIB_NC);
|
||||
settingsMap[tbPressPin] = yamlConfig["Input"]["TrackballPress"].as<int>(RADIOLIB_NC);
|
||||
portduino_config.keyboardDevice = (yamlConfig["Input"]["KeyboardDevice"]).as<std::string>("");
|
||||
portduino_config.pointerDevice = (yamlConfig["Input"]["PointerDevice"]).as<std::string>("");
|
||||
|
||||
readGPIOFromYaml(yamlConfig["Input"]["User"], portduino_config.userButtonPin);
|
||||
readGPIOFromYaml(yamlConfig["Input"]["TrackballUp"], portduino_config.tbUpPin);
|
||||
readGPIOFromYaml(yamlConfig["Input"]["TrackballDown"], portduino_config.tbDownPin);
|
||||
readGPIOFromYaml(yamlConfig["Input"]["TrackballLeft"], portduino_config.tbLeftPin);
|
||||
readGPIOFromYaml(yamlConfig["Input"]["TrackballRight"], portduino_config.tbRightPin);
|
||||
readGPIOFromYaml(yamlConfig["Input"]["TrackballPress"], portduino_config.tbPressPin);
|
||||
|
||||
if (yamlConfig["Input"]["TrackballDirection"].as<std::string>("RISING") == "RISING") {
|
||||
settingsMap[tbDirection] = 4;
|
||||
portduino_config.tbDirection = 4;
|
||||
} else if (yamlConfig["Input"]["TrackballDirection"].as<std::string>("RISING") == "FALLING") {
|
||||
settingsMap[tbDirection] = 3;
|
||||
portduino_config.tbDirection = 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (yamlConfig["Webserver"]) {
|
||||
settingsMap[webserverport] = (yamlConfig["Webserver"]["Port"]).as<int>(-1);
|
||||
settingsStrings[webserverrootpath] =
|
||||
portduino_config.webserverport = (yamlConfig["Webserver"]["Port"]).as<int>(-1);
|
||||
portduino_config.webserver_root_path =
|
||||
(yamlConfig["Webserver"]["RootPath"]).as<std::string>("/usr/share/meshtasticd/web");
|
||||
settingsStrings[websslkeypath] =
|
||||
portduino_config.webserver_ssl_key_path =
|
||||
(yamlConfig["Webserver"]["SSLKey"]).as<std::string>("/etc/meshtasticd/ssl/private_key.pem");
|
||||
settingsStrings[websslcertpath] =
|
||||
portduino_config.webserver_ssl_cert_path =
|
||||
(yamlConfig["Webserver"]["SSLCert"]).as<std::string>("/etc/meshtasticd/ssl/certificate.pem");
|
||||
}
|
||||
|
||||
if (yamlConfig["HostMetrics"]) {
|
||||
settingsMap[hostMetrics_channel] = (yamlConfig["HostMetrics"]["Channel"]).as<int>(0);
|
||||
settingsMap[hostMetrics_interval] = (yamlConfig["HostMetrics"]["ReportInterval"]).as<int>(0);
|
||||
settingsStrings[hostMetrics_user_command] = (yamlConfig["HostMetrics"]["UserStringCommand"]).as<std::string>("");
|
||||
portduino_config.hostMetrics_channel = (yamlConfig["HostMetrics"]["Channel"]).as<int>(0);
|
||||
portduino_config.hostMetrics_interval = (yamlConfig["HostMetrics"]["ReportInterval"]).as<int>(0);
|
||||
portduino_config.hostMetrics_user_command = (yamlConfig["HostMetrics"]["UserStringCommand"]).as<std::string>("");
|
||||
}
|
||||
|
||||
if (yamlConfig["Config"]) {
|
||||
if (yamlConfig["Config"]["DisplayMode"]) {
|
||||
settingsMap[has_configDisplayMode] = true;
|
||||
portduino_config.has_configDisplayMode = true;
|
||||
if ((yamlConfig["Config"]["DisplayMode"]).as<std::string>("") == "TWOCOLOR") {
|
||||
settingsMap[configDisplayMode] = meshtastic_Config_DisplayConfig_DisplayMode_TWOCOLOR;
|
||||
portduino_config.configDisplayMode = meshtastic_Config_DisplayConfig_DisplayMode_TWOCOLOR;
|
||||
} else if ((yamlConfig["Config"]["DisplayMode"]).as<std::string>("") == "INVERTED") {
|
||||
settingsMap[configDisplayMode] = meshtastic_Config_DisplayConfig_DisplayMode_INVERTED;
|
||||
portduino_config.configDisplayMode = meshtastic_Config_DisplayConfig_DisplayMode_INVERTED;
|
||||
} else if ((yamlConfig["Config"]["DisplayMode"]).as<std::string>("") == "COLOR") {
|
||||
settingsMap[configDisplayMode] = meshtastic_Config_DisplayConfig_DisplayMode_COLOR;
|
||||
portduino_config.configDisplayMode = meshtastic_Config_DisplayConfig_DisplayMode_COLOR;
|
||||
} else {
|
||||
settingsMap[configDisplayMode] = meshtastic_Config_DisplayConfig_DisplayMode_DEFAULT;
|
||||
portduino_config.configDisplayMode = meshtastic_Config_DisplayConfig_DisplayMode_DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (yamlConfig["General"]) {
|
||||
settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as<int>(200);
|
||||
settingsMap[maxtophone] = (yamlConfig["General"]["MaxMessageQueue"]).as<int>(100);
|
||||
settingsStrings[config_directory] = (yamlConfig["General"]["ConfigDirectory"]).as<std::string>("");
|
||||
settingsStrings[available_directory] =
|
||||
portduino_config.MaxNodes = (yamlConfig["General"]["MaxNodes"]).as<int>(200);
|
||||
portduino_config.maxtophone = (yamlConfig["General"]["MaxMessageQueue"]).as<int>(100);
|
||||
portduino_config.config_directory = (yamlConfig["General"]["ConfigDirectory"]).as<std::string>("");
|
||||
portduino_config.available_directory =
|
||||
(yamlConfig["General"]["AvailableDirectory"]).as<std::string>("/etc/meshtasticd/available.d/");
|
||||
if ((yamlConfig["General"]["MACAddress"]).as<std::string>("") != "" &&
|
||||
(yamlConfig["General"]["MACAddressSource"]).as<std::string>("") != "") {
|
||||
std::cout << "Cannot set both MACAddress and MACAddressSource!" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
settingsStrings[mac_address] = (yamlConfig["General"]["MACAddress"]).as<std::string>("");
|
||||
if ((yamlConfig["General"]["MACAddressSource"]).as<std::string>("") != "") {
|
||||
std::ifstream infile("/sys/class/net/" + (yamlConfig["General"]["MACAddressSource"]).as<std::string>("") +
|
||||
"/address");
|
||||
std::getline(infile, settingsStrings[mac_address]);
|
||||
portduino_config.mac_address = (yamlConfig["General"]["MACAddress"]).as<std::string>("");
|
||||
if (portduino_config.mac_address != "") {
|
||||
portduino_config.mac_address_explicit = true;
|
||||
} else if ((yamlConfig["General"]["MACAddressSource"]).as<std::string>("") != "") {
|
||||
portduino_config.mac_address_source = (yamlConfig["General"]["MACAddressSource"]).as<std::string>("");
|
||||
std::ifstream infile("/sys/class/net/" + portduino_config.mac_address_source + "/address");
|
||||
std::getline(infile, portduino_config.mac_address);
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/20326454
|
||||
settingsStrings[mac_address].erase(
|
||||
std::remove(settingsStrings[mac_address].begin(), settingsStrings[mac_address].end(), ':'),
|
||||
settingsStrings[mac_address].end());
|
||||
portduino_config.mac_address.erase(
|
||||
std::remove(portduino_config.mac_address.begin(), portduino_config.mac_address.end(), ':'),
|
||||
portduino_config.mac_address.end());
|
||||
}
|
||||
} catch (YAML::Exception &e) {
|
||||
std::cout << "*** Exception " << e.what() << std::endl;
|
||||
@@ -851,12 +730,12 @@ bool MAC_from_string(std::string mac_str, uint8_t *dmac)
|
||||
{
|
||||
mac_str.erase(std::remove(mac_str.begin(), mac_str.end(), ':'), mac_str.end());
|
||||
if (mac_str.length() == 12) {
|
||||
dmac[0] = std::stoi(settingsStrings[mac_address].substr(0, 2), nullptr, 16);
|
||||
dmac[1] = std::stoi(settingsStrings[mac_address].substr(2, 2), nullptr, 16);
|
||||
dmac[2] = std::stoi(settingsStrings[mac_address].substr(4, 2), nullptr, 16);
|
||||
dmac[3] = std::stoi(settingsStrings[mac_address].substr(6, 2), nullptr, 16);
|
||||
dmac[4] = std::stoi(settingsStrings[mac_address].substr(8, 2), nullptr, 16);
|
||||
dmac[5] = std::stoi(settingsStrings[mac_address].substr(10, 2), nullptr, 16);
|
||||
dmac[0] = std::stoi(portduino_config.mac_address.substr(0, 2), nullptr, 16);
|
||||
dmac[1] = std::stoi(portduino_config.mac_address.substr(2, 2), nullptr, 16);
|
||||
dmac[2] = std::stoi(portduino_config.mac_address.substr(4, 2), nullptr, 16);
|
||||
dmac[3] = std::stoi(portduino_config.mac_address.substr(6, 2), nullptr, 16);
|
||||
dmac[4] = std::stoi(portduino_config.mac_address.substr(8, 2), nullptr, 16);
|
||||
dmac[5] = std::stoi(portduino_config.mac_address.substr(10, 2), nullptr, 16);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -875,4 +754,19 @@ std::string exec(const char *cmd)
|
||||
result += buffer.data();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void readGPIOFromYaml(YAML::Node sourceNode, pinMapping &destPin, int pinDefault)
|
||||
{
|
||||
if (sourceNode.IsMap()) {
|
||||
destPin.enabled = true;
|
||||
destPin.pin = sourceNode["pin"].as<int>(pinDefault);
|
||||
destPin.line = sourceNode["line"].as<int>(destPin.pin);
|
||||
destPin.gpiochip = sourceNode["gpiochip"].as<int>(portduino_config.lora_default_gpiochip);
|
||||
} else if (sourceNode) { // backwards API compatibility
|
||||
destPin.enabled = true;
|
||||
destPin.pin = sourceNode.as<int>(pinDefault);
|
||||
destPin.line = destPin.pin;
|
||||
destPin.gpiochip = portduino_config.lora_default_gpiochip;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "LR11x0Interface.h"
|
||||
#include "Module.h"
|
||||
#include "platform/portduino/USBHal.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
|
||||
// Product strings for auto-configuration
|
||||
// {"PRODUCT_STRING", "CONFIG.YAML"}
|
||||
@@ -19,36 +20,10 @@ inline const std::unordered_map<std::string, std::string> configProducts = {
|
||||
{"RAK6421-13300-S1", "lora-RAK6421-13300-slot1.yaml"},
|
||||
{"RAK6421-13300-S2", "lora-RAK6421-13300-slot2.yaml"}};
|
||||
|
||||
enum configNames {
|
||||
default_gpiochip,
|
||||
cs_pin,
|
||||
cs_line,
|
||||
cs_gpiochip,
|
||||
irq_pin,
|
||||
irq_line,
|
||||
irq_gpiochip,
|
||||
busy_pin,
|
||||
busy_line,
|
||||
busy_gpiochip,
|
||||
reset_pin,
|
||||
reset_line,
|
||||
reset_gpiochip,
|
||||
txen_pin,
|
||||
txen_line,
|
||||
txen_gpiochip,
|
||||
rxen_pin,
|
||||
rxen_line,
|
||||
rxen_gpiochip,
|
||||
sx126x_ant_sw_pin,
|
||||
sx126x_ant_sw_line,
|
||||
sx126x_ant_sw_gpiochip,
|
||||
sx126x_max_power,
|
||||
sx128x_max_power,
|
||||
lr1110_max_power,
|
||||
lr1120_max_power,
|
||||
rf95_max_power,
|
||||
dio2_as_rf_switch,
|
||||
dio3_tcxo_voltage,
|
||||
enum screen_modules { no_screen, x11, fb, st7789, st7735, st7735s, st7796, ili9341, ili9342, ili9486, ili9488, hx8357d };
|
||||
enum touchscreen_modules { no_touchscreen, xpt2046, stmpe610, gt911, ft5x06 };
|
||||
enum portduino_log_level { level_error, level_warn, level_info, level_debug, level_trace };
|
||||
enum lora_module_enum {
|
||||
use_simradio,
|
||||
use_autoconf,
|
||||
use_rf95,
|
||||
@@ -58,72 +33,18 @@ enum configNames {
|
||||
use_lr1110,
|
||||
use_lr1120,
|
||||
use_lr1121,
|
||||
use_llcc68,
|
||||
lora_usb_serial_num,
|
||||
lora_usb_pid,
|
||||
lora_usb_vid,
|
||||
userButtonPin,
|
||||
tbUpPin,
|
||||
tbDownPin,
|
||||
tbLeftPin,
|
||||
tbRightPin,
|
||||
tbPressPin,
|
||||
tbDirection,
|
||||
spidev,
|
||||
spiSpeed,
|
||||
i2cdev,
|
||||
has_gps,
|
||||
touchscreenModule,
|
||||
touchscreenCS,
|
||||
touchscreenIRQ,
|
||||
touchscreenI2CAddr,
|
||||
touchscreenBusFrequency,
|
||||
touchscreenRotate,
|
||||
touchscreenspidev,
|
||||
displayspidev,
|
||||
displayBusFrequency,
|
||||
displayPanel,
|
||||
displayWidth,
|
||||
displayHeight,
|
||||
displayCS,
|
||||
displayDC,
|
||||
displayRGBOrder,
|
||||
displayBacklight,
|
||||
displayBacklightPWMChannel,
|
||||
displayBacklightInvert,
|
||||
displayReset,
|
||||
displayRotate,
|
||||
displayOffsetRotate,
|
||||
displayOffsetX,
|
||||
displayOffsetY,
|
||||
displayInvert,
|
||||
keyboardDevice,
|
||||
pointerDevice,
|
||||
logoutputlevel,
|
||||
traceFilename,
|
||||
webserver,
|
||||
webserverport,
|
||||
webserverrootpath,
|
||||
websslkeypath,
|
||||
websslcertpath,
|
||||
maxtophone,
|
||||
maxnodes,
|
||||
ascii_logs,
|
||||
config_directory,
|
||||
available_directory,
|
||||
mac_address,
|
||||
hostMetrics_interval,
|
||||
hostMetrics_channel,
|
||||
hostMetrics_user_command,
|
||||
configDisplayMode,
|
||||
has_configDisplayMode
|
||||
use_llcc68
|
||||
};
|
||||
|
||||
struct pinMapping {
|
||||
std::string config_section;
|
||||
std::string config_name;
|
||||
int pin = RADIOLIB_NC;
|
||||
int gpiochip;
|
||||
int line;
|
||||
bool enabled = false;
|
||||
};
|
||||
enum { no_screen, x11, fb, st7789, st7735, st7735s, st7796, ili9341, ili9342, ili9486, ili9488, hx8357d };
|
||||
enum { no_touchscreen, xpt2046, stmpe610, gt911, ft5x06 };
|
||||
enum { level_error, level_warn, level_info, level_debug, level_trace };
|
||||
|
||||
extern std::map<configNames, int> settingsMap;
|
||||
extern std::map<configNames, std::string> settingsStrings;
|
||||
extern std::ofstream traceFile;
|
||||
extern Ch341Hal *ch341Hal;
|
||||
int initGPIOPin(int pinNum, std::string gpioChipname, int line);
|
||||
@@ -131,13 +52,422 @@ bool loadConfig(const char *configPath);
|
||||
static bool ends_with(std::string_view str, std::string_view suffix);
|
||||
void getMacAddr(uint8_t *dmac);
|
||||
bool MAC_from_string(std::string mac_str, uint8_t *dmac);
|
||||
void readGPIOFromYaml(YAML::Node sourceNode, pinMapping &destPin, int pinDefault = RADIOLIB_NC);
|
||||
std::string exec(const char *cmd);
|
||||
|
||||
extern struct portduino_config_struct {
|
||||
// Lora
|
||||
std::map<lora_module_enum, std::string> loraModules = {
|
||||
{use_simradio, "sim"}, {use_autoconf, "auto"}, {use_rf95, "RF95"}, {use_sx1262, "sx1262"}, {use_sx1268, "sx1268"},
|
||||
{use_sx1280, "sx1280"}, {use_lr1110, "lr1110"}, {use_lr1120, "lr1120"}, {use_lr1121, "lr1121"}, {use_llcc68, "LLCC68"}};
|
||||
|
||||
std::map<screen_modules, std::string> screen_names = {{x11, "X11"}, {fb, "FB"}, {st7789, "ST7789"},
|
||||
{st7735, "ST7735"}, {st7735s, "ST7735S"}, {st7796, "ST7796"},
|
||||
{ili9341, "ILI9341"}, {ili9342, "ILI9342"}, {ili9486, "ILI9486"},
|
||||
{ili9488, "ILI9488"}, {hx8357d, "HX8357D"}};
|
||||
|
||||
lora_module_enum lora_module;
|
||||
bool has_rfswitch_table = false;
|
||||
uint32_t rfswitch_dio_pins[5] = {RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC};
|
||||
Module::RfSwitchMode_t rfswitch_table[8];
|
||||
bool force_simradio = false;
|
||||
bool has_device_id = false;
|
||||
uint8_t device_id[16] = {0};
|
||||
std::string lora_spi_dev = "";
|
||||
std::string lora_usb_serial_num = "";
|
||||
int lora_spi_dev_int = 0;
|
||||
int lora_default_gpiochip = 0;
|
||||
int sx126x_max_power = 22;
|
||||
int sx128x_max_power = 13;
|
||||
int lr1110_max_power = 22;
|
||||
int lr1120_max_power = 13;
|
||||
int rf95_max_power = 20;
|
||||
bool dio2_as_rf_switch = false;
|
||||
int dio3_tcxo_voltage = 0;
|
||||
int lora_usb_pid = 0x5512;
|
||||
int lora_usb_vid = 0x1A86;
|
||||
int spiSpeed = 2000000;
|
||||
pinMapping lora_cs_pin = {"Lora", "CS"};
|
||||
pinMapping lora_irq_pin = {"Lora", "IRQ"};
|
||||
pinMapping lora_busy_pin = {"Lora", "Busy"};
|
||||
pinMapping lora_reset_pin = {"Lora", "Reset"};
|
||||
pinMapping lora_txen_pin = {"Lora", "TXen"};
|
||||
pinMapping lora_rxen_pin = {"Lora", "RXen"};
|
||||
pinMapping lora_sx126x_ant_sw_pin = {"Lora", "SX126X_ANT_SW"};
|
||||
|
||||
// GPS
|
||||
bool has_gps = false;
|
||||
|
||||
// I2C
|
||||
std::string i2cdev = "";
|
||||
|
||||
// Display
|
||||
std::string display_spi_dev = "";
|
||||
int display_spi_dev_int = 0;
|
||||
int displayBusFrequency = 40000000;
|
||||
screen_modules displayPanel = no_screen;
|
||||
int displayWidth = 0;
|
||||
int displayHeight = 0;
|
||||
bool displayRGBOrder = false;
|
||||
bool displayBacklightInvert = false;
|
||||
bool displayRotate = false;
|
||||
int displayOffsetRotate = 1;
|
||||
bool displayInvert = false;
|
||||
int displayOffsetX = 0;
|
||||
int displayOffsetY = 0;
|
||||
pinMapping displayDC = {"Display", "DC"};
|
||||
pinMapping displayCS = {"Display", "CS"};
|
||||
pinMapping displayBacklight = {"Display", "Backlight"};
|
||||
pinMapping displayBacklightPWMChannel = {"Display", "BacklightPWMChannel"};
|
||||
pinMapping displayReset = {"Display", "Reset"};
|
||||
|
||||
// Touchscreen
|
||||
std::string touchscreen_spi_dev = "";
|
||||
int touchscreen_spi_dev_int = 0;
|
||||
touchscreen_modules touchscreenModule = no_touchscreen;
|
||||
int touchscreenI2CAddr = -1;
|
||||
int touchscreenBusFrequency = 1000000;
|
||||
int touchscreenRotate = -1;
|
||||
pinMapping touchscreenCS = {"Touchscreen", "CS"};
|
||||
pinMapping touchscreenIRQ = {"Touchscreen", "IRQ"};
|
||||
|
||||
// Input
|
||||
std::string keyboardDevice = "";
|
||||
std::string pointerDevice = "";
|
||||
int tbDirection;
|
||||
pinMapping userButtonPin = {"Input", "User"};
|
||||
pinMapping tbUpPin = {"Input", "TrackballUp"};
|
||||
pinMapping tbDownPin = {"Input", "TrackballDown"};
|
||||
pinMapping tbLeftPin = {"Input", "TrackballLwft"};
|
||||
pinMapping tbRightPin = {"Input", "TrackballRight"};
|
||||
pinMapping tbPressPin = {"Input", "TrackballPress"};
|
||||
|
||||
// Logging
|
||||
portduino_log_level logoutputlevel = level_debug;
|
||||
std::string traceFilename;
|
||||
bool ascii_logs = !isatty(1);
|
||||
bool ascii_logs_explicit = false;
|
||||
|
||||
// Webserver
|
||||
std::string webserver_root_path = "";
|
||||
std::string webserver_ssl_key_path = "/etc/meshtasticd/ssl/private_key.pem";
|
||||
std::string webserver_ssl_cert_path = "/etc/meshtasticd/ssl/certificate.pem";
|
||||
int webserverport = -1;
|
||||
|
||||
// HostMetrics
|
||||
std::string hostMetrics_user_command = "";
|
||||
int hostMetrics_interval = 0;
|
||||
int hostMetrics_channel = 0;
|
||||
|
||||
// config
|
||||
int configDisplayMode = 0;
|
||||
bool has_configDisplayMode = false;
|
||||
|
||||
// General
|
||||
std::string mac_address = "";
|
||||
bool mac_address_explicit = false;
|
||||
std::string mac_address_source = "";
|
||||
std::string config_directory = "";
|
||||
std::string available_directory = "/etc/meshtasticd/available.d/";
|
||||
int maxtophone = 100;
|
||||
int MaxNodes = 200;
|
||||
|
||||
pinMapping *all_pins[20] = {&lora_cs_pin,
|
||||
&lora_irq_pin,
|
||||
&lora_busy_pin,
|
||||
&lora_reset_pin,
|
||||
&lora_txen_pin,
|
||||
&lora_rxen_pin,
|
||||
&lora_sx126x_ant_sw_pin,
|
||||
&displayDC,
|
||||
&displayCS,
|
||||
&displayBacklight,
|
||||
&displayBacklightPWMChannel,
|
||||
&displayReset,
|
||||
&touchscreenCS,
|
||||
&touchscreenIRQ,
|
||||
&userButtonPin,
|
||||
&tbUpPin,
|
||||
&tbDownPin,
|
||||
&tbLeftPin,
|
||||
&tbRightPin,
|
||||
&tbPressPin};
|
||||
|
||||
std::string emit_yaml()
|
||||
{
|
||||
YAML::Emitter out;
|
||||
out << YAML::BeginMap;
|
||||
|
||||
// Lora
|
||||
out << YAML::Key << "Lora" << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "Module" << YAML::Value << loraModules[lora_module];
|
||||
|
||||
for (auto lora_pin : all_pins) {
|
||||
if (lora_pin->config_section == "Lora" && lora_pin->enabled) {
|
||||
out << YAML::Key << lora_pin->config_name << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "pin" << YAML::Value << lora_pin->pin;
|
||||
out << YAML::Key << "line" << YAML::Value << lora_pin->line;
|
||||
out << YAML::Key << "gpiochip" << YAML::Value << lora_pin->gpiochip;
|
||||
out << YAML::EndMap; // User
|
||||
}
|
||||
}
|
||||
|
||||
if (sx126x_max_power != 22)
|
||||
out << YAML::Key << "SX126X_MAX_POWER" << YAML::Value << sx126x_max_power;
|
||||
if (sx128x_max_power != 13)
|
||||
out << YAML::Key << "SX128X_MAX_POWER" << YAML::Value << sx128x_max_power;
|
||||
if (lr1110_max_power != 22)
|
||||
out << YAML::Key << "LR1110_MAX_POWER" << YAML::Value << lr1110_max_power;
|
||||
if (lr1120_max_power != 13)
|
||||
out << YAML::Key << "LR1120_MAX_POWER" << YAML::Value << lr1120_max_power;
|
||||
if (rf95_max_power != 20)
|
||||
out << YAML::Key << "RF95_MAX_POWER" << YAML::Value << rf95_max_power;
|
||||
out << YAML::Key << "DIO2_AS_RF_SWITCH" << YAML::Value << dio2_as_rf_switch;
|
||||
if (dio3_tcxo_voltage != 0)
|
||||
out << YAML::Key << "DIO3_TCXO_VOLTAGE" << YAML::Value << dio3_tcxo_voltage;
|
||||
if (lora_usb_pid != 0x5512)
|
||||
out << YAML::Key << "USB_PID" << YAML::Value << YAML::Hex << lora_usb_pid;
|
||||
if (lora_usb_vid != 0x1A86)
|
||||
out << YAML::Key << "USB_VID" << YAML::Value << YAML::Hex << lora_usb_vid;
|
||||
if (lora_spi_dev != "")
|
||||
out << YAML::Key << "spidev" << YAML::Value << lora_spi_dev;
|
||||
if (lora_usb_serial_num != "")
|
||||
out << YAML::Key << "USB_Serialnum" << YAML::Value << lora_usb_serial_num;
|
||||
out << YAML::Key << "spiSpeed" << YAML::Value << spiSpeed;
|
||||
if (rfswitch_dio_pins[0] != RADIOLIB_NC) {
|
||||
out << YAML::Key << "rfswitch_table" << YAML::Value << YAML::BeginMap;
|
||||
|
||||
out << YAML::Key << "pins";
|
||||
out << YAML::Value << YAML::Flow << YAML::BeginSeq;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// set up the pin array first
|
||||
if (rfswitch_dio_pins[i] == RADIOLIB_LR11X0_DIO5)
|
||||
out << "DIO5";
|
||||
if (rfswitch_dio_pins[i] == RADIOLIB_LR11X0_DIO6)
|
||||
out << "DIO6";
|
||||
if (rfswitch_dio_pins[i] == RADIOLIB_LR11X0_DIO7)
|
||||
out << "DIO7";
|
||||
if (rfswitch_dio_pins[i] == RADIOLIB_LR11X0_DIO8)
|
||||
out << "DIO8";
|
||||
if (rfswitch_dio_pins[i] == RADIOLIB_LR11X0_DIO10)
|
||||
out << "DIO10";
|
||||
}
|
||||
out << YAML::EndSeq;
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
out << YAML::Key << "MODE_STBY";
|
||||
break;
|
||||
case 1:
|
||||
out << YAML::Key << "MODE_RX";
|
||||
break;
|
||||
case 2:
|
||||
out << YAML::Key << "MODE_TX";
|
||||
break;
|
||||
case 3:
|
||||
out << YAML::Key << "MODE_TX_HP";
|
||||
break;
|
||||
case 4:
|
||||
out << YAML::Key << "MODE_TX_HF";
|
||||
break;
|
||||
case 5:
|
||||
out << YAML::Key << "MODE_GNSS";
|
||||
break;
|
||||
case 6:
|
||||
out << YAML::Key << "MODE_WIFI";
|
||||
break;
|
||||
}
|
||||
|
||||
out << YAML::Value << YAML::Flow << YAML::BeginSeq;
|
||||
for (int j = 0; j < 5; j++) {
|
||||
if (rfswitch_table[i].values[j] == HIGH) {
|
||||
out << "HIGH";
|
||||
} else {
|
||||
out << "LOW";
|
||||
}
|
||||
}
|
||||
out << YAML::EndSeq;
|
||||
}
|
||||
out << YAML::EndMap; // rfswitch_table
|
||||
}
|
||||
out << YAML::EndMap; // Lora
|
||||
|
||||
if (i2cdev != "") {
|
||||
out << YAML::Key << "I2C" << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "I2CDevice" << YAML::Value << i2cdev;
|
||||
out << YAML::EndMap; // I2C
|
||||
}
|
||||
|
||||
// Display
|
||||
if (displayPanel != no_screen) {
|
||||
out << YAML::Key << "Display" << YAML::Value << YAML::BeginMap;
|
||||
for (auto &screen_name : screen_names) {
|
||||
if (displayPanel == screen_name.first)
|
||||
out << YAML::Key << "Module" << YAML::Value << screen_name.second;
|
||||
}
|
||||
for (auto display_pin : all_pins) {
|
||||
if (display_pin->config_section == "Display" && display_pin->enabled) {
|
||||
out << YAML::Key << display_pin->config_name << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "pin" << YAML::Value << display_pin->pin;
|
||||
out << YAML::Key << "line" << YAML::Value << display_pin->line;
|
||||
out << YAML::Key << "gpiochip" << YAML::Value << display_pin->gpiochip;
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
}
|
||||
out << YAML::Key << "spidev" << YAML::Value << display_spi_dev;
|
||||
out << YAML::Key << "BusFrequency" << YAML::Value << displayBusFrequency;
|
||||
if (displayWidth)
|
||||
out << YAML::Key << "Width" << YAML::Value << displayWidth;
|
||||
if (displayHeight)
|
||||
out << YAML::Key << "Height" << YAML::Value << displayHeight;
|
||||
if (displayRGBOrder)
|
||||
out << YAML::Key << "RGBOrder" << YAML::Value << true;
|
||||
if (displayBacklightInvert)
|
||||
out << YAML::Key << "BacklightInvert" << YAML::Value << true;
|
||||
if (displayRotate)
|
||||
out << YAML::Key << "Rotate" << YAML::Value << true;
|
||||
if (displayInvert)
|
||||
out << YAML::Key << "Invert" << YAML::Value << true;
|
||||
if (displayOffsetX)
|
||||
out << YAML::Key << "OffsetX" << YAML::Value << displayOffsetX;
|
||||
if (displayOffsetY)
|
||||
out << YAML::Key << "OffsetY" << YAML::Value << displayOffsetY;
|
||||
|
||||
out << YAML::Key << "OffsetRotate" << YAML::Value << displayOffsetRotate;
|
||||
|
||||
out << YAML::EndMap; // Display
|
||||
}
|
||||
|
||||
// Touchscreen
|
||||
if (touchscreen_spi_dev != "") {
|
||||
out << YAML::Key << "Touchscreen" << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "spidev" << YAML::Value << touchscreen_spi_dev;
|
||||
out << YAML::Key << "BusFrequency" << YAML::Value << touchscreenBusFrequency;
|
||||
switch (touchscreenModule) {
|
||||
case xpt2046:
|
||||
out << YAML::Key << "Module" << YAML::Value << "XPT2046";
|
||||
case stmpe610:
|
||||
out << YAML::Key << "Module" << YAML::Value << "STMPE610";
|
||||
case gt911:
|
||||
out << YAML::Key << "Module" << YAML::Value << "GT911";
|
||||
case ft5x06:
|
||||
out << YAML::Key << "Module" << YAML::Value << "FT5x06";
|
||||
}
|
||||
for (auto touchscreen_pin : all_pins) {
|
||||
if (touchscreen_pin->config_section == "Touchscreen" && touchscreen_pin->enabled) {
|
||||
out << YAML::Key << touchscreen_pin->config_name << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "pin" << YAML::Value << touchscreen_pin->pin;
|
||||
out << YAML::Key << "line" << YAML::Value << touchscreen_pin->line;
|
||||
out << YAML::Key << "gpiochip" << YAML::Value << touchscreen_pin->gpiochip;
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
}
|
||||
if (touchscreenRotate != -1)
|
||||
out << YAML::Key << "Rotate" << YAML::Value << touchscreenRotate;
|
||||
if (touchscreenI2CAddr != -1)
|
||||
out << YAML::Key << "I2CAddr" << YAML::Value << touchscreenI2CAddr;
|
||||
out << YAML::EndMap; // Touchscreen
|
||||
}
|
||||
|
||||
// Input
|
||||
out << YAML::Key << "Input" << YAML::Value << YAML::BeginMap;
|
||||
if (keyboardDevice != "")
|
||||
out << YAML::Key << "KeyboardDevice" << YAML::Value << keyboardDevice;
|
||||
if (pointerDevice != "")
|
||||
out << YAML::Key << "PointerDevice" << YAML::Value << pointerDevice;
|
||||
|
||||
for (auto input_pin : all_pins) {
|
||||
if (input_pin->config_section == "Input" && input_pin->enabled) {
|
||||
out << YAML::Key << input_pin->config_name << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "pin" << YAML::Value << input_pin->pin;
|
||||
out << YAML::Key << "line" << YAML::Value << input_pin->line;
|
||||
out << YAML::Key << "gpiochip" << YAML::Value << input_pin->gpiochip;
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
}
|
||||
if (tbDirection == 3)
|
||||
out << YAML::Key << "TrackballDirection" << YAML::Value << "FALLING";
|
||||
|
||||
out << YAML::EndMap; // Input
|
||||
|
||||
out << YAML::Key << "Logging" << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "LogLevel" << YAML::Value;
|
||||
switch (logoutputlevel) {
|
||||
case level_error:
|
||||
out << "error";
|
||||
break;
|
||||
case level_warn:
|
||||
out << "warn";
|
||||
break;
|
||||
case level_info:
|
||||
out << "info";
|
||||
break;
|
||||
case level_debug:
|
||||
out << "debug";
|
||||
break;
|
||||
case level_trace:
|
||||
out << "trace";
|
||||
break;
|
||||
}
|
||||
if (traceFilename != "")
|
||||
out << YAML::Key << "TraceFile" << YAML::Value << traceFilename;
|
||||
if (ascii_logs_explicit) {
|
||||
out << YAML::Key << "AsciiLogs" << YAML::Value << ascii_logs;
|
||||
}
|
||||
out << YAML::EndMap; // Logging
|
||||
|
||||
// Webserver
|
||||
if (webserver_root_path != "") {
|
||||
out << YAML::Key << "Webserver" << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "RootPath" << YAML::Value << webserver_root_path;
|
||||
out << YAML::Key << "SSLKey" << YAML::Value << webserver_ssl_key_path;
|
||||
out << YAML::Key << "SSLCert" << YAML::Value << webserver_ssl_cert_path;
|
||||
out << YAML::Key << "Port" << YAML::Value << webserverport;
|
||||
out << YAML::EndMap; // Webserver
|
||||
}
|
||||
|
||||
// HostMetrics
|
||||
if (hostMetrics_user_command != "") {
|
||||
out << YAML::Key << "HostMetrics" << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "UserStringCommand" << YAML::Value << hostMetrics_user_command;
|
||||
out << YAML::Key << "ReportInterval" << YAML::Value << hostMetrics_interval;
|
||||
out << YAML::Key << "Channel" << YAML::Value << hostMetrics_channel;
|
||||
|
||||
out << YAML::EndMap; // HostMetrics
|
||||
}
|
||||
|
||||
// config
|
||||
if (has_configDisplayMode) {
|
||||
out << YAML::Key << "Config" << YAML::Value << YAML::BeginMap;
|
||||
switch (configDisplayMode) {
|
||||
case meshtastic_Config_DisplayConfig_DisplayMode_TWOCOLOR:
|
||||
out << YAML::Key << "DisplayMode" << YAML::Value << "TWOCOLOR";
|
||||
case meshtastic_Config_DisplayConfig_DisplayMode_INVERTED:
|
||||
out << YAML::Key << "DisplayMode" << YAML::Value << "INVERTED";
|
||||
case meshtastic_Config_DisplayConfig_DisplayMode_COLOR:
|
||||
out << YAML::Key << "DisplayMode" << YAML::Value << "COLOR";
|
||||
case meshtastic_Config_DisplayConfig_DisplayMode_DEFAULT:
|
||||
out << YAML::Key << "DisplayMode" << YAML::Value << "DEFAULT";
|
||||
}
|
||||
|
||||
out << YAML::EndMap; // Config
|
||||
}
|
||||
|
||||
// General
|
||||
out << YAML::Key << "General" << YAML::Value << YAML::BeginMap;
|
||||
if (config_directory != "")
|
||||
out << YAML::Key << "ConfigDirectory" << YAML::Value << config_directory;
|
||||
if (mac_address_explicit)
|
||||
out << YAML::Key << "MACAddress" << YAML::Value << mac_address;
|
||||
if (mac_address_source != "")
|
||||
out << YAML::Key << "MACAddressSource" << YAML::Value << mac_address_source;
|
||||
if (available_directory != "")
|
||||
out << YAML::Key << "AvailableDirectory" << YAML::Value << available_directory;
|
||||
out << YAML::Key << "MaxMessageQueue" << YAML::Value << maxtophone;
|
||||
out << YAML::Key << "MaxNodes" << YAML::Value << MaxNodes;
|
||||
out << YAML::EndMap; // General
|
||||
return out.c_str();
|
||||
}
|
||||
} portduino_config;
|
||||
@@ -28,9 +28,9 @@
|
||||
#endif
|
||||
#ifndef HAS_TRACKBALL
|
||||
#define HAS_TRACKBALL 1
|
||||
#define TB_DOWN (uint8_t) settingsMap[tbDownPin]
|
||||
#define TB_UP (uint8_t) settingsMap[tbUpPin]
|
||||
#define TB_LEFT (uint8_t) settingsMap[tbLeftPin]
|
||||
#define TB_RIGHT (uint8_t) settingsMap[tbRightPin]
|
||||
#define TB_PRESS (uint8_t) settingsMap[tbPressPin]
|
||||
#define TB_DOWN (uint8_t) portduino_config.tbDownPin.pin
|
||||
#define TB_UP (uint8_t) portduino_config.tbUpPin.pin
|
||||
#define TB_LEFT (uint8_t) portduino_config.tbLeftPin.pin
|
||||
#define TB_RIGHT (uint8_t) portduino_config.tbRightPin.pin
|
||||
#define TB_PRESS (uint8_t) portduino_config.tbPressPin.pin
|
||||
#endif
|
||||
Reference in New Issue
Block a user