| 1 | /* |
| 2 | * SPDX-License-Identifier: GPL-2.0+ |
| 3 | * SPDX-FileCopyrightText: 2002 (C) Curtis L. Olson - http://www.flightgear.org/~curt |
| 4 | * |
| 5 | * kr-87.hxx -- class to impliment the King KR 87 Digital ADF |
| 6 | * Written by Curtis Olson, started June 2002. |
| 7 | * |
| 8 | * Copyright (C) 2002 Curtis L. Olson - http://www.flightgear.org/~curt |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of the |
| 13 | * License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 23 | * |
| 24 | * $Id$ |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | #pragma once |
| 29 | |
| 30 | |
| 31 | #include <Main/fg_props.hxx> |
| 32 | |
| 33 | #include <simgear/compiler.h> |
| 34 | #include <simgear/structure/subsystem_mgr.hxx> |
| 35 | #include <simgear/props/tiedpropertylist.hxx> |
| 36 | #include <simgear/timing/timestamp.hxx> |
| 37 | |
| 38 | #include <Navaids/navlist.hxx> |
| 39 | |
| 40 | class SGSampleGroup; |
| 41 | |
| 42 | class FGKR_87 : public SGSubsystem |
| 43 | { |
| 44 | private: |
| 45 | SGPropertyNode_ptr bus_power; |
| 46 | SGPropertyNode_ptr serviceable; |
| 47 | |
| 48 | bool need_update; |
| 49 | |
| 50 | // internal values |
| 51 | std::string ident; |
| 52 | std::string trans_ident; |
| 53 | bool valid; |
| 54 | bool inrange; |
| 55 | double stn_lon; |
| 56 | double stn_lat; |
| 57 | double stn_elev; |
| 58 | double range; |
| 59 | double effective_range; |
| 60 | double dist; |
| 61 | double heading; |
| 62 | SGVec3d xyz; |
| 63 | double goal_needle_deg; |
| 64 | double et_flash_time; |
| 65 | |
| 66 | // modes |
| 67 | int ant_mode; // 0 = ADF mode (needle active), 1 = ANT mode |
| 68 | // (needle turned to 90, improved audio rcpt) |
| 69 | int stby_mode; // 0 = show stby freq, 1 = show timer |
| 70 | int timer_mode; // 0 = flt, 1 = et |
| 71 | int count_mode; // 0 = count up, 1 = count down, 2 = set et |
| 72 | // count down |
| 73 | |
| 74 | // input and buttons |
| 75 | double rotation; // compass faceplace rotation |
| 76 | bool power_btn; // 0 = off, 1 = powered |
| 77 | bool audio_btn; // 0 = off, 1 = on |
| 78 | double vol_btn; |
| 79 | bool adf_btn; // 0 = normal, 1 = depressed |
| 80 | bool bfo_btn; // 0 = normal, 1 = depressed |
| 81 | bool frq_btn; // 0 = normal, 1 = depressed |
| 82 | bool last_frq_btn; |
| 83 | bool flt_et_btn; // 0 = normal, 1 = depressed |
| 84 | bool last_flt_et_btn; |
| 85 | bool set_rst_btn; // 0 = normal, 1 = depressed |
| 86 | bool last_set_rst_btn; // 0 = normal, 1 = depressed |
| 87 | |
| 88 | // outputs |
| 89 | int freq; |
| 90 | int stby_freq; |
| 91 | double needle_deg; |
| 92 | double flight_timer; |
| 93 | double elapsed_timer; |
| 94 | double tmp_timer; |
| 95 | |
| 96 | // annunciators |
| 97 | bool ant_ann; |
| 98 | bool adf_ann; |
| 99 | bool bfo_ann; |
| 100 | bool frq_ann; |
| 101 | bool flt_ann; |
| 102 | bool et_ann; |
| 103 | |
| 104 | // internal periodic station search timer |
| 105 | double _time_before_search_sec; |
| 106 | |
| 107 | SGSharedPtr<SGSampleGroup> _sgr; |
| 108 | simgear::TiedPropertyList _tiedProperties; |
| 109 | |
| 110 | public: |
| 111 | FGKR_87( SGPropertyNode *node ); |
| 112 | ~FGKR_87(); |
| 113 | |
| 114 | // Subsystem API. |
| 115 | void bind() override; |
| 116 | void init() override; |
| 117 | void reinit() override; |
| 118 | void unbind() override; |
| 119 | void update(double dt_sec) override; |
| 120 | |
| 121 | // Subsystem identification. |
| 122 | static const char* staticSubsystemClassId() { return "KR-87"; } |
| 123 | |
| 124 | // Update nav/adf radios based on current postition |
| 125 | void search (); |
| 126 | |
| 127 | // internal values |
| 128 | inline const std::string& get_ident() const { return ident; } |
| 129 | inline bool get_valid() const { return valid; } |
| 130 | inline bool get_inrange() const { return inrange; } |
| 131 | inline double get_stn_lon() const { return stn_lon; } |
| 132 | inline double get_stn_lat() const { return stn_lat; } |
| 133 | inline double get_dist() const { return dist; } |
| 134 | inline double get_heading() const { return heading; } |
| 135 | inline bool has_power() const { |
| 136 | return power_btn && (bus_power->getDoubleValue() > 1.0); |
| 137 | } |
| 138 | |
| 139 | // modes |
| 140 | inline int get_ant_mode() const { return ant_mode; } |
| 141 | inline int get_stby_mode() const { return stby_mode; } |
| 142 | inline int get_timer_mode() const { return timer_mode; } |
| 143 | inline int get_count_mode() const { return count_mode; } |
| 144 | |
| 145 | // input and buttons |
| 146 | inline double get_rotation () const { return rotation; } |
| 147 | inline void set_rotation( double rot ) { rotation = rot; } |
| 148 | inline bool get_power_btn() const { return power_btn; } |
| 149 | inline void set_power_btn( bool val ) { |
| 150 | power_btn = val; |
| 151 | } |
| 152 | inline bool get_audio_btn() const { return audio_btn; } |
| 153 | inline void set_audio_btn( bool val ) { |
| 154 | audio_btn = val; |
| 155 | } |
| 156 | inline double get_vol_btn() const { return vol_btn; } |
| 157 | inline void set_vol_btn( double val ) { |
| 158 | if ( val < 0.0 ) val = 0.0; |
| 159 | if ( val > 1.0 ) val = 1.0; |
| 160 | vol_btn = val; |
| 161 | } |
| 162 | inline bool get_adf_btn() const { return adf_btn; } |
| 163 | inline void set_adf_btn( bool val ) { adf_btn = val; } |
| 164 | inline bool get_bfo_btn() const { return bfo_btn; } |
| 165 | inline void set_bfo_btn( bool val ) { bfo_btn = val; } |
| 166 | inline bool get_frq_btn() const { return frq_btn; } |
| 167 | inline void set_frq_btn( bool val ) { frq_btn = val; } |
| 168 | inline bool get_flt_et_btn() const { return flt_et_btn; } |
| 169 | inline void set_flt_et_btn( bool val ) { flt_et_btn = val; } |
| 170 | inline bool get_set_rst_btn() const { return set_rst_btn; } |
| 171 | inline void set_set_rst_btn( bool val ) { set_rst_btn = val; } |
| 172 | |
| 173 | // outputs |
| 174 | inline int get_freq () const { return freq; } |
| 175 | inline void set_freq( int f ) { |
| 176 | freq = f; |
| 177 | need_update = true; |
| 178 | } |
| 179 | int get_stby_freq () const; |
| 180 | inline void set_stby_freq( int f ) { stby_freq = f; } |
| 181 | inline double get_needle_deg() const { return needle_deg; } |
| 182 | inline double get_flight_timer() const { return flight_timer; } |
| 183 | inline double get_elapsed_timer() const { return elapsed_timer; } |
| 184 | inline void set_elapsed_timer( double val ) { elapsed_timer = val; } |
| 185 | |
| 186 | // annunciators |
| 187 | inline bool get_ant_ann() const { return ant_ann; } |
| 188 | inline bool get_adf_ann() const { return adf_ann; } |
| 189 | inline bool get_bfo_ann() const { return bfo_ann; } |
| 190 | inline bool get_frq_ann() const { return frq_ann; } |
| 191 | inline bool get_flt_ann() const { return flt_ann; } |
| 192 | inline bool get_et_ann() const { return et_ann; } |
| 193 | }; |