]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/kr_87.cxx
Fix an init order bug and do some minor cleanups.
[flightgear.git] / src / Cockpit / kr_87.cxx
index 611f367c121c56f0b0495b14f69472b165ff0efb..67a0586dbf341ae13d53f58ab928e8525f079cc2 100644 (file)
@@ -73,9 +73,12 @@ FGKR_87::FGKR_87() :
     lon_node(fgGetNode("/position/longitude-deg", true)),
     lat_node(fgGetNode("/position/latitude-deg", true)),
     alt_node(fgGetNode("/position/altitude-ft", true)),
+    bus_power(fgGetNode("/systems/electrical/outputs/adf", true)),
     need_update(true),
     valid(false),
     inrange(false),
+    dist(0.0),
+    heading(0.0),
     goal_needle_deg(0.0),
     et_flash_time(0.0),
     ant_mode(0),
@@ -83,7 +86,8 @@ FGKR_87::FGKR_87() :
     timer_mode(0),
     count_mode(0),
     rotation(0),
-    on_off_vol_btn(0.5),
+    power_btn(true),
+    vol_btn(0.5),
     adf_btn(true),
     bfo_btn(false),
     frq_btn(false),
@@ -100,32 +104,16 @@ FGKR_87::FGKR_87() :
     elapsed_timer(0.0),
     tmp_timer(0.0)
 {
-    SGPath path( globals->get_fg_root() );
-    SGPath term = path;
-    term.append( "Navaids/range.term" );
-    SGPath low = path;
-    low.append( "Navaids/range.low" );
-    SGPath high = path;
-    high.append( "Navaids/range.high" );
-
-    term_tbl = new SGInterpTable( term.str() );
-    low_tbl = new SGInterpTable( low.str() );
-    high_tbl = new SGInterpTable( high.str() );
 }
 
 
 // Destructor
 FGKR_87::~FGKR_87() {
-    delete term_tbl;
-    delete low_tbl;
-    delete high_tbl;
 }
 
 
 void FGKR_87::init () {
     morse.init();
-
-    update(0);                 // FIXME: use dt
 }
 
 
@@ -150,10 +138,14 @@ void FGKR_87::bind () {
     fgTie("/radios/kr-87/inputs/rotation-deg", this,
          &FGKR_87::get_rotation, &FGKR_87::set_rotation);
     fgSetArchivable("/radios/kr-87/inputs/rotation-deg");
-    fgTie("/radios/kr-87/inputs/on-off-volume", this,
-         &FGKR_87::get_on_off_vol_btn,
-         &FGKR_87::set_on_off_vol_btn);
-    fgSetArchivable("/radios/kr-87/inputs/on-off-volume");
+    fgTie("/radios/kr-87/inputs/power-btn", this,
+         &FGKR_87::get_power_btn,
+         &FGKR_87::set_power_btn);
+    fgSetArchivable("/radios/kr-87/inputs/power-btn");
+    fgTie("/radios/kr-87/inputs/volume", this,
+         &FGKR_87::get_vol_btn,
+         &FGKR_87::set_vol_btn);
+    fgSetArchivable("/radios/kr-87/inputs/volume");
     fgTie("/radios/kr-87/inputs/adf-btn", this,
          &FGKR_87::get_adf_btn,
          &FGKR_87::set_adf_btn);
@@ -211,7 +203,8 @@ void FGKR_87::unbind () {
 
     // input and buttons
     fgUntie("/radios/kr-87/inputs/rotation-deg");
-    fgUntie("/radios/kr-87/inputs/on-off-volume");
+    fgUntie("/radios/kr-87/inputs/power-btn");
+    fgUntie("/radios/kr-87/inputs/volume");
     fgUntie("/radios/kr-87/inputs/adf-btn");
     fgUntie("/radios/kr-87/inputs/bfo-btn");
     fgUntie("/radios/kr-87/inputs/frq-btn");
@@ -252,7 +245,7 @@ void FGKR_87::update( double dt ) {
     // Radio
     ////////////////////////////////////////////////////////////////////////
 
-    if ( on_off_vol_btn >= 0.01 ) {
+    if ( has_power() ) {
         // buttons
         if ( adf_btn == 0 ) {
             ant_mode = 1;
@@ -395,7 +388,39 @@ void FGKR_87::update( double dt ) {
         et_ann = false;
     }
 
-    
+    // formatted timer
+    double time;
+    int hours, min, sec;
+    if ( timer_mode == 0 ) {
+        time = flight_timer;
+    } else {
+        time = elapsed_timer;
+    }
+    // cout << time << endl;
+    hours = (int)(time / 3600.0);
+    time -= hours * 3600.00;
+    min = (int)(time / 60.0);
+    time -= min * 60.0;
+    sec = (int)time;
+    int big, little;
+    if ( hours > 0 ) {
+        big = hours;
+        if ( big > 99 ) {
+            big = 99;
+        }
+        little = min;
+    } else {
+        big = min;
+        little = sec;
+    }
+    if ( big > 99 ) {
+        big = 99;
+    }
+    char formatted_timer[128];
+    // cout << big << ":" << little << endl;
+    snprintf(formatted_timer, 6, "%02d:%02d", big, little);
+    fgSetString( "/radios/kr-87/outputs/timer-string", formatted_timer );
+
     while ( goal_needle_deg < 0.0 ) { goal_needle_deg += 360.0; }
     while ( goal_needle_deg >= 360.0 ) { goal_needle_deg -= 360.0; }
 
@@ -416,11 +441,11 @@ void FGKR_87::update( double dt ) {
     if ( valid && inrange ) {
        // play station ident via audio system if on + ident_btn,
        // otherwise turn it off
-       if ( on_off_vol_btn >= 0.01 && ident_btn ) {
+       if ( vol_btn >= 0.01 && ident_btn ) {
            FGSimpleSound *sound;
            sound = globals->get_soundmgr()->find( "adf-ident" );
             if ( sound != NULL ) {
-                sound->set_volume( on_off_vol_btn );
+                sound->set_volume( vol_btn );
             } else {
                 SG_LOG( SG_COCKPIT, SG_ALERT, "Can't find adf-ident sound" );
             }