From 4d96cac7515ebe0b6b60fed0b7038c15ce8f6972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sun, 21 May 2017 11:55:54 +0200 Subject: [PATCH] Improve support fro H801 led controller, thanks to Minh Phuong Ly --- code/espurna/config/general.h | 1 + code/espurna/config/hardware.h | 10 ++++------ code/espurna/hardware.ino | 14 ++++++++++++++ code/espurna/light.ino | 14 ++++++++++++-- code/espurna/relay.ino | 4 ++-- code/platformio.ini | 21 +++++++++++++++++++++ 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index ddb632c7..5615db0b 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -232,6 +232,7 @@ #define LIGHT_PROVIDER_RGB 2 #define LIGHT_PROVIDER_RGBW 3 #define LIGHT_PROVIDER_MY9192 4 +#define LIGHT_PROVIDER_RGB2W 5 #define LIGHT_DEFAULT_COLOR "#000080" #define LIGHT_SAVE_DELAY 5 diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 3bed1fd2..138f5e19 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -299,16 +299,14 @@ // HUACANXING H801 // ----------------------------------------------------------------------------- -#elif defined(H801) +#elif defined(H801_LED_CONTROLLER) #define MANUFACTURER "HUACANXING" #define DEVICE "H801" #define LED1_PIN 5 #define LED1_PIN_INVERSE 1 - #define LED2_PIN 2 - #define LED2_PIN_INVERSE 1 #define RELAY_PROVIDER RELAY_PROVIDER_LIGHT - #define LIGHT_PROVIDER LIGHT_PROVIDER_RGBW + #define LIGHT_PROVIDER LIGHT_PROVIDER_RGB2W #undef RGBW_INVERSE_LOGIC #undef RGBW_RED_PIN @@ -316,12 +314,12 @@ #undef RGBW_BLUE_PIN #undef RGBW_WHITE_PIN - #define RGBW_INVERSE_LOGIC 0 + #define RGBW_INVERSE_LOGIC 1 #define RGBW_RED_PIN 15 #define RGBW_GREEN_PIN 13 #define RGBW_BLUE_PIN 12 #define RGBW_WHITE_PIN 14 - //#define RGBW_WHITE_PIN 4 <= warm white + #define RGBW_WHITE2_PIN 4 // ----------------------------------------------------------------------------- // Jan Goedeke Wifi Relay diff --git a/code/espurna/hardware.ino b/code/espurna/hardware.ino index e074fcd8..a34e4466 100644 --- a/code/espurna/hardware.ino +++ b/code/espurna/hardware.ino @@ -264,6 +264,20 @@ void hwUpwardsCompatibility() { setSetting("relayLogic", 1, 1); #endif + #ifdef H801_LED_CONTROLLER + setSetting("board", 24); + setSetting("relayProvider", RELAY_PROVIDER_LIGHT); + setSetting("lightProvider", LIGHT_PROVIDER_RGB2W); + setSetting("ledGPIO", 5, 1); + setSetting("ledLogic", 1, 1); + setSetting("redGPIO", 15); + setSetting("greenGPIO", 13); + setSetting("blueGPIO", 12); + setSetting("whiteGPIO", 14); + setSetting("white2GPIO", 4); + setSetting("lightLogic", 1); + #endif + saveSettings(); } diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 8f3f7038..4b552270 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -19,6 +19,7 @@ my9291 * _my9291; #endif #if ENABLE_GAMMA_CORRECTION + #define GAMMA_TABLE_SIZE (256) #undef LIGHT_PWM_RANGE #define LIGHT_PWM_RANGE (4095) @@ -41,6 +42,7 @@ my9291 * _my9291; 2315,2346,2378,2410,2442,2474,2507,2540,2573,2606,2640,2674,2708,2743,2778,2813, 2849,2884,2920,2957,2993,3030,3067,3105,3143,3181,3219,3258,3297,3336,3376,3416, 3456,3496,3537,3578,3619,3661,3703,3745,3788,3831,3874,3918,3962,4006,4050,4095 }; + #endif #ifndef LIGHT_PWM_FREQUENCY @@ -164,7 +166,7 @@ void _lightProviderSet(bool state, unsigned int red, unsigned int green, unsigne unsigned int white = 0; - #if (LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192) || (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW) + #if (LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192) || (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW) || (LIGHT_PROVIDER == LIGHT_PROVIDER_RGB2W) // If all set to the same value use white instead if ((red == green) && (green == blue)) { white = red; @@ -177,7 +179,7 @@ void _lightProviderSet(bool state, unsigned int red, unsigned int green, unsigne _my9291->setColor((my9291_color_t) { red, green, blue, white }); #endif - #if (LIGHT_PROVIDER == LIGHT_PROVIDER_RGB) || (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW) + #if (LIGHT_PROVIDER == LIGHT_PROVIDER_RGB) || (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW) || (LIGHT_PROVIDER == LIGHT_PROVIDER_RGB2W) // Check state if (!state) red = green = blue = white = 0; @@ -188,6 +190,10 @@ void _lightProviderSet(bool state, unsigned int red, unsigned int green, unsigne #if (LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW) analogWrite(RGBW_WHITE_PIN, _intensity2pwm(white)); #endif + #if (LIGHT_PROVIDER == LIGHT_PROVIDER_RGB2W) + analogWrite(RGBW_WHITE_PIN, _intensity2pwm(white)); + analogWrite(RGBW_WHITE2_PIN, _intensity2pwm(white)); + #endif #endif } @@ -288,6 +294,10 @@ void lightSetup() { #if LIGHT_PROVIDER == LIGHT_PROVIDER_RGBW pinMode(RGBW_WHITE_PIN, OUTPUT); #endif + #if LIGHT_PROVIDER == LIGHT_PROVIDER_RGB2W + pinMode(RGBW_WHITE_PIN, OUTPUT); + pinMode(RGBW_WHITE2_PIN, OUTPUT); + #endif #endif _lightColorRestore(); diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 19e35f19..262f0b53 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -453,9 +453,9 @@ void relaySetup() { _relays.push_back((relay_t) {0, 0}); _relays.push_back((relay_t) {0, 0}); - #elif defined(AI_LIGHT) | defined(LED_CONTROLLER) + #elif defined(AI_LIGHT) | defined(LED_CONTROLLER) | defined(H801_LED_CONTROLLER) - // One dummy relay for the AI Thinker Light & Magic Home Led Controller + // One dummy relay for the AI Thinker Light & Magic Home and H801 led controllers _relays.push_back((relay_t) {0, 0}); #else diff --git a/code/platformio.ini b/code/platformio.ini index b1d417f4..27a01024 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -456,3 +456,24 @@ build_flags = ${common.build_flags_1m128} -DLED_CONTROLLER upload_speed = 115200 upload_port = "192.168.4.1" upload_flags = --auth=fibonacci --port 8266 + +[env:h801-debug] +platform = espressif8266 +framework = arduino +board = esp01_1m +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +extra_script = pio_hooks.py +build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DH801_LED_CONTROLLER -DDEBUG_PORT=Serial1 + +[env:h801-debug-ota] +platform = espressif8266 +framework = arduino +board = esp01_1m +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +extra_script = pio_hooks.py +build_flags = -g -Wl,-Tesp8266.flash.1m128.ld -DH801_LED_CONTROLLER -DDEBUG_PORT=Serial1 +upload_speed = 115200 +upload_port = "192.168.4.1" +upload_flags = --auth=fibonacci --port 8266