FlightGear next
AbstractInstrument.cxx
Go to the documentation of this file.
1// Copyright (C) 2019 James Turner <james@flightgear.org>
2//
3// This program is free software; you can redistribute it and/or
4// modify it under the terms of the GNU General Public License as
5// published by the Free Software Foundation; either version 2 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful, but
9// WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17#include "config.h"
18
19#include <simgear/debug/logstream.hxx>
20
22#include <Main/fg_props.hxx>
23
24void AbstractInstrument::readConfig(SGPropertyNode* config,
25 std::string defaultName)
26{
27 _name = config->getStringValue("name", defaultName.c_str());
28 _index = config->getIntValue("number", 0);
29 if (_powerSupplyPath.empty()) {
30 _powerSupplyPath = "/systems/electrical/outputs/" + defaultName + "[" + std::to_string(_index) + "]";
31 }
32
33 if (config->hasChild("power-supply")) {
34 _powerSupplyPath = config->getStringValue("power-supply");
35 }
36
37 // the default output values are volts, but various places have been
38 // treating the value as a bool, so we default to 1.0 as our minimum
39 // supply volts
40 _minimumSupplyVolts = config->getDoubleValue("minimum-supply-volts", 1.0);
41}
42
44{
45 return "/instrumentation/" + _name + "[" + std::to_string(_index) + "]";
46}
47
49{
50 _serviceableNode = node->getNode("serviceable", 0, true);
51 if (_serviceableNode->getType() == simgear::props::NONE)
52 _serviceableNode->setBoolValue(true);
53
54 _powerButtonNode = node->getChild("power-btn", 0, true);
55
56 // if the user didn't define a node, default to true
57 if (_powerButtonNode->getType() == simgear::props::NONE)
58 _powerButtonNode->setBoolValue(true);
59
60 if (_powerSupplyPath != "NO_DEFAULT") {
61 _powerSupplyNode = fgGetNode(_powerSupplyPath, true);
62 }
63
64 node->tie( "operable", SGRawValueMethods<AbstractInstrument,bool>
66}
67
69{
70 auto nd = fgGetNode(nodePath());
71 if (nd) {
72 nd->untie("operable");
73 }
74}
75
77{
78 if (!_serviceableNode->getBoolValue() || !isPowerSwitchOn())
79 return false;
80
81 if (_powerSupplyNode && (_powerSupplyNode->getDoubleValue() < _minimumSupplyVolts))
82 return false;
83
84 return true;
85}
86
88{
89 _powerSupplyPath = p;
90}
91
93{
94 _minimumSupplyVolts = v;
95}
96
98{
99 return _powerButtonNode->getBoolValue();
100}
#define p(x)
void initServicePowerProperties(SGPropertyNode *node)
virtual bool isPowerSwitchOn() const
void setMinimumSupplyVolts(double v)
void readConfig(SGPropertyNode *config, std::string defaultName)
std::string nodePath() const
void setDefaultPowerSupplyPath(const std::string &p)
specify the default path to use to power the instrument, if it's non- standard.
bool isServiceableAndPowered() const
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
Definition proptest.cpp:27