chronograph.nas 1.5 KB

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