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),
20 _standstill_offset(0),
24 _indicated_string[0] = '\0';
27 for ( i = 0; i < node->nChildren(); ++i ) {
28 SGPropertyNode *child = node->getChild(i);
29 string cname = child->getName();
30 string cval = child->getStringValue();
31 if ( cname == "name" ) {
33 } else if ( cname == "number" ) {
34 num = child->getIntValue();
36 SG_LOG( SG_INSTR, SG_WARN, "Error in clock config logic" );
37 if ( name.length() ) {
38 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
45 : _is_serviceable(true),
51 _indicated_string[0] = '\0';
62 branch = "/instrumentation/" + name;
64 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
65 _serviceable_node = node->getChild("serviceable", 0, true);
66 _offset_node = node->getChild("offset-sec", 0, true);
67 _sec_node = node->getChild("indicated-sec", 0, true);
68 _string_node = node->getChild("indicated-string", 0, true);
72 Clock::update (double delta_time_sec)
74 if (!_serviceable_node->getBoolValue()) {
75 if (_is_serviceable) {
76 _string_node->setStringValue("");
77 _is_serviceable = false;
82 struct tm *t = globals->get_time_params()->getGmt();
83 int hour = t->tm_hour;
87 long gmt = (hour * 60 + min) * 60 + sec;
88 int offset = _offset_node->getLongValue();
90 if (!_is_serviceable) {
91 _standstill_offset -= gmt - _gmt_time_sec;
92 } else if (_gmt_time_sec == gmt && _offset_sec == offset)
98 _indicated_sec = _gmt_time_sec + offset + _standstill_offset;
99 _sec_node->setLongValue(_indicated_sec);
123 sprintf(_indicated_string, "%02d:%02d:%02d", hour, min, sec);
124 _string_node->setStringValue(_indicated_string);
125 _is_serviceable = true;