Browse Source

Update my9291 to my92xx. Fixes issues with Sonoff B1

fastled
Xose Pérez 7 years ago
parent
commit
41804ae01d
5 changed files with 67 additions and 52 deletions
  1. +5
    -2
      code/espurna/config/general.h
  2. +38
    -25
      code/espurna/config/hardware.h
  3. +11
    -3
      code/espurna/hardware.ino
  4. +12
    -21
      code/espurna/light.ino
  5. +1
    -1
      code/platformio.ini

+ 5
- 2
code/espurna/config/general.h View File

@ -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


+ 38
- 25
code/espurna/config/hardware.h View File

@ -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


+ 11
- 3
code/espurna/hardware.ino View File

@ -13,6 +13,8 @@ the migration to future version 2 will be straigh forward.
*/
#include <my92xx.h>
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);


+ 12
- 21
code/espurna/light.ino View File

@ -31,9 +31,9 @@ std::vector<channel_t> _channels;
bool _lightState = false;
unsigned int _brightness = LIGHT_MAX_BRIGHTNESS;
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
#include <my9291.h>
my9291 * _my9291;
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
#include <my92xx.h>
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<MY9291_CHANNELS; i++) {
_my92xx = new my92xx(MY92XX_MODEL, MY92XX_CHIPS, MY92XX_DI_PIN, MY92XX_DCKI_PIN, MY92XX_COMMAND);
for (unsigned char i=0; i<LIGHT_CHANNELS; i++) {
_channels.push_back((channel_t) {0, false, 0});
}


+ 1
- 1
code/platformio.ini View File

@ -31,7 +31,7 @@ lib_deps =
https://bitbucket.org/xoseperez/nofuss.git#0.2.5
https://bitbucket.org/xoseperez/emonliteesp.git#0.2.0
https://bitbucket.org/xoseperez/debounceevent.git#2.0.1
https://github.com/xoseperez/my9291#2.0.0
https://github.com/xoseperez/my92xx#3.0.0
https://github.com/xoseperez/RemoteSwitch-arduino-library.git
https://github.com/FastLED/FastLED#v3.1.6
https://github.com/markszabo/IRremoteESP8266#v2.2.0


Loading…
Cancel
Save