| 1 |
# Code to handle 8.33 khz for the KX165A radio |
| 2 |
var increment = func(index, direction) { |
| 3 |
var selector = getprop("instrumentation/comm[" ~ index ~ "]/channel-mode-selector"); |
| 4 |
if (selector == 1) { |
| 5 |
setprop("instrumentation/comm[" ~ index ~ "]/frequencies/standby-channel", getprop("instrumentation/comm[" ~ index ~ "]/frequencies/standby-channel") + direction); |
| 6 |
} elsif (selector == 0) { |
| 7 |
setprop("instrumentation/comm[" ~ index ~ "]/frequencies/standby-channel", getprop("instrumentation/comm[" ~ index ~ "]/frequencies/standby-channel") + (direction * 4)); |
| 8 |
} |
| 9 |
} |
| 10 |
|
| 11 |
setlistener("/instrumentation/comm[0]/channel-mode-selector", func() { |
| 12 |
if (getprop("/instrumentation/comm[0]/channel-mode-selector") == 0) { |
| 13 |
var result = math.round(getprop("/instrumentation/comm[0]/frequencies/standby-channel") / 4) * 4; |
| 14 |
setprop("/instrumentation/comm[0]/frequencies/standby-channel", result); |
| 15 |
|
| 16 |
var result = math.round(getprop("/instrumentation/comm[0]/frequencies/selected-channel") / 4) * 4; |
| 17 |
setprop("/instrumentation/comm[0]/frequencies/selected-channel", result); |
| 18 |
} |
| 19 |
}, 0, 0); |
| 20 |
|
| 21 |
setlistener("/instrumentation/comm[1]/channel-mode-selector", func() { |
| 22 |
if (getprop("/instrumentation/comm[1]/channel-mode-selector") == 0) { |
| 23 |
var result = math.round(getprop("/instrumentation/comm[1]/frequencies/standby-channel") / 4) * 4; |
| 24 |
setprop("/instrumentation/comm[1]/frequencies/standby-channel", result); |
| 25 |
|
| 26 |
var result = math.round(getprop("/instrumentation/comm[1]/frequencies/selected-channel") / 4) * 4; |
| 27 |
setprop("/instrumentation/comm[1]/frequencies/selected-channel", result); |
| 28 |
} |
| 29 |
}, 0, 0); |
| 30 |
|
| 31 |
var hackListener = setlistener("/sim/signals/fdm-initialized", func() { |
| 32 |
# a dirty hack but it works. It triggers the above setlisteners on startup (passing the startup argument did not work) |
| 33 |
# in case a 8.33 frequency has been saved but 25k is selected on startup |
| 34 |
var selector = getprop("instrumentation/comm[0]/channel-mode-selector"); |
| 35 |
setprop("/instrumentation/comm[0]/channel-mode-selector", 2); |
| 36 |
setprop("/instrumentation/comm[0]/channel-mode-selector", selector); |
| 37 |
var selector = getprop("instrumentation/comm[1]/channel-mode-selector"); |
| 38 |
setprop("/instrumentation/comm[1]/channel-mode-selector", 2); |
| 39 |
setprop("/instrumentation/comm[1]/channel-mode-selector", selector); |
| 40 |
|
| 41 |
# after the first startup we don't need this |
| 42 |
removelistener(hackListener); |
| 43 |
}); |