Browse Source

lights: finish up provider settings

get rid of LIGHT_CHANNELS, but keep channel setting for the my92xx
also clean up recent changes, channel command did not actually work
mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
7434ea3878
7 changed files with 121 additions and 85 deletions
  1. +4
    -4
      code/espurna/config/defaults.h
  2. +7
    -47
      code/espurna/config/hardware.h
  3. +76
    -26
      code/espurna/light.cpp
  4. +0
    -1
      code/espurna/light.h
  5. +33
    -5
      code/espurna/light_config.h
  6. +0
    -1
      code/test/build/light_dimmer.h
  7. +1
    -1
      code/test/build/light_my92xx.h

+ 4
- 4
code/espurna/config/defaults.h View File

@ -995,10 +995,6 @@
// Lights // Lights
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef LIGHT_CHANNELS
#define LIGHT_CHANNELS 0
#endif
#ifndef LIGHT_ENABLE_PIN #ifndef LIGHT_ENABLE_PIN
#define LIGHT_ENABLE_PIN GPIO_NONE #define LIGHT_ENABLE_PIN GPIO_NONE
#endif #endif
@ -1047,6 +1043,10 @@
// my92xx // my92xx
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef MY92XX_CHANNELS
#define MY92XX_CHANNELS 0
#endif
#ifndef MY92XX_CH1 #ifndef MY92XX_CH1
#define MY92XX_CH1 0 #define MY92XX_CH1 0
#endif #endif


+ 7
- 47
code/espurna/config/hardware.h View File

@ -782,7 +782,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 1
#define LIGHT_CH1_PIN 12 #define LIGHT_CH1_PIN 12
#elif defined(ITEAD_SONOFF_RFBRIDGE) #elif defined(ITEAD_SONOFF_RFBRIDGE)
@ -831,7 +830,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX
// Light // Light
#define LIGHT_CHANNELS 5
#define MY92XX_MODEL MY92XX_MODEL_MY9231 #define MY92XX_MODEL MY92XX_MODEL_MY9231
#define MY92XX_CHIPS 2 #define MY92XX_CHIPS 2
@ -839,6 +837,7 @@
#define MY92XX_DCKI_PIN 14 #define MY92XX_DCKI_PIN 14
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_CHANNELS 5
#define MY92XX_CH1 4 #define MY92XX_CH1 4
#define MY92XX_CH2 3 #define MY92XX_CH2 3
#define MY92XX_CH3 5 #define MY92XX_CH3 5
@ -859,7 +858,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 2
#define LIGHT_CH1_PIN 12 // Cold white #define LIGHT_CH1_PIN 12 // Cold white
#define LIGHT_CH2_PIN 14 // Warm white #define LIGHT_CH2_PIN 14 // Warm white
@ -1257,12 +1255,12 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX
// Light // Light
#define LIGHT_CHANNELS 4
#define MY92XX_MODEL MY92XX_MODEL_MY9291 #define MY92XX_MODEL MY92XX_MODEL_MY9291
#define MY92XX_CHIPS 1 #define MY92XX_CHIPS 1
#define MY92XX_DI_PIN 13 #define MY92XX_DI_PIN 13
#define MY92XX_DCKI_PIN 15 #define MY92XX_DCKI_PIN 15
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_CHANNELS 4
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Lyasi LED // Lyasi LED
@ -1276,12 +1274,12 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX
// Light // Light
#define LIGHT_CHANNELS 4
#define MY92XX_MODEL MY92XX_MODEL_MY9291 #define MY92XX_MODEL MY92XX_MODEL_MY9291
#define MY92XX_CHIPS 1 #define MY92XX_CHIPS 1
#define MY92XX_DI_PIN 4 #define MY92XX_DI_PIN 4
#define MY92XX_DCKI_PIN 5 #define MY92XX_DCKI_PIN 5
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_CHANNELS 4
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// LED Controller // LED Controller
@ -1299,7 +1297,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 5 // GREEN #define LIGHT_CH2_PIN 5 // GREEN
#define LIGHT_CH3_PIN 12 // BLUE #define LIGHT_CH3_PIN 12 // BLUE
@ -1322,7 +1319,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 5 // RED #define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -1347,7 +1343,6 @@
#define LED2_PIN_INVERSE 1 #define LED2_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 12 // RED #define LIGHT_CH1_PIN 12 // RED
#define LIGHT_CH2_PIN 5 // GREEN #define LIGHT_CH2_PIN 5 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -1372,7 +1367,6 @@
#define LED2_PIN_INVERSE 1 #define LED2_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 5 // GREEN #define LIGHT_CH2_PIN 5 // GREEN
#define LIGHT_CH3_PIN 12 // BLUE #define LIGHT_CH3_PIN 12 // BLUE
@ -1400,7 +1394,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 1
#define LIGHT_CH1_PIN 12 // WHITE #define LIGHT_CH1_PIN 12 // WHITE
#elif defined(MAGICHOME_ZJ_ESPM_5CH_B_13) #elif defined(MAGICHOME_ZJ_ESPM_5CH_B_13)
@ -1420,7 +1413,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -1435,7 +1427,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 5 // RED #define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 4 // GREEN #define LIGHT_CH2_PIN 4 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -1460,7 +1451,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 15 // RED #define LIGHT_CH1_PIN 15 // RED
#define LIGHT_CH2_PIN 13 // GREEN #define LIGHT_CH2_PIN 13 // GREEN
#define LIGHT_CH3_PIN 12 // BLUE #define LIGHT_CH3_PIN 12 // BLUE
@ -1477,7 +1467,6 @@
#define SERIAL_RX_ENABLED 1 #define SERIAL_RX_ENABLED 1
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 12 // RED #define LIGHT_CH1_PIN 12 // RED
#define LIGHT_CH2_PIN 14 // GREEN #define LIGHT_CH2_PIN 14 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -1823,7 +1812,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 2
#define LIGHT_CH1_PIN 0 #define LIGHT_CH1_PIN 0
#define LIGHT_CH2_PIN 2 #define LIGHT_CH2_PIN 2
@ -1839,7 +1827,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 3
#define LIGHT_CH1_PIN 5 // RED #define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -1852,7 +1839,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 12 // RED #define LIGHT_CH1_PIN 12 // RED
#define LIGHT_CH2_PIN 5 // GREEN #define LIGHT_CH2_PIN 5 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -1866,7 +1852,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 5 // GREEN #define LIGHT_CH2_PIN 5 // GREEN
#define LIGHT_CH3_PIN 12 // BLUE #define LIGHT_CH3_PIN 12 // BLUE
@ -1885,7 +1870,6 @@
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
// Light // Light
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -1900,7 +1884,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 5 // RED #define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 4 // GREEN #define LIGHT_CH2_PIN 4 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -1915,12 +1898,12 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX
// Light // Light
#define LIGHT_CHANNELS 4
#define MY92XX_MODEL MY92XX_MODEL_MY9291 #define MY92XX_MODEL MY92XX_MODEL_MY9291
#define MY92XX_CHIPS 1 #define MY92XX_CHIPS 1
#define MY92XX_DI_PIN 13 #define MY92XX_DI_PIN 13
#define MY92XX_DCKI_PIN 15 #define MY92XX_DCKI_PIN 15
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_CHANNELS 4
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// XENON SM-PW701U // XENON SM-PW701U
@ -1983,7 +1966,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 13 // RED #define LIGHT_CH1_PIN 13 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -2014,7 +1996,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 3
#define LIGHT_CH1_PIN 15 // RED #define LIGHT_CH1_PIN 15 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -3642,7 +3623,6 @@
#define LED2_MODE LED_MODE_RELAY #define LED2_MODE LED_MODE_RELAY
// Light // Light
#define LIGHT_CHANNELS 3
#define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 13 // GREEN #define LIGHT_CH2_PIN 13 // GREEN
#define LIGHT_CH3_PIN 12 // BLUE #define LIGHT_CH3_PIN 12 // BLUE
@ -3684,7 +3664,6 @@
#define LED2_MODE LED_MODE_RELAY #define LED2_MODE LED_MODE_RELAY
// Light // Light
#define LIGHT_CHANNELS 3
#define LIGHT_CH1_PIN 4 // RED #define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -3883,12 +3862,12 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX
// Light // Light
#define LIGHT_CHANNELS 5
#define MY92XX_MODEL MY92XX_MODEL_MY9231 #define MY92XX_MODEL MY92XX_MODEL_MY9231
#define MY92XX_CHIPS 2 #define MY92XX_CHIPS 2
#define MY92XX_DI_PIN 13 #define MY92XX_DI_PIN 13
#define MY92XX_DCKI_PIN 15 #define MY92XX_DCKI_PIN 15
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_CHANNELS 5
#define LIGHT_WHITE_FACTOR (0.1) // White LEDs are way more bright in the B1 #define LIGHT_WHITE_FACTOR (0.1) // White LEDs are way more bright in the B1
@ -3902,7 +3881,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 5 // RED #define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 4 // GREEN #define LIGHT_CH2_PIN 4 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -3919,7 +3897,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 4 // RED #define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -3957,7 +3934,6 @@
// Light // Light
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define LIGHT_STEP 8 #define LIGHT_STEP 8
#define LIGHT_CHANNELS 2
#define LIGHT_CH1_PIN 5 // warm white #define LIGHT_CH1_PIN 5 // warm white
#define LIGHT_CH2_PIN 4 // cold white #define LIGHT_CH2_PIN 4 // cold white
@ -3987,7 +3963,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 3
#define LIGHT_CH1_PIN 4 // RED #define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 14 // GREEN #define LIGHT_CH2_PIN 14 // GREEN
#define LIGHT_CH3_PIN 12 // BLUE #define LIGHT_CH3_PIN 12 // BLUE
@ -4005,7 +3980,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 12 // RED #define LIGHT_CH1_PIN 12 // RED
#define LIGHT_CH2_PIN 5 // GREEN #define LIGHT_CH2_PIN 5 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -4024,7 +3998,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -4043,7 +4016,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 4 // RED #define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -4061,7 +4033,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 2
#define LIGHT_CH1_PIN 12 // WARM WHITE #define LIGHT_CH1_PIN 12 // WARM WHITE
#define LIGHT_CH2_PIN 14 // COLD WHITE #define LIGHT_CH2_PIN 14 // COLD WHITE
@ -4077,7 +4048,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 5 // RED #define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 4 // GREEN #define LIGHT_CH2_PIN 4 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -4097,7 +4067,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 12 // RED #define LIGHT_CH1_PIN 12 // RED
#define LIGHT_CH2_PIN 15 // GREEN #define LIGHT_CH2_PIN 15 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -4115,13 +4084,12 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX
// Light // Light
#define LIGHT_CHANNELS 2
#define MY92XX_MODEL MY92XX_MODEL_MY9291 #define MY92XX_MODEL MY92XX_MODEL_MY9291
#define MY92XX_CHIPS 1 #define MY92XX_CHIPS 1
#define MY92XX_DI_PIN 4 #define MY92XX_DI_PIN 4
#define MY92XX_DCKI_PIN 5 #define MY92XX_DCKI_PIN 5
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_CHANNELS 2
// No RGB on this bulb. Warm white on channel 0, cool white on channel 3 // No RGB on this bulb. Warm white on channel 0, cool white on channel 3
#define MY92XX_CH1 3 #define MY92XX_CH1 3
@ -4139,12 +4107,12 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX
// Light // Light
#define LIGHT_CHANNELS 4
#define MY92XX_MODEL MY92XX_MODEL_MY9291 #define MY92XX_MODEL MY92XX_MODEL_MY9291
#define MY92XX_CHIPS 1 #define MY92XX_CHIPS 1
#define MY92XX_DI_PIN 4 #define MY92XX_DI_PIN 4
#define MY92XX_DCKI_PIN 5 #define MY92XX_DCKI_PIN 5
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_CHANNELS 4
// RGB on channels 0/1/2, either cool or warm white on channel 3 // RGB on channels 0/1/2, either cool or warm white on channel 3
// The bulb *should* have cool leds, but could also have warm leds as a common defect // The bulb *should* have cool leds, but could also have warm leds as a common defect
@ -4194,7 +4162,6 @@
// Light RGBW // Light RGBW
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 5 // RED #define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 14 // GREEN #define LIGHT_CH2_PIN 14 // GREEN
#define LIGHT_CH3_PIN 12 // BLUE #define LIGHT_CH3_PIN 12 // BLUE
@ -4229,7 +4196,6 @@
// Light // Light
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define LIGHT_CHANNELS 3
#define LIGHT_CH1_PIN 0 // RED #define LIGHT_CH1_PIN 0 // RED
#define LIGHT_CH2_PIN 4 // GREEN #define LIGHT_CH2_PIN 4 // GREEN
#define LIGHT_CH3_PIN 2 // BLUE #define LIGHT_CH3_PIN 2 // BLUE
@ -4441,7 +4407,6 @@
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 5 // RED #define LIGHT_CH1_PIN 5 // RED
#define LIGHT_CH2_PIN 4 // GREEN #define LIGHT_CH2_PIN 4 // GREEN
#define LIGHT_CH3_PIN 12 // BLUE #define LIGHT_CH3_PIN 12 // BLUE
@ -4637,7 +4602,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 14 // RED #define LIGHT_CH1_PIN 14 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 13 // BLUE #define LIGHT_CH3_PIN 13 // BLUE
@ -4766,7 +4730,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light RGBW // Light RGBW
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 4 // RED #define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -4980,7 +4943,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 4
#define LIGHT_CH1_PIN 4 // RED #define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -4999,7 +4961,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 4 // RED #define LIGHT_CH1_PIN 4 // RED
#define LIGHT_CH2_PIN 12 // GREEN #define LIGHT_CH2_PIN 12 // GREEN
#define LIGHT_CH3_PIN 14 // BLUE #define LIGHT_CH3_PIN 14 // BLUE
@ -5018,7 +4979,6 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
// Light // Light
#define LIGHT_CHANNELS 2
#define LIGHT_CH1_PIN 5 // WARM WHITE LED PWM PIN #define LIGHT_CH1_PIN 5 // WARM WHITE LED PWM PIN
#define LIGHT_CH1_INVERSE 0 #define LIGHT_CH1_INVERSE 0
#define LIGHT_CH2_PIN 4 // COLD WHITE LED PWM PIN #define LIGHT_CH2_PIN 4 // COLD WHITE LED PWM PIN


+ 76
- 26
code/espurna/light.cpp View File

@ -19,8 +19,6 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include "ws.h" #include "ws.h"
#include "libs/OnceFlag.h" #include "libs/OnceFlag.h"
#include "light_config.h"
#include <Ticker.h> #include <Ticker.h>
#include <Schedule.h> #include <Schedule.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
@ -28,6 +26,10 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <array> #include <array>
#include <vector> #include <vector>
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
#include <my92xx.h>
#endif
extern "C" { extern "C" {
#include "libs/fs_math.h" #include "libs/fs_math.h"
} }
@ -42,6 +44,8 @@ extern "C" {
#endif #endif
#include "light_config.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if RELAY_SUPPORT #if RELAY_SUPPORT
@ -163,7 +167,6 @@ bool _light_state_changed = false;
LightStateListener _light_state_listener = nullptr; LightStateListener _light_state_listener = nullptr;
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
#include <my92xx.h>
my92xx* _my92xx { nullptr }; my92xx* _my92xx { nullptr };
#endif #endif
@ -175,6 +178,36 @@ std::unique_ptr<LightProvider> _light_provider;
// UTILS // UTILS
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
namespace settings {
namespace internal {
template <>
my92xx_model_t convert(const String& value) {
if (value.length() == 1) {
switch (*value.c_str()) {
case 0x01:
return MY92XX_MODEL_MY9291;
case 0x02:
return MY92XX_MODEL_MY9231;
}
} else {
if (value == "9291") {
return MY92XX_MODEL_MY9291;
} else if (value == "9231") {
return MY92XX_MODEL_MY9231;
}
}
return Light::build::my92xxModel();
}
} // namespace internal
} // namespace settings
#endif
bool _setValue(unsigned char, unsigned int) __attribute__((warn_unused_result)); bool _setValue(unsigned char, unsigned int) __attribute__((warn_unused_result));
bool _setValue(unsigned char id, unsigned int value) { bool _setValue(unsigned char id, unsigned int value) {
if (_light_channels[id].value != value) { if (_light_channels[id].value != value) {
@ -285,7 +318,8 @@ char _lightTag(size_t channels, unsigned char index) {
constexpr size_t Columns { 5ul }; constexpr size_t Columns { 5ul };
constexpr size_t Rows { 5ul }; constexpr size_t Rows { 5ul };
if (channels < Rows) {
auto row = channels - 1ul;
if (row < Rows) {
constexpr char tags[Rows][Columns] = { constexpr char tags[Rows][Columns] = {
{'W', 0, 0, 0, 0}, {'W', 0, 0, 0, 0},
{'W', 'C', 0, 0, 0}, {'W', 'C', 0, 0, 0},
@ -294,7 +328,7 @@ char _lightTag(size_t channels, unsigned char index) {
{'R', 'G', 'B', 'W', 'C'}, {'R', 'G', 'B', 'W', 'C'},
}; };
return tags[channels][index];
return tags[row][index];
} }
return 0; return 0;
@ -658,7 +692,7 @@ void _lightAdjustMireds(const String& payload) {
namespace { namespace {
// Gamma Correction lookup table (8 bit, ~2.2) // Gamma Correction lookup table (8 bit, ~2.2)
// (note that the table could be constexpr, *but* the whole function needs to be constexpr as well)
// (TODO: could be constexpr, but the gamma table is still loaded into the RAM when marked as if it is a non-constexpr array)
uint8_t _lightGammaMap(uint8_t value) { uint8_t _lightGammaMap(uint8_t value) {
static uint8_t gamma[256] PROGMEM { static uint8_t gamma[256] PROGMEM {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -731,7 +765,7 @@ public:
} }
float diff = static_cast<float>(channel.target) - channel.current; float diff = static_cast<float>(channel.target) - channel.current;
if (isImmediateTransition(target_state, diff)) {
if (isImmediate(target_state, diff)) {
Transition transition { channel.current, channel.target, diff, 1}; Transition transition { channel.current, channel.target, diff, 1};
_transitions.push_back(std::move(transition)); _transitions.push_back(std::move(transition));
return false; return false;
@ -807,7 +841,7 @@ public:
} }
private: private:
bool isImmediateTransition(bool state, float diff) {
bool isImmediate(bool state, float diff) {
return (!_time || (_step >= _time) || (std::abs(diff) <= std::numeric_limits<float>::epsilon())); return (!_time || (_step >= _time) || (std::abs(diff) <= std::numeric_limits<float>::epsilon()));
} }
@ -887,8 +921,15 @@ void _lightProviderSchedule(unsigned long ms);
#if (LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER) || (LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX) #if (LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER) || (LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX)
// there is no PWM stop and it seems my92xx version is fine by just setting 0 values for channels
void _lightProviderHandleState(bool) {
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
unsigned char _light_my92xx_channel_map[Light::ChannelsMax] = {};
#endif
// there is no PWM stop, but my92xx has some internal state control that will send 0 as values when OFF
void _lightProviderHandleState(bool state [[gnu::unused]]) {
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
_my92xx->setState(state);
#endif
} }
// See cores/esp8266/WMath.cpp::map // See cores/esp8266/WMath.cpp::map
@ -912,7 +953,7 @@ void _lightProviderHandleValue(unsigned char channel, float value) {
#if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
pwm_set_duty(pwm, channel); pwm_set_duty(pwm, channel);
#elif LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX #elif LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
_my92xx->setChannel(Light::build::my92xxChannel(channel), pwm);
_my92xx->setChannel(_light_my92xx_channel_map[channel], pwm);
#endif #endif
} }
@ -920,7 +961,6 @@ void _lightProviderHandleUpdate() {
#if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
pwm_start(); pwm_start();
#elif LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX #elif LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
_my92xx->setState(true);
_my92xx->update(); _my92xx->update();
#endif #endif
} }
@ -1605,7 +1645,8 @@ void _lightInitCommands() {
terminalRegisterCommand(F("CHANNEL"), [](const terminal::CommandContext& ctx) { terminalRegisterCommand(F("CHANNEL"), [](const terminal::CommandContext& ctx) {
auto channels = lightChannels(); auto channels = lightChannels();
if (channels) {
if (!channels) {
terminalError(ctx, F("No channels configured"));
return; return;
} }
@ -1622,6 +1663,7 @@ void _lightInitCommands() {
for (unsigned char index = 0; index < channels; ++index) { for (unsigned char index = 0; index < channels; ++index) {
description(index); description(index);
} }
terminalOK(ctx);
return; return;
} }
@ -1931,16 +1973,11 @@ const unsigned long _light_iofunc[16] PROGMEM = {
namespace { namespace {
inline bool _lightUseGamma(size_t channels, unsigned char index) { inline bool _lightUseGamma(size_t channels, unsigned char index) {
if (_light_has_color && _light_use_gamma) {
switch (_lightTag(channels, index)) {
case 'R':
case 'G':
case 'B':
return true;
case 'W':
case 'C':
return false;
}
switch (_lightTag(channels, index)) {
case 'R':
case 'G':
case 'B':
return true;
} }
return false; return false;
@ -1994,9 +2031,13 @@ void _lightConfigure() {
_light_use_gamma = getSetting("useGamma", 1 == LIGHT_USE_GAMMA); _light_use_gamma = getSetting("useGamma", 1 == LIGHT_USE_GAMMA);
for (unsigned char index = 0; index < lightChannels(); ++index) { for (unsigned char index = 0; index < lightChannels(); ++index) {
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
_light_my92xx_channel_map[index] = getSetting({"ltMy92xxCh", index}, Light::build::my92xxChannel(index));
#endif
_light_channels[index].inverse = getSetting({"ltInv", index}, Light::build::inverse(index)); _light_channels[index].inverse = getSetting({"ltInv", index}, Light::build::inverse(index));
_light_channels[index].gamma = _lightUseGamma(channels, index);
_light_channels[index].gamma = (_light_has_color && _light_use_gamma) && _lightUseGamma(channels, index);
} }
} }
#if RELAY_SUPPORT #if RELAY_SUPPORT
@ -2135,8 +2176,17 @@ void lightSetup() {
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
{ {
_my92xx = new my92xx(MY92XX_MODEL, MY92XX_CHIPS, MY92XX_DI_PIN, MY92XX_DCKI_PIN, MY92XX_COMMAND);
for (unsigned char index = 0; index < Light::Channels; ++index) {
// TODO: library API specifies some hard-coded amount of channels, based off of the model and chips
// we always map channel index 1-to-1, to simplify hw config, but most of the time there are less active channels
// than the value generated by the lib (ref. `my92xx::getChannels()`)
auto channels = getSetting("ltMy92xxChannels", Light::build::my92xxChannels());
_my92xx = new my92xx(
getSetting("ltMy92xxModel", Light::build::my92xxModel()),
getSetting("ltMy92xxChips", Light::build::my92xxChips()),
getSetting("ltMy92xxDiGPIO", Light::build::my92xxDiPin()),
getSetting("ltMy92xxDckiGPIO", Light::build::my92xxDckiPin()),
Light::build::my92xxCommand());
for (unsigned char index = 0; index < channels; ++index) {
_light_channels.emplace_back(GPIO_NONE); _light_channels.emplace_back(GPIO_NONE);
} }
} }


+ 0
- 1
code/espurna/light.h View File

@ -21,7 +21,6 @@
// TODO: lowercase // TODO: lowercase
namespace Light { namespace Light {
constexpr size_t Channels = LIGHT_CHANNELS;
constexpr size_t ChannelsMax = 5; constexpr size_t ChannelsMax = 5;
constexpr long ValueMin = LIGHT_MIN_VALUE; constexpr long ValueMin = LIGHT_MIN_VALUE;


+ 33
- 5
code/espurna/light_config.h View File

@ -35,15 +35,41 @@ constexpr bool inverse(unsigned char index) {
); );
} }
#if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX
constexpr my92xx_cmd_t my92xxCommand() {
return MY92XX_COMMAND;
}
constexpr unsigned char my92xxChannels() {
return MY92XX_CHANNELS;
}
constexpr my92xx_model_t my92xxModel() {
return MY92XX_MODEL;
}
constexpr int my92xxChips() {
return MY92XX_CHIPS;
}
constexpr int my92xxDiPin() {
return MY92XX_DI_PIN;
}
constexpr int my92xxDckiPin() {
return MY92XX_DCKI_PIN;
}
#ifdef MY92XX_MAPPING #ifdef MY92XX_MAPPING
constexpr unsigned char _my92xx_mapping[LIGHT_CHANNELS] {
constexpr unsigned char _my92xx_mapping[MY92XX_CHANNELS] {
MY92XX_MAPPING MY92XX_MAPPING
}; };
constexpr unsigned char my92xxChannel(unsigned char) constexpr unsigned char my92xxChannel(unsigned char)
__attribute__((deprecated("MY92XX_CH# flags should be used instead of MY92XX_MAPPING"))); __attribute__((deprecated("MY92XX_CH# flags should be used instead of MY92XX_MAPPING")));
constexpr unsigned char _lightMy92xxChannel(unsigned char channel) {
constexpr unsigned char my92xxChannel(unsigned char channel) {
return _my92xx_mapping[channel]; return _my92xx_mapping[channel];
} }
@ -54,10 +80,12 @@ constexpr unsigned char my92xxChannel(unsigned char channel) {
(channel == 1) ? MY92XX_CH2 : (channel == 1) ? MY92XX_CH2 :
(channel == 2) ? MY92XX_CH3 : (channel == 2) ? MY92XX_CH3 :
(channel == 3) ? MY92XX_CH4 : (channel == 3) ? MY92XX_CH4 :
(channel == 4) ? MY92XX_CH5 : 255u;
(channel == 4) ? MY92XX_CH5 : Light::ChannelsMax;
} }
} // namespace build
} // namespace Light
#endif
#endif #endif
} // namespace build
} // namespace Light

+ 0
- 1
code/test/build/light_dimmer.h View File

@ -1,5 +1,4 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define LIGHT_CHANNELS 5
#define LIGHT_CH1_PIN 5 #define LIGHT_CH1_PIN 5
#define LIGHT_CH2_PIN 4 #define LIGHT_CH2_PIN 4
#define LIGHT_CH3_PIN 12 #define LIGHT_CH3_PIN 12


+ 1
- 1
code/test/build/light_my92xx.h View File

@ -1,10 +1,10 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX
#define LIGHT_CHANNELS 5
#define MY92XX_MODEL MY92XX_MODEL_MY9231 #define MY92XX_MODEL MY92XX_MODEL_MY9231
#define MY92XX_CHIPS 2 #define MY92XX_CHIPS 2
#define MY92XX_DI_PIN 1 #define MY92XX_DI_PIN 1
#define MY92XX_DCKI_PIN 2 #define MY92XX_DCKI_PIN 2
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_CHANNELS 5
#define MY92XX_CH1 4 #define MY92XX_CH1 4
#define MY92XX_CH2 3 #define MY92XX_CH2 3
#define MY92XX_CH3 5 #define MY92XX_CH3 5


Loading…
Cancel
Save