mirror of https://github.com/arendst/Tasmota.git
Fix Shelly Pro led functionality
This commit is contained in:
parent
89d4e87195
commit
0d45590ac4
|
@ -1036,6 +1036,9 @@ void CmndMaxEnergyStart(void) {
|
||||||
|
|
||||||
void EnergyDrvInit(void) {
|
void EnergyDrvInit(void) {
|
||||||
memset(&Energy, 0, sizeof(Energy)); // Reset all to 0 and false;
|
memset(&Energy, 0, sizeof(Energy)); // Reset all to 0 and false;
|
||||||
|
// Energy.voltage_common = false;
|
||||||
|
// Energy.frequency_common = false;
|
||||||
|
// Energy.use_overtemp = false;
|
||||||
for (uint32_t phase = 0; phase < ENERGY_MAX_PHASES; phase++) {
|
for (uint32_t phase = 0; phase < ENERGY_MAX_PHASES; phase++) {
|
||||||
Energy.apparent_power[phase] = NAN;
|
Energy.apparent_power[phase] = NAN;
|
||||||
Energy.reactive_power[phase] = NAN;
|
Energy.reactive_power[phase] = NAN;
|
||||||
|
|
|
@ -23,18 +23,18 @@
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Shelly Pro support
|
* Shelly Pro support
|
||||||
*
|
*
|
||||||
* {"NAME":"Shelly Pro 1","GPIO":[0,0,0,0,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,0,0,0,32,0,0,160,0],"FLAG":0,"BASE":1}
|
* {"NAME":"Shelly Pro 1","GPIO":[0,1,0,1,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,0,0,0,32,4736,0,160,0],"FLAG":0,"BASE":1,"CMND":"AdcParam1 2,10000,10000,3350"}
|
||||||
* {"NAME":"Shelly Pro 2","GPIO":[0,0,0,0,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,0,0,0,32,0,0,160,161],"FLAG":0,"BASE":1}
|
* {"NAME":"Shelly Pro 1PM","GPIO":[9568,1,9472,1,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,3459,0,0,32,4736,0,160,0],"FLAG":0,"BASE":1,"CMND":"AdcParam1 2,10000,10000,3350"}
|
||||||
|
* {"NAME":"Shelly Pro 2","GPIO":[0,1,0,1,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,0,0,0,32,4736,4737,160,161],"FLAG":0,"BASE":1,"CMND":"AdcParam1 2,10000,10000,3350;AdcParam2 2,10000,10000,3350"}
|
||||||
|
* {"NAME":"Shelly Pro 2PM","GPIO":[9568,1,9472,1,768,0,0,0,672,704,736,9569,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,3460,0,0,32,4736,4737,160,161],"FLAG":0,"BASE":1,"CMND":"AdcParam1 2,10000,10000,3350;AdcParam2 2,10000,10000,3350"}
|
||||||
*
|
*
|
||||||
* Shelly Pro uses SPI to control one 74HC595 for relays/leds and one ADE7953 (1PM) or two ADE7953 (2PM) for energy monitoring
|
* Shelly Pro uses SPI to control one 74HC595 for relays/leds and one ADE7953 (1PM) or two ADE7953 (2PM) for energy monitoring
|
||||||
*
|
|
||||||
* Testset
|
|
||||||
* {"NAME":"Shelly Pro 2PM (POC)","GPIO":[1,0,1,0,768,1,0,0,672,704,736,1,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,1,1,1,32,1,1,160,161],"FLAG":0,"BASE":1}
|
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XDRV_88 88
|
#define XDRV_88 88
|
||||||
|
|
||||||
struct SPro {
|
struct SPro {
|
||||||
|
uint32_t last_update;
|
||||||
uint8_t pin_shift595_rclk;
|
uint8_t pin_shift595_rclk;
|
||||||
uint8_t ledlink;
|
uint8_t ledlink;
|
||||||
uint8_t power;
|
uint8_t power;
|
||||||
|
@ -53,9 +53,9 @@ void ShellyProUpdate(void) {
|
||||||
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
|
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
|
||||||
SPI.transfer(val); // Write 74HC595 shift register
|
SPI.transfer(val); // Write 74HC595 shift register
|
||||||
SPI.endTransaction();
|
SPI.endTransaction();
|
||||||
|
delayMicroseconds(2); // Wait for SPI clock to stop
|
||||||
digitalWrite(SPro.pin_shift595_rclk, 1);
|
digitalWrite(SPro.pin_shift595_rclk, 1); // Latch data
|
||||||
delayMicroseconds(200); // Shelly 10mS
|
delayMicroseconds(2); // Shelly 10mS
|
||||||
digitalWrite(SPro.pin_shift595_rclk, 0);
|
digitalWrite(SPro.pin_shift595_rclk, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,13 +71,13 @@ void ShellyProPreInit(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SPro.pin_shift595_rclk = Pin(GPIO_SPI_CS);
|
SPro.pin_shift595_rclk = Pin(GPIO_SPI_CS);
|
||||||
pinMode(SPro.pin_shift595_rclk, OUTPUT);
|
|
||||||
digitalWrite(SPro.pin_shift595_rclk, 0);
|
digitalWrite(SPro.pin_shift595_rclk, 0);
|
||||||
|
pinMode(SPro.pin_shift595_rclk, OUTPUT);
|
||||||
// Does nothing if SPI is already initiated (by ADE7953) so no harm done
|
// Does nothing if SPI is already initiated (by ADE7953) so no harm done
|
||||||
SPI.begin(Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_MOSI), -1);
|
SPI.begin(Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_MOSI), -1);
|
||||||
|
|
||||||
SPro.power = TasmotaGlobal.power &3; // Restore power
|
SPro.power = TasmotaGlobal.power &3; // Restore power
|
||||||
SPro.ledlink = 0x1C; // All leds off
|
SPro.ledlink = 0x18; // Blue led on
|
||||||
ShellyProUpdate();
|
ShellyProUpdate();
|
||||||
|
|
||||||
SPro.detected = true;
|
SPro.detected = true;
|
||||||
|
@ -90,11 +90,41 @@ void ShellyProPower(void) {
|
||||||
ShellyProUpdate();
|
ShellyProUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShellyProLedLink(void) {
|
void ShellyProUpdateLedLink(uint32_t ledlink) {
|
||||||
// bit 2 = blue, 3 = green, 4 = red
|
if (ledlink != SPro.ledlink) {
|
||||||
SPro.ledlink = (XdrvMailbox.index) ? 0x18 : 0x1C; // Blue on (wifi link) or all off
|
SPro.ledlink = ledlink;
|
||||||
ShellyProUpdate();
|
ShellyProUpdate();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShellyProLedLink(void) {
|
||||||
|
/*
|
||||||
|
bit 2 = blue, 3 = green, 4 = red
|
||||||
|
Shelly Pro documentation
|
||||||
|
- Blue light indicator will be on if in AP mode.
|
||||||
|
- Red light indicator will be on if in STA mode and not connected to a Wi-Fi network.
|
||||||
|
- Yellow light indicator will be on if in STA mode and connected to a Wi-Fi network.
|
||||||
|
- Green light indicator will be on if in STA mode and connected to a Wi-Fi network and to the Shelly Cloud.
|
||||||
|
- The light indicator will be flashing Red/Blue if OTA update is in progress.
|
||||||
|
Tasmota default behaviour
|
||||||
|
- Blue light indicator will blink if no wifi or mqtt.
|
||||||
|
*/
|
||||||
|
SPro.last_update = TasmotaGlobal.uptime;
|
||||||
|
uint32_t ledlink = 0x1C;
|
||||||
|
if (XdrvMailbox.index) { ledlink &= 0xFB; } // Blue blinks if wifi/mqtt lost
|
||||||
|
if (!TasmotaGlobal.global_state.wifi_down) { ledlink &= 0xF7; } // Green On
|
||||||
|
ShellyProUpdateLedLink(ledlink);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShellyProLedLinkWifiOff(void) {
|
||||||
|
/*
|
||||||
|
bit 2 = blue, 3 = green, 4 = red
|
||||||
|
- Green light indicator will be on if in STA mode and connected to a Wi-Fi network.
|
||||||
|
*/
|
||||||
|
if (SPro.last_update +1 < TasmotaGlobal.uptime) {
|
||||||
|
ShellyProUpdateLedLink((TasmotaGlobal.global_state.wifi_down) ? 0x1C : 0x14); // Green off if wifi OFF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Interface
|
* Interface
|
||||||
|
@ -107,6 +137,9 @@ bool Xdrv88(uint8_t function) {
|
||||||
ShellyProPreInit();
|
ShellyProPreInit();
|
||||||
} else if (SPro.detected) {
|
} else if (SPro.detected) {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
|
case FUNC_EVERY_SECOND:
|
||||||
|
ShellyProLedLinkWifiOff();
|
||||||
|
break;
|
||||||
case FUNC_SET_POWER:
|
case FUNC_SET_POWER:
|
||||||
ShellyProPower();
|
ShellyProPower();
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue