]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/kt_70.cxx
Connect to the electrical system.
[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     update(0);                  // FIXME: use dt
68 }
69
70
71 void FGKT_70::bind () {
72     // internal values
73
74     // modes
75
76     // input and buttons
77     fgTie("/radios/kt-70/inputs/ident-btn", this,
78           &FGKT_70::get_ident_btn, &FGKT_70::set_ident_btn);
79     fgSetArchivable("/radios/kt-70/inputs/rotation-deg");
80     fgTie("/radios/kt-70/inputs/digit1", this,
81           &FGKT_70::get_digit1, &FGKT_70::set_digit1);
82     fgSetArchivable("/radios/kt-70/inputs/digit1");
83     fgTie("/radios/kt-70/inputs/digit2", this,
84           &FGKT_70::get_digit2, &FGKT_70::set_digit2);
85     fgSetArchivable("/radios/kt-70/inputs/digit2");
86     fgTie("/radios/kt-70/inputs/digit3", this,
87           &FGKT_70::get_digit3, &FGKT_70::set_digit3);
88     fgSetArchivable("/radios/kt-70/inputs/digit3");
89     fgTie("/radios/kt-70/inputs/digit4", this,
90           &FGKT_70::get_digit4, &FGKT_70::set_digit4);
91     fgSetArchivable("/radios/kt-70/inputs/digit4");
92     fgTie("/radios/kt-70/inputs/func-knob", this,
93           &FGKT_70::get_func_knob, &FGKT_70::set_func_knob);
94     fgSetArchivable("/radios/kt-70/inputs/func-knob");
95
96     // outputs
97     fgTie("/radios/kt-70/outputs/id-code", this,
98           &FGKT_70::get_id_code, &FGKT_70::set_id_code);
99     fgSetArchivable("/radios/kt-70/outputs/id-code");
100     fgTie("/radios/kt-70/outputs/flight-level", this,
101           &FGKT_70::get_flight_level);
102
103     // annunciators
104     fgTie("/radios/kt-70/annunciators/fl", this, &FGKT_70::get_fl_ann );
105     fgTie("/radios/kt-70/annunciators/alt", this, &FGKT_70::get_alt_ann );
106     fgTie("/radios/kt-70/annunciators/gnd", this, &FGKT_70::get_gnd_ann );
107     fgTie("/radios/kt-70/annunciators/on", this, &FGKT_70::get_on_ann );
108     fgTie("/radios/kt-70/annunciators/sby", this, &FGKT_70::get_sby_ann );
109     fgTie("/radios/kt-70/annunciators/reply", this, &FGKT_70::get_reply_ann );
110 }
111
112
113 void FGKT_70::unbind () {
114     // internal values
115
116     // modes
117
118     // input and buttons
119     fgUntie("/radios/kt-70/inputs/ident-btn");
120     fgUntie("/radios/kt-70/inputs/digit1");
121     fgUntie("/radios/kt-70/inputs/digit2");
122     fgUntie("/radios/kt-70/inputs/digit3");
123     fgUntie("/radios/kt-70/inputs/digit4");
124     fgUntie("/radios/kt-70/inputs/func-knob");
125
126     // outputs
127     fgUntie("/radios/kt-70/outputs/id-code");
128     fgUntie("/radios/kt-70/outputs/flight-level");
129
130     // annunciators
131     fgUntie("/radios/kt-70/annunciators/fl");
132     fgUntie("/radios/kt-70/annunciators/alt");
133     fgUntie("/radios/kt-70/annunciators/gnd");
134     fgUntie("/radios/kt-70/annunciators/on");
135     fgUntie("/radios/kt-70/annunciators/sby");
136     fgUntie("/radios/kt-70/annunciators/reply");
137 }
138
139
140 // Update the various nav values based on position and valid tuned in navs
141 void FGKT_70::update( double dt ) {
142     // start with all annunciators off (reply ann is handled
143     // separately) and then turn on the ones we want
144     fl_ann = false;
145     alt_ann = false;
146     gnd_ann = false;
147     on_ann = false;
148     sby_ann = false;
149     reply_ann = false;
150
151     if ( has_power() ) {
152         // sanity checks
153         if ( digit1 < 0 ) { digit1 = 0; }
154         if ( digit1 > 7 ) { digit1 = 7; }
155         if ( digit2 < 0 ) { digit2 = 0; }
156         if ( digit2 > 7 ) { digit2 = 7; }
157         if ( digit3 < 0 ) { digit3 = 0; }
158         if ( digit3 > 7 ) { digit3 = 7; }
159         if ( digit4 < 0 ) { digit4 = 0; }
160         if ( digit4 > 7 ) { digit4 = 7; }
161
162         id_code = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
163
164         // flight level computation
165
166         // FIXME!!!! This needs to be computed relative to 29.92 inHg,
167         // but for the moment, until I figure out how to do that, I'll
168         // just use true altitude.
169         flight_level = (int)( (alt_node->getDoubleValue() + 50.0) / 100.0);
170
171         // ident button
172         if ( ident_btn && !last_ident_btn ) {
173             // ident button depressed
174             r_flash_time = 0.0;
175             ident_mode = true;
176         }
177         r_flash_time += dt;
178         if ( r_flash_time > 18.0 ) {
179             ident_mode = false;
180         }
181     
182         if ( ident_mode ) {
183             reply_ann = true;
184         } else {
185             reply_ann = false;
186         }
187
188         if ( func_knob == 1 ) {
189             sby_ann = true;
190         } else if ( func_knob == 2 ) {
191             fl_ann = true;
192             alt_ann = true;
193             gnd_ann = true;
194             on_ann = true;
195             sby_ann = true;
196             reply_ann = true;
197         } else if ( func_knob == 3 ) {
198             fl_ann = true;
199             gnd_ann = true;
200         } else if ( func_knob == 4 ) {
201             on_ann = true;
202         } else if ( func_knob == 5 ) {
203             fl_ann = true;
204             alt_ann = true;
205         }
206     }
207 }