diff --git a/data/config.html b/data/config.html index 22673ace..93a8dfdc 100644 --- a/data/config.html +++ b/data/config.html @@ -162,22 +162,24 @@

YaSolR Configuration

zcd_enable: ["Enable Zero-Cross Detection", "switch"], "Hardware (config)": "TITLE", - grid_freq: ["Nominal Grid Frequency (0 == auto-detect)", "select", "0,50,60"], + disp_angle: ["Display Rotation", "select", "0,90,180,270"], disp_speed: ["Display Speed (s)", "select", "1,2,3,4,5,6,7,8,9,10"], disp_type: ["Display Type", "select", "SH1106,SH1107,SSD1306"], - disp_angle: ["Display Rotation", "select", "0,90,180,270"], - relay1_type: ["Relay 1 Type", "select", "NO,NC"], - relay2_type: ["Relay 2 Type", "select", "NO,NC"], - relay1_load: ["Relay 1 Automatic Control: Connected Load (Watts)", "uint"], - relay2_load: ["Relay 2 Automatic Control: Connected Load (Watts)", "uint"], - o1_relay_type: ["Output 1 Bypass Relay Type", "select", "NO,NC"], - o2_relay_type: ["Output 2 Bypass Relay Type", "select", "NO,NC"], + grid_freq: ["Nominal Grid Frequency (0 == auto-detect)", "select", "0,50,60"], o1_dim_min: ["Output 1 Dimmer Remap Min (%)", "percent"], o1_dim_max: ["Output 1 Dimmer Remap Max (%)", "percent"], + o1_dim_type: ["Output 1 Dimmer Type", "select", "LSA + DAC GP8211S (DFR1071),LSA + DAC GP8403 (DFR0971),LSA + DAC GP8413 (DFR1073),LSA + PWM->Analog,Robodyn 24A / 40A,SSR Random,SSR Sync (Zero-Cross),Triac / Thyristor"], + o1_relay_type: ["Output 1 Bypass Relay Type", "select", "NO,NC"], + o1_resistance: ["Output 1 Resistance (Ohm)", "uint"], o2_dim_min: ["Output 2 Dimmer Remap Min (%)", "percent"], o2_dim_max: ["Output 2 Dimmer Remap Max (%)", "percent"], - o1_resistance: ["Output 1 Resistance (Ohm)", "uint"], + o2_dim_type: ["Output 2 Dimmer Type", "select", "LSA + DAC GP8211S (DFR1071),LSA + DAC GP8403 (DFR0971),LSA + DAC GP8413 (DFR1073),LSA + PWM->Analog,Robodyn 24A / 40A,SSR Random,SSR Sync (Zero-Cross),Triac / Thyristor"], + o2_relay_type: ["Output 2 Bypass Relay Type", "select", "NO,NC"], o2_resistance: ["Output 2 Resistance (Ohm)", "uint"], + relay1_load: ["Relay 1 Automatic Control: Connected Load (Watts)", "uint"], + relay1_type: ["Relay 1 Type", "select", "NO,NC"], + relay2_load: ["Relay 2 Automatic Control: Connected Load (Watts)", "uint"], + relay2_type: ["Relay 2 Type", "select", "NO,NC"], "PID Calibration": "TITLE", pid_pmode: ["Proportional Mode (1: On Error, 2: On Input, 3: Both)", "select", "1,2,3"], diff --git a/include/i18n/en.h b/include/i18n/en.h index cbc69853..0c7a676c 100644 --- a/include/i18n/en.h +++ b/include/i18n/en.h @@ -148,8 +148,8 @@ #define YASOLR_LBL_146 YASOLR_LBL_070 " Resistance (Ω)" #define YASOLR_LBL_147 YASOLR_LBL_046 " PZEM Pairing" #define YASOLR_LBL_148 YASOLR_LBL_070 " PZEM Pairing" -#define YASOLR_LBL_149 YASOLR_LBL_046 " Relay Type (Bypass)" -#define YASOLR_LBL_150 YASOLR_LBL_070 " Relay Type (Bypass)" +#define YASOLR_LBL_149 YASOLR_LBL_046 " Bypass Relay Type" +#define YASOLR_LBL_150 YASOLR_LBL_070 " Bypass Relay Type" #define YASOLR_LBL_151 YASOLR_LBL_074 " Type" #define YASOLR_LBL_152 YASOLR_LBL_077 " Type" #define YASOLR_LBL_153 "Duplicate" @@ -185,7 +185,7 @@ #define YASOLR_LBL_183 YASOLR_LBL_046 " Dimmer Min/Max Remapping" #define YASOLR_LBL_184 YASOLR_LBL_070 " Dimmer Min/Max Remapping" #define YASOLR_LBL_185 "Restart required!" -#define YASOLR_LBL_186 "Resistance Value Detection" +#define YASOLR_LBL_186 "Output Resistance Calibration" #define YASOLR_LBL_187 "JSY Remote" #define YASOLR_LBL_030 "Relay: " YASOLR_LBL_046 " Bypass Relay Switch Count" #define YASOLR_LBL_031 "Relay: " YASOLR_LBL_070 " Bypass Relay Switch Count" @@ -196,8 +196,8 @@ #define YASOLR_LBL_190 "Gateway" #define YASOLR_LBL_191 "DNS Server" #define YASOLR_LBL_192 "Device: Reboot Reason" -// #define YASOLR_LBL_193 -// #define YASOLR_LBL_194 +#define YASOLR_LBL_193 YASOLR_LBL_046 " Dimmer Type" +#define YASOLR_LBL_194 YASOLR_LBL_070 " Dimmer Type" // #define YASOLR_LBL_195 // #define YASOLR_LBL_196 // #define YASOLR_LBL_197 diff --git a/include/i18n/fr.h b/include/i18n/fr.h index c4eafeb1..9ff5a451 100644 --- a/include/i18n/fr.h +++ b/include/i18n/fr.h @@ -53,7 +53,7 @@ #define YASOLR_LBL_047 "État" #define YASOLR_LBL_048 "Température" #define YASOLR_LBL_049 "Supprimer le certificat serveur" -#define YASOLR_LBL_050 "variateur" +#define YASOLR_LBL_050 "Variateur" #define YASOLR_LBL_051 "Marche forcée" #define YASOLR_LBL_052 "Puissance" #define YASOLR_LBL_053 "Puissance Apparente" @@ -65,7 +65,7 @@ #define YASOLR_LBL_059 "Énergie" #define YASOLR_LBL_060 "Routage automatique" #define YASOLR_LBL_061 "Limite de surplus (W)" -#define YASOLR_LBL_062 "Limitation du dimmer" +#define YASOLR_LBL_062 "Limitation du variateur" #define YASOLR_LBL_063 "Température de consigne d'arrêt du routage (°C)" #define YASOLR_LBL_064 "Marche forcée automatique" #define YASOLR_LBL_065 "Température de démarrage de la marche forcée (°C)" @@ -196,8 +196,8 @@ #define YASOLR_LBL_190 "Passerelle" #define YASOLR_LBL_191 "Serveur DNS" #define YASOLR_LBL_192 "Micro-contrôleur: Raison du reboot" -// #define YASOLR_LBL_193 -// #define YASOLR_LBL_194 +#define YASOLR_LBL_193 "Sortie 1: Type de variateur" +#define YASOLR_LBL_194 "Sortie 2: Type de variateur" // #define YASOLR_LBL_195 // #define YASOLR_LBL_196 // #define YASOLR_LBL_197 diff --git a/include/yasolr_macros.h b/include/yasolr_macros.h index cf4f8f72..7943f2bc 100644 --- a/include/yasolr_macros.h +++ b/include/yasolr_macros.h @@ -43,6 +43,14 @@ // default settings #define YASOLR_ADMIN_USERNAME "admin" +#define YASOLR_DIMMER_LSA_GP8211S "LSA + DAC GP8211S (DFR1071)" +#define YASOLR_DIMMER_LSA_GP8403 "LSA + DAC GP8403 (DFR0971)" +#define YASOLR_DIMMER_LSA_GP8413 "LSA + DAC GP8413 (DFR1073)" +#define YASOLR_DIMMER_LSA_PWM "LSA + PWM->Analog" +#define YASOLR_DIMMER_ROBODYN "Robodyn 24A / 40A" +#define YASOLR_DIMMER_SSR_RANDOM "SSR Random" +#define YASOLR_DIMMER_SSR_SYNC "SSR Sync (Zero-Cross)" +#define YASOLR_DIMMER_TRIAC "Triac / Thyristor" #define YASOLR_DISPLAY_LINE_SIZE 21 #define YASOLR_DISPLAY_LINES 5 #define YASOLR_GRAPH_POINTS 60 @@ -132,8 +140,9 @@ #define KEY_OUTPUT1_DIMMER_MAX "o1_dim_max" #define KEY_OUTPUT1_DIMMER_MIN "o1_dim_min" #define KEY_OUTPUT1_DIMMER_TEMP_LIMITER "o1_dim_max_t" -#define KEY_OUTPUT1_RELAY_TYPE "o1_relay_type" +#define KEY_OUTPUT1_DIMMER_TYPE "o1_dim_type" #define KEY_OUTPUT1_EXCESS_LIMITER "o1_excess_limit" +#define KEY_OUTPUT1_RELAY_TYPE "o1_relay_type" #define KEY_OUTPUT1_RESISTANCE "o1_resistance" #define KEY_OUTPUT1_TEMPERATURE_MQTT_TOPIC "o1_temp_mqtt" #define KEY_OUTPUT1_TEMPERATURE_START "o1_temp_start" @@ -145,8 +154,9 @@ #define KEY_OUTPUT2_DIMMER_MAX "o2_dim_max" #define KEY_OUTPUT2_DIMMER_MIN "o2_dim_min" #define KEY_OUTPUT2_DIMMER_TEMP_LIMITER "o2_dim_max_t" -#define KEY_OUTPUT2_RELAY_TYPE "o2_relay_type" +#define KEY_OUTPUT2_DIMMER_TYPE "o2_dim_type" #define KEY_OUTPUT2_EXCESS_LIMITER "o2_excess_limit" +#define KEY_OUTPUT2_RELAY_TYPE "o2_relay_type" #define KEY_OUTPUT2_RESISTANCE "o2_resistance" #define KEY_OUTPUT2_TEMPERATURE_MQTT_TOPIC "o2_temp_mqtt" #define KEY_OUTPUT2_TEMPERATURE_START "o2_temp_start" diff --git a/src/yasolr_config.cpp b/src/yasolr_config.cpp index 024b258d..9b4fb0b6 100644 --- a/src/yasolr_config.cpp +++ b/src/yasolr_config.cpp @@ -22,8 +22,8 @@ void yasolr_init_config() { config.configure(KEY_ENABLE_DISPLAY, YASOLR_FALSE); config.configure(KEY_ENABLE_DS18_SYSTEM, YASOLR_FALSE); config.configure(KEY_ENABLE_HA_DISCOVERY, YASOLR_FALSE); - config.configure(KEY_ENABLE_JSY, YASOLR_FALSE); config.configure(KEY_ENABLE_JSY_REMOTE, YASOLR_FALSE); + config.configure(KEY_ENABLE_JSY, YASOLR_FALSE); config.configure(KEY_ENABLE_LIGHTS, YASOLR_FALSE); config.configure(KEY_ENABLE_MQTT, YASOLR_FALSE); config.configure(KEY_ENABLE_OUTPUT1_AUTO_BYPASS, YASOLR_FALSE); @@ -60,11 +60,12 @@ void yasolr_init_config() { config.configure(KEY_NTP_TIMEZONE, "Europe/Paris"); config.configure(KEY_OUTPUT1_DAYS, YASOLR_WEEK_DAYS); config.configure(KEY_OUTPUT1_DIMMER_LIMIT, "100"); - config.configure(KEY_OUTPUT1_DIMMER_TEMP_LIMITER, "0"); config.configure(KEY_OUTPUT1_DIMMER_MAX, "100"); config.configure(KEY_OUTPUT1_DIMMER_MIN, "0"); - config.configure(KEY_OUTPUT1_RELAY_TYPE, YASOLR_RELAY_TYPE_NO); + config.configure(KEY_OUTPUT1_DIMMER_TEMP_LIMITER, "0"); + config.configure(KEY_OUTPUT1_DIMMER_TYPE, YASOLR_DIMMER_ROBODYN); config.configure(KEY_OUTPUT1_EXCESS_LIMITER, "0"); + config.configure(KEY_OUTPUT1_RELAY_TYPE, YASOLR_RELAY_TYPE_NO); config.configure(KEY_OUTPUT1_RESISTANCE, "0"); config.configure(KEY_OUTPUT1_TEMPERATURE_MQTT_TOPIC); config.configure(KEY_OUTPUT1_TEMPERATURE_START, "50"); @@ -73,11 +74,12 @@ void yasolr_init_config() { config.configure(KEY_OUTPUT1_TIME_STOP, "06:00"); config.configure(KEY_OUTPUT2_DAYS, YASOLR_WEEK_DAYS); config.configure(KEY_OUTPUT2_DIMMER_LIMIT, "100"); - config.configure(KEY_OUTPUT2_DIMMER_TEMP_LIMITER, "0"); config.configure(KEY_OUTPUT2_DIMMER_MAX, "100"); config.configure(KEY_OUTPUT2_DIMMER_MIN, "0"); - config.configure(KEY_OUTPUT2_RELAY_TYPE, YASOLR_RELAY_TYPE_NO); + config.configure(KEY_OUTPUT2_DIMMER_TEMP_LIMITER, "0"); + config.configure(KEY_OUTPUT2_DIMMER_TYPE, YASOLR_DIMMER_ROBODYN); config.configure(KEY_OUTPUT2_EXCESS_LIMITER, "0"); + config.configure(KEY_OUTPUT2_RELAY_TYPE, YASOLR_RELAY_TYPE_NO); config.configure(KEY_OUTPUT2_RESISTANCE, "0"); config.configure(KEY_OUTPUT2_TEMPERATURE_MQTT_TOPIC); config.configure(KEY_OUTPUT2_TEMPERATURE_START, "50"); diff --git a/src/yasolr_dashboard.cpp b/src/yasolr_dashboard.cpp index c9b4e347..53a679f9 100644 --- a/src/yasolr_dashboard.cpp +++ b/src/yasolr_dashboard.cpp @@ -241,38 +241,41 @@ dash::FeedbackSwitchCard _jsy(dashboard, YASOLR_LBL_128); dash::FeedbackSwitchCard _jsyRemote(dashboard, YASOLR_LBL_187); dash::FeedbackSwitchCard _led(dashboard, YASOLR_LBL_129); dash::FeedbackSwitchCard _mqtt(dashboard, YASOLR_LBL_095); +dash::FeedbackSwitchCard _output1Relay(dashboard, YASOLR_LBL_134); dash::FeedbackSwitchCard _output1Dimmer(dashboard, YASOLR_LBL_131); dash::FeedbackSwitchCard _output1DS18(dashboard, YASOLR_LBL_132); dash::FeedbackSwitchCard _output1PZEM(dashboard, YASOLR_LBL_133); -dash::FeedbackSwitchCard _output1Relay(dashboard, YASOLR_LBL_134); +dash::FeedbackSwitchCard _output2Relay(dashboard, YASOLR_LBL_138); dash::FeedbackSwitchCard _output2Dimmer(dashboard, YASOLR_LBL_135); dash::FeedbackSwitchCard _output2DS18(dashboard, YASOLR_LBL_136); dash::FeedbackSwitchCard _output2PZEM(dashboard, YASOLR_LBL_137); -dash::FeedbackSwitchCard _output2Relay(dashboard, YASOLR_LBL_138); dash::FeedbackSwitchCard _relay1(dashboard, YASOLR_LBL_074); dash::FeedbackSwitchCard _relay2(dashboard, YASOLR_LBL_077); dash::FeedbackSwitchCard _routerDS18(dashboard, YASOLR_LBL_139); dash::FeedbackSwitchCard _zcd(dashboard, YASOLR_LBL_125); dash::Tab _hardwareConfigTab(dashboard, "\u2699 " YASOLR_LBL_140); -dash::DropdownCard _gridFreq(dashboard, YASOLR_LBL_141, "Auto-detect,50 Hz,60 Hz"); dash::SliderCard _displaySpeed(dashboard, YASOLR_LBL_142, 1, 10, 1, "s"); dash::DropdownCard _displayType(dashboard, YASOLR_LBL_143, "SH1106,SH1107,SSD1306"); dash::DropdownCard _displayRotation(dashboard, YASOLR_LBL_144, "0,90,180,270"); -dash::DropdownCard _relay1Type(dashboard, YASOLR_LBL_151, "NO,NC"); -dash::DropdownCard _relay2Type(dashboard, YASOLR_LBL_152, "NO,NC"); -dash::TextInputCard _relay1Load(dashboard, YASOLR_LBL_072); -dash::TextInputCard _relay2Load(dashboard, YASOLR_LBL_075); +dash::DropdownCard _gridFreq(dashboard, YASOLR_LBL_141, "Auto-detect,50 Hz,60 Hz"); dash::DropdownCard _output1RelayType(dashboard, YASOLR_LBL_149, "NO,NC"); -dash::DropdownCard _output2RelayType(dashboard, YASOLR_LBL_150, "NO,NC"); dash::RangeSliderCard _output1DimmerMapper(dashboard, YASOLR_LBL_183, 0, 100, 1, "%"); -dash::RangeSliderCard _output2DimmerMapper(dashboard, YASOLR_LBL_184, 0, 100, 1, "%"); +dash::DropdownCard _output1DimmerType(dashboard, YASOLR_LBL_193, YASOLR_DIMMER_LSA_GP8211S "," YASOLR_DIMMER_LSA_GP8403 "," YASOLR_DIMMER_LSA_GP8413 "," YASOLR_DIMMER_LSA_PWM "," YASOLR_DIMMER_ROBODYN "," YASOLR_DIMMER_SSR_RANDOM "," YASOLR_DIMMER_SSR_SYNC "," YASOLR_DIMMER_TRIAC); dash::SwitchCard _output1PZEMSync(dashboard, YASOLR_LBL_147); -dash::SwitchCard _output2PZEMSync(dashboard, YASOLR_LBL_148); dash::FeedbackTextInputCard _output1ResistanceInput(dashboard, YASOLR_LBL_145); +dash::DropdownCard _output2RelayType(dashboard, YASOLR_LBL_150, "NO,NC"); +dash::RangeSliderCard _output2DimmerMapper(dashboard, YASOLR_LBL_184, 0, 100, 1, "%"); +dash::DropdownCard _output2DimmerType(dashboard, YASOLR_LBL_193, YASOLR_DIMMER_LSA_GP8211S "," YASOLR_DIMMER_LSA_GP8403 "," YASOLR_DIMMER_LSA_GP8413 "," YASOLR_DIMMER_LSA_PWM "," YASOLR_DIMMER_ROBODYN "," YASOLR_DIMMER_SSR_RANDOM "," YASOLR_DIMMER_SSR_SYNC "," YASOLR_DIMMER_TRIAC); +dash::SwitchCard _output2PZEMSync(dashboard, YASOLR_LBL_148); dash::FeedbackTextInputCard _output2ResistanceInput(dashboard, YASOLR_LBL_146); dash::SwitchCard _resistanceCalibration(dashboard, YASOLR_LBL_186); +dash::TextInputCard _relay1Load(dashboard, YASOLR_LBL_072); +dash::DropdownCard _relay1Type(dashboard, YASOLR_LBL_151, "NO,NC"); +dash::TextInputCard _relay2Load(dashboard, YASOLR_LBL_075); +dash::DropdownCard _relay2Type(dashboard, YASOLR_LBL_152, "NO,NC"); + dash::Tab _pidTab(dashboard, "\u2699 " YASOLR_LBL_159); dash::SwitchCard _pidView(dashboard, YASOLR_LBL_169); dash::DropdownCard _pidPMode(dashboard, YASOLR_LBL_160, YASOLR_PID_P_MODE_1 "," YASOLR_PID_P_MODE_2 "," YASOLR_PID_P_MODE_3); @@ -663,22 +666,24 @@ void YaSolR::Website::begin() { // Hardware (config) - _gridFreq.setTab(_hardwareConfigTab); _displayRotation.setTab(_hardwareConfigTab); - _displayType.setTab(_hardwareConfigTab); _displaySpeed.setTab(_hardwareConfigTab); + _displayType.setTab(_hardwareConfigTab); + _gridFreq.setTab(_hardwareConfigTab); + _output1DimmerMapper.setTab(_hardwareConfigTab); + _output1DimmerType.setTab(_hardwareConfigTab); _output1PZEMSync.setTab(_hardwareConfigTab); - _output2PZEMSync.setTab(_hardwareConfigTab); _output1RelayType.setTab(_hardwareConfigTab); + _output1ResistanceInput.setTab(_hardwareConfigTab); + _output2DimmerMapper.setTab(_hardwareConfigTab); + _output2DimmerType.setTab(_hardwareConfigTab); + _output2PZEMSync.setTab(_hardwareConfigTab); _output2RelayType.setTab(_hardwareConfigTab); - _relay1Type.setTab(_hardwareConfigTab); - _relay2Type.setTab(_hardwareConfigTab); + _output2ResistanceInput.setTab(_hardwareConfigTab); _relay1Load.setTab(_hardwareConfigTab); + _relay1Type.setTab(_hardwareConfigTab); _relay2Load.setTab(_hardwareConfigTab); - _output1ResistanceInput.setTab(_hardwareConfigTab); - _output2ResistanceInput.setTab(_hardwareConfigTab); - _output1DimmerMapper.setTab(_hardwareConfigTab); - _output2DimmerMapper.setTab(_hardwareConfigTab); + _relay2Type.setTab(_hardwareConfigTab); _resistanceCalibration.setTab(_hardwareConfigTab); _gridFreq.onChange([](const char* value) { @@ -695,12 +700,14 @@ void YaSolR::Website::begin() { _numConfig(_displayRotation, KEY_DISPLAY_ROTATION); _numConfig(_relay1Load, KEY_RELAY1_LOAD); _numConfig(_relay2Load, KEY_RELAY2_LOAD); + _sliderConfig(_displaySpeed, KEY_DISPLAY_SPEED); _textConfig(_displayType, KEY_DISPLAY_TYPE); + _textConfig(_output1DimmerType, KEY_OUTPUT1_DIMMER_TYPE); _textConfig(_output1RelayType, KEY_OUTPUT1_RELAY_TYPE); + _textConfig(_output2DimmerType, KEY_OUTPUT2_DIMMER_TYPE); _textConfig(_output2RelayType, KEY_OUTPUT2_RELAY_TYPE); _textConfig(_relay1Type, KEY_RELAY1_TYPE); _textConfig(_relay2Type, KEY_RELAY2_TYPE); - _sliderConfig(_displaySpeed, KEY_DISPLAY_SPEED); _output1ResistanceInput.onChange([](const std::optional value) { if (value.has_value()) @@ -1110,38 +1117,42 @@ void YaSolR::Website::initCards() { break; } - _displayType.setValue(config.get(KEY_DISPLAY_TYPE)); - _displaySpeed.setValue(config.getInt(KEY_DISPLAY_SPEED)); _displayRotation.setValue(config.getInt(KEY_DISPLAY_ROTATION)); + _displaySpeed.setValue(config.getInt(KEY_DISPLAY_SPEED)); + _displayType.setValue(config.get(KEY_DISPLAY_TYPE)); + _output1DimmerType.setValue(config.get(KEY_OUTPUT1_DIMMER_TYPE)); _output1RelayType.setValue(config.get(KEY_OUTPUT1_RELAY_TYPE)); + _output1ResistanceInput.setStatus(_output1ResistanceInput.value() ? dash::Status::SUCCESS : dash::Status::DANGER); + _output1ResistanceInput.setValue(config.getFloat(KEY_OUTPUT1_RESISTANCE)); + _output2DimmerType.setValue(config.get(KEY_OUTPUT2_DIMMER_TYPE)); _output2RelayType.setValue(config.get(KEY_OUTPUT2_RELAY_TYPE)); - _relay1Type.setValue(config.get(KEY_RELAY1_TYPE)); - _relay2Type.setValue(config.get(KEY_RELAY2_TYPE)); + _output2ResistanceInput.setStatus(_output2ResistanceInput.value() ? dash::Status::SUCCESS : dash::Status::DANGER); + _output2ResistanceInput.setValue(config.getFloat(KEY_OUTPUT2_RESISTANCE)); _relay1Load.setValue(load1); + _relay1Type.setValue(config.get(KEY_RELAY1_TYPE)); _relay2Load.setValue(load2); - _output1ResistanceInput.setValue(config.getFloat(KEY_OUTPUT1_RESISTANCE)); - _output1ResistanceInput.setStatus(_output1ResistanceInput.value() ? dash::Status::SUCCESS : dash::Status::DANGER); - _output2ResistanceInput.setValue(config.getFloat(KEY_OUTPUT2_RESISTANCE)); - _output2ResistanceInput.setStatus(_output2ResistanceInput.value() ? dash::Status::SUCCESS : dash::Status::DANGER); + _relay2Type.setValue(config.get(KEY_RELAY2_TYPE)); _output1DimmerMapper.setValue({static_cast(config.getInt(KEY_OUTPUT1_DIMMER_MIN)), static_cast(config.getInt(KEY_OUTPUT1_DIMMER_MAX))}); _output2DimmerMapper.setValue({static_cast(config.getInt(KEY_OUTPUT2_DIMMER_MIN)), static_cast(config.getInt(KEY_OUTPUT2_DIMMER_MAX))}); - _displayType.setDisplay(config.getBool(KEY_ENABLE_DISPLAY)); - _displaySpeed.setDisplay(config.getBool(KEY_ENABLE_DISPLAY)); _displayRotation.setDisplay(config.getBool(KEY_ENABLE_DISPLAY)); - _relay1Load.setDisplay(relay1Enabled); - _relay2Load.setDisplay(relay2Enabled); - _output1ResistanceInput.setDisplay(dimmer1Enabled); - _output2ResistanceInput.setDisplay(dimmer2Enabled); + _displaySpeed.setDisplay(config.getBool(KEY_ENABLE_DISPLAY)); + _displayType.setDisplay(config.getBool(KEY_ENABLE_DISPLAY)); + _output1DimmerMapper.setDisplay(dimmer1Enabled); + _output1DimmerType.setDisplay(dimmer1Enabled); _output1PZEMSync.setDisplay(pzem1Enabled); - _output2PZEMSync.setDisplay(pzem2Enabled); _output1RelayType.setDisplay(config.getBool(KEY_ENABLE_OUTPUT1_RELAY)); + _output1ResistanceInput.setDisplay(dimmer1Enabled); + _output2DimmerMapper.setDisplay(dimmer2Enabled); + _output2DimmerType.setDisplay(dimmer2Enabled); + _output2PZEMSync.setDisplay(pzem2Enabled); _output2RelayType.setDisplay(config.getBool(KEY_ENABLE_OUTPUT2_RELAY)); + _output2ResistanceInput.setDisplay(dimmer2Enabled); + _relay1Load.setDisplay(relay1Enabled); _relay1Type.setDisplay(relay1Enabled); + _relay2Load.setDisplay(relay2Enabled); _relay2Type.setDisplay(relay2Enabled); - _output1DimmerMapper.setDisplay(dimmer1Enabled); - _output2DimmerMapper.setDisplay(dimmer2Enabled); _resistanceCalibration.setDisplay((dimmer1Enabled && jsyEnabled) || (dimmer1Enabled && pzem1Enabled) || (dimmer2Enabled && jsyEnabled) || diff --git a/src/yasolr_router.cpp b/src/yasolr_router.cpp index 61d3d1db..74cc5d1c 100644 --- a/src/yasolr_router.cpp +++ b/src/yasolr_router.cpp @@ -43,48 +43,78 @@ Mycila::Task routerTask("Router", [](void* params) { // functions +bool isTriacBased(const char* type) { + return strcmp(type, YASOLR_DIMMER_LSA_PWM) == 0 || strcmp(type, YASOLR_DIMMER_ROBODYN) == 0 || strcmp(type, YASOLR_DIMMER_SSR_RANDOM) == 0 || strcmp(type, YASOLR_DIMMER_TRIAC) == 0; +} + Mycila::Dimmer* createDimmer1(uint16_t semiPeriod) { if (config.getBool(KEY_ENABLE_OUTPUT1_DIMMER)) { - triacDimmer1 = new Mycila::TriacDimmer(); - triacDimmer1->setPin((gpio_num_t)config.getInt(KEY_PIN_OUTPUT1_DIMMER)); - triacDimmer1->setSemiPeriod(semiPeriod); - triacDimmer1->begin(); + const char* type = config.get(KEY_OUTPUT1_DIMMER_TYPE); + Mycila::Dimmer* dimmer = nullptr; + + if (isTriacBased(type)) { + logger.info(TAG, "Initializing Output 1 dimmer type: %s", type); - if (triacDimmer1->isEnabled()) { - triacDimmer1->setDutyCycleMin(config.getFloat(KEY_OUTPUT1_DIMMER_MIN) / 100); - triacDimmer1->setDutyCycleMax(config.getFloat(KEY_OUTPUT1_DIMMER_MAX) / 100); - triacDimmer1->setDutyCycleLimit(config.getFloat(KEY_OUTPUT1_DIMMER_LIMIT) / 100); + triacDimmer1 = new Mycila::TriacDimmer(); + triacDimmer1->setPin((gpio_num_t)config.getInt(KEY_PIN_OUTPUT1_DIMMER)); + triacDimmer1->setSemiPeriod(semiPeriod); + triacDimmer1->begin(); + + if (triacDimmer1->isEnabled()) { + triacDimmer1->setDutyCycleMin(config.getFloat(KEY_OUTPUT1_DIMMER_MIN) / 100); + triacDimmer1->setDutyCycleMax(config.getFloat(KEY_OUTPUT1_DIMMER_MAX) / 100); + triacDimmer1->setDutyCycleLimit(config.getFloat(KEY_OUTPUT1_DIMMER_LIMIT) / 100); + dimmer = triacDimmer1; + + } else { + logger.error(TAG, "Output 1 Dimmer failed to initialize!"); + delete triacDimmer1; + triacDimmer1 = nullptr; + } } else { - logger.error(TAG, "Output 1 Dimmer failed to initialize!"); - delete triacDimmer1; - triacDimmer1 = nullptr; + logger.error(TAG, "Output 1 Dimmer type not supported: %s", type); } + + return dimmer; } - return triacDimmer1; + return nullptr; } Mycila::Dimmer* createDimmer2(uint16_t semiPeriod) { if (config.getBool(KEY_ENABLE_OUTPUT2_DIMMER)) { - triacDimmer2 = new Mycila::TriacDimmer(); - triacDimmer2->setPin((gpio_num_t)config.getInt(KEY_PIN_OUTPUT2_DIMMER)); - triacDimmer2->setSemiPeriod(semiPeriod); - triacDimmer2->begin(); + const char* type = config.get(KEY_OUTPUT2_DIMMER_TYPE); + Mycila::Dimmer* dimmer = nullptr; + + if (isTriacBased(type)) { + logger.info(TAG, "Initializing Output 2 dimmer type: %s", type); + + triacDimmer2 = new Mycila::TriacDimmer(); + triacDimmer2->setPin((gpio_num_t)config.getInt(KEY_PIN_OUTPUT2_DIMMER)); + triacDimmer2->setSemiPeriod(semiPeriod); + triacDimmer2->begin(); + + if (triacDimmer2->isEnabled()) { + triacDimmer2->setDutyCycleMin(config.getFloat(KEY_OUTPUT2_DIMMER_MIN) / 100); + triacDimmer2->setDutyCycleMax(config.getFloat(KEY_OUTPUT2_DIMMER_MAX) / 100); + triacDimmer2->setDutyCycleLimit(config.getFloat(KEY_OUTPUT2_DIMMER_LIMIT) / 100); + dimmer = triacDimmer2; - if (triacDimmer2->isEnabled()) { - triacDimmer2->setDutyCycleMin(config.getFloat(KEY_OUTPUT2_DIMMER_MIN) / 100); - triacDimmer2->setDutyCycleMax(config.getFloat(KEY_OUTPUT2_DIMMER_MAX) / 100); - triacDimmer2->setDutyCycleLimit(config.getFloat(KEY_OUTPUT2_DIMMER_LIMIT) / 100); + } else { + logger.error(TAG, "Output 2 Dimmer failed to initialize!"); + delete triacDimmer2; + triacDimmer2 = nullptr; + } } else { - logger.error(TAG, "Output 2 Dimmer failed to initialize!"); - delete triacDimmer2; - triacDimmer2 = nullptr; + logger.error(TAG, "Output 2 Dimmer type not supported: %s", type); } + + return dimmer; } - return triacDimmer2; + return nullptr; } Mycila::Relay* createBypassRelay1() { @@ -267,29 +297,32 @@ void yasolr_init_router() { calibrationTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS); // ZCD Task that will keep the grid semi-period in sync with the dimmers - if (pulseAnalyzer && (triacDimmer1 || triacDimmer2)) { + if (pulseAnalyzer || triacDimmer1 || triacDimmer2) { logger.info(TAG, "Initialize ZCD sync..."); zcdTask = new Mycila::Task("ZCD", [](void* params) { // check if ZCD is online (connected to the grid) // this is required for dimmers to work if (pulseAnalyzer->isOnline()) { - if (!Thyristor::getSemiPeriod()) { + if (!Thyristor::getSemiPeriod() || (triacDimmer1 && !triacDimmer1->getSemiPeriod()) || (triacDimmer2 && !triacDimmer2->getSemiPeriod())) { const float frequency = yasolr_frequency(); const uint16_t semiPeriod = frequency ? 1000000 / 2 / frequency : 0; if (semiPeriod) { logger.info(TAG, "Detected grid frequency: %.2f Hz with semi-period: %" PRIu16 " us", frequency, semiPeriod); - Thyristor::setSemiPeriod(semiPeriod); - Thyristor::begin(); + if (!Thyristor::getSemiPeriod()) { + logger.info(TAG, "Starting Thyristor..."); + Thyristor::setSemiPeriod(semiPeriod); + Thyristor::begin(); + } - if (triacDimmer1) { + if (triacDimmer1 && !triacDimmer1->getSemiPeriod()) { triacDimmer1->setSemiPeriod(semiPeriod); triacDimmer1->off(); } - if (triacDimmer2) { + if (triacDimmer2 && !triacDimmer2->getSemiPeriod()) { triacDimmer2->setSemiPeriod(semiPeriod); triacDimmer2->off(); } @@ -299,26 +332,26 @@ void yasolr_init_router() { } } else { - if (Thyristor::getSemiPeriod()) { + if (Thyristor::getSemiPeriod() || (triacDimmer1 && triacDimmer1->getSemiPeriod()) || (triacDimmer2 && triacDimmer2->getSemiPeriod())) { logger.warn(TAG, "No electricity detected by ZCD module"); if (Thyristor::getSemiPeriod()) { - logger.info(TAG, "Stopping Thyristor"); + logger.info(TAG, "Stopping Thyristor..."); Thyristor::setSemiPeriod(0); Thyristor::end(); + } - if (triacDimmer1) { - logger.info(TAG, "Setting dimmer 1 semi-period to 0"); - triacDimmer1->setSemiPeriod(0); - } - - if (triacDimmer2) { - logger.info(TAG, "Setting dimmer 2 semi-period to 0"); - triacDimmer2->setSemiPeriod(0); - } + if (triacDimmer1 && triacDimmer1->getSemiPeriod()) { + logger.info(TAG, "Setting dimmer 1 semi-period to 0"); + triacDimmer1->setSemiPeriod(0); + } - dashboardInitTask.resume(); + if (triacDimmer2 && triacDimmer2->getSemiPeriod()) { + logger.info(TAG, "Setting dimmer 2 semi-period to 0"); + triacDimmer2->setSemiPeriod(0); } + + dashboardInitTask.resume(); } } });