mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-01 02:09:57 +00:00
Convert userprefs to a json file instead of header file which has to be included everywhere (#5471)
* WIP * Got string quoting and macro expansion working * Need the placeholder * Cleanup * Missed a user prefs reference * Update jsonc
This commit is contained in:
parent
594af0cacd
commit
d00e0f6911
@ -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
|
@ -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()
|
||||
|
@ -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 @@ prefsLoc = projenv["PROJECT_DIR"] + "/version.properties"
|
||||
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,
|
||||
)
|
@ -1,5 +1,5 @@
|
||||
#include "ButtonThread.h"
|
||||
#include "../userPrefs.h"
|
||||
|
||||
#include "configuration.h"
|
||||
#if !MESHTASTIC_EXCLUDE_GPS
|
||||
#include "GPS.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
|
@ -1,4 +1,3 @@
|
||||
#include "../userPrefs.h"
|
||||
#include "configuration.h"
|
||||
#if !MESHTASTIC_EXCLUDE_GPS
|
||||
#include "GPS.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "Channels.h"
|
||||
#include "../userPrefs.h"
|
||||
|
||||
#include "CryptoEngine.h"
|
||||
#include "Default.h"
|
||||
#include "DisplayFormatters.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "Default.h"
|
||||
#include "../userPrefs.h"
|
||||
|
||||
#include "meshUtils.h"
|
||||
|
||||
uint32_t Default::getConfiguredOrDefaultMs(uint32_t configuredInterval, uint32_t defaultInterval)
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "FloodingRouter.h"
|
||||
#include "../userPrefs.h"
|
||||
|
||||
#include "configuration.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include "../userPrefs.h"
|
||||
#include "configuration.h"
|
||||
#if !MESHTASTIC_EXCLUDE_GPS
|
||||
#include "GPS.h"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
107
userPrefs.h
107
userPrefs.h
@ -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
|
@ -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"
|
||||
}
|
37
userPrefs.jsonc
Normal file
37
userPrefs.jsonc
Normal file
@ -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": "{}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user