Merge pull request #13360 from curzon01/dev-neopool

Refactor neopool filtration speed setting
This commit is contained in:
Theo Arends 2021-10-14 14:59:51 +02:00 committed by GitHub
commit 7d49b66ef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 22 deletions

View File

@ -82,8 +82,12 @@ enum NeoPoolRegister {
// addr Unit Description
// ------ ------ ------------------------------------------------------------
// MODBUS page (0x0000 - 0x002E - unknown - for internal use only)
MBF_VOLT_24_36 = 0x0022, // 0x0022 Current 24-36V line in mV
MBF_VOLT_12 = 0x0023, // 0x0023 Current 12V line in mV
MBF_POWER_MODULE_VERSION = 0x0002, // 0x0002 undocumented - power module version
MBF_POWER_MODULE_NODEID = 0x0004, // 0x0004 undocumented - power module Node ID (6 register 0x0004 - 0x0009)
MBF_POWER_MODULE_REGISTER = 0x000C, // 0x000C undocumented - Writing an address in this register causes the power module register address to be read out into MBF_POWER_MODULE_DATA, see MBF_POWER_MODULE_REG_*
MBF_POWER_MODULE_DATA = 0x000D, // 0x000D undocumented - power module data as requested in MBF_POWER_MODULE_REGISTER
MBF_VOLT_24_36 = 0x0022, // 0x0022 undocumented - Current 24-36V line in mV
MBF_VOLT_12 = 0x0023, // 0x0023 undocumented - Current 12V line in mV
// MEASURE page (0x01xx)
MBF_ION_CURRENT = 0x0100, // 0x0100* Current measured in the ionization system
@ -108,6 +112,8 @@ enum NeoPoolRegister {
MBF_CELL_RUNTIME_LOW = 0x0206, // 0x0206* undocumented - cell runtime (32 bit) - low word
MBF_CELL_RUNTIME_HIGH = 0x0207, // 0x0207* undocumented - cell runtime (32 bit) - high word
MBF_BOOST_CTRL = 0x020C, // 0x020C undocumented - 0x0000 = Boost Off, 0x05A0 = Boost with redox ctrl, 0x85A0 = Boost without redox ctrl
MBF_HIDRO_MODULE_VERSION = 0x0280, // 0x0280 undocumented - Hydrolysis module version
MBF_HIDRO_MODULE_CONNECTIVITY = 0x0281, // 0x0281 undocumented - Hydrolysis module connection quality (in myriad: 0..10000)
MBF_SET_MANUAL_CTRL = 0x0289, // 0x0289 undocumented - write a 1 before manual control MBF_RELAY_STATE, after done write 0 and do MBF_EXEC
MBF_ESCAPE = 0x0297, // 0x0297 undocumented - A write operation to this register is the same as using the ESC button on main screen - clears error
MBF_SAVE_TO_EEPROM = 0x02F0, // 0x02F0 A write operation to this register starts a EEPROM storage operation immediately. During the EEPROM storage procedure, the system may be unresponsive to MODBUS requests. The operation will last always less than 1 second.
@ -211,7 +217,7 @@ enum NeoPoolRegister {
MBF_PAR_PH2, // 0x0505 Lower limit of the pH regulation system. The value set in this register is multiplied by 100. This means that if we want to set a value of 7.0, the numerical content that we must write in this register is 700. This register must be always lower than MBF_PAR_PH1.
MBF_PAR_RX1 = 0x0508, // 0x0508 Set point for the redox regulation system. This value must be in the range of 0 to 1000.
MBF_PAR_CL1 = 0x050A, // 0x050A Set point for the chlorine regulation system. The value stored in this register is multiplied by 100. This mean that if we want to set a value of 1.5 ppm, we will have to write a numerical value of 150. This value stored in this register must be in the range of 0 to 1000.
MBF_PAR_FILTRATION_TYPE = 0x050F, // 0x050F undocumented - filtration type, see MBV_PAR_FILTRATION_TYPE_* 0 = Standard, 1 = Variable Hayward, 2 = Variable speed B
MBF_PAR_FILTRATION_CONF = 0x050F, // 0x050F mask undocumented - filtration type and speed, see MBMSK_PAR_FILTRATION_CONF_*
MBF_PAR_FILTRATION_SPEED_FUNC = 0x0513, // 0x0513 undocumented - filtration speed function control
MBF_PAR_FUNCTION_DEPENDENCY = 0x051B, // 0x051B mask Specification for the dependency of different functions, such as heating, from external events like FL1 (see MBMSK_FCTDEP_HEATING/MBMSK_DEPENDENCY_*)
@ -418,14 +424,23 @@ enum NeoPoolConstAndBitMask {
MBV_PAR_RELAY_MODE_SHOW_ONLY = 1, // The system only shows the alarm on screen, but the dosing continues.
MBV_PAR_RELAY_MODE_SHOW_AND_STOP = 2, // The system shows the alarm on screen and stops the dosing pump
// MBF_PAR_FILTRATION_TYPE
MBV_PAR_FILTRATION_TYPE_STANDARD = 0x00, // Standard (without speed control)
MBV_PAR_FILTRATION_TYPE_HAYWARD_SLOW = 0x01, // Variable Hayward Slow
MBV_PAR_FILTRATION_TYPE_HAYWARD_MEDIUM = 0x11, // Variable Hayward Medium
MBV_PAR_FILTRATION_TYPE_HAYWARD_FAST = 0x21, // Variable Hayward Fast
MBV_PAR_FILTRATION_TYPE_SPEED_B_SLOW = 0x02, // Variable speed B Slow
MBV_PAR_FILTRATION_TYPE_SPEED_B_MEDIUM = 0x12, // Variable speed B Medium
MBV_PAR_FILTRATION_TYPE_SPEED_B_FAST = 0x22, // Variable speed B Fast
// MBF_PAR_FILTRATION_CONF
MBMSK_PAR_FILTRATION_CONF_TYPE = 0x000F, // Filtration pump type, see MBV_PAR_FILTRATION_TYPE_*
MBMSK_PAR_FILTRATION_CONF_DEF_SPEED = 0x0070, // Filtration default speed, see MBV_PAR_FILTRATION_SPEED_*
MBMSK_PAR_FILTRATION_CONF_INT1_SPEED = 0x0380, // Filtration speed for timer interval 1, see MBV_PAR_FILTRATION_SPEED_*
MBMSK_PAR_FILTRATION_CONF_INT2_SPEED = 0x1C00, // Filtration speed for timer interval 2, see MBV_PAR_FILTRATION_SPEED_*
MBMSK_PAR_FILTRATION_CONF_INT3_SPEED = 0xE000, // Filtration speed for timer interval 3, see MBV_PAR_FILTRATION_SPEED_*
MBSHFT_PAR_FILTRATION_CONF_TYPE = 0, // Filtration pump type bit shift
MBSHFT_PAR_FILTRATION_CONF_DEF_SPEED = 4, // Filtration default speed bit shift
MBSHFT_PAR_FILTRATION_CONF_INT1_SPEED = 7, // Filtration speed for timer interval 1 bit shift
MBSHFT_PAR_FILTRATION_CONF_INT2_SPEED = 10, // Filtration speed for timer interval 2 bit shift
MBSHFT_PAR_FILTRATION_CONF_INT3_SPEED = 13, // Filtration speed for timer interval 3 bit shift
MBV_PAR_FILTRATION_TYPE_STANDARD = 0, // Standard (without speed control)
MBV_PAR_FILTRATION_TYPE_HAYWARD = 1, // Variable speed B
MBV_PAR_FILTRATION_TYPE_SPEED_B = 2, // Variable speed B
MBV_PAR_FILTRATION_SPEED_SLOW = 0, // Speed Slow
MBV_PAR_FILTRATION_SPEED_MEDIUM = 1, // Speed Medium
MBV_PAR_FILTRATION_SPEED_FAST = 2, // Speed Fast
// MBF_PAR_FUNCTION_DEPENDENCY
MBMSK_FCTDEP_HEATING = 0x0007, // Heating function dependency:
@ -529,6 +544,9 @@ enum NeoPoolConstAndBitMask {
MBMSK_VS_FORCE_UNITS_GRH = 0x2000, // Display the hydrolysis/electrolysis in units of grams per hour (gr/h).
MBMSK_VS_FORCE_UNITS_PERCENTAGE = 0x4000, // Display the hydrolysis/electrolysis in percentage units (%).
MBMSK_ELECTROLISIS = 0x8000, // Display the word electrolysis instead of hydrolysis in generic mode.
// MBF_POWER_MODULE_REG_*
MBV_POWER_MODULE_REG_INFO = 0, // undocumented - set of 26-byte power module register stores an ASCIIZ string containing the subversion and timestamp of the module, e. g. ".57\nMay 26 2020\n01:08:10\n\0"
};
#include <TasmotaModbus.h>
@ -588,15 +606,10 @@ struct {
{NEOPOOL_REG_TYPE_BLOCK, {MBF_CELL_RUNTIME_LOW, MBF_CELL_RUNTIME_HIGH - MBF_CELL_RUNTIME_LOW + 1, nullptr}},
{NEOPOOL_REG_TYPE_BLOCK, {MBF_PAR_VERSION, MBF_PAR_MODEL - MBF_PAR_VERSION + 1, nullptr}},
{NEOPOOL_REG_TYPE_BLOCK, {MBF_PAR_TIME_LOW, MBF_PAR_FILT_GPIO - MBF_PAR_TIME_LOW + 1, nullptr}},
{NEOPOOL_REG_TYPE_BLOCK, {MBF_PAR_ION, MBF_PAR_FILTRATION_TYPE - MBF_PAR_ION + 1, nullptr}},
{NEOPOOL_REG_TYPE_BLOCK, {MBF_PAR_ION, MBF_PAR_FILTRATION_CONF - MBF_PAR_ION + 1, nullptr}},
{NEOPOOL_REG_TYPE_BLOCK, {MBF_PAR_UICFG_MACHINE, MBF_PAR_UICFG_MACH_VISUAL_STYLE - MBF_PAR_UICFG_MACHINE + 1, nullptr}}
};
uint16_t filtration_types[2][3] = {
{MBV_PAR_FILTRATION_TYPE_HAYWARD_SLOW, MBV_PAR_FILTRATION_TYPE_HAYWARD_MEDIUM, MBV_PAR_FILTRATION_TYPE_HAYWARD_FAST},
{MBV_PAR_FILTRATION_TYPE_SPEED_B_SLOW, MBV_PAR_FILTRATION_TYPE_SPEED_B_MEDIUM, MBV_PAR_FILTRATION_TYPE_SPEED_B_FAST}
};
// NeoPool modbus function errors
enum NeoPoolModbusCode {
NEOPOOL_MODBUS_OK = 0,
@ -1823,24 +1836,25 @@ void CmndNeopoolFiltration(void)
{
uint16_t addr = MBF_PAR_FILT_MANUAL_STATE;
uint16_t data;
uint16_t filtration_type;
uint16_t filtration_conf;
uint32_t value[2] = { 0 };
uint32_t params_cnt = ParseParameters(nitems(value), value);
if (XdrvMailbox.data_len) {
if (NEOPOOL_MODBUS_OK != NeoPoolReadRegister(MBF_PAR_FILTRATION_TYPE, &filtration_type, 1)) {
if (NEOPOOL_MODBUS_OK != NeoPoolReadRegister(MBF_PAR_FILTRATION_CONF, &filtration_conf, 1)) {
NeopoolResponseError();
return;
}
if (params_cnt > 2 || (MBV_PAR_FILTRATION_TYPE_STANDARD == filtration_type && params_cnt > 1)) {
// no speed control for standard types
if (params_cnt > 2 || (params_cnt > 1 && (MBV_PAR_FILTRATION_TYPE_STANDARD == (filtration_conf & MBMSK_PAR_FILTRATION_CONF_TYPE)))) {
// no speed control for standard filtration types
NeopoolCmndError();
return;
}
if (params_cnt > 1) {
if (value[1] >= 1 && value[1] <= 3) {
// Set filtration speed first
NeoPoolWriteRegisterWord(MBF_PAR_FILTRATION_TYPE, (filtration_type & 0xFF00) | filtration_types[(filtration_type & 0x0F) - 1][value[1] - 1]);
NeoPoolWriteRegisterWord(MBF_PAR_FILTRATION_CONF,
(filtration_conf & MBMSK_PAR_FILTRATION_CONF_DEF_SPEED) | ((value[1] - 1) << MBSHFT_PAR_FILTRATION_CONF_DEF_SPEED));
NeoPoolWriteRegisterWord(MBF_EXEC, 1);
} else {
NeopoolCmndError();