Skip to content

Conversation

@SpudGunMan
Copy link
Contributor

To set the index 0 name to the preset name from localConfig.lora.modem_preset when empty

and compute hash so the output will not have bad index0 name or hash, also removes all disabled for clarity.

This outputs Device1 Channel Hash Table: [{'index': 0, 'role': 'PRIMARY', 'name': 'LongFast', 'hash': 8} for a LongFast

To set the index 0 name to the preset name from localConfig.lora.modem_prese and compute hash so the output will not have bad index0 name or hash, also removes all disabled for clarity. this outputs `Device1 Channel Hash Table: [{'index': 0, 'role': 'PRIMARY', 'name': 'LongFast', 'hash': 8}` for a LongFast
Copy link
Contributor

@ianmcorvidae ianmcorvidae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of issues here -- the generated names won't always be right as-is and this needs to be done for secondary channels too. But a good change in general/otherwise

result = []
def format_preset_name(name):
# Convert name like MODEM_PRESET to ModemPreset
return ''.join(word.capitalize() for word in name.split('_'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite correct, because not every preset uses the full name for this. You can see what names firmware uses at https://github.com/meshtastic/firmware/blob/7212fb9caa15119c500edb3a074a5bc6b956605d/src/DisplayFormatters.cpp#L3-L41

Primarily it's just LONG_MODERATE though, and that the name Custom is used if a modem preset isn't in use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this too bulky? or should be in util?

MODEM_PRESET_DISPLAY_NAMES = {
    "SHORT_TURBO": ("ShortTurbo", "ShortT"),
    "SHORT_SLOW": ("ShortSlow", "ShortS"),
    "SHORT_FAST": ("ShortFast", "ShortF"),
    "MEDIUM_SLOW": ("MediumSlow", "MedS"),
    "MEDIUM_FAST": ("MediumFast", "MedF"),
    "LONG_SLOW": ("LongSlow", "LongS"),
    "LONG_FAST": ("LongFast", "LongF"),
    "LONG_MODERATE": ("LongMod", "LongM"),
}

def format_preset_name(name=None, use_short_name=False):
    # Returns a user-friendly display name for a given preset.
    if name is None:
        return "Custom"
    # Normalize input: extract the preset part from full enum string
    if isinstance(name, str):
        parts = name.split('_')
        # Find the preset part (e.g., LONG_FAST)
        for i in range(len(parts)):
            key = '_'.join(parts[i:])
            if key in MODEM_PRESET_DISPLAY_NAMES:
                names = MODEM_PRESET_DISPLAY_NAMES[key]
                return names[1] if use_short_name else names[0]
    return "Invalid"

SpudGunMan and others added 2 commits November 12, 2025 10:21
Co-authored-by: Ian McEwen <[email protected]>
modem preset is set to none, the name used should be Custom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants