calc default channel; keep channel_num if UNSET (#127)

This commit is contained in:
Manuel
2025-05-10 14:27:26 +02:00
committed by GitHub
parent 35576e131e
commit 92f37c0258
4 changed files with 40 additions and 24 deletions
+2 -1
View File
@@ -16,7 +16,8 @@ class LoRaPresets
static float getFrequencyStart(meshtastic_Config_LoRaConfig_RegionCode region);
static float getFrequencyEnd(meshtastic_Config_LoRaConfig_RegionCode region);
static uint16_t getDefaultSlot(meshtastic_Config_LoRaConfig_RegionCode region,
meshtastic_Config_LoRaConfig_ModemPreset preset);
meshtastic_Config_LoRaConfig_ModemPreset preset,
const char* channelName = nullptr);
struct ModemPreset {
const char *preset;
+1 -1
View File
@@ -431,5 +431,5 @@ class TFTView_320x240 : public MeshtasticView
meshtastic_DeviceConnectionStatus connectionStatus; // wifi/bluetooth/ethernet
};
meshtastic_DeviceProfile_full db; // full copy of the node's configuration db (except nodeinfos) plus ui data
meshtastic_DeviceProfile_full db{}; // full copy of the node's configuration db (except nodeinfos) plus ui data
};
+34 -20
View File
@@ -3614,7 +3614,11 @@ void TFTView_320x240::ui_event_ok(lv_event_t *e)
lv_label_set_text(objects.basic_settings_region_label, buf2);
meshtastic_Config_LoRaConfig &lora = THIS->db.config.lora;
uint32_t defaultSlot = LoRaPresets::getDefaultSlot(region, THIS->db.config.lora.modem_preset);
uint32_t defaultSlot = lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET ? lora.channel_num : 0;
if (defaultSlot == 0) {
defaultSlot = LoRaPresets::getDefaultSlot(region, THIS->db.config.lora.modem_preset,
THIS->db.channel[0].settings.name);
}
lora.region = region;
lora.channel_num = (defaultSlot <= numChannels ? defaultSlot : 1);
THIS->controller->sendConfig(meshtastic_Config_LoRaConfig{lora}, THIS->ownNode);
@@ -3699,7 +3703,11 @@ void TFTView_320x240::ui_event_ok(lv_event_t *e)
lv_label_set_text(objects.basic_settings_region_label, buf2);
meshtastic_Config_LoRaConfig &lora = THIS->db.config.lora;
uint32_t defaultSlot = LoRaPresets::getDefaultSlot(region, THIS->db.config.lora.modem_preset);
uint32_t defaultSlot = lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET ? lora.channel_num : 0;
if (defaultSlot == 0) {
defaultSlot = LoRaPresets::getDefaultSlot(region, THIS->db.config.lora.modem_preset,
THIS->db.channel[0].settings.name);
}
lora.region = region;
lora.channel_num = (defaultSlot <= numChannels ? defaultSlot : 1);
THIS->controller->sendConfig(meshtastic_Config_LoRaConfig{lora}, THIS->ownNode);
@@ -3953,27 +3961,30 @@ void TFTView_320x240::ui_event_ok(lv_event_t *e)
// delete channel
THIS->channel_scratch[ch].role = meshtastic_Channel_Role_DISABLED;
THIS->channel_scratch[ch].settings.psk.size = 0;
strcpy(THIS->channel_scratch[ch].settings.name, "");
memset(THIS->channel_scratch[ch].settings.name, 0, sizeof(THIS->channel_scratch[ch].settings.name));
memset(THIS->channel_scratch[ch].settings.psk.bytes, 0, sizeof(THIS->channel_scratch[ch].settings.psk.bytes));
THIS->channel_scratch[ch].has_settings = false;
lv_label_set_text(THIS->ch_label[btn_id], _("<unset>"));
THIS->activeSettings = eChannel;
}
int paddings = (4 - strlen(base64) % 4) % 4;
while (paddings-- > 0) {
lv_textarea_add_text(objects.settings_modify_channel_psk_textarea, "=");
}
if (THIS->base64ToPsk(lv_textarea_get_text(objects.settings_modify_channel_psk_textarea), psk.bytes, psk.size)) {
if (strlen(name) || psk.size) {
// TODO: fill temp storage -> user data
lv_label_set_text(THIS->ch_label[btn_id], name);
strcpy(THIS->channel_scratch[ch].settings.name, name);
memcpy(THIS->channel_scratch[ch].settings.psk.bytes, psk.bytes, 32);
THIS->channel_scratch[ch].settings.psk.size = psk.size;
THIS->activeSettings = eChannel;
else {
int paddings = (4 - strlen(base64) % 4) % 4;
while (paddings-- > 0) {
lv_textarea_add_text(objects.settings_modify_channel_psk_textarea, "=");
}
if (THIS->base64ToPsk(lv_textarea_get_text(objects.settings_modify_channel_psk_textarea), psk.bytes, psk.size)) {
if (strlen(name) || psk.size) {
// TODO: fill temp storage -> user data
lv_label_set_text(THIS->ch_label[btn_id], name);
strcpy(THIS->channel_scratch[ch].settings.name, name);
memcpy(THIS->channel_scratch[ch].settings.psk.bytes, psk.bytes, 32);
THIS->channel_scratch[ch].settings.psk.size = psk.size;
THIS->activeSettings = eChannel;
}
}
THIS->channel_scratch[ch].role = (ch == 0) ? meshtastic_Channel_Role_PRIMARY : meshtastic_Channel_Role_SECONDARY;
}
if (THIS->activeSettings == eChannel) {
lv_obj_add_flag(objects.settings_modify_channel_panel, LV_OBJ_FLAG_HIDDEN);
THIS->enablePanel(objects.settings_channel_panel);
@@ -4156,7 +4167,8 @@ void TFTView_320x240::ui_event_modem_preset_dropdown(lv_event_t *e)
return;
}
uint32_t channel = LoRaPresets::getDefaultSlot(THIS->db.config.lora.region, preset);
uint32_t channel = LoRaPresets::getDefaultSlot(THIS->db.config.lora.region, preset,
THIS->db.channel[0].settings.name);
if (channel > numChannels)
channel = 1;
lv_slider_set_range(objects.frequency_slot_slider, 1, numChannels);
@@ -5676,7 +5688,9 @@ void TFTView_320x240::updateLoRaConfig(const meshtastic_Config_LoRaConfig &cfg)
lv_slider_set_range(objects.frequency_slot_slider, 1, numChannels);
if (!db.config.lora.channel_num) {
db.config.lora.channel_num = LoRaPresets::getDefaultSlot(db.config.lora.region, THIS->db.config.lora.modem_preset);
db.config.lora.channel_num = LoRaPresets::getDefaultSlot(db.config.lora.region,
THIS->db.config.lora.modem_preset,
THIS->db.channel[0].settings.name);
}
lv_slider_set_value(objects.frequency_slot_slider, db.config.lora.channel_num, LV_ANIM_OFF);
+3 -2
View File
@@ -36,7 +36,8 @@ float LoRaPresets::getFrequencyEnd(meshtastic_Config_LoRaConfig_RegionCode regio
* Default slot number is generated using the same firmware hash algorithm
*/
uint16_t LoRaPresets::getDefaultSlot(meshtastic_Config_LoRaConfig_RegionCode region,
meshtastic_Config_LoRaConfig_ModemPreset preset)
meshtastic_Config_LoRaConfig_ModemPreset preset,
const char* channelName)
{
auto hash = [](const char *str) -> uint32_t {
uint32_t hash = 5381;
@@ -47,7 +48,7 @@ uint16_t LoRaPresets::getDefaultSlot(meshtastic_Config_LoRaConfig_RegionCode reg
};
uint32_t numChannels = getNumChannels(region, preset);
return numChannels == 0 ? 1 : hash(modemPreset[preset].preset) % numChannels + 1;
return numChannels == 0 ? 1 : hash(channelName ? channelName : modemPreset[preset].preset) % numChannels + 1;
}
float LoRaPresets::getBandwidth(meshtastic_Config_LoRaConfig_ModemPreset preset)