@@ -71,52 +71,54 @@ struct PwmNode
71
71
std::string name;
72
72
std::string type;
73
73
std::string bind;
74
- int minpwm{}, maxpwm{};
74
+ int minpwm{}, maxpwm{PWM_MAX_VAL };
75
75
Pwm::Mode mode{Pwm::Mode::NoChange};
76
76
int fanStopHyst{FANSTOP_DISABLE};
77
77
};
78
78
79
79
static void operator >>(const YAML::Node& node, PwmNode& pwmNode)
80
80
{
81
- for (auto it = node.begin (); it != node.end (); ++it) {
82
- pwmNode.name = it->first .as <std::string>();
83
- for (auto it2 = it->second .begin (); it2 != it->second .end (); ++it2) {
84
- auto key = it2->first .as <std::string>();
85
- if (key == " type" ) {
86
- pwmNode.type = it2->second .as <std::string>();
87
- }
88
- else if (key == " bind" ) {
89
- pwmNode.bind = it2->second .as <std::string>();
90
- }
91
- else if (key == " mode" ) {
92
- auto rawMode = it2->second .as <std::string>();
93
- if (rawMode == " dc" ) {
94
- pwmNode.mode = Pwm::Mode::Dc;
95
- }
96
- else if (rawMode == " pwm" ) {
97
- pwmNode.mode = Pwm::Mode::Pwm;
98
- }
99
- else {
100
- cout << " Incompatible PWM mode, no change: " + rawMode << " \n " ;
101
- }
102
- }
103
- else if (key == " minpwm" ) {
104
- pwmNode.minpwm = it2->second .as <int >();
105
- }
106
- else if (key == " maxpwm" ) {
107
- pwmNode.maxpwm = it2->second .as <int >();
108
- }
109
- else if (key == " fan_stop" ) {
110
- pwmNode.fanStopHyst = it2->second .as <bool >() ? FANSTOP_DEFAULT_HYSTERESIS : FANSTOP_DISABLE;
81
+ auto it = node.begin ();
82
+ pwmNode.name = it->first .as <std::string>();
83
+ for (auto it2 = it->second .begin (); it2 != it->second .end (); ++it2) {
84
+ auto key = it2->first .as <std::string>();
85
+ if (key == " type" ) {
86
+ pwmNode.type = it2->second .as <std::string>();
87
+ }
88
+ else if (key == " bind" ) {
89
+ pwmNode.bind = it2->second .as <std::string>();
90
+ }
91
+ else if (key == " mode" ) {
92
+ auto rawMode = it2->second .as <std::string>();
93
+ if (rawMode == " dc" ) {
94
+ pwmNode.mode = Pwm::Mode::Dc;
111
95
}
112
- else if (key == " fan_stop_hysteresis " ) {
113
- pwmNode.fanStopHyst = static_cast < int >(it2-> second . as < uint32_t >()) ;
96
+ else if (rawMode == " pwm " ) {
97
+ pwmNode.mode = Pwm::Mode::Pwm ;
114
98
}
115
-
116
99
else {
117
- cout << " unknown attribute: " << key << " \n " ;
100
+ cout << " Incompatible PWM mode, no change: " + rawMode << " \n " ;
118
101
}
119
102
}
103
+ else if (key == " minpwm" ) {
104
+ pwmNode.minpwm = it2->second .as <int >();
105
+ }
106
+ else if (key == " maxpwm" ) {
107
+ pwmNode.maxpwm = it2->second .as <int >();
108
+ }
109
+ else if (key == " fan_stop" ) {
110
+ pwmNode.fanStopHyst = it2->second .as <bool >() ? FANSTOP_DEFAULT_HYSTERESIS : FANSTOP_DISABLE;
111
+ }
112
+ else if (key == " fan_stop_hysteresis" ) {
113
+ pwmNode.fanStopHyst = static_cast <int >(it2->second .as <uint32_t >());
114
+ }
115
+
116
+ else {
117
+ cout << " unknown attribute:" << key << " \n " ;
118
+ }
119
+ }
120
+ if (pwmNode.type .empty () || pwmNode.bind .empty ()) {
121
+ throw std::invalid_argument (R"( PWM config entry is inconsistent, must contain 'bind' and 'type' fields)" );
120
122
}
121
123
}
122
124
0 commit comments