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>
15 Clock::Clock ( SGPropertyNode *node )
16 : _is_serviceable(true),
22 _standstill_offset(0),
26 _indicated_string[0] = '\0';
29 for ( i = 0; i < node->nChildren(); ++i ) {
30 SGPropertyNode *child = node->getChild(i);
31 string cname = child->getName();
32 string cval = child->getStringValue();
33 if ( cname == "name" ) {
35 } else if ( cname == "number" ) {
36 num = child->getIntValue();
38 SG_LOG( SG_INSTR, SG_WARN, "Error in clock config logic" );
39 if ( name.length() ) {
40 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
47 : _is_serviceable(true),
53 _indicated_string[0] = '\0';
54 _indicated_short_string[0] = '\0';
65 branch = "/instrumentation/" + name;
67 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
68 _serviceable_node = node->getChild("serviceable", 0, true);
69 _offset_node = node->getChild("offset-sec", 0, true);
70 _sec_node = node->getChild("indicated-sec", 0, true);
71 _min_node = node->getChild("indicated-min", 0, true);
72 _hour_node = node->getChild("indicated-hour", 0, true);
73 _string_node = node->getChild("indicated-string", 0, true);
74 _string_node1 = node->getChild("indicated-short-string", 0, true);
78 Clock::update (double delta_time_sec)
80 if (!_serviceable_node->getBoolValue()) {
81 if (_is_serviceable) {
82 _string_node->setStringValue("");
83 _is_serviceable = false;
88 struct tm *t = globals->get_time_params()->getGmt();
89 int hour = t->tm_hour;
93 long gmt = (hour * 60 + min) * 60 + sec;
94 int offset = _offset_node->getLongValue();
96 if (!_is_serviceable) {
97 _standstill_offset -= gmt - _gmt_time_sec;
98 } else if (_gmt_time_sec == gmt && _offset_sec == offset)
102 _offset_sec = offset;
104 _indicated_sec = _gmt_time_sec + offset + _standstill_offset;
105 _sec_node->setLongValue(_indicated_sec);
129 sprintf(_indicated_string, "%02d:%02d:%02d", hour, min, sec);
130 _string_node->setStringValue(_indicated_string);
131 sprintf(_indicated_short_string, "%02d:%02d", hour, min);
132 _string_node1->setStringValue(_indicated_short_string);
133 _is_serviceable = true;
135 _indicated_min = min;
136 _min_node->setLongValue(_indicated_min);
137 _indicated_hour = hour;
138 _hour_node->setLongValue(_indicated_hour);