diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 040712e1d2..743f4214da 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -30,7 +30,7 @@ lint: - git-diff-check - gitleaks@8.21.1 - clang-format@16.0.3 - - prettier@3.3.3 + #- prettier@3.3.3 ignore: - linters: [ALL] paths: @@ -46,4 +46,4 @@ actions: enabled: - trunk-fmt-pre-commit - trunk-check-pre-push - - trunk-upgrade-available + - trunk-upgrade-available \ No newline at end of file diff --git a/bin/build-userprefs-json.py b/bin/build-userprefs-json.py index 58f460bcfa..d155bae018 100644 --- a/bin/build-userprefs-json.py +++ b/bin/build-userprefs-json.py @@ -24,7 +24,7 @@ def write_macros_to_json(macros, output_file): def main(): header_file = 'userPrefs.h' - output_file = 'userPrefs.json' + output_file = 'userPrefs.jsonc' # Uncomment all macros in the header file with open(header_file, 'r') as file: lines = file.readlines() diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py index 701f6b5d80..acfeae10cf 100644 --- a/bin/platformio-custom.py +++ b/bin/platformio-custom.py @@ -3,6 +3,8 @@ # trunk-ignore-all(flake8/F821): For SConstruct imports import sys from os.path import join +import json +import re from readprops import readProps @@ -90,11 +92,37 @@ def esp32_create_combined_bin(source, target, env): verObj = readProps(prefsLoc) print("Using meshtastic platformio-custom.py, firmware version " + verObj["long"] + " on " + env.get("PIOENV")) +jsonLoc = env["PROJECT_DIR"] + "/userPrefs.jsonc" +with open(jsonLoc) as f: + jsonStr = re.sub("//.*","", f.read(), flags=re.MULTILINE) + userPrefs = json.loads(jsonStr) + +pref_flags = [] +# Pre-process the userPrefs +for pref in userPrefs: + if userPrefs[pref].startswith("{"): + pref_flags.append("-D" + pref + "=" + userPrefs[pref]) + elif userPrefs[pref].replace(".", "").isdigit(): + pref_flags.append("-D" + pref + "=" + userPrefs[pref]) + elif userPrefs[pref] == "true" or userPrefs[pref] == "false": + pref_flags.append("-D" + pref + "=" + userPrefs[pref]) + elif userPrefs[pref].startswith("meshtastic_"): + pref_flags.append("-D" + pref + "=" + userPrefs[pref]) + # If the value is a string, we need to wrap it in quotes + else: + pref_flags.append("-D" + pref + "=" + env.StringifyMacro(userPrefs[pref]) + "") + # General options that are passed to the C and C++ compilers -projenv.Append( - CCFLAGS=[ +flags = [ "-DAPP_VERSION=" + verObj["long"], "-DAPP_VERSION_SHORT=" + verObj["short"], "-DAPP_ENV=" + env.get("PIOENV"), - ] -) + ] + pref_flags + +print ("Using flags:") +for flag in flags: + print(flag) + +projenv.Append( + CCFLAGS=flags, +) \ No newline at end of file diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index 2383599528..3f64b3b3e2 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -1,5 +1,5 @@ #include "ButtonThread.h" -#include "../userPrefs.h" + #include "configuration.h" #if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 41c90ca9ab..00884c5af9 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -1,6 +1,5 @@ #pragma once -#include "../userPrefs.h" #include "configuration.h" #include "detect/ScanI2C.h" @@ -606,4 +605,4 @@ class Screen : public concurrency::OSThread } // namespace graphics -#endif +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 9036cd59ca..902668d231 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,3 @@ -#include "../userPrefs.h" #include "configuration.h" #if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index a516268eb5..cfaff7640a 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -1,5 +1,5 @@ #include "Channels.h" -#include "../userPrefs.h" + #include "CryptoEngine.h" #include "Default.h" #include "DisplayFormatters.h" diff --git a/src/mesh/Default.cpp b/src/mesh/Default.cpp index ba1dafe702..1bd0340f83 100644 --- a/src/mesh/Default.cpp +++ b/src/mesh/Default.cpp @@ -1,5 +1,5 @@ #include "Default.h" -#include "../userPrefs.h" + #include "meshUtils.h" uint32_t Default::getConfiguredOrDefaultMs(uint32_t configuredInterval, uint32_t defaultInterval) diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index 81ea723817..e959297bff 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -1,5 +1,5 @@ #include "FloodingRouter.h" -#include "../userPrefs.h" + #include "configuration.h" #include "mesh-pb-constants.h" diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 0d63d3b9bf..8935e12150 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1,4 +1,3 @@ -#include "../userPrefs.h" #include "configuration.h" #if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 7b792db308..1303c5caa4 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -20,7 +20,6 @@ #if ENABLE_JSON_LOGGING || ARCH_PORTDUINO #include "serialization/MeshPacketSerializer.h" #endif -#include "../userPrefs.h" #define MAX_RX_FROMRADIO \ 4 // max number of packets destined to our queue, we dispatch packets quickly so it doesn't need to be big diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index c81b6ede4a..2d33b723d6 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -18,7 +18,7 @@ #ifdef ARCH_PORTDUINO #include "unistd.h" #endif -#include "../userPrefs.h" + #include "Default.h" #include "TypeConversions.h" @@ -1123,4 +1123,4 @@ void disableBluetooth() nrf52Bluetooth->shutdown(); #endif #endif -} +} \ No newline at end of file diff --git a/userPrefs.h b/userPrefs.h deleted file mode 100644 index 00f04149ad..0000000000 --- a/userPrefs.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef _USERPREFS_ -#define _USERPREFS_ - -// Slipstream values: - -#define USERPREFS_TZ_STRING "tzplaceholder " - -// Uncomment and modify to set device defaults - -// #define USERPREFS_EVENT_MODE 1 - -// #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 USERPREFS_CONFIG_GPS_MODE meshtastic_Config_PositionConfig_GpsMode_ENABLED - -// #define USERPREFS_CHANNELS_TO_WRITE 3 -/* -#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 USERPREFS_CHANNEL_0_NAME "DEFCONnect" -// #define USERPREFS_CHANNEL_0_PRECISION 14 -// #define USERPREFS_CHANNEL_0_UPLINK_ENABLED true -// #define USERPREFS_CHANNEL_0_DOWNLINK_ENABLED true -/* -#define USERPREFS_CHANNEL_1_PSK \ - { \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \ - } -*/ -// #define USERPREFS_CHANNEL_1_NAME "REPLACEME" -// #define USERPREFS_CHANNEL_1_PRECISION 14 -// #define USERPREFS_CHANNEL_1_UPLINK_ENABLED true -// #define USERPREFS_CHANNEL_1_DOWNLINK_ENABLED true -/* -#define USERPREFS_CHANNEL_2_PSK \ - { \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \ - } -*/ -// #define USERPREFS_CHANNEL_2_NAME "REPLACEME" -// #define USERPREFS_CHANNEL_2_PRECISION 14 -// #define USERPREFS_CHANNEL_2_UPLINK_ENABLED true -// #define USERPREFS_CHANNEL_2_DOWNLINK_ENABLED true - -// #define USERPREFS_CONFIG_OWNER_LONG_NAME "My Long Name" -// #define USERPREFS_CONFIG_OWNER_SHORT_NAME "MLN" - -// #define USERPREFS_SPLASH_TITLE "DEFCONtastic" -// #define icon_width 34 -// #define icon_height 29 -// #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, - 0x9E, 0xE7, 0x00, 0x00, 0x00, 0x0E, 0xC7, 0x01, 0x00, 0x1C, 0x0F, 0xC7, 0x01, 0x00, 0x1C, 0xDF, 0xE7, 0x63, 0x00, 0x1C, 0xFF, - 0xBF, 0xE1, 0x00, 0x3C, 0xF3, 0xBF, 0xE3, 0x00, 0x7F, 0xF7, 0xBF, 0xF1, 0x00, 0xFF, 0xF7, 0xBF, 0xF9, 0x03, 0xFF, 0xE7, 0x9F, - 0xFF, 0x03, 0xC0, 0xCF, 0xEF, 0xDF, 0x03, 0x00, 0xDF, 0xE3, 0x8F, 0x00, 0x00, 0x7C, 0xFB, 0x03, 0x00, 0x00, 0xF8, 0xFF, 0x00, - 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0x78, 0x3F, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0x00, 0x00, - 0x98, 0x3F, 0xF0, 0x23, 0x00, 0xFC, 0x0F, 0xE0, 0x7F, 0x00, 0xFC, 0x03, 0x80, 0xFF, 0x01, 0xFC, 0x00, 0x00, 0x3E, 0x00, 0x70, - 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00}; -*/ - -/* - * PKI Admin keys. - * If a Admin key is set with '{};' - * then it will be ignored, a PKI key must have a size of 32 byte. - */ -/* -#define USERPREFS_USE_ADMIN_KEY_0 \ - { \ - 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 \ - }; -*/ -// #define USERPREFS_USE_ADMIN_KEY_1 {}; -// #define USERPREFS_USE_ADMIN_KEY_2 {}; - -/* - * USERPREF_FIXED_GPS_LAT and USERPREF_FIXED_GPS_LON must be set, USERPREF_FIXED_GPS_ALT is optional - * - * Fixed GPS is Eiffel Tower, Paris, France - */ -// #define USERPREFS_FIXED_GPS -// #define USERPREFS_FIXED_GPS_LAT 48.85873920 -// #define USERPREFS_FIXED_GPS_LON 2.294508368 -// #define USERPREFS_FIXED_GPS_ALT 0 - -/* - * Set Fixed Bluetooth paring code - */ -// #define USERPREFS_FIXED_BLUETOOTH 121212 - -/* - * Will overwrite BUTTON_PIN if set - */ -// #define USERPREFS_BUTTON_PIN 36 - -#endif \ No newline at end of file diff --git a/userPrefs.json b/userPrefs.json deleted file mode 100644 index bc62602be3..0000000000 --- a/userPrefs.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "USERPREFS_CHANNEL_0_NAME": "\"DEFCONnect\"", - "USERPREFS_CHANNEL_0_PRECISION": "14", - "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 }", - "USERPREFS_CONFIG_LORA_IGNORE_MQTT": "true", - "USERPREFS_CONFIG_LORA_REGION": "meshtastic_Config_LoRaConfig_RegionCode_US", - "USERPREFS_CONFIG_OWNER_LONG_NAME": "\"My Long Name\"", - "USERPREFS_CONFIG_OWNER_SHORT_NAME": "\"MLN\"", - "USERPREFS_EVENT_MODE": "1", - "USERPREFS_HAS_SPLASH": "", - "USERPREFS_LORACONFIG_CHANNEL_NUM": "31", - "USERPREFS_LORACONFIG_MODEM_PRESET": "meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST", - "USERPREFS_SPLASH_TITLE": "\"DEFCONtastic\"", - "USERPREFS_TZ_STRING": "\"tzplaceholder \"", - "USERPREFS_USE_ADMIN_KEY": "1" -} diff --git a/userPrefs.jsonc b/userPrefs.jsonc new file mode 100644 index 0000000000..055f592734 --- /dev/null +++ b/userPrefs.jsonc @@ -0,0 +1,37 @@ +{ + // "USERPREFS_BUTTON_PIN": "36", + // "USERPREFS_CHANNELS_TO_WRITE": "3", + // "USERPREFS_CHANNEL_0_DOWNLINK_ENABLED": "true", + // "USERPREFS_CHANNEL_0_NAME": "DEFCONnect", + // "USERPREFS_CHANNEL_0_PRECISION": "14", + // "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 }", + // "USERPREFS_CHANNEL_0_UPLINK_ENABLED": "true", + // "USERPREFS_CHANNEL_1_DOWNLINK_ENABLED": "true", + // "USERPREFS_CHANNEL_1_NAME": "REPLACEME", + // "USERPREFS_CHANNEL_1_PRECISION": "14", + // "USERPREFS_CHANNEL_1_PSK": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }", + // "USERPREFS_CHANNEL_1_UPLINK_ENABLED": "true", + // "USERPREFS_CHANNEL_2_DOWNLINK_ENABLED": "true", + // "USERPREFS_CHANNEL_2_NAME": "REPLACEME", + // "USERPREFS_CHANNEL_2_PRECISION": "14", + // "USERPREFS_CHANNEL_2_PSK": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }", + // "USERPREFS_CHANNEL_2_UPLINK_ENABLED": "true", + // "USERPREFS_CONFIG_GPS_MODE": "meshtastic_Config_PositionConfig_GpsMode_ENABLED", + // "USERPREFS_CONFIG_LORA_IGNORE_MQTT": "true", + // "USERPREFS_CONFIG_LORA_REGION": "meshtastic_Config_LoRaConfig_RegionCode_US", + // "USERPREFS_CONFIG_OWNER_LONG_NAME": "My Long Name", + // "USERPREFS_CONFIG_OWNER_SHORT_NAME": "MLN", + // "USERPREFS_EVENT_MODE": "1", + // "USERPREFS_FIXED_BLUETOOTH": "121212", + // "USERPREFS_FIXED_GPS": "", + // "USERPREFS_FIXED_GPS_ALT": "0", + // "USERPREFS_FIXED_GPS_LAT": "48.85873920", + // "USERPREFS_FIXED_GPS_LON": "2.294508368", + // "USERPREFS_LORACONFIG_CHANNEL_NUM": "31", + // "USERPREFS_LORACONFIG_MODEM_PRESET": "meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST", + // "USERPREFS_SPLASH_TITLE": "DEFCONtastic", + "USERPREFS_TZ_STRING": "tzplaceholder " + // "USERPREFS_USE_ADMIN_KEY_0": "{ 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 }", + // "USERPREFS_USE_ADMIN_KEY_1": "{}", + // "USERPREFS_USE_ADMIN_KEY_2": "{}" +} \ No newline at end of file