Skip to content

Commit

Permalink
Merge pull request #9330 from effelle/development
Browse files Browse the repository at this point in the history
TuyaMCU Update
  • Loading branch information
arendst authored Sep 17, 2020
2 parents 022315d + 0bca9a2 commit eaed13a
Show file tree
Hide file tree
Showing 5 changed files with 427 additions and 112 deletions.
2 changes: 1 addition & 1 deletion tasmota/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ struct {
uint8_t display_font; // 312

char ex_state_text[4][11]; // 313
uint8_t ex_energy_power_delta; // 33F - Free since 6.6.0.20
uint8_t tuyamcu_topic; // 33F Manage tuyaSend topic. ex_energy_power_delta on 6.6.0.20, replaced on 8.5.0.1

uint16_t domoticz_update_timer; // 340
uint16_t pwm_range; // 342
Expand Down
4 changes: 2 additions & 2 deletions tasmota/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,8 @@ void SettingsDelta(void)
Settings.ex_sbaudrate = 0;
*/
Settings.flag3.fast_power_cycle_disable = 0;
Settings.ex2_energy_power_delta = Settings.ex_energy_power_delta;
Settings.ex_energy_power_delta = 0;
Settings.ex2_energy_power_delta = Settings.tuyamcu_topic;
Settings.tuyamcu_topic = 0; // replaced ex_energy_power_delta on 8.5.0.1
}
if (Settings.version < 0x06060015) {
if ((EX_WIFI_SMARTCONFIG == Settings.ex_sta_config) || (EX_WIFI_WPSCONFIG == Settings.ex_sta_config)) {
Expand Down
9 changes: 6 additions & 3 deletions tasmota/tasmota.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,13 @@ const SerConfu8 kTasmotaSerialConfig[] PROGMEM = {

enum TuyaSupportedFunctions { TUYA_MCU_FUNC_NONE, TUYA_MCU_FUNC_SWT1 = 1, TUYA_MCU_FUNC_SWT2, TUYA_MCU_FUNC_SWT3, TUYA_MCU_FUNC_SWT4,
TUYA_MCU_FUNC_REL1 = 11, TUYA_MCU_FUNC_REL2, TUYA_MCU_FUNC_REL3, TUYA_MCU_FUNC_REL4, TUYA_MCU_FUNC_REL5,
TUYA_MCU_FUNC_REL6, TUYA_MCU_FUNC_REL7, TUYA_MCU_FUNC_REL8, TUYA_MCU_FUNC_DIMMER = 21, TUYA_MCU_FUNC_POWER = 31,
TUYA_MCU_FUNC_CURRENT, TUYA_MCU_FUNC_VOLTAGE, TUYA_MCU_FUNC_BATTERY_STATE, TUYA_MCU_FUNC_BATTERY_PERCENTAGE,
TUYA_MCU_FUNC_REL6, TUYA_MCU_FUNC_REL7, TUYA_MCU_FUNC_REL8, TUYA_MCU_FUNC_DIMMER = 21, TUYA_MCU_FUNC_DIMMER2,
TUYA_MCU_FUNC_CT, TUYA_MCU_FUNC_RGB, TUYA_MCU_FUNC_WHITE, TUYA_MCU_FUNC_MODESET, TUYA_MCU_FUNC_REPORT1, TUYA_MCU_FUNC_REPORT2,
TUYA_MCU_FUNC_POWER = 31, TUYA_MCU_FUNC_CURRENT, TUYA_MCU_FUNC_VOLTAGE, TUYA_MCU_FUNC_BATTERY_STATE, TUYA_MCU_FUNC_BATTERY_PERCENTAGE,
TUYA_MCU_FUNC_REL1_INV = 41, TUYA_MCU_FUNC_REL2_INV, TUYA_MCU_FUNC_REL3_INV, TUYA_MCU_FUNC_REL4_INV, TUYA_MCU_FUNC_REL5_INV,
TUYA_MCU_FUNC_REL6_INV, TUYA_MCU_FUNC_REL7_INV, TUYA_MCU_FUNC_REL8_INV, TUYA_MCU_FUNC_LOWPOWER_MODE = 51, TUYA_MCU_FUNC_LAST = 255
TUYA_MCU_FUNC_REL6_INV, TUYA_MCU_FUNC_REL7_INV, TUYA_MCU_FUNC_REL8_INV, TUYA_MCU_FUNC_LOWPOWER_MODE = 51,
TUYA_MCU_FUNC_FAN3 = 61, TUYA_MCU_FUNC_FAN4, TUYA_MCU_FUNC_FAN5, TUYA_MCU_FUNC_FAN6,
TUYA_MCU_FUNC_MOTOR_DIR = 97, TUYA_MCU_FUNC_ERROR = 98 , TUYA_MCU_FUNC_DUMMY = 99, TUYA_MCU_FUNC_LAST = 255
};

#endif // _TASMOTA_H_
69 changes: 69 additions & 0 deletions tasmota/xdrv_01_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,31 @@ void HandleRoot(void)
#endif // USE_SONOFF_IFAN
WSContentSend_P(PSTR("</tr></table>"));
}
#ifdef USE_TUYA_MCU
if (IsModuleTuya()) {
uint8_t modeset = 0;
if (AsModuleTuyaMS()) {
WSContentSend_P(HTTP_TABLE100);
WSContentSend_P(PSTR("<tr><div></div>"));
snprintf_P(stemp, sizeof(stemp), PSTR("" D_JSON_IRHVAC_MODE ""));
WSContentSend_P(HTTP_DEVICE_CONTROL, 26, devices_present + 1,
(strlen(SettingsText(SET_BUTTON1 + devices_present))) ? SettingsText(SET_BUTTON1 + devices_present) : stemp, "");
WSContentSend_P(PSTR("</tr></table>"));
modeset = 1;
}
if (IsTuyaFanCtrl()) {
uint8_t device = devices_present + modeset;
WSContentSend_P(HTTP_TABLE100);
WSContentSend_P(PSTR("<tr><div></div>"));
for (uint32_t i = device + 1; i <= (TuyaFanSpeeds() + device) + 1; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i - (device + 1));
WSContentSend_P(HTTP_DEVICE_CONTROL, 16, i,
(strlen(SettingsText(SET_BUTTON1 + i))) ? SettingsText(SET_BUTTON1 + i) : stemp, "");
}
WSContentSend_P(PSTR("</tr></table>"));
}
}
#endif // USE_TUYA_MCU
#ifdef USE_SONOFF_RF
if (SONOFF_BRIDGE == my_module_type) {
WSContentSend_P(HTTP_TABLE100);
Expand Down Expand Up @@ -1535,6 +1560,33 @@ bool HandleRootStatusRefresh(void)
}
} else {
#endif // USE_SONOFF_IFAN
#ifdef USE_TUYA_MCU
if (IsModuleTuya()) {
uint8_t FuncIdx = 0;
if (device <= devices_present) {
ExecuteCommandPower(device, POWER_TOGGLE, SRC_IGNORE);
} else {
if (AsModuleTuyaMS() && device == devices_present + 1) {
uint8_t dpId = TuyaGetDpId(TUYA_MCU_FUNC_MODESET);
snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend4 %d,%d"), dpId, !TuyaModeSet());
ExecuteCommand(svalue, SRC_WEBGUI);
}
if (IsTuyaFanCtrl()) {
uint8_t dpId = 0;
for (uint32_t i = 0; i <= 3; i++) { // Tuya Function FAN3 to FAN6
if (TuyaGetDpId(TUYA_MCU_FUNC_FAN3 + i) != 0) {
dpId = TuyaGetDpId(TUYA_MCU_FUNC_FAN3 + i);
}
}
if ((AsModuleTuyaMS() && device != devices_present + 1) || !AsModuleTuyaMS()) {
if (AsModuleTuyaMS()) {FuncIdx = 1;}
snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend2 %d,%d"), dpId, (device - (devices_present + FuncIdx) - 1));
ExecuteCommand(svalue, SRC_WEBGUI);
}
}
}
} else {
#endif // USE_TUYA_MCU
#ifdef USE_SHUTTER
int32_t ShutterWebButton;
if (ShutterWebButton = IsShutterWebButton(device)) {
Expand All @@ -1549,6 +1601,9 @@ bool HandleRootStatusRefresh(void)
#ifdef USE_SONOFF_IFAN
}
#endif // USE_SONOFF_IFAN
#ifdef USE_TUYA_MCU
}
#endif // USE_TUYA_MCU
}
#ifdef USE_LIGHT
WebGetArg("d0", tmp, sizeof(tmp)); // 0 - 100 Dimmer value
Expand Down Expand Up @@ -1629,8 +1684,22 @@ bool HandleRootStatusRefresh(void)
#ifdef USE_SONOFF_IFAN
}
#endif // USE_SONOFF_IFAN

WSContentSend_P(PSTR("</tr></table>"));
}
#ifdef USE_TUYA_MCU
if (IsModuleTuya()) {
uint32_t fanspeed = TuyaFanState();
uint32_t modeset = TuyaModeSet();
if (IsTuyaFanCtrl() && !AsModuleTuyaMS()) {
WSContentSend_P(PSTR("<div style='text-align:center;font-size:25px;'>" D_JSON_IRHVAC_FANSPEED ": %d</div>"), fanspeed);
} else if (!IsTuyaFanCtrl() && AsModuleTuyaMS()) {
WSContentSend_P(PSTR("<div style='text-align:center;font-size:25px;'>" D_JSON_IRHVAC_MODE ": %d</div>"), modeset);
} else if (IsTuyaFanCtrl() && AsModuleTuyaMS()) {
WSContentSend_P(PSTR("<div style='text-align:center;font-size:25px;'>" D_JSON_IRHVAC_MODE ": %d - " D_JSON_IRHVAC_FANSPEED ": %d</div>"), modeset, fanspeed);
}
}
#endif // USE_TUYA_MCU
WSContentEnd();

return true;
Expand Down
Loading

0 comments on commit eaed13a

Please sign in to comment.