]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/kt_70.cxx
Begin interfacing the navcom's to the electrical model.
[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     r_flash_time(0.0),
44     ident_mode(false),
45     ident_btn(false),
46     last_ident_btn(false),
47     digit1(1), digit2(2), digit3(0), digit4(0),
48     func_knob(4),
49     id_code(1200),
50     flight_level(0),
51     fl_ann(0),
52     alt_ann(0),
53     gnd_ann(0),
54     on_ann(0),
55     sby_ann(0),
56     reply_ann(0)
57 {
58 }
59
60
61 // Destructor
62 FGKT_70::~FGKT_70() { }
63
64
65 void FGKT_70::init () {
66     update(0);                  // FIXME: use dt
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     // double acft_lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
142     // double acft_lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
143     // double acft_elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
144     // Point3D aircraft = sgGeodToCart( Point3D( acft_lon, acft_lat,
145     //                                           acft_elev ) );
146
147     // sanity checks
148     if ( digit1 < 0 ) { digit1 = 0; }
149     if ( digit1 > 7 ) { digit1 = 7; }
150     if ( digit2 < 0 ) { digit2 = 0; }
151     if ( digit2 > 7 ) { digit2 = 7; }
152     if ( digit3 < 0 ) { digit3 = 0; }
153     if ( digit3 > 7 ) { digit3 = 7; }
154     if ( digit4 < 0 ) { digit4 = 0; }
155     if ( digit4 > 7 ) { digit4 = 7; }
156
157     id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
158
159     // flight level computation
160
161     // FIXME!!!! This needs to be computed relative to 29.92 inHg, but
162     // for the moment, until I figure out how to do that, I'll just
163     // use true altitude.
164     flight_level = (int)( (alt_node->getDoubleValue() + 50.0) / 100.0);
165
166     // ident button
167     if ( ident_btn && !last_ident_btn ) {
168         // ident button depressed
169         r_flash_time = 0.0;
170         ident_mode = true;
171     }
172     r_flash_time += dt;
173     if ( r_flash_time > 18.0 ) {
174         ident_mode = false;
175     }
176     
177     // start with all annunciators off (reply ann is handled
178     // separately) and then turn on the ones we want
179     fl_ann = false;
180     alt_ann = false;
181     gnd_ann = false;
182     on_ann = false;
183     sby_ann = false;
184
185     if ( ident_mode ) {
186         reply_ann = true;
187     } else {
188         reply_ann = false;
189     }
190
191     if ( func_knob == 0 ) {
192         // leave everything off
193     } else if ( func_knob == 1 ) {
194         sby_ann = true;
195     } else if ( func_knob == 2 ) {
196         fl_ann = true;
197         alt_ann = true;
198         gnd_ann = true;
199         on_ann = true;
200         sby_ann = true;
201         reply_ann = true;
202     } else if ( func_knob == 3 ) {
203         fl_ann = true;
204         gnd_ann = true;
205     } else if ( func_knob == 4 ) {
206         on_ann = true;
207     } else if ( func_knob == 5 ) {
208         fl_ann = true;
209         alt_ann = true;
210     }
211
212 }