1<PropertyList> 2 3 <name>GoFlight GF-46</name> 4 <debug-events type="bool">false</debug-events> 5 6<nasal> 7 <open> 8 <![CDATA[ 9 10 var transponderNode = props.globals.getNode("/instrumentation/transponder/id-code", 1); 11 var modeNode = props.globals.getNode("/instrumentation/transponder/inputs/knob-mode", 1); 12 var identNode = props.globals.getNode("/instrumentation/transponder/inputs/ident-btn", 1); 13 var brightnessNode = props.globals.getNode("/input/goflight/gf46/brightness", 8); 14 15 var formatTransponder = func(squawk) 16 { 17 var s = sprintf("%04d ", squawk); 18 return goflight.reverseBytes(goflight.bytesForString(s, 6)); 19 } 20 21 var displaySevenSegment = func() { 22 if (modeNode.getValue() == 0) { 23 # OFF, blank display 24 return goflight.bytesForString(" ", 6); 25 } 26 return formatTransponder(transponderNode.getValue()); 27 } 28 29 var modeNames = ['OFF ', 'STBY', 'TEST', 'XPDR', ' TA ', 'TARA']; 30 var displayFourteenSegment = func() { 31 var mode = modeNode.getValue(); 32 return goflight.formatFourteenSegment(modeNames[mode], 4); 33 } 34 35 var powerOfTen = [1, 10, 100, 1000]; 36 var powerOfEight = [1, 8, 64, 512]; 37 38 # adapted from gui/dialogs/radios.xml 39 var extractDigit = func(code, index) { 40 return math.mod(code / powerOfTen[index], 10); 41 } 42 43 var extractOctal = func(code, index) { 44 return math.mod(code / powerOfEight[index], 8); 45 } 46 47 var adjustIdCode = func(offset) { 48 var code = transponderNode.getValue(); 49 50 # convert ID code to decimal 51 var decCode = 0; 52 for (var i=0; i<3; i +=1) { 53 decCode += extractDigit(code, i) * powerOfEight[i]; 54 } 55 56 # apply offset and clamp 57 decCode = math.clamp(decCode + offset, 0, 4095); 58 59 # convert back to octal-as-decimal 60 code = 0; 61 for (var i=0; i<3; i +=1) { 62 code += extractOctal(decCode, i) * powerOfTen[i]; 63 } 64 65 transponderNode.setIntValue(code); 66 } 67 68 ]]> 69 </open> 70</nasal> 71 72 73<!-- 74adding item:rel-dial, bits: 0:8, report=1 75adding item:rel-dial-1, bits: 8:8, report=1 76adding item:button-1, bits: 16:1, report=1 77adding item:undefined-0, bits: 17:1, report=1 78adding item:undefined-0-1, bits: 18:1, report=1 79adding item:undefined-0-2, bits: 19:1, report=1 80adding item:undefined-0-3, bits: 20:1, report=1 81adding item:undefined-0-4, bits: 21:1, report=1 82adding item:undefined-0-5, bits: 22:1, report=1 83adding item:undefined-0-6, bits: 23:1, report=1 84 85 86adding item:undefined-0-5, bits: 22:1, report=1 87adding item:undefined-0-6, bits: 23:1, report=1 88Unhandled HID alphanumeric usage:54 89adding item:unknown, bits: 0:4, report=2 90Unhandled HID alphanumeric usage:53 91adding item:unknown-1, bits: 4:4, report=2 92Unhandled HID alphanumeric usage:69 93adding item:unknown-2, bits: 8:1, report=2 94adding item:undefined-0-7, bits: 9:1, report=2 95adding item:undefined-0-8, bits: 10:1, report=2 96adding item:undefined-0-9, bits: 11:1, report=2 97adding item:undefined-0-10, bits: 12:1, report=2 98adding item:undefined-0-11, bits: 13:1, report=2 99adding item:undefined-0-12, bits: 14:1, report=2 100adding item:undefined-0-13, bits: 15:1, report=2 101adding item:display-data, bits: 0:16, report=3 102adding item:display-data-1, bits: 16:16, report=3 103adding item:display-data-2, bits: 32:16, report=3 104adding item:display-data-3, bits: 48:16, report=3 105Unhandled HID alphanumeric usage:54 106adding item:unknown-3, bits: 0:4, report=4 107Unhandled HID alphanumeric usage:53 108adding item:unknown-4, bits: 4:4, report=4 109Unhandled HID alphanumeric usage:67 110adding item:unknown-5, bits: 8:1, report=4 111 112--> 113 <event> 114 <name>rel-dial-0</name> 115 <binding> 116 <command>nasal</command> 117 <script>adjustIdCode(cmdarg().getNode("setting").getValue())</script> 118 </binding> 119 120 <interpolater> 121 <mirrored type="bool">true</mirrored> 122 <entry><ind>0</ind><dep>0</dep></entry> 123 <entry><ind>1</ind><dep>1</dep></entry> 124 <entry><ind>2</ind><dep>10</dep></entry> 125 <entry><ind>3</ind><dep>100</dep></entry> 126 <entry><ind>4</ind><dep>1000</dep></entry> 127 </interpolater> 128 </event> 129 130<event> 131 <name>rel-dial-1</name> 132 <binding> 133 <command>property-adjust</command> 134 <property>/instrumentation/transponder/inputs/knob-mode</property> 135 <min>0</min> 136 <max>5</max> 137 </binding> 138</event> 139 140 <report> 141 <report-id type="int">3</report-id> 142 <watch>/instrumentation/transponder/inputs/knob-mode</watch> 143 <nasal-function>displayFourteenSegment</nasal-function> 144</report> 145 146<report> 147 <report-id type="int">5</report-id> 148 <watch>/instrumentation/transponder/id-code</watch> 149 <watch>/instrumentation/transponder/inputs/knob-mode</watch> 150 <nasal-function>displaySevenSegment</nasal-function> 151</report> 152 153 <event> 154 <name>display-brightness</name> 155 <setting> 156 <property>/input/goflight/gf46/brightness</property> 157 </setting> 158 </event> 159 160 <event> 161 <desc>Ident</desc> 162 <name>button-1</name> 163 <binding> 164 <command>nasal</command> 165 <script>identNode.setBoolValue(1);</script> 166 </binding> 167 <mod-up> 168 <binding> 169 <command>nasal</command> 170 <script>identNode.setBoolValue(0);</script> 171 </binding> 172 </mod-up> 173 </event> 174 175</PropertyList> 176