From 41804ae01da5e76cc1b030a64a31f0eb8c6db2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 13 Nov 2017 23:31:00 +0100 Subject: [PATCH] Update my9291 to my92xx. Fixes issues with Sonoff B1 --- code/espurna/config/general.h | 7 ++-- code/espurna/config/hardware.h | 63 ++++++++++++++++++++-------------- code/espurna/hardware.ino | 14 ++++++-- code/espurna/light.ino | 33 +++++++----------- code/platformio.ini | 2 +- 5 files changed, 67 insertions(+), 52 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index a09c5d88..fa72c6ac 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -11,6 +11,9 @@ #define DEVICE_NAME MANUFACTURER "_" DEVICE // Concatenate both to get a unique device name #define LOOP_DELAY_TIME 10 // Delay for this millis in the main loop [0-250] +#define ARRAYINIT(type, name, ...) \ + type name[] = {__VA_ARGS__}; + //------------------------------------------------------------------------------ // TELNET //------------------------------------------------------------------------------ @@ -480,7 +483,7 @@ PROGMEM const char* const custom_reset_string[] = { // Available light providers (do not change) #define LIGHT_PROVIDER_NONE 0 -#define LIGHT_PROVIDER_MY9192 1 // works with MY9231 also (Sonoff B1) +#define LIGHT_PROVIDER_MY92XX 1 // works with MY9291 and MY9231 #define LIGHT_PROVIDER_DIMMER 2 // LIGHT_PROVIDER_DIMMER can have from 1 to 5 different channels. @@ -505,7 +508,7 @@ PROGMEM const char* const custom_reset_string[] = { #ifndef LIGHT_MAX_PWM -#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192 +#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX #define LIGHT_MAX_PWM 255 #endif diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index eac36be8..106c56a6 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -464,7 +464,7 @@ #define LED1_PIN 13 #define LED1_PIN_INVERSE 1 - // Channels + // Light #define LIGHT_CHANNELS 1 #define LIGHT_CH1_PIN 12 #define LIGHT_CH1_INVERSE 0 @@ -497,12 +497,17 @@ #define MANUFACTURER "ITEAD" #define DEVICE "SONOFF_B1" #define RELAY_PROVIDER RELAY_PROVIDER_LIGHT - #define LIGHT_PROVIDER LIGHT_PROVIDER_MY9192 + #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define DUMMY_RELAY_COUNT 1 - #define MY9291_DI_PIN 12 - #define MY9291_DCKI_PIN 14 - #define MY9291_COMMAND MY9291_COMMAND_DEFAULT - #define MY9291_CHANNELS 5 + + // Light + #define LIGHT_CHANNELS 5 + #define MY92XX_MODEL MY92XX_MODEL_MY9231 + #define MY92XX_CHIPS 2 + #define MY92XX_DI_PIN 12 + #define MY92XX_DCKI_PIN 14 + #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT + #define MY92XX_MAPPING 4, 3, 5, 0, 1 #elif defined(ITEAD_SONOFF_LED) @@ -517,7 +522,7 @@ #define LED1_PIN 13 #define LED1_PIN_INVERSE 1 - // Channels + // Light #define LIGHT_CHANNELS 2 #define LIGHT_CH1_PIN 12 // Cold white #define LIGHT_CH2_PIN 14 // Warm white @@ -700,12 +705,17 @@ #define MANUFACTURER "AITHINKER" #define DEVICE "AI_LIGHT" #define RELAY_PROVIDER RELAY_PROVIDER_LIGHT - #define LIGHT_PROVIDER LIGHT_PROVIDER_MY9192 + #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define DUMMY_RELAY_COUNT 1 - #define MY9291_DI_PIN 13 - #define MY9291_DCKI_PIN 15 - #define MY9291_COMMAND MY9291_COMMAND_DEFAULT - #define MY9291_CHANNELS 4 + + // Light + #define LIGHT_CHANNELS 4 + #define MY92XX_MODEL MY92XX_MODEL_MY9291 + #define MY92XX_CHIPS 1 + #define MY92XX_DI_PIN 13 + #define MY92XX_DCKI_PIN 15 + #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT + #define MY92XX_MAPPING 0, 1, 2, 3 // ----------------------------------------------------------------------------- // LED Controller @@ -724,7 +734,7 @@ #define LED1_PIN 2 #define LED1_PIN_INVERSE 1 - // Channels + // Light #define LIGHT_CHANNELS 4 #define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH2_PIN 5 // GREEN @@ -755,7 +765,7 @@ #define LED1_PIN 2 #define LED1_PIN_INVERSE 1 - // Channels + // Light #define LIGHT_CHANNELS 4 #define LIGHT_CH1_PIN 5 // RED #define LIGHT_CH2_PIN 12 // GREEN @@ -788,7 +798,7 @@ #define LED1_PIN 5 #define LED1_PIN_INVERSE 1 - // Channels + // Light #define LIGHT_CHANNELS 5 #define LIGHT_CH1_PIN 15 // RED #define LIGHT_CH2_PIN 13 // GREEN @@ -810,7 +820,7 @@ #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define DUMMY_RELAY_COUNT 1 - // Channels + // Light #define LIGHT_CHANNELS 4 #define LIGHT_CH1_PIN 12 // RED #define LIGHT_CH2_PIN 14 // GREEN @@ -1047,7 +1057,7 @@ #define LED1_PIN 5 #define LED1_PIN_INVERSE 1 - // Channels + // Light #define LIGHT_CHANNELS 2 #define LIGHT_CH1_PIN 0 #define LIGHT_CH2_PIN 2 @@ -1067,7 +1077,7 @@ #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define DUMMY_RELAY_COUNT 1 - // Channels + // Light #define LIGHT_CHANNELS 5 #define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH2_PIN 12 // GREEN @@ -1087,14 +1097,17 @@ #define MANUFACTURER "ARILUX" #define DEVICE "E27" #define RELAY_PROVIDER RELAY_PROVIDER_LIGHT - #define LIGHT_PROVIDER LIGHT_PROVIDER_MY9192 + #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define DUMMY_RELAY_COUNT 1 - // Channels - #define MY9291_CHANNELS 4 - #define MY9291_DI_PIN 13 - #define MY9291_DCKI_PIN 15 - #define MY9291_COMMAND MY9291_COMMAND_DEFAULT + // Light + #define LIGHT_CHANNELS 4 + #define MY92XX_MODEL MY92XX_MODEL_MY9291 + #define MY92XX_CHIPS 1 + #define MY92XX_DI_PIN 13 + #define MY92XX_DCKI_PIN 15 + #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT + #define MY92XX_MAPPING 0, 1, 2, 3 // ----------------------------------------------------------------------------- // XENON SM-PW701U @@ -1133,7 +1146,7 @@ #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define DUMMY_RELAY_COUNT 1 - // Channels + // Light #define LIGHT_CHANNELS 4 #define LIGHT_CH1_PIN 13 // RED #define LIGHT_CH2_PIN 12 // GREEN diff --git a/code/espurna/hardware.ino b/code/espurna/hardware.ino index b290deb6..78c335eb 100644 --- a/code/espurna/hardware.ino +++ b/code/espurna/hardware.ino @@ -13,6 +13,8 @@ the migration to future version 2 will be straigh forward. */ +#include + void hwUpwardsCompatibility() { unsigned int board = getSetting("board", 0).toInt(); @@ -222,7 +224,9 @@ void hwUpwardsCompatibility() { setSetting("board", 20); setSetting("relayProvider", RELAY_PROVIDER_LIGHT); - setSetting("lightProvider", LIGHT_PROVIDER_MY9192); + setSetting("lightProvider", LIGHT_PROVIDER_MY92XX); + setSetting("myModel", MY92XX_MODEL_MY9291); + setSetting("myChips", 1); setSetting("myDIGPIO", 13); setSetting("myDCKIGPIO", 15); setSetting("relays", 1); @@ -349,7 +353,9 @@ void hwUpwardsCompatibility() { setSetting("board", 28); setSetting("relayProvider", RELAY_PROVIDER_LIGHT); - setSetting("lightProvider", LIGHT_PROVIDER_MY9192); + setSetting("lightProvider", LIGHT_PROVIDER_MY92XX); + setSetting("myModel", MY92XX_MODEL_MY9231); + setSetting("myChips", 2); setSetting("myDIGPIO", 12); setSetting("myDCKIGPIO", 14); setSetting("relays", 1); @@ -561,7 +567,9 @@ void hwUpwardsCompatibility() { setSetting("board", 46); setSetting("relayProvider", RELAY_PROVIDER_LIGHT); - setSetting("lightProvider", LIGHT_PROVIDER_MY9192); + setSetting("lightProvider", LIGHT_PROVIDER_MY92XX); + setSetting("myModel", MY92XX_MODEL_MY9291); + setSetting("myChips", 1); setSetting("myDIGPIO", 13); setSetting("myDCKIGPIO", 15); setSetting("relays", 1); diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 26ec1f7b..2c0208a9 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -31,9 +31,9 @@ std::vector _channels; bool _lightState = false; unsigned int _brightness = LIGHT_MAX_BRIGHTNESS; -#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192 -#include -my9291 * _my9291; +#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX +#include +my92xx * _my92xx; #endif // Gamma Correction lookup table (8 bit) @@ -387,24 +387,15 @@ void _lightProviderUpdate() { digitalWrite(LIGHT_ENABLE_PIN, _lightState); #endif - #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192 + #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX - if (_lightState) { - - unsigned int red = _toPWM(0); - unsigned int green = _toPWM(1); - unsigned int blue = _toPWM(2); - unsigned int white = _toPWM(3); - unsigned int warm = _toPWM(4); - _my9291->setColor((my9291_color_t) { red, green, blue, white, warm }); - _my9291->setState(true); - - } else { - - _my9291->setColor((my9291_color_t) { 0, 0, 0, 0, 0 }); - _my9291->setState(false); + ARRAYINIT(unsigned char, channels, MY92XX_MAPPING); + for (unsigned char i=0; i<_channels.size(); i++) { + _my92xx->setChannel(channels[i], _toPWM(i)); } + _my92xx->setState(_lightState); + _my92xx->update(); #endif @@ -803,10 +794,10 @@ void lightSetup() { pinMode(LIGHT_ENABLE_PIN, OUTPUT); #endif - #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192 + #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX - _my9291 = new my9291(MY9291_DI_PIN, MY9291_DCKI_PIN, MY9291_COMMAND, MY9291_CHANNELS); - for (unsigned char i=0; i