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.
13 #include <simgear/timing/sg_time.hxx>
14 #include <Main/fg_props.hxx>
15 #include <Main/util.hxx>
18 Clock::Clock(SGPropertyNode *node) :
19 _name(node->getStringValue("name", "clock")),
20 _num(node->getIntValue("number", 0)),
21 _is_serviceable(true),
30 _indicated_string[0] = '\0';
41 branch = "/instrumentation/" + _name;
43 SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
44 _serviceable_node = node->getChild("serviceable", 0, true);
45 _offset_node = node->getChild("offset-sec", 0, true);
46 _sec_node = node->getChild("indicated-sec", 0, true);
47 _min_node = node->getChild("indicated-min", 0, true);
48 _hour_node = node->getChild("indicated-hour", 0, true);
49 _lhour_node = node->getChild("local-hour", 0, true);
50 _string_node = node->getChild("indicated-string", 0, true);
51 _string_node1 = node->getChild("indicated-short-string", 0, true);
52 _string_node2 = node->getChild("local-short-string", 0, true);
56 Clock::update (double delta_time_sec)
58 if (!_serviceable_node->getBoolValue()) {
59 if (_is_serviceable) {
60 _string_node->setStringValue("");
61 _is_serviceable = false;
66 struct tm *t = globals->get_time_params()->getGmt();
67 int hour = t->tm_hour;
71 // compute local time zone hour
72 int tzoffset_hours = globals->get_time_params()->get_local_offset() / 3600;
73 int lhour = hour + tzoffset_hours;
79 long gmt = (hour * 60 + min) * 60 + sec;
80 int offset = _offset_node->getLongValue();
82 if (!_is_serviceable) {
83 _standstill_offset -= gmt - _gmt_time_sec;
84 } else if (_gmt_time_sec == gmt && _offset_sec == offset)
90 _indicated_sec = _gmt_time_sec + offset + _standstill_offset;
91 _sec_node->setLongValue(_indicated_sec);
115 sprintf(_indicated_string, "%02d:%02d:%02d", hour, min, sec);
116 _string_node->setStringValue(_indicated_string);
117 sprintf(_indicated_short_string, "%02d:%02d", hour, min);
118 _string_node1->setStringValue(_indicated_short_string);
119 sprintf(_local_short_string, "%02d:%02d", lhour, min);
120 _string_node2->setStringValue(_local_short_string);
121 _is_serviceable = true;
123 _indicated_min = min;
124 _min_node->setLongValue(_indicated_min);
125 _indicated_hour = hour;
126 _hour_node->setLongValue(_indicated_hour);
128 _lhour_node->setLongValue(_local_hour);