Add support for Shelly Pro 1/2

Add support for Shelly Pro 1/2 (#16773)
This commit is contained in:
Theo Arends 2022-10-24 11:32:10 +02:00
parent bfb40f16dc
commit b4269d262c
6 changed files with 138 additions and 5 deletions

View File

@ -6,7 +6,8 @@ All notable changes to this project will be documented in this file.
## [12.2.0.1]
### Added
- DS18x20 support on up to four GPIOs by md5sum-as (#16833)
- Berry add `bytes().setbytes()`
- Berry add `bytes().setbytes()` (#16892)
- Support for Shelly Pro 1/2 (#16773)
### Breaking Changed
@ -14,6 +15,7 @@ All notable changes to this project will be documented in this file.
- DS18x20 ``DS18Alias`` to ``DS18Sens`` (#16833)
- Compiling with reduced boards manifests in favour of Autoconfig (#16848)
- Add NeoPool ``NPFiltration 2`` toggle cmnd (#16859)
- ESP32 NimBLE library from v1.4.0 to v1.4.1 (#16775)
### Fixed
- BP5758D red channel corruption regression from v12.1.1.6 (#16850)

View File

@ -110,10 +110,13 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
## Changelog v12.2.0.1
### Added
- DS18x20 support on up to four GPIOs by md5sum-as [#16833](https://github.com/arendst/Tasmota/issues/16833)
- Berry add `bytes().setbytes()` [#16892](https://github.com/arendst/Tasmota/issues/16892)
- Support for Shelly Pro 1/2 [#16773](https://github.com/arendst/Tasmota/issues/16773)
### Breaking Changed
### Changed
- ESP32 NimBLE library from v1.4.0 to v1.4.1 [#16775](https://github.com/arendst/Tasmota/issues/16775)
- DS18x20 ``DS18Alias`` to ``DS18Sens`` [#16833](https://github.com/arendst/Tasmota/issues/16833)
- Compiling with reduced boards manifests in favour of Autoconfig [#16848](https://github.com/arendst/Tasmota/issues/16848)

View File

@ -642,6 +642,7 @@
//#define USE_RC522 // Add support for MFRC522 13.56Mhz Rfid reader (+6k code)
//#define USE_MCP2515 // Add support for can bus using MCP2515 (+7k code)
//#define USE_CANSNIFFER // Add support for can bus sniffer using MCP2515 (+5k code)
#define USE_SHELLY_PRO // Add support for Shelly Pro
#define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code)
#define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code)

View File

@ -208,7 +208,7 @@ enum ProgramSelectablePins {
GPIO_USER, // User configurable needs to be 2047
GPIO_MAX };
#define MAX_OPTIONS_A 6 // Increase if more bits are used from GpioOptionABits
#define MAX_OPTIONS_A 7 // Increase if more bits are used from GpioOptionABits
typedef union { // Restricted by MISRA-C Rule 18.4 but so useful...
uint32_t data; // Allow bit manipulation using SetOption
@ -219,7 +219,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t enable_ccloader : 1; // bit 3 (v9.4.0.5) - Option_A4 - (Zigbee) Enable CCLoader using Zigbee Rx/Tx/Rst Gpios
uint32_t rotary_mi_desk : 1; // bit 4 (v9.5.0.5) - Option_A5 - (Rotary) Enable Mi Desk emulation
uint32_t linkind_support : 1; // bit 5 (v10.1.0.4) - Option_A6 - (Light) LinkInd support
uint32_t spare06 : 1; // bit 6
uint32_t shelly_pro : 1; // bit 6 (v12.2.0.1) - Option_A7 - (Device) Shelly Pro
uint32_t spare07 : 1; // bit 7
uint32_t spare08 : 1; // bit 8
uint32_t spare09 : 1; // bit 9

View File

@ -517,8 +517,10 @@ void SetLedPowerAll(uint32_t state)
}
}
void SetLedLink(uint32_t state)
{
void SetLedLink(uint32_t state) {
#ifdef USE_SHELLY_PRO
if (ShellyProLedLink(state)) { return; }
#endif // USE_SHELLY_PRO
int led_pin = Pin(GPIO_LEDLNK);
uint32_t led_inv = TasmotaGlobal.ledlnk_inverted;
if (-1 == led_pin) { // Legacy - LED1 is status

View File

@ -0,0 +1,125 @@
/*
xdrv_88_shelly_pro.ino - Shelly pro family support for Tasmota
Copyright (C) 2022 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef ESP32
#ifdef USE_SPI
#ifdef USE_SHELLY_PRO
/*********************************************************************************************\
* 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 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}
*
* Shelly Pro uses SPI to control one 74HC595 for relays/leds and one ADE7953 (1PM) or two ADE7953 (2PM) for energy monitoring
\*********************************************************************************************/
#define XDRV_88 88
struct SPro {
uint8_t pin_shift595_rclk;
uint8_t ledlink;
uint8_t power;
bool detected;
} SPro;
void ShellyProUpdate(void) {
// Shelly Pro 595 register
// bit 0 = relay/led 1
// bit 1 = relay/led 2
// bit 2 = wifi led blue
// bit 3 = wifi led green
// bit 4 = wifi led red
// bit 5 - 7 = nc
uint32_t val = SPro.power | SPro.ledlink;
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
SPI.transfer(val); // Write 74HC595 shift register
SPI.endTransaction();
digitalWrite(SPro.pin_shift595_rclk, 1);
delayMicroseconds(200); // Shelly 10mS
digitalWrite(SPro.pin_shift595_rclk, 0);
}
void ShellyProPreInit(void) {
if ((SPI_MOSI_MISO == TasmotaGlobal.spi_enabled) &&
PinUsed(GPIO_SPI_CS) &&
TasmotaGlobal.gpio_optiona.shelly_pro) { // Option_A7
if (PinUsed(GPIO_SWT1)) {
TasmotaGlobal.devices_present++; // Shelly Pro 1
if (PinUsed(GPIO_SWT1, 1)) {
TasmotaGlobal.devices_present++; // Shelly Pro 2
}
SPro.pin_shift595_rclk = Pin(GPIO_SPI_CS);
pinMode(SPro.pin_shift595_rclk, OUTPUT);
digitalWrite(SPro.pin_shift595_rclk, 0);
// 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);
SPro.power = TasmotaGlobal.power &3; // Restore power
SPro.ledlink = 0x1C; // All leds off
ShellyProUpdate();
SPro.detected = true;
}
}
}
void ShellyProPower(void) {
SPro.power = XdrvMailbox.index &3;
ShellyProUpdate();
}
/*********************************************************************************************\
* External called functions
\*********************************************************************************************/
bool ShellyProLedLink(uint32_t state) {
if (SPro.detected) {
// bit 2 = blue, 3 = green, 4 = red
SPro.ledlink = (state) ? 0x18 : 0x1C; // Blue on (wifi link) or all off
ShellyProUpdate();
return true;
}
return false;
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xdrv88(uint8_t function) {
bool result = false;
if (FUNC_PRE_INIT == function) {
ShellyProPreInit();
} else if (SPro.detected) {
switch (function) {
case FUNC_SET_POWER:
ShellyProPower();
break;
}
}
return result;
}
#endif // USE_SHELLY_PRO
#endif // USE_SPI
#endif // ESP32