From 00f15459eceee4b63fce0b86371fa37e1e5e8a75 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 2 Oct 2024 06:14:24 -0500 Subject: [PATCH] Userprefs prefix macros for clarity and consistency (#4923) * Convert userprefs macros to prefixed ones for clarity * Fix key --- src/graphics/Screen.cpp | 4 ++-- src/graphics/img/icon.xbm | 2 +- src/mesh/Channels.cpp | 22 +++++++++++----------- src/mesh/Default.cpp | 2 +- src/mesh/FloodingRouter.cpp | 2 +- src/mesh/NodeDB.cpp | 24 ++++++++++++------------ src/mesh/Router.cpp | 2 +- src/modules/AdminModule.cpp | 2 +- userPrefs.h | 28 ++++++++++++++-------------- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index ef6b05ca4..50350a310 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -163,8 +163,8 @@ static void drawIconScreen(const char *upperMsg, OLEDDisplay *display, OLEDDispl display->setFont(FONT_MEDIUM); display->setTextAlignment(TEXT_ALIGN_LEFT); -#ifdef SPLASH_TITLE_USERPREFS - const char *title = SPLASH_TITLE_USERPREFS; +#ifdef USERPREFS_SPLASH_TITLE + const char *title = USERPREFS_SPLASH_TITLE; #else const char *title = "meshtastic.org"; #endif diff --git a/src/graphics/img/icon.xbm b/src/graphics/img/icon.xbm index f90cf4946..4e78ae8a1 100644 --- a/src/graphics/img/icon.xbm +++ b/src/graphics/img/icon.xbm @@ -1,4 +1,4 @@ -#ifndef HAS_USERPREFS_SPLASH +#ifndef USERPREFS_HAS_SPLASH #define icon_width 50 #define icon_height 28 static uint8_t icon_bits[] = { diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 47c013443..c8ac09a37 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -99,26 +99,26 @@ void Channels::initDefaultChannel(ChannelIndex chIndex) ch.has_settings = true; ch.role = meshtastic_Channel_Role_PRIMARY; -#ifdef LORACONFIG_MODEM_PRESET_USERPREFS - loraConfig.modem_preset = LORACONFIG_MODEM_PRESET_USERPREFS; +#ifdef USERPREFS_LORACONFIG_MODEM_PRESET + loraConfig.modem_preset = USERPREFS_LORACONFIG_MODEM_PRESET; #endif -#ifdef LORACONFIG_CHANNEL_NUM_USERPREFS - loraConfig.channel_num = LORACONFIG_CHANNEL_NUM_USERPREFS; +#ifdef USERPREFS_LORACONFIG_CHANNEL_NUM + loraConfig.channel_num = USERPREFS_LORACONFIG_CHANNEL_NUM; #endif // Install custom defaults. Will eventually support setting multiple default channels if (chIndex == 0) { -#ifdef CHANNEL_0_PSK_USERPREFS - static const uint8_t defaultpsk[] = CHANNEL_0_PSK_USERPREFS; +#ifdef USERPREFS_CHANNEL_0_PSK + static const uint8_t defaultpsk[] = USERPREFS_CHANNEL_0_PSK; memcpy(channelSettings.psk.bytes, defaultpsk, sizeof(defaultpsk)); channelSettings.psk.size = sizeof(defaultpsk); #endif -#ifdef CHANNEL_0_NAME_USERPREFS - strcpy(channelSettings.name, CHANNEL_0_NAME_USERPREFS); +#ifdef USERPREFS_CHANNEL_0_NAME + strcpy(channelSettings.name, USERPREFS_CHANNEL_0_NAME); #endif -#ifdef CHANNEL_0_PRECISION_USERPREFS - channelSettings.module_settings.position_precision = CHANNEL_0_PRECISION_USERPREFS; +#ifdef USERPREFS_CHANNEL_0_PRECISION + channelSettings.module_settings.position_precision = USERPREFS_CHANNEL_0_PRECISION; #endif } } @@ -273,7 +273,7 @@ void Channels::setChannel(const meshtastic_Channel &c) bool Channels::anyMqttEnabled() { -#if EVENT_MODE +#if USERPREFS_EVENT_MODE // Don't publish messages on the public MQTT broker if we are in event mode if (strcmp(moduleConfig.mqtt.address, default_mqtt_address) == 0) { return false; diff --git a/src/mesh/Default.cpp b/src/mesh/Default.cpp index ac7441394..0bedcfc91 100644 --- a/src/mesh/Default.cpp +++ b/src/mesh/Default.cpp @@ -45,7 +45,7 @@ uint32_t Default::getConfiguredOrDefaultMsScaled(uint32_t configured, uint32_t d uint8_t Default::getConfiguredOrDefaultHopLimit(uint8_t configured) { -#if EVENT_MODE +#if USERPREFS_EVENT_MODE return (configured > HOP_RELIABLE) ? HOP_RELIABLE : config.lora.hop_limit; #else return (configured >= HOP_MAX) ? HOP_MAX : config.lora.hop_limit; diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index e2dbd8997..037fdd2ae 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -47,7 +47,7 @@ void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas meshtastic_MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it tosend->hop_limit--; // bump down the hop count -#if EVENT_MODE +#if USERPREFS_EVENT_MODE if (tosend->hop_limit > 2) { // if we are "correcting" the hop_limit, "correct" the hop_start by the same amount to preserve hops away. tosend->hop_start -= (tosend->hop_limit - 2); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index b78827e65..25314a086 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -286,24 +286,24 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) true; // FIXME: maybe false in the future, and setting region to enable it. (unset region forces it off) config.lora.override_duty_cycle = false; config.lora.config_ok_to_mqtt = false; -#ifdef CONFIG_LORA_REGION_USERPREFS - config.lora.region = CONFIG_LORA_REGION_USERPREFS; +#ifdef USERPREFS_CONFIG_LORA_REGION + config.lora.region = USERPREFS_CONFIG_LORA_REGION; #else config.lora.region = meshtastic_Config_LoRaConfig_RegionCode_UNSET; #endif -#ifdef LORACONFIG_MODEM_PRESET_USERPREFS - config.lora.modem_preset = LORACONFIG_MODEM_PRESET_USERPREFS; +#ifdef USERPREFS_LORACONFIG_MODEM_PRESET + config.lora.modem_preset = USERPREFS_LORACONFIG_MODEM_PRESET; #else config.lora.modem_preset = meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST; #endif config.lora.hop_limit = HOP_RELIABLE; -#ifdef CONFIG_LORA_IGNORE_MQTT_USERPREFS - config.lora.ignore_mqtt = CONFIG_LORA_IGNORE_MQTT_USERPREFS; +#ifdef USERPREFS_CONFIG_LORA_IGNORE_MQTT + config.lora.ignore_mqtt = USERPREFS_CONFIG_LORA_IGNORE_MQTT; #else config.lora.ignore_mqtt = false; #endif -#ifdef ADMIN_KEY_USERPREFS - memcpy(config.security.admin_key[0].bytes, admin_key_userprefs, 32); +#ifdef USERPREFS_USE_ADMIN_KEY + memcpy(config.security.admin_key[0].bytes, USERPREFS_ADMIN_KEY, 32); config.security.admin_key[0].size = 32; #else config.security.admin_key[0].size = 0; @@ -617,13 +617,13 @@ void NodeDB::installDefaultDeviceState() // Set default owner name pickNewNodeNum(); // based on macaddr now -#ifdef CONFIG_OWNER_LONG_NAME_USERPREFS - snprintf(owner.long_name, sizeof(owner.long_name), CONFIG_OWNER_LONG_NAME_USERPREFS); +#ifdef USERPREFS_CONFIG_OWNER_LONG_NAME + snprintf(owner.long_name, sizeof(owner.long_name), USERPREFS_CONFIG_OWNER_LONG_NAME); #else snprintf(owner.long_name, sizeof(owner.long_name), "Meshtastic %02x%02x", ourMacAddr[4], ourMacAddr[5]); #endif -#ifdef CONFIG_OWNER_SHORT_NAME_USERPREFS - snprintf(owner.short_name, sizeof(owner.short_name), CONFIG_OWNER_SHORT_NAME_USERPREFS); +#ifdef USERPREFS_CONFIG_OWNER_SHORT_NAME + snprintf(owner.short_name, sizeof(owner.short_name), USERPREFS_CONFIG_OWNER_SHORT_NAME); #else snprintf(owner.short_name, sizeof(owner.short_name), "%02x%02x", ourMacAddr[4], ourMacAddr[5]); #endif diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 610d5303e..6ff4364d1 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -590,7 +590,7 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) skipHandle = true; } -#if EVENT_MODE +#if USERPREFS_EVENT_MODE if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag && (p->decoded.portnum == meshtastic_PortNum_ATAK_FORWARDER || p->decoded.portnum == meshtastic_PortNum_ATAK_PLUGIN || p->decoded.portnum == meshtastic_PortNum_PAXCOUNTER_APP || p->decoded.portnum == meshtastic_PortNum_IP_TUNNEL_APP || diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 4a7af4817..b94bbddf2 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -467,7 +467,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) requiresReboot = true; } } -#if EVENT_MODE +#if USERPREFS_EVENT_MODE // If we're in event mode, nobody is a Router or Repeater if (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER || config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER) { diff --git a/userPrefs.h b/userPrefs.h index 3b32bf79b..40f2cc6d2 100644 --- a/userPrefs.h +++ b/userPrefs.h @@ -3,29 +3,29 @@ // Uncomment and modify to set device defaults -// #define EVENT_MODE 1 +// #define USERPREFS_EVENT_MODE 1 -// #define CONFIG_LORA_REGION_USERPREFS meshtastic_Config_LoRaConfig_RegionCode_US -// #define LORACONFIG_MODEM_PRESET_USERPREFS meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST -// #define LORACONFIG_CHANNEL_NUM_USERPREFS 31 -// #define CONFIG_LORA_IGNORE_MQTT_USERPREFS true +// #define USERPREFS_CONFIG_LORA_REGION meshtastic_Config_LoRaConfig_RegionCode_US +// #define USERPREFS_LORACONFIG_MODEM_PRESET meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST +// #define USERPREFS_LORACONFIG_CHANNEL_NUM 31 +// #define USERPREFS_CONFIG_LORA_IGNORE_MQTT true /* -#define CHANNEL_0_PSK_USERPREFS \ +#define USERPREFS_CHANNEL_0_PSK \ { \ 0x38, 0x4b, 0xbc, 0xc0, 0x1d, 0xc0, 0x22, 0xd1, 0x81, 0xbf, 0x36, 0xb8, 0x61, 0x21, 0xe1, 0xfb, 0x96, 0xb7, 0x2e, 0x55, \ 0xbf, 0x74, 0x22, 0x7e, 0x9d, 0x6a, 0xfb, 0x48, 0xd6, 0x4c, 0xb1, 0xa1 \ } */ -// #define CHANNEL_0_NAME_USERPREFS "DEFCONnect" -// #define CHANNEL_0_PRECISION_USERPREFS 14 +// #define USERPREFS_CHANNEL_0_NAME "DEFCONnect" +// #define USERPREFS_CHANNEL_0_PRECISION 14 -// #define CONFIG_OWNER_LONG_NAME_USERPREFS "My Long Name" -// #define CONFIG_OWNER_SHORT_NAME_USERPREFS "MLN" +// #define USERPREFS_CONFIG_OWNER_LONG_NAME "My Long Name" +// #define USERPREFS_CONFIG_OWNER_SHORT_NAME "MLN" -// #define SPLASH_TITLE_USERPREFS "DEFCONtastic" +// #define USERPREFS_SPLASH_TITLE "DEFCONtastic" // #define icon_width 34 // #define icon_height 29 -// #define HAS_USERPREFS_SPLASH +// #define USERPREFS_HAS_SPLASH /* static unsigned char icon_bits[] = { 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xF8, 0x7F, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0x00, @@ -37,8 +37,8 @@ static unsigned char icon_bits[] = { 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00}; */ /* -#define ADMIN_KEY_USERPREFS 1 -static unsigned char admin_key_userprefs[] = {0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6, +#define USERPREFS_USE_ADMIN_KEY 1 +static unsigned char USERPREFS_ADMIN_KEY[] = {0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6, 0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, 0x04, 0x1a, 0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c}; */