]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/kt_70.cxx
Moved src/Model/loader.[ch]xx and src/Model/model.[ch]xx to
[flightgear.git] / src / Cockpit / kt_70.cxx
1 // kt-70.cxx -- class to impliment the King KT 70 panel-m transponder
2 //
3 // Written by Curtis Olson, started July 2002.
4 //
5 // Copyright (C) 2002  Curtis L. Olson - curt@flightgear.org
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <stdio.h>      // snprintf
29
30 #include <simgear/compiler.h>
31 #include <simgear/math/sg_random.h>
32
33 #include <Aircraft/aircraft.hxx>
34
35 #include "kt_70.hxx"
36
37
38 // Constructor
39 FGKT_70::FGKT_70() :
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)),
44     r_flash_time(0.0),
45     ident_mode(false),
46     ident_btn(false),
47     last_ident_btn(false),
48     digit1(1), digit2(2), digit3(0), digit4(0),
49     func_knob(4),
50     id_code(1200),
51     flight_level(0),
52     fl_ann(0),
53     alt_ann(0),
54     gnd_ann(0),
55     on_ann(0),
56     sby_ann(0),
57     reply_ann(0)
58 {
59 }
60
61
62 // Destructor
63 FGKT_70::~FGKT_70() { }
64
65
66 void FGKT_70::init () {
67 }
68
69
70 void FGKT_70::bind () {
71     // internal values
72
73     // modes
74
75     // input and buttons
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");
94
95     // outputs
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);
101
102     // annunciators
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 );
109 }
110
111
112 void FGKT_70::unbind () {
113     // internal values
114
115     // modes
116
117     // input and buttons
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");
124
125     // outputs
126     fgUntie("/radios/kt-70/outputs/id-code");
127     fgUntie("/radios/kt-70/outputs/flight-level");
128
129     // annunciators
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");
136 }
137
138
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
143     fl_ann = false;
144     alt_ann = false;
145     gnd_ann = false;
146     on_ann = false;
147     sby_ann = false;
148     reply_ann = false;
149
150     if ( has_power() ) {
151         // sanity checks
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; }
160
161         id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
162
163         // flight level computation
164
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);
169
170         // ident button
171         if ( ident_btn && !last_ident_btn ) {
172             // ident button depressed
173             r_flash_time = 0.0;
174             ident_mode = true;
175         }
176         r_flash_time += dt;
177         if ( r_flash_time > 18.0 ) {
178             ident_mode = false;
179         }
180     
181         if ( ident_mode ) {
182             reply_ann = true;
183         } else {
184             reply_ann = false;
185         }
186
187         if ( func_knob == 1 ) {
188             sby_ann = true;
189         } else if ( func_knob == 2 ) {
190             fl_ann = true;
191             alt_ann = true;
192             gnd_ann = true;
193             on_ann = true;
194             sby_ann = true;
195             reply_ann = true;
196         } else if ( func_knob == 3 ) {
197             fl_ann = true;
198             gnd_ann = true;
199         } else if ( func_knob == 4 ) {
200             on_ann = true;
201         } else if ( func_knob == 5 ) {
202             fl_ann = true;
203             alt_ann = true;
204         }
205     }
206 }