Optimize iFan fan sequencing

Optimize iFan fan sequencing
This commit is contained in:
Theo Arends 2019-07-14 16:26:02 +02:00
parent 49022d0320
commit a68d11c676
1 changed files with 22 additions and 73 deletions

View File

@ -25,9 +25,9 @@
const uint8_t MAX_FAN_SPEED = 4; // Max number of iFan02 fan speeds (0 .. 3)
const uint8_t kIFan02Speed[MAX_FAN_SPEED][3] = {{6,6,6}, {7,6,6}, {7,7,6}, {7,6,7}}; // Do not use PROGMEM as it fails
const uint8_t kIFan03Speed[MAX_FAN_SPEED +2][3] = {{6,6,6}, {7,6,6}, {7,7,6}, {6,6,7}, {7,6,7}, {6,7,7}}; // Do not use PROGMEM as it fails
const uint8_t kIFan02Speed[MAX_FAN_SPEED] = { 0x00, 0x01, 0x03, 0x05 };
const uint8_t kIFan03Speed[MAX_FAN_SPEED +2] = { 0x00, 0x01, 0x03, 0x04, 0x05, 0x06 };
const uint8_t kIFan03Sequence[MAX_FAN_SPEED][MAX_FAN_SPEED] = {{0, 2, 2, 2}, {0, 1, 2, 4}, {1, 1, 2, 5}, {4, 4, 5, 3}};
uint8_t ifan_fanspeed_timer = 0;
uint8_t ifan_fanspeed_goal = 0;
@ -66,23 +66,6 @@ uint8_t GetFanspeed(void)
}
}
void SetFanspeed(uint8_t fanspeed)
{
if (SONOFF_IFAN02 == my_module_type) {
for (uint32_t i = 0; i < 3; i++) {
uint8_t state = kIFan02Speed[fanspeed][i];
ExecuteCommandPower(i +2, state, SRC_IGNORE); // Use relay 2, 3 and 4
}
#ifdef USE_DOMOTICZ
DomoticzUpdateFanState(); // Command FanSpeed feedback
#endif // USE_DOMOTICZ
}
else if (SONOFF_IFAN03 == my_module_type) {
SonoffIFanSetFanspeed(fanspeed, true);
}
}
/*********************************************************************************************/
void SonoffIFanSetFanspeed(uint8_t fanspeed, bool sequence)
@ -94,58 +77,24 @@ void SonoffIFanSetFanspeed(uint8_t fanspeed, bool sequence)
if (fanspeed == fanspeed_now) { return; }
// Change to lookup table
uint8_t fans = kIFan02Speed[fanspeed];
if (SONOFF_IFAN03 == my_module_type) {
if (sequence) {
fanspeed = kIFan03Sequence[fanspeed_now][ifan_fanspeed_goal];
if (fanspeed != ifan_fanspeed_goal) {
if (0 == fanspeed_now) {
switch (fanspeed) {
case 1:
case 3:
fanspeed = 2;
ifan_fanspeed_timer = 20;
break;
}
}
if (1 == fanspeed_now) {
switch (fanspeed) {
case 3:
fanspeed = 4;
ifan_fanspeed_timer = 20; // Need extra time to power up fan
} else {
ifan_fanspeed_timer = 2;
break;
}
}
if (2 == fanspeed_now) {
switch (fanspeed) {
case 0:
fanspeed = 1;
ifan_fanspeed_timer = 2;
break;
case 3:
fanspeed = 5;
ifan_fanspeed_timer = 2;
break;
}
fans = kIFan03Speed[fanspeed];
}
if (3 == fanspeed_now) {
switch (fanspeed) {
case 0:
case 1:
fanspeed = 4;
ifan_fanspeed_timer = 2;
break;
case 2:
fanspeed = 5;
ifan_fanspeed_timer = 2;
break;
}
}
// if (fanspeed == ifan_fanspeed_goal) {
// sequence = false;
// }
}
for (uint32_t i = 0; i < 3; i++) {
uint8_t state = kIFan03Speed[fanspeed][i];
ExecuteCommandPower(i +2, state, SRC_IGNORE); // Use relay 2, 3 and 4
for (uint32_t i = 2; i < 5; i++) {
uint8_t state = (fans &1) + 6; // Add no publishPowerState
ExecuteCommandPower(i, state, SRC_IGNORE); // Use relay 2, 3 and 4
fans >>= 1;
}
#ifdef USE_DOMOTICZ
@ -269,7 +218,7 @@ bool SonoffIfanCommand(void)
}
}
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < MAX_FAN_SPEED)) {
SetFanspeed(XdrvMailbox.payload);
SonoffIFanSetFanspeed(XdrvMailbox.payload, true);
}
Response_P(S_JSON_COMMAND_NVALUE, command, GetFanspeed());
} else serviced = false; // Unknown command