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 - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 #include <simgear/compiler.h>
33 #include <simgear/math/sg_random.h>
39 FGKT_70::FGKT_70(SGPropertyNode *node) :
43 last_ident_btn(false),
44 digit1(1), digit2(2), digit3(0), digit4(0),
58 for ( i = 0; i < node->nChildren(); ++i ) {
59 SGPropertyNode *child = node->getChild(i);
60 string cname = child->getName();
61 string cval = child->getStringValue();
62 if ( cname == "name" ) {
64 } else if ( cname == "number" ) {
65 num = child->getIntValue();
67 SG_LOG( SG_INSTR, SG_WARN,
68 "Error in kt-70 config logic" );
69 if ( name.length() ) {
70 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
79 FGKT_70::~FGKT_70() { }
85 branch = "/instrumentation/" + name;
87 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
89 lon_node = fgGetNode("/position/longitude-deg", true);
90 lat_node = fgGetNode("/position/latitude-deg", true);
91 alt_node = fgGetNode("/position/altitude-ft", true);
92 bus_power = fgGetNode("/systems/electrical/outputs/transponder", true);
93 serviceable_node = (node->getChild("inputs", 0, true))
94 ->getChild("serviceable", 0, true);
95 serviceable_node->setBoolValue(true);
101 std::ostringstream temp;
104 branch = "/instrumentation/" + name + "[" + temp.str() + "]";
105 _tiedProperties.setRoot(fgGetNode(branch, true));
111 _tiedProperties.Tie("inputs/ident-btn", this,
112 &FGKT_70::get_ident_btn, &FGKT_70::set_ident_btn);
113 fgSetArchivable((branch + "/inputs/rotation-deg").c_str());
114 _tiedProperties.Tie("inputs/digit1", this,
115 &FGKT_70::get_digit1, &FGKT_70::set_digit1);
116 fgSetArchivable((branch + "/inputs/digit1").c_str());
117 _tiedProperties.Tie("inputs/digit2", this,
118 &FGKT_70::get_digit2, &FGKT_70::set_digit2);
119 fgSetArchivable((branch + "/inputs/digit2").c_str());
120 _tiedProperties.Tie("inputs/digit3", this,
121 &FGKT_70::get_digit3, &FGKT_70::set_digit3);
122 fgSetArchivable((branch + "/inputs/digit3").c_str());
123 _tiedProperties.Tie("inputs/digit4", this,
124 &FGKT_70::get_digit4, &FGKT_70::set_digit4);
125 fgSetArchivable((branch + "/inputs/digit4").c_str());
126 _tiedProperties.Tie("inputs/func-knob", this,
127 &FGKT_70::get_func_knob, &FGKT_70::set_func_knob);
128 fgSetArchivable((branch + "/inputs/func-knob").c_str());
131 _tiedProperties.Tie("outputs/id-code", this,
132 &FGKT_70::get_id_code, &FGKT_70::set_id_code);
133 fgSetArchivable((branch + "/outputs/id-code").c_str());
134 _tiedProperties.Tie("outputs/flight-level", this,
135 &FGKT_70::get_flight_level);
138 _tiedProperties.Tie("annunciators/fl", this,
139 &FGKT_70::get_fl_ann );
140 _tiedProperties.Tie("annunciators/alt", this,
141 &FGKT_70::get_alt_ann );
142 _tiedProperties.Tie("annunciators/gnd", this,
143 &FGKT_70::get_gnd_ann );
144 _tiedProperties.Tie("annunciators/on", this,
145 &FGKT_70::get_on_ann );
146 _tiedProperties.Tie("annunciators/sby", this,
147 &FGKT_70::get_sby_ann );
148 _tiedProperties.Tie("annunciators/reply", this,
149 &FGKT_70::get_reply_ann );
153 void FGKT_70::unbind () {
154 _tiedProperties.Untie();
158 // Update the various nav values based on position and valid tuned in navs
159 void FGKT_70::update( double dt ) {
160 // start with all annunciators off (reply ann is handled
161 // separately) and then turn on the ones we want
169 if ( has_power() && serviceable_node->getBoolValue() ) {
171 if ( digit1 < 0 ) { digit1 = 0; }
172 if ( digit1 > 7 ) { digit1 = 7; }
173 if ( digit2 < 0 ) { digit2 = 0; }
174 if ( digit2 > 7 ) { digit2 = 7; }
175 if ( digit3 < 0 ) { digit3 = 0; }
176 if ( digit3 > 7 ) { digit3 = 7; }
177 if ( digit4 < 0 ) { digit4 = 0; }
178 if ( digit4 > 7 ) { digit4 = 7; }
180 id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
182 // flight level computation
184 // FIXME!!!! This needs to be computed relative to 29.92 inHg,
185 // but for the moment, until I figure out how to do that, I'll
186 // just use true altitude.
187 flight_level = (int)( (alt_node->getDoubleValue() + 50.0) / 100.0);
190 if ( ident_btn && !last_ident_btn ) {
191 // ident button depressed
196 if ( r_flash_time > 18.0 ) {
206 if ( func_knob == 1 ) {
208 } else if ( func_knob == 2 ) { // selftest
217 } else if ( func_knob == 3 ) {
220 } else if ( func_knob == 4 ) {
222 } else if ( func_knob == 5 ) {