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.
15 #include <simgear/timing/sg_time.hxx>
16 #include <Main/fg_props.hxx>
17 #include <Main/util.hxx>
20 Clock::Clock(SGPropertyNode *node) :
21 _name(node->getStringValue("name", "clock")),
22 _num(node->getIntValue("number", 0)),
23 _is_serviceable(true),
32 _indicated_string[0] = '\0';
43 branch = "/instrumentation/" + _name;
45 SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
46 _serviceable_node = node->getChild("serviceable", 0, true);
47 _offset_node = node->getChild("offset-sec", 0, true);
48 _sec_node = node->getChild("indicated-sec", 0, true);
49 _min_node = node->getChild("indicated-min", 0, true);
50 _hour_node = node->getChild("indicated-hour", 0, true);
51 _lhour_node = node->getChild("local-hour", 0, true);
52 _string_node = node->getChild("indicated-string", 0, true);
53 _string_node1 = node->getChild("indicated-short-string", 0, true);
54 _string_node2 = node->getChild("local-short-string", 0, true);
58 Clock::update (double delta_time_sec)
60 if (!_serviceable_node->getBoolValue()) {
61 if (_is_serviceable) {
62 _string_node->setStringValue("");
63 _is_serviceable = false;
68 struct tm *t = globals->get_time_params()->getGmt();
69 int hour = t->tm_hour;
73 // compute local time zone hour
74 int tzoffset_hours = globals->get_time_params()->get_local_offset() / 3600;
75 int lhour = hour + tzoffset_hours;
81 long gmt = (hour * 60 + min) * 60 + sec;
82 int offset = _offset_node->getLongValue();
84 if (!_is_serviceable) {
85 _standstill_offset -= gmt - _gmt_time_sec;
86 } else if (_gmt_time_sec == gmt && _offset_sec == offset)
92 _indicated_sec = _gmt_time_sec + offset + _standstill_offset;
93 _sec_node->setLongValue(_indicated_sec);
117 sprintf(_indicated_string, "%02d:%02d:%02d", hour, min, sec);
118 _string_node->setStringValue(_indicated_string);
119 sprintf(_indicated_short_string, "%02d:%02d", hour, min);
120 _string_node1->setStringValue(_indicated_short_string);
121 sprintf(_local_short_string, "%02d:%02d", lhour, min);
122 _string_node2->setStringValue(_local_short_string);
123 _is_serviceable = true;
125 _indicated_min = min;
126 _min_node->setLongValue(_indicated_min);
127 _indicated_hour = hour;
128 _hour_node->setLongValue(_indicated_hour);
130 _lhour_node->setLongValue(_local_hour);