1 // kt-70.cxx -- class to impliment the King KT 70 panel-m transponder
3 // Written by Curtis Olson, started July 2002.
5 // Copyright (C) 2002 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <stdio.h> // snprintf
30 #include <simgear/compiler.h>
31 #include <simgear/math/sg_random.h>
33 #include <Aircraft/aircraft.hxx>
40 lon_node(fgGetNode("/position/longitude-deg", true)),
41 lat_node(fgGetNode("/position/latitude-deg", true)),
42 alt_node(fgGetNode("/position/altitude-ft", true)),
43 bus_power(fgGetNode("/systems/electrical/outputs/transponder", true)),
47 last_ident_btn(false),
48 digit1(1), digit2(2), digit3(0), digit4(0),
63 FGKT_70::~FGKT_70() { }
66 void FGKT_70::init () {
70 void FGKT_70::bind () {
76 fgTie("/radios/kt-70/inputs/ident-btn", this,
77 &FGKT_70::get_ident_btn, &FGKT_70::set_ident_btn);
78 fgSetArchivable("/radios/kt-70/inputs/rotation-deg");
79 fgTie("/radios/kt-70/inputs/digit1", this,
80 &FGKT_70::get_digit1, &FGKT_70::set_digit1);
81 fgSetArchivable("/radios/kt-70/inputs/digit1");
82 fgTie("/radios/kt-70/inputs/digit2", this,
83 &FGKT_70::get_digit2, &FGKT_70::set_digit2);
84 fgSetArchivable("/radios/kt-70/inputs/digit2");
85 fgTie("/radios/kt-70/inputs/digit3", this,
86 &FGKT_70::get_digit3, &FGKT_70::set_digit3);
87 fgSetArchivable("/radios/kt-70/inputs/digit3");
88 fgTie("/radios/kt-70/inputs/digit4", this,
89 &FGKT_70::get_digit4, &FGKT_70::set_digit4);
90 fgSetArchivable("/radios/kt-70/inputs/digit4");
91 fgTie("/radios/kt-70/inputs/func-knob", this,
92 &FGKT_70::get_func_knob, &FGKT_70::set_func_knob);
93 fgSetArchivable("/radios/kt-70/inputs/func-knob");
96 fgTie("/radios/kt-70/outputs/id-code", this,
97 &FGKT_70::get_id_code, &FGKT_70::set_id_code);
98 fgSetArchivable("/radios/kt-70/outputs/id-code");
99 fgTie("/radios/kt-70/outputs/flight-level", this,
100 &FGKT_70::get_flight_level);
103 fgTie("/radios/kt-70/annunciators/fl", this, &FGKT_70::get_fl_ann );
104 fgTie("/radios/kt-70/annunciators/alt", this, &FGKT_70::get_alt_ann );
105 fgTie("/radios/kt-70/annunciators/gnd", this, &FGKT_70::get_gnd_ann );
106 fgTie("/radios/kt-70/annunciators/on", this, &FGKT_70::get_on_ann );
107 fgTie("/radios/kt-70/annunciators/sby", this, &FGKT_70::get_sby_ann );
108 fgTie("/radios/kt-70/annunciators/reply", this, &FGKT_70::get_reply_ann );
112 void FGKT_70::unbind () {
118 fgUntie("/radios/kt-70/inputs/ident-btn");
119 fgUntie("/radios/kt-70/inputs/digit1");
120 fgUntie("/radios/kt-70/inputs/digit2");
121 fgUntie("/radios/kt-70/inputs/digit3");
122 fgUntie("/radios/kt-70/inputs/digit4");
123 fgUntie("/radios/kt-70/inputs/func-knob");
126 fgUntie("/radios/kt-70/outputs/id-code");
127 fgUntie("/radios/kt-70/outputs/flight-level");
130 fgUntie("/radios/kt-70/annunciators/fl");
131 fgUntie("/radios/kt-70/annunciators/alt");
132 fgUntie("/radios/kt-70/annunciators/gnd");
133 fgUntie("/radios/kt-70/annunciators/on");
134 fgUntie("/radios/kt-70/annunciators/sby");
135 fgUntie("/radios/kt-70/annunciators/reply");
139 // Update the various nav values based on position and valid tuned in navs
140 void FGKT_70::update( double dt ) {
141 // start with all annunciators off (reply ann is handled
142 // separately) and then turn on the ones we want
152 if ( digit1 < 0 ) { digit1 = 0; }
153 if ( digit1 > 7 ) { digit1 = 7; }
154 if ( digit2 < 0 ) { digit2 = 0; }
155 if ( digit2 > 7 ) { digit2 = 7; }
156 if ( digit3 < 0 ) { digit3 = 0; }
157 if ( digit3 > 7 ) { digit3 = 7; }
158 if ( digit4 < 0 ) { digit4 = 0; }
159 if ( digit4 > 7 ) { digit4 = 7; }
161 id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
163 // flight level computation
165 // FIXME!!!! This needs to be computed relative to 29.92 inHg,
166 // but for the moment, until I figure out how to do that, I'll
167 // just use true altitude.
168 flight_level = (int)( (alt_node->getDoubleValue() + 50.0) / 100.0);
171 if ( ident_btn && !last_ident_btn ) {
172 // ident button depressed
177 if ( r_flash_time > 18.0 ) {
187 if ( func_knob == 1 ) {
189 } else if ( func_knob == 2 ) {
196 } else if ( func_knob == 3 ) {
199 } else if ( func_knob == 4 ) {
201 } else if ( func_knob == 5 ) {