| 1 |
# Chronograph ############# |
| 2 |
|
| 3 |
# One button elapsed counter |
| 4 |
|
| 5 |
var chrono_onoff = props.globals.getNode("instrumentation/clock/chronometer-on",1); |
| 6 |
var reset_state = props.globals.getNode("instrumentation/clock/reset-state",1); |
| 7 |
var elapsed_sec = props.globals.getNode("instrumentation/clock/elapsed-sec", 1); |
| 8 |
var indicated_sec = props.globals.getNode("instrumentation/clock/indicated-sec"); |
| 9 |
|
| 10 |
aircraft.data.add("/instrumentation/clock/offset-sec"); |
| 11 |
|
| 12 |
chrono_onoff.setBoolValue( 0 ); |
| 13 |
reset_state.setBoolValue( 1 ); |
| 14 |
elapsed_sec.setValue( 0 ); |
| 15 |
var offset = 0; |
| 16 |
|
| 17 |
var click = func { |
| 18 |
var on = chrono_onoff.getBoolValue(); |
| 19 |
var reset = reset_state.getBoolValue(); |
| 20 |
if ( ! on ) { |
| 21 |
if ( ! reset ) { |
| 22 |
# Had been former started and stoped, now, has to be reset. |
| 23 |
offset = 0; |
| 24 |
elapsed_sec.setValue( 0 ); |
| 25 |
reset_state.setBoolValue( 1 ); |
| 26 |
} else { |
| 27 |
# Is not started but allready reset, start it. |
| 28 |
chrono_onoff.setBoolValue( 1 ); |
| 29 |
reset_state.setBoolValue( 0 ); |
| 30 |
offset = indicated_sec.getValue(); |
| 31 |
} |
| 32 |
} else { |
| 33 |
# Stop it. |
| 34 |
chrono_onoff.setBoolValue( 0 ); |
| 35 |
reset_state.setBoolValue( 0 ); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
var update_chrono = func { |
| 40 |
var on = chrono_onoff.getBoolValue(); |
| 41 |
if ( on ) { |
| 42 |
var i_sec = indicated_sec.getValue(); |
| 43 |
var e_sec = i_sec - offset; |
| 44 |
elapsed_sec.setValue( e_sec ); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
# Comment the following if update_chrono() is launched from a |
| 49 |
# centralized loop in order to save some CPU cycles. |
| 50 |
|
| 51 |
var chrono_loop = func { |
| 52 |
update_chrono(); |
| 53 |
settimer(chrono_loop, 0.1); |
| 54 |
} |
| 55 |
settimer(chrono_loop, 0.5); |