Skip to content

Commit

Permalink
Convert userprefs to a json file instead of header file which has to …
Browse files Browse the repository at this point in the history
…be included everywhere (#5471)

* WIP

* Got string quoting and macro expansion working

* Need the placeholder

* Cleanup

* Missed a user prefs reference

* Update jsonc
  • Loading branch information
thebentern authored Dec 3, 2024
1 parent 594af0c commit d00e0f6
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 141 deletions.
4 changes: 2 additions & 2 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lint:
- git-diff-check
- [email protected]
- [email protected]
- [email protected]
#- [email protected]
ignore:
- linters: [ALL]
paths:
Expand All @@ -46,4 +46,4 @@ actions:
enabled:
- trunk-fmt-pre-commit
- trunk-check-pre-push
- trunk-upgrade-available
- trunk-upgrade-available
2 changes: 1 addition & 1 deletion bin/build-userprefs-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
36 changes: 32 additions & 4 deletions bin/platformio-custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion src/ButtonThread.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ButtonThread.h"
#include "../userPrefs.h"

#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_GPS
#include "GPS.h"
Expand Down
3 changes: 1 addition & 2 deletions src/graphics/Screen.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "../userPrefs.h"
#include "configuration.h"

#include "detect/ScanI2C.h"
Expand Down Expand Up @@ -606,4 +605,4 @@ class Screen : public concurrency::OSThread

} // namespace graphics

#endif
#endif
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "../userPrefs.h"
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_GPS
#include "GPS.h"
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/Channels.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Channels.h"
#include "../userPrefs.h"

#include "CryptoEngine.h"
#include "Default.h"
#include "DisplayFormatters.h"
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/Default.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Default.h"
#include "../userPrefs.h"

#include "meshUtils.h"

uint32_t Default::getConfiguredOrDefaultMs(uint32_t configuredInterval, uint32_t defaultInterval)
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/FloodingRouter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "FloodingRouter.h"
#include "../userPrefs.h"

#include "configuration.h"
#include "mesh-pb-constants.h"

Expand Down
1 change: 0 additions & 1 deletion src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "../userPrefs.h"
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_GPS
#include "GPS.h"
Expand Down
1 change: 0 additions & 1 deletion src/mesh/Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/modules/AdminModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#ifdef ARCH_PORTDUINO
#include "unistd.h"
#endif
#include "../userPrefs.h"

#include "Default.h"
#include "TypeConversions.h"

Expand Down Expand Up @@ -1123,4 +1123,4 @@ void disableBluetooth()
nrf52Bluetooth->shutdown();
#endif
#endif
}
}
107 changes: 0 additions & 107 deletions userPrefs.h

This file was deleted.

16 changes: 0 additions & 16 deletions userPrefs.json

This file was deleted.

37 changes: 37 additions & 0 deletions userPrefs.jsonc
Original file line number Diff line number Diff line change
@@ -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": "{}"
}

0 comments on commit d00e0f6

Please sign in to comment.