Skip to content

Commit

Permalink
tdh8.py: allow pasting of airband frequencies - (3 of 3) - fixes #11363
Browse files Browse the repository at this point in the history
Add support to mark mode as immutable so it doesn't get blocked, and
let the radio override it during set.
  • Loading branch information
KC9HI committed Jun 5, 2024
1 parent 8adfe90 commit a8a8948
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion chirp/drivers/tdh8.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ class TDH8(chirp_common.CloneModeRadio):
ident_mode = b'P31183\xff\xff'
BAUD_RATE = 38400
NEEDS_COMPAT_SERIAL = False
MODES = ["FM", "NFM"]
_memsize = 0x1eef
_ranges_main = [(0x0000, 0x1eef)]
_idents = [TD_H8]
Expand All @@ -1024,6 +1025,22 @@ class TDH8(chirp_common.CloneModeRadio):
chirp_common.PowerLevel("Mid", watts=4.00),
chirp_common.PowerLevel("High", watts=8.00)]

def check_set_memory_immutable_policy(self, existing, new):
if (AIRBAND[0] <= new.freq <= AIRBAND[1] and
new.mode == 'AM'):
# This is valid, so mark mode as immutable so it doesn't get
# blocked, and let the radio override it during set.
new.immutable.append('mode')
existing.immutable = []
elif existing.mode == 'AM' and new.mode in self.MODES:
# If we're going from a forced-AM channel to some valid one,
# clear immutable so we allow the change.
try:
existing.immutable.remove('mode')
except ValueError:
pass
super().check_set_memory_immutable_policy(existing, new)

@classmethod
def detect_from_serial(cls, pipe):
ident = _do_ident(pipe, cls._idents[0])
Expand Down Expand Up @@ -1076,7 +1093,7 @@ def get_features(self):
"DTCS->DTCS"]
rf.valid_power_levels = [x for x in self._tx_power if x]
rf.valid_duplexes = ["", "-", "+", "split", "off"]
rf.valid_modes = ["FM", "NFM"]
rf.valid_modes = self.MODES
rf.valid_tuning_steps = STEPS

rf.valid_bands = self._txbands + self._rxbands
Expand Down Expand Up @@ -1265,6 +1282,10 @@ def get_memory(self, number):
mem.duplex = 'off'
mem.immutable.append('duplex')
if in_range(mem.freq, [AIRBAND]):
# NOTE: AM is not in valid_modes because you can't arbitrarily
# enable it on this radio. However, we can expose it as immutable
# which will display properly in the UI and not allow the user
# to change those channels to FM.
mem.mode = 'AM'
mem.immutable.append('mode')

Expand Down

0 comments on commit a8a8948

Please sign in to comment.