Skip to content

Commit

Permalink
v5.8.0d - Add Color/Dimmer control to PWM
Browse files Browse the repository at this point in the history
5.8.0d
 * Remove previous GPIO configuration when another module is
selected
 * Fix inverted relay power on state (arendst#909)
 * Change default
PWM assignments for H801 RGB(CW) led controller to support optional
Color/Dimmer control
 *   GPIO04 (W2)    from GPIO_PWM2 to GPIO_USER to
be user configurable for GPIO_PWM5 (second White - Warm if W1 is Cold)

*   GPIO12 (Blue)  GPIO_PWM3 no change
 *   GPIO13 (Green) from
GPIO_PWM4 to GPIO_PWM2
 *   GPIO14 (W1)    from GPIO_PWM1 to GPIO_USER
to be user configurable for GPIO_PWM4 (first White - Cold or Warm)
 *
GPIO15 (Red)   from GPIO_PWM5 to GPIO_PWM1
 * Change default PWM
assignments for MagicHome RGB(W) led controller to support optional
Color/Dimmer control
 *   GPIO05 (Green) from GPIO_PWM4 to GPIO_PWM2
 *
GPIO12 (Blue)  from GPIO_PWM5 to GPIO_PWM3
 *   GPIO13 (White) GPIO_USER
to be user configurable for GPIO_PWM4 (White - Cold or Warm)
 *   GPIO14
(Red)   from GPIO_PWM3 to GPIO_PWM1
 * Add command SetOption15 0
(default) for command PWM control or SetOption15 1 for commands
Color/Dimmer control to PWM RGB(CW) leds (arendst#941)
  • Loading branch information
arendst committed Oct 1, 2017
1 parent 9a2adc5 commit e8e8aa0
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Sonoff-Tasmota
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.

Current version is **5.8.0c** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
Current version is **5.8.0d** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.

### ATTENTION All versions

Expand Down
18 changes: 17 additions & 1 deletion sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
/* 5.8.0c
/* 5.8.0d
* Remove previous GPIO configuration when another module is selected
* Fix inverted relay power on state (#909)
* Change default PWM assignments for H801 RGB(CW) led controller to support optional Color/Dimmer control
* GPIO04 (W2) from GPIO_PWM2 to GPIO_USER to be user configurable for GPIO_PWM5 (second White - Warm if W1 is Cold)
* GPIO12 (Blue) GPIO_PWM3 no change
* GPIO13 (Green) from GPIO_PWM4 to GPIO_PWM2
* GPIO14 (W1) from GPIO_PWM1 to GPIO_USER to be user configurable for GPIO_PWM4 (first White - Cold or Warm)
* GPIO15 (Red) from GPIO_PWM5 to GPIO_PWM1
* Change default PWM assignments for MagicHome RGB(W) led controller to support optional Color/Dimmer control
* GPIO05 (Green) from GPIO_PWM4 to GPIO_PWM2
* GPIO12 (Blue) from GPIO_PWM5 to GPIO_PWM3
* GPIO13 (White) GPIO_USER to be user configurable for GPIO_PWM4 (White - Cold or Warm)
* GPIO14 (Red) from GPIO_PWM3 to GPIO_PWM1
* Add command SetOption15 0 (default) for command PWM control or SetOption15 1 for commands Color/Dimmer control to PWM RGB(CW) leds (#941)
*
* 5.8.0c
* Add warning to webpage when USE_MINIMAL is selected (#929)
* Fix compile error when DOMOTICZ_UPDATE_TIMER is not defined (#930)
* Fix alignment of web page items in some browsers (#935)
Expand Down
2 changes: 1 addition & 1 deletion sonoff/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t stop_flash_rotate : 1; // bit 12 (v5.2.0)
uint32_t button_single : 1; // bit 13 (v5.4.0)
uint32_t interlock : 1; // bit 14 (v5.6.0)
uint32_t spare15 : 1;
uint32_t pwm_control : 1; // bit 15 (v5.8.1)
uint32_t spare16 : 1;
uint32_t spare17 : 1;
uint32_t spare18 : 1;
Expand Down
41 changes: 28 additions & 13 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
- Select IDE Tools - Flash Size: "1M (no SPIFFS)"
====================================================*/

#define VERSION 0x05080003 // 5.8.0c
#define VERSION 0x05080004 // 5.8.0d

enum week_t {Last, First, Second, Third, Fourth};
enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
Expand Down Expand Up @@ -290,7 +290,7 @@ uint8_t hlw_flg = 0; // Power monitor configured
uint8_t i2c_flg = 0; // I2C configured
uint8_t spi_flg = 0; // SPI configured
uint8_t pwm_flg = 0; // PWM configured
uint8_t sfl_flg = 0; // Sonoff Led flag (0 = No led, 1 = BN-SZ01, 2 = Sonoff Led, 5 = Sonoff B1)
uint8_t sfl_flg = 0; // Sonoff Led flag (0 = No led, 1 = BN-SZ01, 2 = Sonoff Led, 3 = H801/MagicHome, 4 = H801/MagicHome, 5 = H801, 11 = WS2812, 12 = AiLight, 13 = Sonoff B1)
uint8_t pwm_idxoffset = 0; // Allowed PWM command offset (change for Sonoff Led)

boolean mDNSbegun = false;
Expand Down Expand Up @@ -1079,7 +1079,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAVEDATA "\":\"%s\"}"), (sysCfg.savedata > 1) ? stemp1 : getStateText(sysCfg.savedata));
}
else if (!strcasecmp_P(type, PSTR(D_CMND_SETOPTION)) && ((index >= 0) && (index <= 14)) || ((index > 31) && (index <= P_MAX_PARAM8 +31))) {
else if (!strcasecmp_P(type, PSTR(D_CMND_SETOPTION)) && ((index >= 0) && (index <= 15)) || ((index > 31) && (index <= P_MAX_PARAM8 +31))) {
if (index <= 31) {
ptype = 0; // SetOption0 .. 31
} else {
Expand All @@ -1091,6 +1091,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
if (payload <= 1) {
switch (index) {
case 3: // mqtt
case 15: // pwm_control
restartflag = 2;
case 0: // savestate
case 1: // button_restrict
Expand Down Expand Up @@ -2324,7 +2325,7 @@ void stateloop()
button_handler();
switch_handler();

if (sfl_flg) { // Sonoff B1, AiLight, Sonoff led or BN-SZ01
if (sfl_flg) {
sl_animate();
}

Expand Down Expand Up @@ -2619,6 +2620,15 @@ void GPIO_init()
analogWriteRange(PWM_RANGE); // Default is 1023 (Arduino.h)
analogWriteFreq(PWM_FREQ); // Default is 1000 (core_esp8266_wiring_pwm.c)

if (sysCfg.flag.pwm_control) {
sfl_flg = 0;
for (byte i = 0; i < 5; i++) {
if (pin[GPIO_PWM1 +i] < 99) {
sfl_flg++;
}
}
}

Maxdevice = 1;
if (SONOFF_BRIDGE == sysCfg.module) {
Baudrate = 19200;
Expand All @@ -2635,17 +2645,22 @@ void GPIO_init()
Maxdevice = 0;
Baudrate = 19200;
}
else if (SONOFF_BN == sysCfg.module) { // Single color led (White)
else if ((H801 == sysCfg.module) || (MAGICHOME == sysCfg.module)) { // PWM RGBCW led
if (!sysCfg.flag.pwm_control) {
sfl_flg = 0;
}
}
else if (SONOFF_BN == sysCfg.module) { // PWM Single color led (White)
sfl_flg = 1;
}
else if (SONOFF_LED == sysCfg.module) { // Dual color led (White warm and cold)
else if (SONOFF_LED == sysCfg.module) { // PWM Dual color led (White warm and cold)
sfl_flg = 2;
}
else if (AILIGHT == sysCfg.module) { // RGBW led
sfl_flg = 4;
sfl_flg = 12;
}
else if (SONOFF_B1 == sysCfg.module) { // RGBWC led
sfl_flg = 5;
sfl_flg = 13;
}
else {
Maxdevice = 0;
Expand Down Expand Up @@ -2674,14 +2689,14 @@ void GPIO_init()
}

#ifdef USE_WS2812
if (!sfl_flg && (pin[GPIO_WS2812] < 99)) {
if (!sfl_flg && (pin[GPIO_WS2812] < 99)) { // RGB led
Maxdevice++;
sfl_flg = 3;
sfl_flg = 11;
}
#endif // USE_WS2812
if (sfl_flg) { // Sonoff B1, AiLight, Sonoff Led or BN-SZ01, WS2812
if (sfl_flg < 3) {
pwm_idxoffset = sfl_flg; // 1 for BN-SZ01, 2 for Sonoff Led
if (sfl_flg < 6) {
pwm_idxoffset = sfl_flg; // 1 for BN-SZ01, 2 for Sonoff Led, 3,4,5 for H801 and MagicHome
}
sl_init();
}
Expand Down Expand Up @@ -2833,7 +2848,7 @@ void setup()

// Issue #526
for (byte i = 0; i < Maxdevice; i++) {
if ((pin[GPIO_REL1 +i] < 99) && (digitalRead(pin[GPIO_REL1 +i]))) {
if ((pin[GPIO_REL1 +i] < 99) && (digitalRead(pin[GPIO_REL1 +i]) ^ rel_inverted[i])) {
bitSet(power, i);
pulse_timer[i] = sysCfg.pulsetime[i];
}
Expand Down
26 changes: 13 additions & 13 deletions sonoff/sonoff_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ enum upins_t {
GPIO_LED2_INV,
GPIO_LED3_INV,
GPIO_LED4_INV,
GPIO_PWM1, // Sonoff Led Cold
GPIO_PWM2, // Sonoff Led Warm
GPIO_PWM3, // Red (swapped with Blue from original)
GPIO_PWM4, // Green
GPIO_PWM5, // Blue (swapped with Red from original)
GPIO_PWM1, // RGB Red or C Cold White
GPIO_PWM2, // RGB Green or CW Warm White
GPIO_PWM3, // RGB Blue
GPIO_PWM4, // RGBW (Cold) White
GPIO_PWM5, // RGBCW Warm White
GPIO_CNTR1,
GPIO_CNTR2,
GPIO_CNTR3,
Expand Down Expand Up @@ -467,13 +467,13 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_LED1, // GPIO01 Green LED
GPIO_TXD, // GPIO02 RX - Pin next to TX on the PCB
GPIO_RXD, // GPIO03 TX - Pin next to GND on the PCB
GPIO_PWM2, // GPIO04 W2
GPIO_USER, // GPIO04 W2 - PWM5
GPIO_LED2_INV, // GPIO05 Red LED
0, 0, 0, 0, 0, 0, // Flash connection
GPIO_PWM3, // GPIO12 Blue
GPIO_PWM4, // GPIO13 Green
GPIO_PWM1, // GPIO14 W1
GPIO_PWM5, // GPIO15 Red
GPIO_PWM2, // GPIO13 Green
GPIO_USER, // GPIO14 W1 - PWM4
GPIO_PWM1, // GPIO15 Red
0, 0
},
{ "Sonoff SC", // Sonoff SC (ESP8266)
Expand Down Expand Up @@ -658,11 +658,11 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_LED1_INV, // GPIO02 Blue onboard LED
0,
GPIO_USER, // GPIO04 IR receiver (optional)
GPIO_PWM4, // GPIO05 RGB LED Green
GPIO_PWM2, // GPIO05 RGB LED Green
0, 0, 0, 0, 0, 0, // Flash connection
GPIO_PWM5, // GPIO12 RGB LED Blue
GPIO_USER, // GPIO13 RGBW LED White (optional - set to PWM1 for Cold White or PWM2 for Warm White)
GPIO_PWM3, // GPIO14 RGB LED Red
GPIO_PWM3, // GPIO12 RGB LED Blue
GPIO_USER, // GPIO13 RGBW LED White (optional - set to PWM4 for Cold White or Warm White)
GPIO_PWM1, // GPIO14 RGB LED Red
0, 0, 0
}
};
Expand Down
13 changes: 7 additions & 6 deletions sonoff/webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void handleRoot()
page += F("<div id='l1' name='l1'></div>");
if (Maxdevice) {
if (sfl_flg) {
if ((2 == sfl_flg) || (5 == sfl_flg)) {
if ((2 == (sfl_flg &7)) || (5 == (sfl_flg &7))) {
snprintf_P(line, sizeof(line), HTTP_MSG_SLIDER1, sl_getColorTemp());
page += line;
}
Expand Down Expand Up @@ -1051,11 +1051,12 @@ void handleSave()
for (byte i = 0; i < MAX_GPIO_PIN; i++) {
if (new_modflg) {
sysCfg.my_module.gp.io[i] = 0;
}
if (GPIO_USER == cmodule.gp.io[i]) {
snprintf_P(stemp, sizeof(stemp), PSTR("g%d"), i);
sysCfg.my_module.gp.io[i] = (!strlen(webServer->arg(stemp).c_str())) ? 0 : atoi(webServer->arg(stemp).c_str());
gpios += F(", " D_GPIO ); gpios += String(i); gpios += F(" "); gpios += String(sysCfg.my_module.gp.io[i]);
} else {
if (GPIO_USER == cmodule.gp.io[i]) {
snprintf_P(stemp, sizeof(stemp), PSTR("g%d"), i);
sysCfg.my_module.gp.io[i] = (!strlen(webServer->arg(stemp).c_str())) ? 0 : atoi(webServer->arg(stemp).c_str());
gpios += F(", " D_GPIO ); gpios += String(i); gpios += F(" "); gpios += String(sysCfg.my_module.gp.io[i]);
}
}
}
snprintf_P(stemp, sizeof(stemp), modules[sysCfg.module].name);
Expand Down
Loading

0 comments on commit e8e8aa0

Please sign in to comment.