refactor: centralize shade GPIO initialization and board guards

Use one initialization method for saved configuration and JSON updates. Reject the complete output assignment when any pin belongs to integrated board hardware, retaining separate UI validation and runtime output guards. Exercise production GPIO initialization on generic and Plus profiles.
This commit is contained in:
R. Sid Shaytay 2026-11-06 12:51:36 -08:00
parent a5afcfacea
commit d4c13d5134
6 changed files with 41 additions and 14 deletions

View file

@ -6,7 +6,6 @@
#include "Utils.h"
#include "ConfigSettings.h"
#include "RollingCode.h"
#include "BoardProfile.h"
static const char *TAG = "ConfigFile";
@ -288,12 +287,7 @@ void ShadeConfigFile::readShade(SomfyShade *shade) {
shade->gpioMy = rec.gpioMy;
shade->gpioFlags = rec.gpioFlags;
shade->roomId = rec.roomId;
if(shade->proto == radio_proto::GP_Relay || shade->proto == radio_proto::GP_Remote) {
if(!BoardProfile::usesPin(shade->gpioUp)) pinMode(shade->gpioUp, OUTPUT);
if(!BoardProfile::usesPin(shade->gpioDown)) pinMode(shade->gpioDown, OUTPUT);
}
if(shade->proto == radio_proto::GP_Remote && !BoardProfile::usesPin(shade->gpioMy))
pinMode(shade->gpioMy, OUTPUT);
shade->initGPIOs();
}
void ShadeConfigFile::readGroup(SomfyGroup *group) {
group_record_t rec = groupRecord(group);

View file

@ -12,6 +12,17 @@ static bool usesBoardGPIOs(const SomfyShade &shade) {
(shade.proto == radio_proto::GP_Remote && BoardProfile::usesPin(shade.gpioMy));
}
// Shared by saved/backup configuration loading and JSON updates. Refuse the
// entire assignment if any output belongs to integrated board hardware.
void SomfyShade::initGPIOs() {
if(usesBoardGPIOs(*this)) return;
if(this->proto == radio_proto::GP_Relay || this->proto == radio_proto::GP_Remote) {
pinMode(this->gpioUp, OUTPUT);
pinMode(this->gpioDown, OUTPUT);
}
if(this->proto == radio_proto::GP_Remote) pinMode(this->gpioMy, OUTPUT);
}
void SomfyShade::setGPIOs() {
if(usesBoardGPIOs(*this)) return;
if(this->proto == radio_proto::GP_Relay) {

View file

@ -152,6 +152,7 @@ class SomfyShade : public SomfyRemote, public ShadeSettings, private MotorLink,
void commit();
void clear();
int8_t transformPosition(float fpos);
void initGPIOs();
void setGPIOs();
void triggerGPIOs(somfy_frame_t &frame);
bool usesPin(uint8_t pin);

View file

@ -157,13 +157,11 @@ int8_t SomfyShade::fromJSON(JsonObject &obj) {
if(this->proto == radio_proto::GP_Remote || this->proto == radio_proto::GP_Relay) {
if(!obj["gpioUp"].isNull()) this->gpioUp = obj["gpioUp"];
if(!obj["gpioDown"].isNull()) this->gpioDown = obj["gpioDown"];
if(!BoardProfile::usesPin(this->gpioUp)) pinMode(this->gpioUp, OUTPUT);
if(!BoardProfile::usesPin(this->gpioDown)) pinMode(this->gpioDown, OUTPUT);
}
if(this->proto == radio_proto::GP_Remote) {
if(!obj["gpioMy"].isNull()) this->gpioMy = obj["gpioMy"];
if(!BoardProfile::usesPin(this->gpioMy)) pinMode(this->gpioMy, OUTPUT);
}
this->initGPIOs();
}
return err;
}