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 : _is_serviceable(true),
26 _standstill_offset(0),
30 _indicated_string[0] = '\0';
33 for ( i = 0; i < node->nChildren(); ++i ) {
34 SGPropertyNode *child = node->getChild(i);
35 string cname = child->getName();
36 string cval = child->getStringValue();
37 if ( cname == "name" ) {
39 } else if ( cname == "number" ) {
40 num = child->getIntValue();
42 SG_LOG( SG_INSTR, SG_WARN, "Error in clock config logic" );
43 if ( name.length() ) {
44 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
51 : _is_serviceable(true),
57 _indicated_string[0] = '\0';
58 _indicated_short_string[0] = '\0';
69 branch = "/instrumentation/" + name;
71 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
72 _serviceable_node = node->getChild("serviceable", 0, true);
73 _offset_node = node->getChild("offset-sec", 0, true);
74 _sec_node = node->getChild("indicated-sec", 0, true);
75 _min_node = node->getChild("indicated-min", 0, true);
76 _hour_node = node->getChild("indicated-hour", 0, true);
77 _lhour_node = node->getChild("local-hour", 0, true);
78 _string_node = node->getChild("indicated-string", 0, true);
79 _string_node1 = node->getChild("indicated-short-string", 0, true);
80 _string_node2 = node->getChild("local-short-string", 0, true);
84 Clock::update (double delta_time_sec)
86 if (!_serviceable_node->getBoolValue()) {
87 if (_is_serviceable) {
88 _string_node->setStringValue("");
89 _is_serviceable = false;
94 struct tm *t = globals->get_time_params()->getGmt();
95 int hour = t->tm_hour;
99 // compute local time zone hour
100 int tzoffset_hours = globals->get_time_params()->get_local_offset() / 3600;
101 int lhour = hour + tzoffset_hours;
102 if ( lhour < 0 ) { lhour += 24; }
103 if ( lhour >= 24 ) { lhour -= 24; }
105 long gmt = (hour * 60 + min) * 60 + sec;
106 int offset = _offset_node->getLongValue();
108 if (!_is_serviceable) {
109 _standstill_offset -= gmt - _gmt_time_sec;
110 } else if (_gmt_time_sec == gmt && _offset_sec == offset)
114 _offset_sec = offset;
116 _indicated_sec = _gmt_time_sec + offset + _standstill_offset;
117 _sec_node->setLongValue(_indicated_sec);
141 sprintf(_indicated_string, "%02d:%02d:%02d", hour, min, sec);
142 _string_node->setStringValue(_indicated_string);
143 sprintf(_indicated_short_string, "%02d:%02d", hour, min);
144 _string_node1->setStringValue(_indicated_short_string);
145 sprintf(_local_short_string, "%02d:%02d", lhour, min);
146 _string_node2->setStringValue(_local_short_string);
147 _is_serviceable = true;
149 _indicated_min = min;
150 _min_node->setLongValue(_indicated_min);
151 _indicated_hour = hour;
152 _hour_node->setLongValue(_indicated_hour);
154 _lhour_node->setLongValue(_local_hour);