if(designator == 0) return nullptr; // no designator then not valid
- // create a new temperature switch module
- TemperatureSwitch *ts= new TemperatureSwitch();
-
- //__debugbreak();
-
- // make a list of temperature controls with matching designators with the same first letter
- // the list is added t the controllers vector given below
- {
- std::vector<struct pad_temperature> controllers;
- bool ok = PublicData::get_value(temperature_control_checksum, poll_controls_checksum, &controllers);
- if (ok) {
- for (auto &c : controllers) {
- if (c.designator[0] == designator) {
- ts->temp_controllers.push_back(c.id);
- }
- }
- }
- }
-
- // if we don't have any matching controllers, then not valid
- if (ts->temp_controllers.empty()) {
- THEKERNEL->streams->printf("WARNING TEMPERATURESWITCH: no controllers matching: %c\n", designator);
- delete ts;
- return nullptr;
- }
-
// load settings from config file
- s = THEKERNEL->config->value(temperatureswitch_checksum, modcs, temperatureswitch_switch_checksum)->by_default("")->as_string();
- if(s.empty()) {
+ string switchname = THEKERNEL->config->value(temperatureswitch_checksum, modcs, temperatureswitch_switch_checksum)->by_default("")->as_string();
+ if(switchname.empty()) {
// handle old configs where this was called type @DEPRECATED
- s = THEKERNEL->config->value(temperatureswitch_checksum, modcs, temperatureswitch_type_checksum)->by_default("")->as_string();
- if(s.empty()) {
+ switchname = THEKERNEL->config->value(temperatureswitch_checksum, modcs, temperatureswitch_type_checksum)->by_default("")->as_string();
+ if(switchname.empty()) {
// no switch specified so invalid entry
THEKERNEL->streams->printf("WARNING TEMPERATURESWITCH: no switch specified\n");
- delete this;
return nullptr;
}
}
+ // create a new temperature switch module
+ TemperatureSwitch *ts= new TemperatureSwitch();
+
+ // save designator
+ ts->designator= designator;
+
// if we should turn the switch on or off when trigger is hit
ts->inverted = THEKERNEL->config->value(temperatureswitch_checksum, modcs, temperatureswitch_inverted_checksum)->by_default(false)->as_bool();
// the mcode used to arm the switch
ts->arm_mcode = THEKERNEL->config->value(temperatureswitch_checksum, modcs, temperatureswitch_arm_command_checksum)->by_default(0)->as_number();
- ts->temperatureswitch_switch_cs= get_checksum(s); // checksum of the switch to use
+ ts->temperatureswitch_switch_cs= get_checksum(switchname); // checksum of the switch to use
ts->temperatureswitch_threshold_temp = THEKERNEL->config->value(temperatureswitch_checksum, modcs, temperatureswitch_threshold_temp_checksum)->by_default(50.0f)->as_number();
// Get the highest temperature from the set of temperature controllers
float TemperatureSwitch::get_highest_temperature()
{
- struct pad_temperature temp;
float high_temp = 0.0;
- for (auto controller : temp_controllers) {
- bool ok = PublicData::get_value(temperature_control_checksum, current_temperature_checksum, controller, &temp);
- if (ok) {
+ std::vector<struct pad_temperature> controllers;
+ bool ok = PublicData::get_value(temperature_control_checksum, poll_controls_checksum, &controllers);
+ if (ok) {
+ for (auto &c : controllers) {
// check if this controller's temp is the highest and save it if so
- if (temp.current_temperature > high_temp) {
- high_temp = temp.current_temperature;
+ if (c.designator[0] == this->designator && c.current_temperature > high_temp) {
+ high_temp = c.current_temperature;
}
}
}
+
return high_temp;
}