diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-06-03 17:05:57 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-06-03 17:05:57 +0300 |
commit | a3471a68552fc8dbacb404c49fec2195632f6c15 (patch) | |
tree | 94709f2d8ffef0318e409a1a8747cab5fadee77a /src/Heating/LocalHeater.cpp | |
parent | a9e074cdeda7195103d2131c7ab7d653dacc8a30 (diff) |
Tidied up previous change
Diffstat (limited to 'src/Heating/LocalHeater.cpp')
-rw-r--r-- | src/Heating/LocalHeater.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/Heating/LocalHeater.cpp b/src/Heating/LocalHeater.cpp index 552b111b..84ecddb8 100644 --- a/src/Heating/LocalHeater.cpp +++ b/src/Heating/LocalHeater.cpp @@ -68,16 +68,26 @@ void LocalHeater::ResetHeater() noexcept // Configure the heater port and the sensor number GCodeResult LocalHeater::ConfigurePortAndSensor(const char *portName, PwmFrequency freq, unsigned int sn, const StringRef& reply) { - PinAccess access[MaxPortsPerHeater]; - IoPort* portAddrs[MaxPortsPerHeater]; - for (size_t i = 0; i < MaxPortsPerHeater; ++i) + if constexpr (MaxPortsPerHeater == 1) { - access[i] = PinAccess::pwm; - portAddrs[i] = &ports[i]; + if (!ports[0].AssignPort(portName, reply, PinUsedBy::heater, PinAccess::pwm)) + { + return GCodeResult::error; + } } - if (IoPort::AssignPorts(portName, reply, PinUsedBy::heater, MaxPortsPerHeater, portAddrs, access) == 0) + else { - return GCodeResult::error; + PinAccess access[MaxPortsPerHeater]; + IoPort* portAddrs[MaxPortsPerHeater]; + for (size_t i = 0; i < MaxPortsPerHeater; ++i) + { + access[i] = PinAccess::pwm; + portAddrs[i] = &ports[i]; + } + if (IoPort::AssignPorts(portName, reply, PinUsedBy::heater, MaxPortsPerHeater, portAddrs, access) == 0) + { + return GCodeResult::error; + } } for (auto& port : ports) @@ -106,11 +116,15 @@ GCodeResult LocalHeater::ReportDetails(const StringRef& reply) const noexcept { reply.printf("Heater %u", GetHeaterNumber()); ports[0].AppendDetails(reply); - for (size_t i = 1; i < MaxPortsPerHeater && ports[i].IsValid(); ++i) + if constexpr (MaxPortsPerHeater > 1) { - reply.cat('+'); - ports[i].AppendDetails(reply); + for (size_t i = 1; i < MaxPortsPerHeater && ports[i].IsValid(); ++i) + { + reply.cat('+'); + ports[i].AppendDetails(reply); + } } + if (GetSensorNumber() >= 0) { reply.catf(", sensor %d", GetSensorNumber()); |