kt76c.nas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # KT-76c Transponder Support
  2. #
  3. # Gary Neely aka 'Buckaroo'
  4. #
  5. var kt76c_WARMUP = 45;
  6. var kt76c_COOLDN = 300;
  7. var kt76c_pwr = props.globals.getNode("/systems/electrical/outputs/kt-76c");
  8. var kt76c_fl = props.globals.getNode("/instrumentation/transponder/flight-level");
  9. var kt76c_code = props.globals.getNode("/instrumentation/transponder/id-code");
  10. var kt76c_goodcode = props.globals.getNode("/instrumentation/transponder/goodcode");
  11. var kt76c_ready = props.globals.getNode("/instrumentation/transponder/ready");
  12. var kt76c_replying = props.globals.getNode("/instrumentation/transponder/replying");
  13. var kt76c_serviceable = props.globals.getNode("/instrumentation/transponder/serviceable");
  14. var encoder_serviceable = props.globals.getNode("/instrumentation/encoder/serviceable");
  15. var kt76c_codes = []; # Array for 4 code digits
  16. var kt76c_last = []; # Holds copy of last known good code
  17. # Set next digit (push on list)
  18. var kt76c_button_code = func(i) { # i = 0-7
  19. if (!kt76c_pwr.getValue()) { return 0; }
  20. if (size(kt76c_codes) >= 4) { return 0; } # Max of 4 digits
  21. append(kt76c_codes,i);
  22. if (size(kt76c_codes) == 4) { # If we now have 4 digits, treat as a good
  23. kt76c_last = kt76c_codes; # code and save; flag that we have a good
  24. kt76c_goodcode.setValue(1); # code available to send
  25. }
  26. else {
  27. kt76c_goodcode.setValue(0);
  28. }
  29. kt76c_copycode();
  30. #kt76c_entry_clock(0);
  31. }
  32. # Clear last digit (pop from list)
  33. var kt76c_button_clr = func {
  34. if (!kt76c_pwr.getValue()) { return 0; }
  35. if (size(kt76c_codes)) {
  36. pop(kt76c_codes);
  37. kt76c_copycode();
  38. }
  39. }
  40. # Standard VFR code is 1200
  41. var kt76c_button_vfr = func {
  42. if (!kt76c_pwr.getValue()) { return 0; }
  43. kt76c_codes = [1,2,0,0];
  44. kt76c_goodcode.setValue(1);
  45. kt76c_copycode();
  46. #kt76c_entry_clock(0);
  47. }
  48. # Send our good code for 18 seconds
  49. var kt76c_button_idt = func {
  50. if (kt76c_pwr.getValue() < 3) { return 0; }
  51. if (kt76c_goodcode.getValue() and kt76c_ready.getValue() == 1) {
  52. kt76c_replying.setValue(1);
  53. settimer(kt76c_disable_reply, 18);
  54. }
  55. }
  56. var kt76c_disable_reply = func {
  57. kt76c_replying.setValue(0);
  58. }
  59. # Codes are held in an array; copycode forms an
  60. # integer from the code
  61. var kt76c_copycode = func {
  62. if (!size(kt76c_codes)) {
  63. kt76c_code.setValue(0);
  64. return 0;
  65. }
  66. var codestr = "";
  67. for(var i=0; i < size(kt76c_codes); i+=1) {
  68. codestr = codestr ~ kt76c_codes[i];
  69. }
  70. var code = 0;
  71. code = code + codestr;
  72. kt76c_code.setValue(code);
  73. }
  74. # Various things to do based on power switch settings
  75. setlistener(kt76c_pwr, func {
  76. #if (kt76c_pwr.getValue() >= 3) {
  77. # #enable blink prop
  78. #{
  79. #else {
  80. # #disable link prop
  81. #}
  82. if (kt76c_pwr.getValue() > 0) { # Enable transponder flight level encoder support
  83. kt76c_serviceable.setValue("true"); # Note that power must also be on the encoder output
  84. encoder_serviceable.setValue("true");
  85. }
  86. else {
  87. kt76c_serviceable.setValue("false");
  88. encoder_serviceable.setValue("false");
  89. }
  90. #if (kt76c_pwr.getValue() > 0 and kt76c_ready.getValue() < 1) }
  91. # interpolate(kt76c_ready, 1, (1-kt76c_ready.getValue())*kt76c_WARMUP);
  92. #}
  93. #if (kt76c_pwr.getValue() == 0 and kt76c_ready.getValue() == 1) {
  94. # interpolate (kt76c_ready, 0, kt76c_ready.getValue()*kt76c_COOLDN);
  95. #}
  96. #if (kt76c_pwr.getValue() < 3) {
  97. # kt76c_replying.setValue(0);
  98. # #setprop alt = 0
  99. #}
  100. #if (kt76c_pwr.getValue() == 4) {
  101. # #setprop alt = 1
  102. #}
  103. });