mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-26 22:33:24 +00:00
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:
parent
8a370c5381
commit
0952d1b252
@ -76,6 +76,23 @@ meshtastic_Channel &Channels::fixupChannel(ChannelIndex chIndex)
|
||||
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
|
||||
*/
|
||||
@ -83,12 +100,7 @@ void Channels::initDefaultChannel(ChannelIndex chIndex)
|
||||
{
|
||||
meshtastic_Channel &ch = getByIndex(chIndex);
|
||||
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;
|
||||
channelSettings.psk.bytes[0] = defaultpskIndex;
|
||||
channelSettings.psk.size = 1;
|
||||
@ -97,21 +109,14 @@ void Channels::initDefaultChannel(ChannelIndex chIndex)
|
||||
channelSettings.has_module_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
|
||||
loraConfig.modem_preset = USERPREFS_LORACONFIG_MODEM_PRESET;
|
||||
#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) {
|
||||
switch (chIndex) {
|
||||
case 0:
|
||||
#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);
|
||||
static const uint8_t defaultpsk0[] = USERPREFS_CHANNEL_0_PSK;
|
||||
memcpy(channelSettings.psk.bytes, defaultpsk0, sizeof(defaultpsk0));
|
||||
channelSettings.psk.size = sizeof(defaultpsk0);
|
||||
|
||||
#endif
|
||||
#ifdef USERPREFS_CHANNEL_0_NAME
|
||||
@ -120,6 +125,37 @@ void Channels::initDefaultChannel(ChannelIndex chIndex)
|
||||
#ifdef USERPREFS_CHANNEL_0_PRECISION
|
||||
channelSettings.module_settings.position_precision = USERPREFS_CHANNEL_0_PRECISION;
|
||||
#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;
|
||||
for (int i = 0; i < channelFile.channels_count; i++)
|
||||
fixupChannel(i);
|
||||
initDefaultLoraConfig();
|
||||
|
||||
#ifdef USERPREFS_CHANNELS_TO_WRITE
|
||||
for (int i = 0; i < USERPREFS_CHANNELS_TO_WRITE; i++) {
|
||||
initDefaultChannel(i);
|
||||
}
|
||||
#else
|
||||
initDefaultChannel(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Channels::onConfigChanged()
|
||||
@ -359,4 +403,4 @@ bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash)
|
||||
int16_t Channels::setActiveByIndex(ChannelIndex channelIndex)
|
||||
{
|
||||
return setCrypto(channelIndex);
|
||||
}
|
||||
}
|
@ -117,7 +117,12 @@ class Channels
|
||||
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);
|
||||
|
||||
|
@ -336,7 +336,9 @@ void NodeDB::installDefaultConfig(bool preserveKey = false)
|
||||
#else
|
||||
config.device.disable_triple_click = true;
|
||||
#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;
|
||||
#elif !defined(GPS_RX_PIN)
|
||||
if (config.position.rx_gpio == 0)
|
||||
|
22
userPrefs.h
22
userPrefs.h
@ -13,6 +13,10 @@
|
||||
// #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 \
|
||||
{ \
|
||||
@ -22,6 +26,24 @@
|
||||
*/
|
||||
// #define USERPREFS_CHANNEL_0_NAME "DEFCONnect"
|
||||
// #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_SHORT_NAME "MLN"
|
||||
|
Loading…
Reference in New Issue
Block a user