Browse Source

lights: refactor my92xx mapping build flags

mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
34d63c155d
5 changed files with 71 additions and 21 deletions
  1. +24
    -0
      code/espurna/config/defaults.h
  2. +14
    -8
      code/espurna/config/hardware.h
  3. +2
    -9
      code/espurna/light.cpp
  4. +26
    -3
      code/espurna/light_config.h
  5. +5
    -1
      code/test/build/light_my92xx.h

+ 24
- 0
code/espurna/config/defaults.h View File

@ -1043,6 +1043,30 @@
#define LIGHT_CH5_INVERSE 0 #define LIGHT_CH5_INVERSE 0
#endif #endif
// -----------------------------------------------------------------------------
// my92xx
// -----------------------------------------------------------------------------
#ifndef MY92XX_CH1
#define MY92XX_CH1 0
#endif
#ifndef MY92XX_CH2
#define MY92XX_CH2 1
#endif
#ifndef MY92XX_CH3
#define MY92XX_CH3 2
#endif
#ifndef MY92XX_CH4
#define MY92XX_CH4 3
#endif
#ifndef MY92XX_CH5
#define MY92XX_CH5 4
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Tuya // Tuya
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 14
- 8
code/espurna/config/hardware.h View File

@ -832,12 +832,19 @@
// Light // Light
#define LIGHT_CHANNELS 5 #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 12 #define MY92XX_DI_PIN 12
#define MY92XX_DCKI_PIN 14 #define MY92XX_DCKI_PIN 14
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
#define MY92XX_MAPPING 4, 3, 5, 0, 1
#define MY92XX_CH1 4
#define MY92XX_CH2 3
#define MY92XX_CH3 5
#define MY92XX_CH4 0
#define MY92XX_CH5 1
#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
#elif defined(ITEAD_SONOFF_LED) #elif defined(ITEAD_SONOFF_LED)
@ -1256,7 +1263,6 @@
#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_MAPPING 0, 1, 2, 3
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Lyasi LED // Lyasi LED
@ -1276,7 +1282,6 @@
#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_MAPPING 0, 1, 2, 3
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// LED Controller // LED Controller
@ -1916,7 +1921,6 @@
#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_MAPPING 0, 1, 2, 3
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// XENON SM-PW701U // XENON SM-PW701U
@ -3885,7 +3889,7 @@
#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_MAPPING 0, 1, 2, 3, 4
#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
// https://www.amazon.com/gp/product/B07T7W7ZMW // https://www.amazon.com/gp/product/B07T7W7ZMW
@ -4111,14 +4115,17 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX #define LIGHT_PROVIDER LIGHT_PROVIDER_MY92XX
// Light // Light
#define LIGHT_CHANNELS 5
#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
// 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_MAPPING 255, 255, 255, 3, 0
#define MY92XX_CH1 3
#define MY92XX_CH2 0
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Lombex Lux Nova 2 White and Color // Lombex Lux Nova 2 White and Color
@ -4140,7 +4147,6 @@
#define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT #define MY92XX_COMMAND MY92XX_COMMAND_DEFAULT
// 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
#define MY92XX_MAPPING 0, 1, 2, 3
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Bestek Smart Plug with 2 USB ports // Bestek Smart Plug with 2 USB ports


+ 2
- 9
code/espurna/light.cpp View File

@ -138,19 +138,12 @@ 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> #include <my92xx.h>
my92xx * _my92xx;
unsigned char _light_channel_map[] {
MY92XX_MAPPING
};
my92xx* _my92xx { nullptr };
#endif #endif
#if LIGHT_PROVIDER == LIGHT_PROVIDER_CUSTOM #if LIGHT_PROVIDER == LIGHT_PROVIDER_CUSTOM
std::unique_ptr<LightProvider> _light_provider; std::unique_ptr<LightProvider> _light_provider;
#endif #endif
// UI hint about channel distribution // UI hint about channel distribution
@ -870,7 +863,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_channel_map[channel], pwm);
_my92xx->setChannel(_lightMy92xxChannel(channel), pwm);
#endif #endif
} }


+ 26
- 3
code/espurna/light_config.h View File

@ -8,11 +8,11 @@ LIGHT MODULE
#include "espurna.h" #include "espurna.h"
constexpr const unsigned char _lightEnablePin() {
constexpr unsigned char _lightEnablePin() {
return LIGHT_ENABLE_PIN; return LIGHT_ENABLE_PIN;
} }
constexpr const unsigned char _lightChannelPin(unsigned char index) {
constexpr unsigned char _lightChannelPin(unsigned char index) {
return ( return (
(index == 0) ? LIGHT_CH1_PIN : (index == 0) ? LIGHT_CH1_PIN :
(index == 1) ? LIGHT_CH2_PIN : (index == 1) ? LIGHT_CH2_PIN :
@ -22,7 +22,7 @@ constexpr const unsigned char _lightChannelPin(unsigned char index) {
); );
} }
constexpr const bool _lightInverse(unsigned char index) {
constexpr bool _lightInverse(unsigned char index) {
return ( return (
(index == 0) ? (1 == LIGHT_CH1_INVERSE) : (index == 0) ? (1 == LIGHT_CH1_INVERSE) :
(index == 1) ? (1 == LIGHT_CH2_INVERSE) : (index == 1) ? (1 == LIGHT_CH2_INVERSE) :
@ -32,3 +32,26 @@ constexpr const bool _lightInverse(unsigned char index) {
); );
} }
#ifdef MY92XX_MAPPING
constexpr unsigned char _my92xx_mapping[LIGHT_CHANNELS] {
MY92XX_MAPPING
};
constexpr unsigned char _lightMy92xxChannel(unsigned char)
__attribute__((deprecated("MY92XX_CH# flags should be used instead of MY92XX_MAPPING")));
constexpr unsigned char _lightMy92xxChannel(unsigned char channel) {
return _my92xx_mapping[channel];
}
#else
constexpr unsigned char _lightMy92xxChannel(unsigned char channel) {
return (channel == 0) ? MY92XX_CH1 :
(channel == 1) ? MY92XX_CH2 :
(channel == 2) ? MY92XX_CH3 :
(channel == 3) ? MY92XX_CH4 :
(channel == 4) ? MY92XX_CH5 : 255u;
}
#endif

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

@ -5,5 +5,9 @@
#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_MAPPING 4,3,5,0,1
#define MY92XX_CH1 4
#define MY92XX_CH2 3
#define MY92XX_CH3 5
#define MY92XX_CH4 0
#define MY92XX_CH5 1
#define IR_SUPPORT 1 #define IR_SUPPORT 1

Loading…
Cancel
Save