UserPrefs - Preconfigure up to 3 channels, GPS Mode (#4930)

* added up to 3 channels via userprefs

* added up to 3 channels via userprefs

* added up to 3 channels via userprefs

* trunk fmt

* Added USERPREFS for GPS MODE
This commit is contained in:
medentem 2024-10-06 02:32:07 -05:00 committed by GitHub
parent 8a370c5381
commit 0952d1b252
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 94 additions and 21 deletions

View File

@ -76,6 +76,23 @@ meshtastic_Channel &Channels::fixupChannel(ChannelIndex chIndex)
return ch; return ch;
} }
void Channels::initDefaultLoraConfig()
{
meshtastic_Config_LoRaConfig &loraConfig = config.lora;
loraConfig.modem_preset = meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST; // Default to Long Range & Fast
loraConfig.use_preset = true;
loraConfig.tx_power = 0; // default
loraConfig.channel_num = 0;
#ifdef USERPREFS_LORACONFIG_MODEM_PRESET
loraConfig.modem_preset = USERPREFS_LORACONFIG_MODEM_PRESET;
#endif
#ifdef USERPREFS_LORACONFIG_CHANNEL_NUM
loraConfig.channel_num = USERPREFS_LORACONFIG_CHANNEL_NUM;
#endif
}
/** /**
* Write a default channel to the specified channel index * Write a default channel to the specified channel index
*/ */
@ -83,12 +100,7 @@ void Channels::initDefaultChannel(ChannelIndex chIndex)
{ {
meshtastic_Channel &ch = getByIndex(chIndex); meshtastic_Channel &ch = getByIndex(chIndex);
meshtastic_ChannelSettings &channelSettings = ch.settings; meshtastic_ChannelSettings &channelSettings = ch.settings;
meshtastic_Config_LoRaConfig &loraConfig = config.lora;
loraConfig.modem_preset = meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST; // Default to Long Range & Fast
loraConfig.use_preset = true;
loraConfig.tx_power = 0; // default
loraConfig.channel_num = 0;
uint8_t defaultpskIndex = 1; uint8_t defaultpskIndex = 1;
channelSettings.psk.bytes[0] = defaultpskIndex; channelSettings.psk.bytes[0] = defaultpskIndex;
channelSettings.psk.size = 1; channelSettings.psk.size = 1;
@ -97,21 +109,14 @@ void Channels::initDefaultChannel(ChannelIndex chIndex)
channelSettings.has_module_settings = true; channelSettings.has_module_settings = true;
ch.has_settings = true; ch.has_settings = true;
ch.role = meshtastic_Channel_Role_PRIMARY; ch.role = chIndex == 0 ? meshtastic_Channel_Role_PRIMARY : meshtastic_Channel_Role_SECONDARY;
#ifdef USERPREFS_LORACONFIG_MODEM_PRESET switch (chIndex) {
loraConfig.modem_preset = USERPREFS_LORACONFIG_MODEM_PRESET; case 0:
#endif
#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 USERPREFS_CHANNEL_0_PSK #ifdef USERPREFS_CHANNEL_0_PSK
static const uint8_t defaultpsk[] = USERPREFS_CHANNEL_0_PSK; static const uint8_t defaultpsk0[] = USERPREFS_CHANNEL_0_PSK;
memcpy(channelSettings.psk.bytes, defaultpsk, sizeof(defaultpsk)); memcpy(channelSettings.psk.bytes, defaultpsk0, sizeof(defaultpsk0));
channelSettings.psk.size = sizeof(defaultpsk); channelSettings.psk.size = sizeof(defaultpsk0);
#endif #endif
#ifdef USERPREFS_CHANNEL_0_NAME #ifdef USERPREFS_CHANNEL_0_NAME
@ -120,6 +125,37 @@ void Channels::initDefaultChannel(ChannelIndex chIndex)
#ifdef USERPREFS_CHANNEL_0_PRECISION #ifdef USERPREFS_CHANNEL_0_PRECISION
channelSettings.module_settings.position_precision = USERPREFS_CHANNEL_0_PRECISION; channelSettings.module_settings.position_precision = USERPREFS_CHANNEL_0_PRECISION;
#endif #endif
break;
case 1:
#ifdef USERPREFS_CHANNEL_1_PSK
static const uint8_t defaultpsk1[] = USERPREFS_CHANNEL_1_PSK;
memcpy(channelSettings.psk.bytes, defaultpsk1, sizeof(defaultpsk1));
channelSettings.psk.size = sizeof(defaultpsk1);
#endif
#ifdef USERPREFS_CHANNEL_1_NAME
strcpy(channelSettings.name, USERPREFS_CHANNEL_1_NAME);
#endif
#ifdef USERPREFS_CHANNEL_1_PRECISION
channelSettings.module_settings.position_precision = USERPREFS_CHANNEL_1_PRECISION;
#endif
break;
case 2:
#ifdef USERPREFS_CHANNEL_2_PSK
static const uint8_t defaultpsk2[] = USERPREFS_CHANNEL_2_PSK;
memcpy(channelSettings.psk.bytes, defaultpsk2, sizeof(defaultpsk2));
channelSettings.psk.size = sizeof(defaultpsk2);
#endif
#ifdef USERPREFS_CHANNEL_2_NAME
strcpy(channelSettings.name, USERPREFS_CHANNEL_2_NAME);
#endif
#ifdef USERPREFS_CHANNEL_2_PRECISION
channelSettings.module_settings.position_precision = USERPREFS_CHANNEL_2_PRECISION;
#endif
break;
default:
break;
} }
} }
@ -209,7 +245,15 @@ void Channels::initDefaults()
channelFile.channels_count = MAX_NUM_CHANNELS; channelFile.channels_count = MAX_NUM_CHANNELS;
for (int i = 0; i < channelFile.channels_count; i++) for (int i = 0; i < channelFile.channels_count; i++)
fixupChannel(i); fixupChannel(i);
initDefaultLoraConfig();
#ifdef USERPREFS_CHANNELS_TO_WRITE
for (int i = 0; i < USERPREFS_CHANNELS_TO_WRITE; i++) {
initDefaultChannel(i);
}
#else
initDefaultChannel(0); initDefaultChannel(0);
#endif
} }
void Channels::onConfigChanged() void Channels::onConfigChanged()
@ -359,4 +403,4 @@ bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash)
int16_t Channels::setActiveByIndex(ChannelIndex channelIndex) int16_t Channels::setActiveByIndex(ChannelIndex channelIndex)
{ {
return setCrypto(channelIndex); return setCrypto(channelIndex);
} }

View File

@ -117,7 +117,12 @@ class Channels
meshtastic_Channel &fixupChannel(ChannelIndex chIndex); meshtastic_Channel &fixupChannel(ChannelIndex chIndex);
/** /**
* Write a default channel to the specified channel index * Writes the default lora config
*/
void initDefaultLoraConfig();
/**
* Write default channels defined in UserPrefs
*/ */
void initDefaultChannel(ChannelIndex chIndex); void initDefaultChannel(ChannelIndex chIndex);

View File

@ -336,7 +336,9 @@ void NodeDB::installDefaultConfig(bool preserveKey = false)
#else #else
config.device.disable_triple_click = true; config.device.disable_triple_click = true;
#endif #endif
#if !HAS_GPS || defined(T_DECK) || defined(TLORA_T3S3_EPAPER) #if defined(USERPREFS_CONFIG_GPS_MODE)
config.position.gps_mode = USERPREFS_CONFIG_GPS_MODE;
#elif !HAS_GPS || defined(T_DECK) || defined(TLORA_T3S3_EPAPER)
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT; config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT;
#elif !defined(GPS_RX_PIN) #elif !defined(GPS_RX_PIN)
if (config.position.rx_gpio == 0) if (config.position.rx_gpio == 0)

View File

@ -13,6 +13,10 @@
// #define USERPREFS_LORACONFIG_MODEM_PRESET meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST // #define USERPREFS_LORACONFIG_MODEM_PRESET meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST
// #define USERPREFS_LORACONFIG_CHANNEL_NUM 31 // #define USERPREFS_LORACONFIG_CHANNEL_NUM 31
// #define USERPREFS_CONFIG_LORA_IGNORE_MQTT true // #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 \ #define USERPREFS_CHANNEL_0_PSK \
{ \ { \
@ -22,6 +26,24 @@
*/ */
// #define USERPREFS_CHANNEL_0_NAME "DEFCONnect" // #define USERPREFS_CHANNEL_0_NAME "DEFCONnect"
// #define USERPREFS_CHANNEL_0_PRECISION 14 // #define USERPREFS_CHANNEL_0_PRECISION 14
/*
#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_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_CONFIG_OWNER_LONG_NAME "My Long Name" // #define USERPREFS_CONFIG_OWNER_LONG_NAME "My Long Name"
// #define USERPREFS_CONFIG_OWNER_SHORT_NAME "MLN" // #define USERPREFS_CONFIG_OWNER_SHORT_NAME "MLN"