Added SetOption37 for RGB remapping

This commit is contained in:
Gabor Simon 2019-02-24 12:07:15 +00:00
parent ff68b20148
commit 4492a14574
6 changed files with 106 additions and 32 deletions

3
sonoff/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.pio
.pioenvs
.piolibdeps

67
sonoff/.travis.yml Normal file
View File

@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < https://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < https://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run
#
# Template #2: The project is intended to be used as a library with examples.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

View File

@ -421,7 +421,6 @@
// #define USE_ALECTO_V2 // Add support for decoding Alecto V2 sensors like ACH2010, WS3000 and DKW2012 weather stations using 868MHz RF sensor receiver (+1k7 code)
#define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code)
#define USE_SM16716_RGB_ORDER SM16716_RGB // SM16716 RGB order (SM16716_RGB, SM16716_RBG, SM16716_GRB, SM16716_GBR, SM16716_BRG, SM16716_BGR)
/*********************************************************************************************\
* Debug features are only supported in development branch

View File

@ -587,6 +587,7 @@ void SettingsDefaultSet2(void)
// Settings.flag.stop_flash_rotate = 0;
Settings.save_data = SAVE_DATA;
Settings.param[P_BOOT_LOOP_OFFSET] = BOOT_LOOP_OFFSET;
Settings.param[P_RGB_REMAP] = RGB_REMAP_RGB;
Settings.sleep = APP_SLEEP;
if (Settings.sleep < 50) {
Settings.sleep = 50; // Default to 50 for sleep, for now
@ -1055,6 +1056,9 @@ void SettingsDelta(void)
if (Settings.version < 0x06040110) {
ModuleDefault(WEMOS);
}
if (Settings.version < 0x06040112) {
Settings.param[P_RGB_REMAP] = RGB_REMAP_RGB;
}
Settings.version = VERSION;
SettingsSave(1);

View File

@ -171,12 +171,16 @@ typedef unsigned long power_t; // Power (Relay) type
#define LT_SM16716 16 // Lights that use SM16716 will have this bit set in light_type
#define SM16716_RGB 0
#define SM16716_RBG 1
#define SM16716_GRB 2
#define SM16716_GBR 3
#define SM16716_BRG 4
#define SM16716_BGR 5
// Remap constants are 3-digit ternary numbers, each digit tells where the corresponding color component is mapped *from*
// digit 0 = ( n % 3) tells where the red is mapped from (0=red, 1=green, 2=blue)
// digit 1 = ((n/3) % 3) tells where the green is mapped from
// digit 2 = ((n/9) % 3) tells where the blue is mapped from
#define RGB_REMAP_RGB (0*1 + 1*3 + 2*9)
#define RGB_REMAP_RBG (0*1 + 2*3 + 1*9)
#define RGB_REMAP_GRB (1*1 + 0*3 + 2*9)
#define RGB_REMAP_GBR (1*1 + 2*3 + 0*9)
#define RGB_REMAP_BRG (2*1 + 0*3 + 1*9)
#define RGB_REMAP_BGR (2*1 + 1*3 + 0*9)
#define MQTT_PUBSUBCLIENT 1 // Mqtt PubSubClient library
#define MQTT_TASMOTAMQTT 2 // Mqtt TasmotaMqtt library based on esp-mqtt-arduino - soon obsolete
@ -237,7 +241,7 @@ enum ButtonStates { PRESSED, NOT_PRESSED };
enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER };
enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49
enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49
enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_MAX_SENSORS};

View File

@ -397,12 +397,6 @@ void SM16716_SendByte(uint8_t v)
}
}
void SM16716_SendRGB(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b) {
SM16716_SendByte(duty_r);
SM16716_SendByte(duty_g);
SM16716_SendByte(duty_b);
}
void SM16716_Update(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b)
{
if (sm16716_pin_sel < 99) {
@ -437,30 +431,18 @@ void SM16716_Update(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b)
// send start bit
SM16716_SendBit(1);
// send 24-bit rgb data
#if USE_SM16716_RGB_ORDER == SM16716_RGB
SM16716_SendRGB(duty_r, duty_g, duty_b);
#elif USE_SM16716_RGB_ORDER == SM16716_RBG
SM16716_SendRGB(duty_r, duty_b, duty_g);
#elif USE_SM16716_RGB_ORDER == SM16716_GRB
SM16716_SendRGB(duty_g, duty_r, duty_b);
#elif USE_SM16716_RGB_ORDER == SM16716_GBR
SM16716_SendRGB(duty_g, duty_b, duty_r);
#elif USE_SM16716_RGB_ORDER == SM16716_BRG
SM16716_SendRGB(duty_b, duty_r, duty_g);
#elif USE_SM16716_RGB_ORDER == SM16716_BGR
SM16716_SendRGB(duty_b, duty_g, duty_r);
#else
// fall back to RGB
SM16716_SendRGB(duty_r, duty_g, duty_b);
#endif
SM16716_SendByte(duty_r);
SM16716_SendByte(duty_g);
SM16716_SendByte(duty_b);
// send a 'do it' pulse
// (if multiple chips are chained, each one processes the 1st '1rgb' 25-bit block and
// passes on the rest, right until the one starting with 0)
//SM16716_Init();
SM16716_SendBit(0);
SM16716_SendRGB(0, 0, 0);
SM16716_SendByte(0);
SM16716_SendByte(0);
SM16716_SendByte(0);
}
bool SM16716_ModuleSelected(void)
@ -980,6 +962,21 @@ void LightAnimate(void)
light_last_color[i] = light_new_color[i];
cur_col[i] = light_last_color[i]*Settings.rgbwwTable[i]/255;
cur_col[i] = (Settings.light_correction) ? ledTable[cur_col[i]] : cur_col[i];
}
// RGB remapping
uint8_t rgb_mapping = Settings.param[P_RGB_REMAP];
if (rgb_mapping != RGB_REMAP_RGB) {
uint8_t orig_col[3];
memcpy(orig_col, cur_col, sizeof(orig_col));
for (uint8_t i = 0; i < 3; i++) {
cur_col[i] = orig_col[rgb_mapping % 3];
rgb_mapping /= 3;
}
}
for (uint8_t i = 0; i < light_subtype; i++) {
if (light_type < LT_PWM6) {
if (pin[GPIO_PWM1 +i] < 99) {
if (cur_col[i] > 0xFC) {