kx165a.nas 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. setlistener("/instrumentation/comm[0]/channel-mode-selector", func() {
  11. if (getprop("/instrumentation/comm[0]/channel-mode-selector") == 0) {
  12. var result = math.round(getprop("/instrumentation/comm[0]/frequencies/standby-channel") / 4) * 4;
  13. setprop("/instrumentation/comm[0]/frequencies/standby-channel", result);
  14. var result = math.round(getprop("/instrumentation/comm[0]/frequencies/selected-channel") / 4) * 4;
  15. setprop("/instrumentation/comm[0]/frequencies/selected-channel", result);
  16. }
  17. }, 0, 0);
  18. setlistener("/instrumentation/comm[1]/channel-mode-selector", func() {
  19. if (getprop("/instrumentation/comm[1]/channel-mode-selector") == 0) {
  20. var result = math.round(getprop("/instrumentation/comm[1]/frequencies/standby-channel") / 4) * 4;
  21. setprop("/instrumentation/comm[1]/frequencies/standby-channel", result);
  22. var result = math.round(getprop("/instrumentation/comm[1]/frequencies/selected-channel") / 4) * 4;
  23. setprop("/instrumentation/comm[1]/frequencies/selected-channel", result);
  24. }
  25. }, 0, 0);
  26. var hackListener = setlistener("/sim/signals/fdm-initialized", func() {
  27. # a dirty hack but it works. It triggers the above setlisteners on startup (passing the startup argument did not work)
  28. # in case a 8.33 frequency has been saved but 25k is selected on startup
  29. var selector = getprop("instrumentation/comm[0]/channel-mode-selector");
  30. setprop("/instrumentation/comm[0]/channel-mode-selector", 2);
  31. setprop("/instrumentation/comm[0]/channel-mode-selector", 1);
  32. var selector = getprop("instrumentation/comm[1]/channel-mode-selector");
  33. setprop("/instrumentation/comm[1]/channel-mode-selector", 2);
  34. setprop("/instrumentation/comm[1]/channel-mode-selector", 1);
  35. # after the first startup we don't need this
  36. removelistener(hackListener);
  37. });