1 // clock.cxx - an electric-powered turn indicator.
2 // Written by Melchior FRANZ, started 2003.
4 // This file is in the Public Domain and comes with no warranty.
10 #include <simgear/timing/sg_time.hxx>
11 #include <Main/fg_props.hxx>
12 #include <Main/util.hxx>
16 : _is_serviceable(true),
22 _indicated_string[0] = '\0';
32 _serviceable_node = fgGetNode("/instrumentation/clock/serviceable", true);
33 _offset_node = fgGetNode("/instrumentation/clock/offset-sec", true);
34 _sec_node = fgGetNode("/instrumentation/clock/indicated-sec", true);
35 _string_node = fgGetNode("/instrumentation/clock/indicated-string", true);
39 Clock::update (double delta_time_sec)
41 if (!_serviceable_node->getBoolValue()) {
42 if (_is_serviceable) {
43 _string_node->setStringValue("");
44 _is_serviceable = false;
49 struct tm *t = globals->get_time_params()->getGmt();
50 int hour = t->tm_hour;
54 long gmt = (hour * 60 + min) * 60 + sec;
55 int offset = _offset_node->getLongValue();
57 if (!_is_serviceable) {
58 _standstill_offset -= gmt - _gmt_time_sec;
59 } else if (_gmt_time_sec == gmt && _offset_sec == offset)
65 _indicated_sec = _gmt_time_sec + offset + _standstill_offset;
66 _sec_node->setLongValue(_indicated_sec);
90 sprintf(_indicated_string, "%02d:%02d:%02d", hour, min, sec);
91 _string_node->setStringValue(_indicated_string);
92 _is_serviceable = true;