From 00509d7cd1a8fe50aa3803ebf93d5d2ee3c236d2 Mon Sep 17 00:00:00 2001 From: Adminius Date: Fri, 3 Apr 2020 20:44:53 +0200 Subject: [PATCH] Release 0.3.0 --- ALEDD1.ino | 364 ++++++++++----------- KONNEKTING_ALEDD1.kdevice.xml | 319 +++++++++++++++--- aledd1.h | 17 +- animations.h | 593 +++++++++++++++++----------------- defines.h | 61 ++++ fakeEEPROM.h | 283 ++++++++++------ kdevice_ALEDD1.h | 228 +++++++++---- knx_events.h | 293 +++++++++++++++++ led_functions.h | 196 +++++++++-- scenes.h | 85 ++--- 10 files changed, 1644 insertions(+), 795 deletions(-) create mode 100644 defines.h create mode 100644 knx_events.h diff --git a/ALEDD1.ino b/ALEDD1.ino index 4d51e49..46b5542 100644 --- a/ALEDD1.ino +++ b/ALEDD1.ino @@ -1,20 +1,21 @@ /* --------------------------------------------------------------------------------------------- -ALEDD 0.2.0 beta (work in progress) +ALEDD 0.3.0 beta (work in progress) Hardware/Firmware/Sketch/kdevice.xml by E.Burkowski / e.burkowski@konnekting.de, GPL Licensed Compatible with: KONNEKTING Device Library 1.0.0 beta 4b */ /* this libraries are required (click on link and download with library manager): -FlashStorage: http://librarymanager/All#FlashStorage -DimmerControl: http://librarymanager/All#DimmerControl -Adafruit Neopixel: http://librarymanager/All#Adafruit_Neopixel -Adafruit_ZeroDMA: http://librarymanager/All#Zero_DMA -Adafruit Neopixel ZeroDMA: http://librarymanager/All#Adafruit_DMA_neopixel_library -NeoPixel Painter: http://librarymanager/All#NeoPixel_Painter -KONNEKTING Device Library: http://librarymanager/All#Konnekting +FlashStorage: http://librarymanager/All#FlashStorage +DimmerControl: http://librarymanager/All#DimmerControl +Adafruit Neopixel: http://librarymanager/All#Adafruit_Neopixel +Adafruit_ZeroDMA: http://librarymanager/All#Zero_DMA +Adafruit Neopixel ZeroDMA 1.0.8: http://librarymanager/All#Adafruit_DMA_neopixel_library +NeoPixel Painter: http://librarymanager/All#NeoPixel_Painter +KONNEKTING Device Library: http://librarymanager/All#Konnekting */ //developer settings +//#define DEVELOPMENT //#define FAKE_EEPROM //don't use this ;) //#define KDEBUG // comment this line to disable DEBUG mode @@ -28,16 +29,7 @@ KONNEKTING Device Library: http://librarymanager/All#Konnekting #include "aledd1.h" #include "kdevice_ALEDD1.h" - - - -//DPT3.007 stuff -#define DPT3_007_MASK_DIRECTION B1000 -#define DPT3_007_INCREASE B1000 -#define DPT3_007_DECREASE B0000 -#define DPT3_007_MASK_STEP B0111 -#define DPT3_007_STOP B0000 - +#include "defines.h" #ifdef KDEBUG #include "src/KonnektingDeviceLibrary/DebugUtil.h" @@ -48,36 +40,33 @@ KONNEKTING Device Library: http://librarymanager/All#Konnekting #endif //global variables - -#define USERCOLORS 5 -#define R 0 -#define G 1 -#define B 2 -#define W 3 - - bool initialized = false; -byte currentTask = 0xFE; //0xFE - idle -byte lastTask = 0xFE; +byte currentTask = TASK_IDLE; //0xFE - idle +byte lastTask = TASK_IDLE; +byte lastTaskBeforeMessage = 0; // all LEDs are off +byte lastStaticColor[4] = {0, 0, 0, 0}; +bool staticColorReady = false; byte sendSceneNumber = 0xFF; byte lastDimmerValue = 0; +unsigned long lastAnimMillis = 0; byte curveR[256]; byte curveG[256]; byte curveB[256]; byte curveW[256]; -#define DEBOUNCE 80 //ms word longClickDurationBtn = 500; unsigned long clickMillis = 0; bool buttonPressed = false; bool ledTestMode = false; +bool pixelsShow = false; //XML group: LED uint8_t ledType = 0xC6; // ~ NEO_RGBW, see Adafruit_NeoPixel.h for more infos bool rgbw = true; byte mixedWhite[] = {255,240,224}; uint16_t numberLeds = 600; //amount of leds on a stripe +uint8_t firstOnValue = 1; uint8_t maxR = 255; // to match the same brightness on different colors uint8_t maxG = 255; // reduce brightnes of some colors uint8_t maxB = 255; // also usefull to make not "to blueisch" white @@ -112,14 +101,47 @@ unsigned long rgbwChangedMillis = 0; unsigned long hsvChangedMillis = 0; word rgbwhsvChangedDelay = 50; - +//XML group messages: +//Message 1 +bool statusM1 = false; //false = wait and do nothing, true = show message1Value +byte newValueM1 = 0; //0 = all LEDs off, 1-255 corresponds to percentage of leds (255 = all LEDs are on, 127 = only 50% of LEDs are on) +byte lastValueM1 = 0; +word ledFirstM1; +word ledLastM1; +byte ledColorM1[4] = {0, 0, 0, 0}; +//Message 2 +bool statusM2 = false; //false = wait and do nothing, true = show message1Value +byte newValueM2 = 0; //0 = all LEDs off, 1-255 corresponds to percentage of leds (255 = all LEDs are on, 128 = only 50% of LEDs are on) +byte lastValueM2 = 0; +word ledFirstM2; +word ledLastM2; +byte ledColorM2[4] = {0, 0, 0, 0}; +//Message 3 +bool statusM3 = false; //false = wait and do nothing, true = show message1Value +byte newValueM3 = 0; //0 = all LEDs off, 1-255 corresponds to percentage of leds (255 = all LEDs are on, 127 = only 50% of LEDs are on) +byte lastValueM3 = 0; +word ledFirstM3; +word ledLastM3; +byte ledColorM3[4] = {0, 0, 0, 0}; +//Message 4 +bool statusM4 = false; //false = wait and do nothing, true = show message1Value +byte newValueM4 = 0; //0 = all LEDs off, 1-255 corresponds to percentage of leds (255 = all LEDs are on, 128 = only 50% of LEDs are on) +byte lastValueM4 = 0; +word ledFirstM4; +word ledLastM4; +byte ledColorM4[4] = {0, 0, 0, 0}; //XML group: Power supply control +bool allLedsOff = true; bool powerSupplyState = false; +bool powerSupplyTurnOn = false; +bool powerSupplyTurnOff = false; bool powerSupplyControl = false; -unsigned long powerSupplyOffDelay = 0; //munutes -bool powerSupplyOffDelayOnGoing = false; +unsigned long powerSupplyOffDelay = 30000; unsigned long powerSupplyOffMillis = 0; +bool psStateChecked = false; +unsigned long psStateCheckedMillis = 0; +bool lastState = false; //create some instances Adafruit_NeoPixel_ZeroDMA *neopixels; @@ -132,17 +154,23 @@ NeoPixelPainterBrush *pixelbrush4on2; //brush 4 on cancas 2 HSV brushcolor; DimmerControl dimmer; +//make functions known +void showPixels (); + #include "hsvrgb.h" #include "animations.h" + #include "led_functions.h" #include "scenes.h" #include "button.h" - +#include "knx_events.h" void setup() { pinMode(PROG_LED_PIN, OUTPUT); pinMode(PROG_BUTTON_PIN, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(PROG_BUTTON_PIN), progButtonPressed, CHANGE); + pinMode(POWER_SUPPLY_PIN, INPUT); + attachInterrupt(PROG_BUTTON_PIN, progButtonPressed, CHANGE); + #ifdef KDEBUG SerialUSB.begin(115200); while (!SerialUSB); @@ -157,11 +185,10 @@ void setup() { Konnekting.setMemoryUpdateFunc(&updateMemory); Konnekting.setMemoryCommitFunc(&commitMemory); Konnekting.init(SerialKNX, &progLed, MANUFACTURER_ID, DEVICE_ID, REVISION); -// Konnekting.init(SerialKNX, PROG_BUTTON_PIN, PROG_LED_PIN, MANUFACTURER_ID, DEVICE_ID, REVISION); - + #ifndef FAKE_EEPROM for (int i = 0; i < Konnekting.getFreeEepromOffset(); i++) { - Debug.println(F("writeMemory(%d,0x%02X);"), i, EEPROM.read(i)); + Debug.println(F("\t\twriteMemory(%d,0x%02X);"), i, EEPROM.read(i)); } #endif if (!Konnekting.isFactorySetting()){ @@ -170,6 +197,7 @@ void setup() { if(ledType == NEO_RGB || ledType == NEO_RBG || ledType == NEO_GRB || ledType == NEO_GBR || ledType == NEO_BRG || ledType == NEO_BGR) rgbw = false; numberLeds = Konnekting.getUINT16Param(PARAM_number_leds_strip); + firstOnValue = Konnekting.getUINT8Param(PARAM_first_on_value); maxR = Konnekting.getUINT8Param(PARAM_r_correction); maxG = Konnekting.getUINT8Param(PARAM_g_correction); maxB = Konnekting.getUINT8Param(PARAM_b_correction); @@ -185,7 +213,9 @@ void setup() { valueMinDay = Konnekting.getUINT8Param(PARAM_day_min); valueMaxDay = Konnekting.getUINT8Param(PARAM_day_max); valueMinNight = Konnekting.getUINT8Param(PARAM_night_min); - + valueMaxNight = Konnekting.getUINT8Param(PARAM_night_max); + //set day values until we know if it is day or night + setDayNightValues(false); //XML group: User colors for (byte uc = 0; uc < USERCOLORS; uc++) { ucRed[uc] = Konnekting.getUINT8Param(PARAM_uc1r + 4 * uc); @@ -193,13 +223,51 @@ void setup() { ucBlue[uc] = Konnekting.getUINT8Param(PARAM_uc1b + 4 * uc); ucWhite[uc] = Konnekting.getUINT8Param(PARAM_uc1w + 4 * uc); } + //XML group: Message 1: + ledFirstM1 = Konnekting.getUINT16Param(PARAM_m1first) - 1; //Code: count from 0.., Suite: Count from 1.. + ledLastM1 = Konnekting.getUINT16Param(PARAM_m1last) - 1; + ledColorM1[R] = Konnekting.getUINT8Param(PARAM_m1r); + ledColorM1[G] = Konnekting.getUINT8Param(PARAM_m1g); + ledColorM1[B] = Konnekting.getUINT8Param(PARAM_m1b); + ledColorM1[W] = Konnekting.getUINT8Param(PARAM_m1w); + //XML group: Message 2: + ledFirstM2 = Konnekting.getUINT16Param(PARAM_m2first) - 1; + ledLastM2 = Konnekting.getUINT16Param(PARAM_m2last) - 1; + ledColorM2[R] = Konnekting.getUINT8Param(PARAM_m2r); + ledColorM2[G] = Konnekting.getUINT8Param(PARAM_m2g); + ledColorM2[B] = Konnekting.getUINT8Param(PARAM_m2b); + ledColorM2[W] = Konnekting.getUINT8Param(PARAM_m2w); + //XML group: Message 3: + ledFirstM3 = Konnekting.getUINT16Param(PARAM_m3first) - 1; //Code: count from 0.., Suite: Count from 1.. + ledLastM3 = Konnekting.getUINT16Param(PARAM_m3last) - 1; + ledColorM3[R] = Konnekting.getUINT8Param(PARAM_m3r); + ledColorM3[G] = Konnekting.getUINT8Param(PARAM_m3g); + ledColorM3[B] = Konnekting.getUINT8Param(PARAM_m3b); + ledColorM3[W] = Konnekting.getUINT8Param(PARAM_m3w); + //XML group: Message 4: + ledFirstM4 = Konnekting.getUINT16Param(PARAM_m4first) - 1; + ledLastM4 = Konnekting.getUINT16Param(PARAM_m4last) - 1; + ledColorM4[R] = Konnekting.getUINT8Param(PARAM_m4r); + ledColorM4[G] = Konnekting.getUINT8Param(PARAM_m4g); + ledColorM4[B] = Konnekting.getUINT8Param(PARAM_m4b); + ledColorM4[W] = Konnekting.getUINT8Param(PARAM_m4w); + //XML group: power supply + powerSupplyControl = Konnekting.getUINT8Param(PARAM_ps_control); + powerSupplyOffDelay = Konnekting.getUINT8Param(PARAM_ps_delay_off) * 60000; + if(!powerSupplyControl){ + powerSupplyState = true; + } #ifdef KDEBUG + Debug.println(F("User Colors:")); Debug.println(F("Idx\tR\tG\tB\tW")); for (byte uc = 0; uc < USERCOLORS; uc++) { Debug.println(F("%d\t%d\t%d\t%d\t%d"),uc,ucRed[uc],ucGreen[uc],ucBlue[uc],ucWhite[uc]); - } + } + Debug.println(F("Message 1: first LED: %d, last LED: %d, R: %d, G: %d, B: %d, W: %d"), ledFirstM1, ledLastM1, ledColorM1[R], ledColorM1[G], ledColorM1[B], ledColorM1[W]); + Debug.println(F("Message 2: first LED: %d, last LED: %d, R: %d, G: %d, B: %d, W: %d"), ledFirstM2, ledLastM2, ledColorM2[R], ledColorM2[G], ledColorM2[B], ledColorM2[W]); + Debug.println(F("Message 3: first LED: %d, last LED: %d, R: %d, G: %d, B: %d, W: %d"), ledFirstM3, ledLastM3, ledColorM3[R], ledColorM3[G], ledColorM3[B], ledColorM3[W]); + Debug.println(F("Message 4: first LED: %d, last LED: %d, R: %d, G: %d, B: %d, W: %d"), ledFirstM4, ledLastM4, ledColorM4[R], ledColorM4[G], ledColorM4[B], ledColorM4[W]); #endif - setDimmingCurves(); initStrip(numberLeds, ledType); } @@ -215,16 +283,66 @@ void setup() { } } +void powerSupply(){ + if(powerSupplyControl){ + if(!lastStaticColor[R] && !lastStaticColor[G] && !lastStaticColor[B] && !lastStaticColor[W] && + !lastValueM1 && !lastValueM2 && !lastValueM3 && !lastValueM4 && currentTask == TASK_IDLE){ + allLedsOff = true; + }else{ + allLedsOff = false; + } + if(powerSupplyTurnOn && !powerSupplyState){ + Knx.write(COMOBJ_power_supply, DPT1_001_on); + Debug.println(F("Turn PS on!")); + powerSupplyTurnOn = false; + } + if(powerSupplyState && allLedsOff && !powerSupplyTurnOff){//power supply is on and all LEDs are off => start to 'turn off power supply' routine + powerSupplyTurnOff = true; + powerSupplyOffMillis = millis(); + Debug.println(F("All LEDs are off, start 'turn off power supply' routine")); + } + if(powerSupplyState && !allLedsOff && powerSupplyTurnOff){//power supply is on and some LEDs are on => PS stays on + powerSupplyTurnOff = false; + Debug.println(F("Some LEDs are on, stop 'turn off power supply' routine")); + } + if(!powerSupplyState && allLedsOff && powerSupplyTurnOff){//stop "power off" routine, PS is already off + Debug.println(F("All LEDs are off, Power Supply is also off, stop 'turn off power supply' routine")); + powerSupplyTurnOff = false; + } + if(powerSupplyTurnOff && (millis() - powerSupplyOffMillis) >= powerSupplyOffDelay){ + Debug.println(F("Time is over, turn PS off")); + Knx.write(COMOBJ_power_supply, DPT1_001_off); + powerSupplyTurnOff = false; + } + } +} + void loop() { Knx.task(); if (Konnekting.isReadyForApplication()) { - dimmer.task(); - taskFunction(); + if(psStateChecked && millis() - psStateCheckedMillis >= 100){ //debounce + psStateChecked = false; + } + if(!psStateChecked){ + powerSupplyState = !digitalRead(POWER_SUPPLY_PIN); //low = ON, high = OFF + psStateCheckedMillis = millis(); + psStateChecked = true; + if(lastState != powerSupplyState){ + lastState = powerSupplyState; + Debug.println(F("PowerSupply state: %d"), powerSupplyState); + } + } + + if(powerSupplyState) { //wait until PS is on... + dimmer.task(); + taskFunction(); + } + powerSupply(); if(rgbwChanged){ if(millis() - rgbwChangedMillis > rgbwhsvChangedDelay && !acceptNewRGBW){ Debug.println(F("apply new rgb(w) values")); - Debug.println(F("newRGBW R: %d, G: %d, B: %d, W: %d"),newRGBW[R],newRGBW[G],newRGBW[B],newRGBW[W]); - Debug.println(F("valuesRGBW R: %d, G: %d, B: %d, W: %d \n"),valuesRGBW[R],valuesRGBW[G],valuesRGBW[B],valuesRGBW[W]); + Debug.println(F("newRGBW R: %d, G: %d, B: %d, W: %d"), newRGBW[R], newRGBW[G], newRGBW[B], newRGBW[W]); + Debug.println(F("valuesRGBW R: %d, G: %d, B: %d, W: %d \n"), valuesRGBW[R], valuesRGBW[G], valuesRGBW[B], valuesRGBW[W]); valuesRGBW[R] = newRGBW[R]; valuesRGBW[G] = newRGBW[G]; @@ -254,161 +372,17 @@ void loop() { Debug.println(F("Send to Obj: %d value: 0"), COMOBJ_dim_state); //if one of channels is off... all can't be on // allChannelsOn = false; - sendSceneNumber = 0; //all off + sendSceneNumber = 0; //all off } Knx.write(COMOBJ_dim_value, dimmer.getCurrentValue()); Debug.println(F("Send to Obj: %d value: %d"), COMOBJ_dim_value, dimmer.getCurrentValue()); - lastDimmerValue = dimmer.getCurrentValue(); + lastDimmerValue = dimmer.getCurrentValue(); dimmer.resetUpdateFlag(); } - if(sendSceneNumber < 64){ - Debug.println(F("Send to Obj: %d value: %d"), COMOBJ_scene_state, sendSceneNumber); - Knx.write(COMOBJ_scene_state, sendSceneNumber); - sendSceneNumber = 0xFF; - } - } -} - - - -void knxEvents(byte comObjIndex) { - Debug.println(F("knxEvents comObjIndex: %d"), comObjIndex); - lastTask = currentTask; - byte newTask = 0xFF; - initialized = false; - switch (comObjIndex) { - case COMOBJ_dim_sw: // Switch - newTask = DIMMER; - - taskSoftOnOff(Knx.read(comObjIndex)); - Debug.println(F("taskSoftOnOff: %d"), Knx.read(comObjIndex)); -// powerSupplyTask(); - break; - - case COMOBJ_dim_rel : // Relative dimming - newTask = DIMMER; - taskDimUpDownStop(Knx.read(comObjIndex)); - Debug.println(F("taskDimUpDownStop: %d"), Knx.read(comObjIndex)); -// powerSupplyTask(); - break; - - case COMOBJ_dim_abs : // Absolute dimming - newTask = DIMMER; - taskNewValue(Knx.read(comObjIndex)); - Debug.println(F("taskNewValue: %d"), Knx.read(comObjIndex)); -// powerSupplyTask(); - break; - - case COMOBJ_scene : // Scene - newTask = Knx.read(comObjIndex); - Debug.println(F("newTask: 0x%02X"), newTask); - - if (newTask != 0xFF) { - currentTask = newTask; - acceptNewRGBW = true; - } -// powerSupplyTask(); - break; - case COMOBJ_RGB : // RGB 232.600 - acceptNewRGBW = true; - newTask = TASK_RGB; - Debug.println(F("newTask: 0x%02X"), newTask); - Knx.read(comObjIndex, new3Byte); - valuesRGBW[R] = new3Byte[R]; - valuesRGBW[G] = new3Byte[G]; - valuesRGBW[B] = new3Byte[B]; - valuesRGBW[W] = 0; - if (newTask != 0xFF) currentTask = newTask; -// powerSupplyTask(); - break; - case COMOBJ_RGBW : // RGBW 251.600 - acceptNewRGBW = true; - newTask = TASK_RGBW; - Debug.println(F("newTask: 0x%02X"), newTask); - Knx.read(comObjIndex, new6Byte); - valuesRGBW[R] = new6Byte[2]; - valuesRGBW[G] = new6Byte[3]; - valuesRGBW[B] = new6Byte[4]; - valuesRGBW[W] = new6Byte[5]; - Debug.println(F("valuesRGBW R: %d, G: %d, B: %d, W: %d \n"),valuesRGBW[R],valuesRGBW[G],valuesRGBW[B],valuesRGBW[W]); - - if (newTask != 0xFF) currentTask = newTask; -// powerSupplyTask(); - break; - case COMOBJ_HSV : // HSV 232.600 - acceptNewHSV = true; - newTask = TASK_HSV; - Debug.println(F("newTask: 0x%02X"), newTask); - Knx.read(comObjIndex, valuesHSV); - Debug.println(F("valuesHSV H: %d, S: %d, V: %d\n"),valuesHSV[0],valuesHSV[1],valuesHSV[2]); - - if (newTask != 0xFF) currentTask = newTask; -// powerSupplyTask(); - break; - - case COMOBJ_r : - rgbwChanged = true; - rgbwChangedMillis = millis(); - newRGBW[R] = Knx.read(comObjIndex); - Debug.println(F("new R: %d / 0x%02x"), newRGBW[R], newRGBW[R]); - newTask = TASK_RGBW; - if (newTask != 0xFF) currentTask = newTask; - break; - case COMOBJ_g : - rgbwChanged = true; - rgbwChangedMillis = millis(); - newRGBW[G] = Knx.read(comObjIndex); - Debug.println(F("new G: %d / 0x%02x"), newRGBW[G], newRGBW[G]); - newTask = TASK_RGBW; - if (newTask != 0xFF) currentTask = newTask; - break; - case COMOBJ_b : - rgbwChanged = true; - rgbwChangedMillis = millis(); - newRGBW[B] = Knx.read(comObjIndex); - Debug.println(F("new B: %d / 0x%02x"), newRGBW[B], newRGBW[B]); - newTask = TASK_RGBW; - if (newTask != 0xFF) currentTask = newTask; - break; - case COMOBJ_w : - rgbwChanged = true; - rgbwChangedMillis = millis(); - newRGBW[W] = Knx.read(comObjIndex); - Debug.println(F("new W: %d / 0x%02x"), newRGBW[W], newRGBW[W]); - newTask = TASK_RGBW; - if (newTask != 0xFF) currentTask = newTask; - break; - - case COMOBJ_h : - hsvChanged = true; - hsvChangedMillis = millis(); - newHSV[0] = Knx.read(comObjIndex); - Debug.println(F("new H"), newHSV[0]); - newTask = TASK_HSV; - if (newTask != 0xFF) currentTask = newTask; - break; - case COMOBJ_s : - hsvChanged = true; - hsvChangedMillis = millis(); - newHSV[1] = Knx.read(comObjIndex); - Debug.println(F("new S"), newHSV[1]); - newTask = TASK_HSV; - if (newTask != 0xFF) currentTask = newTask; - break; - case COMOBJ_v : - hsvChanged = true; - hsvChangedMillis = millis(); - newHSV[2] = Knx.read(comObjIndex); - Debug.println(F("new S"), newHSV[2]); - newTask = TASK_HSV; - if (newTask != 0xFF) currentTask = newTask; - break; - - default: - break; + if(sendSceneNumber < 64){ + Debug.println(F("Send to Obj: %d value: %d"), COMOBJ_scene_state, sendSceneNumber); + Knx.write(COMOBJ_scene_state, sendSceneNumber); + sendSceneNumber = 0xFF; + } } - if(newTask != lastTask && newTask < 64){ - //0 .. 63 are KNX scenes, 64 .. 255 for internal use only! - sendSceneNumber = newTask; - } } diff --git a/KONNEKTING_ALEDD1.kdevice.xml b/KONNEKTING_ALEDD1.kdevice.xml index 3ca7d2d..c2736eb 100644 --- a/KONNEKTING_ALEDD1.kdevice.xml +++ b/KONNEKTING_ALEDD1.kdevice.xml @@ -1,6 +1,6 @@ - + KONNEKTING ALEDD1 @@ -13,155 +13,273 @@ Number of LEDs [1..600] - + + First ON value [1..15] + + + Red color correction [100..255] - + Green color correction [100..255] - + Blue color correction [100..255] - + White color correction [100..255] - + Gamma correction [value * 0.1] - + Mixed white: R part - + Mixed white: G part - + Mixed white: B part - + Soft on/off time - + Relative dimming time - + Min. value day [0..254] - + Max. value day [1..255] - + Min. value night [0..254] - + Max. value night [1..255] - + R - + G - + B - + W - + R - + G - + B - + W - + R - + G - + B - + W - + R - + G - + B - + W - + + R + + + + G + + + + B + + + + W + + + + + + First LED [1..1199] + + + + Last LED [1..1199] + + + + R + + + + G + + + + B + + + + W + + + + + + First LED [1..1199] + + + + Last LED [1..1199] + + + + R + + + + G + + + + B + + + + W + + + + + + First LED [1..1199] + + + + Last LED [1..1199] + + + + R + + + + G + + + + B + + + + W + + + + + + First LED [1..1199] + + + + Last LED [1..1199] + + + R - + G - + B - + W + + + Automatic power supply control + + + + Power supply off after [0..180min] + + + @@ -260,19 +378,142 @@ 232.600 42 - + Scene Status Value 17.001 52 + + Message 1 + Switch + 1.001 + 42 + + + Message 1 + Percentage [0..100] + 5.001 + 42 + + + Message 1 color + RGB + 232.600 + 42 + + + Message 1 color + RGBW + 251.600 + 42 + + + Message 2 + Switch + 1.001 + 42 + + + Message 2 + Percentage [0..100] + 5.001 + 42 + + + Message 2 color + RGB + 232.600 + 42 + + + Message 2 color + RGBW + 251.600 + 42 + + + Message 3 + Switch + 1.001 + 42 + + + Message 3 + Percentage [0..100] + 5.001 + 42 + + + Message 3 color + RGB + 232.600 + 42 + + + Message 3 color + RGBW + 251.600 + 42 + + + Message 4 + Switch + 1.001 + 42 + + + Message 4 + Percentage [0..100] + 5.001 + 42 + + + Message 4 color + RGB + 232.600 + 42 + + + Message 4 color + RGBW + 251.600 + 42 + + + Power supply + Switch + 1.001 + 52 + - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aledd1.h b/aledd1.h index 7929be2..19fdffc 100644 --- a/aledd1.h +++ b/aledd1.h @@ -1,18 +1,31 @@ +#ifndef DEVELOPMENT //ALEDD //create a new Serial on Pins 1=TX and 3=RX Uart SerialKNX (&sercom2, 3, 1, SERCOM_RX_PAD_1, UART_TX_PAD_2); //+pinPeripheral //Interrupt handler for SerialKNX void SERCOM2_Handler() { - SerialKNX.IrqHandler(); + SerialKNX.IrqHandler(); } //Hardware settings #define PROG_BUTTON_PIN 2 //active low #define PROG_LED_PIN 8 #define LED_STRIP_PIN 22 -#define VOLTAGE_OK 38 //active low +#define POWER_SUPPLY_PIN 38 //active low #define EEPROM_EMULATION_SIZE 2048 +#else //test board +//Hardware settings +#define PROG_BUTTON_PIN 7 //active low +#define PROG_LED_PIN 13 +#define LED_STRIP_PIN 6 //LED shield +#define POWER_SUPPLY_PIN 8 //active low +#define EEPROM_EMULATION_SIZE 2048 +#define SerialKNX Serial +#endif + + + #ifndef FAKE_EEPROM byte readMemory(int index) { Debug.println(F("FLASH read on index %d"),index); diff --git a/animations.h b/animations.h index 5bed61f..186f14d 100644 --- a/animations.h +++ b/animations.h @@ -1,328 +1,327 @@ -void rainbow() { - static unsigned int hue = 0; //color hue to set to brush - // HSV brushcolor; //HSV color definition - - if (initialized == false) { - initialized = true; - Debug.println(F("rainbow init")); - neopixels->clear(); - pixelbrush->setSpeed(8000 / numberLeds); //brush moving speed - pixelbrush->setFadeSpeed(90); - pixelbrush->setFadein(false); //brightness will fade-in if set to true - pixelbrush->setFadeout(true); - pixelbrush->setBounce(true); - } - - hue++; - brushcolor.h = hue / 3; //divide by 3 to slow down color fading - brushcolor.s = 255; //full saturation - brushcolor.v = 255; //full brightness - - pixelbrush->setColor(brushcolor); //set new color to the bursh - neopixels->clear(); - - pixelbrush->paint(); //paint the brush to the canvas (and update the brush, i.e. move it a little) - pixelcanvas->transfer(); //transfer (add) the canvas to the neopixels - - neopixels->show(); +// Input a value 0 to 255 to get a color value. +// The colours are a transition r - g - b - back to r. +uint32_t hueDisc(byte pos) { + pos = 255 - pos; + if(pos < 85) { + return neopixels->Color(255 - pos * 3, 0, pos * 3); + } + if(pos < 170) { + pos -= 85; + return neopixels->Color(0, pos * 3, 255 - pos * 3); + } + pos -= 170; + return neopixels->Color(pos * 3, 255 - pos * 3, 0); +} +void rainbow(){ + static uint16_t h = 0; + if (initialized == false) { + initialized = true; + lastAnimMillis = 0; + h = 0; + } + if(millis() - lastAnimMillis >= 50){ + for(uint16_t i = 0; i < numberLeds; i++) { + neopixels->setPixelColor(numberLeds - 1 - i, hueDisc(((i * 256 / numberLeds) + h) & 255)); + } + h++; + if(h > 1280) h = 0; + pixelsShow = true; + lastAnimMillis = millis(); + } } void singlergb(){ - //let set single RGB color to whole strip and go though hue disk - //ToDo + static byte h = 0; + if (initialized == false) { + initialized = true; + lastAnimMillis = 0; + } + if(millis() - lastAnimMillis >= 100){ + for (uint16_t i = 0; i < numberLeds; i++) { + neopixels->setPixelColor(i, hueDisc(h)); + } + h++; + pixelsShow = true; + lastAnimMillis = millis(); + } } - void sparkler() { - // HSV brushcolor; - - if (initialized == false) { - initialized = true; - Debug.println(F("sparkler init")); - pixelbrush->setSpeed(300 * numberLeds / 50); //original 600 - pixelbrush->setFadeout(true); //sparkles fade in - pixelbrush->setFadein(true); //and fade out immediately after reaching the set brightness - pixelbrush->setBounce(true); - } - - //set a new brush color in each loop - brushcolor.h = random(255); //random color - brushcolor.s = random(130); //random but low saturation, giving white-ish sparkles - brushcolor.v = random(200); //random (peak) brighness - - pixelbrush->setColor(brushcolor); - pixelbrush->setFadeSpeed(random(100) + 150); //set a new fadespeed with some randomness - - neopixels->clear(); - - pixelbrush->paint(); //paint the brush to the canvas (and update the brush, i.e. move it a little) - pixelcanvas->transfer(); //transfer (add) the canvas to the neopixels - - neopixels->show(); + if (initialized == false) { + initialized = true; + Debug.println(F("sparkler init")); + pixelbrush->setSpeed(300 * numberLeds / 50); //original 600 + pixelbrush->setFadeout(true); //sparkles fade in + pixelbrush->setFadein(true); //and fade out immediately after reaching the set brightness + pixelbrush->setBounce(true); + } + + //set a new brush color in each loop + brushcolor.h = random(255); //random color + brushcolor.s = random(130); //random but low saturation, giving white-ish sparkles + brushcolor.v = random(200); //random (peak) brighness + + pixelbrush->setColor(brushcolor); + pixelbrush->setFadeSpeed(random(100) + 150); //set a new fadespeed with some randomness + + neopixels->clear(); + + pixelbrush->paint(); //paint the brush to the canvas (and update the brush, i.e. move it a little) + pixelcanvas->transfer(); //transfer (add) the canvas to the neopixels + + pixelsShow = true; } void twinkystars() { - // HSV brushcolor; - - if (initialized == false) { - initialized = true; - Debug.println(F("twinkystars init")); - neopixels->clear(); - pixelbrush->setSpeed(0); //do not move automatically - pixelbrush->setFadein(true); //fade in - pixelbrush->setFadeout(true); //and fade out - } - - if (rand() % 100 == 0) { - brushcolor.h = rand(); - brushcolor.s = random(40); //set low saturation, almost white - brushcolor.v = random(200) + 20; //set random brightness - pixelbrush->setColor(brushcolor); - pixelbrush->moveTo(random(numberLeds)); //move the brush to a new, random pixel - pixelbrush->setFadeSpeed(random(10) + 5); //set random fade speed, minimum of 5 - } - - //add a background color by setting all pixels to a color (instead of clearing all pixels): - // int i; - for (int i = 0; i < numberLeds; i++) { - neopixels->setPixelColor(i, 1, 0, 6); //color in RGB: dark blue - } - - pixelbrush->paint(); //paint the brush to the canvas - pixelcanvas->transfer(); //transfer (add) the canvas to the neopixels - - neopixels->show(); + if (initialized == false) { + initialized = true; + Debug.println(F("twinkystars init")); + neopixels->clear(); + pixelbrush->setSpeed(0); //do not move automatically + pixelbrush->setFadein(true); //fade in + pixelbrush->setFadeout(true); //and fade out + } + + if (rand() % 100 == 0) { + brushcolor.h = rand(); + brushcolor.s = random(40); //set low saturation, almost white + brushcolor.v = random(200) + 20; //set random brightness + pixelbrush->setColor(brushcolor); + pixelbrush->moveTo(random(numberLeds)); //move the brush to a new, random pixel + pixelbrush->setFadeSpeed(random(10) + 5); //set random fade speed, minimum of 5 + } + + //add a background color by setting all pixels to a color (instead of clearing all pixels): + for (int i = 0; i < numberLeds; i++) { + neopixels->setPixelColor(i, 1, 0, 6); //color in RGB: dark blue + } + + pixelbrush->paint(); //paint the brush to the canvas + pixelcanvas->transfer(); //transfer (add) the canvas to the neopixels + + pixelsShow = true; } void chaser() { - if (initialized == false) { - // HSV brushcolor; - - initialized = true; - Debug.println(F("chaser init")); + if (initialized == false) { + initialized = true; + Debug.println(F("chaser init")); + neopixels->clear(); + brushcolor.h = random(255); //choose random color once + brushcolor.s = 255; //full staturation + brushcolor.v = 150; + + //initialize the first brush to move and paint a color, no fading + pixelbrush->setSpeed(8000 / numberLeds); //moving speed //900 + pixelbrush->setColor(brushcolor); + pixelbrush->setFadeout(true); + pixelbrush->setFadein(true); + pixelbrush->setBounce(true); + pixelbrush2->moveTo(0); //move the brush to pixel 0 + //initialize the second brush to move at the same speed but starting at a different position (default position is 0) + brushcolor.v = 0; //zero intensity = black + pixelbrush2->setSpeed(8000 / numberLeds); + pixelbrush2->setColor(brushcolor); + pixelbrush2->setFadeout(true); + pixelbrush2->moveTo(2 * numberLeds / 3); //move the brush + pixelbrush2->setBounce(true); + + } + neopixels->clear(); - brushcolor.h = random(255); //choose random color once - brushcolor.s = 255; //full staturation - brushcolor.v = 150; - - //initialize the first brush to move and paint a color, no fading - pixelbrush->setSpeed(8000 / numberLeds); //moving speed //900 - pixelbrush->setColor(brushcolor); - pixelbrush->setFadeout(true); - pixelbrush->setFadein(true); - pixelbrush->setBounce(true); - pixelbrush2->moveTo(0); //move the brush to pixel 0 - //initialize the second brush to move at the same speed but starting at a different position (default position is 0) - brushcolor.v = 0; //zero intensity = black - pixelbrush2->setSpeed(8000 / numberLeds); - pixelbrush2->setColor(brushcolor); - pixelbrush2->setFadeout(true); - pixelbrush2->moveTo(2 * numberLeds / 3); //move the brush - pixelbrush2->setBounce(true); - - } - - neopixels->clear(); - pixelbrush->paint(); //apply the paint of the first brush to the canvas (and update the brush) - pixelbrush2->paint(); //apply the paint of the second brush to the canvas (and update the brush) - pixelcanvas->transfer(); //transfer the canvas to the neopixels - neopixels->show(); + pixelbrush->paint(); //apply the paint of the first brush to the canvas (and update the brush) + pixelbrush2->paint(); //apply the paint of the second brush to the canvas (and update the brush) + pixelcanvas->transfer(); //transfer the canvas to the neopixels + showPixels(); } void huefader() { - static unsigned int lastposition = 0; - if (pixelbrush->getPosition() == 0 && lastposition > 0) initialized = false; - lastposition = pixelbrush->getPosition(); - if (initialized == false) { - initialized = true; - Debug.println(F("huefader init")); - - HSV brushcolor; - - brushcolor.h = random(255); //random color - brushcolor.s = 255; //full saturation - brushcolor.v = 130; //medium brightness - - pixelbrush->setSpeed(random(150) + 150); //random movement speed - pixelbrush->setFadeSpeed(random(10) + 20); //set random fading speed - pixelbrush->setColor(brushcolor); //update the color of the brush - pixelbrush->setFadeHueNear(true); //fade using the near path on the colorcircle - - //second brush paints on the same canvas - brushcolor.h = random(255); - pixelbrush2->setSpeed(random(150) + 150); - pixelbrush2->setFadeSpeed(random(10) + 20); - pixelbrush2->setColor(brushcolor); - pixelbrush2->setFadeHueNear(true); //fade using the near path on the colorcircle - //pixelbrush->setFadeHueFar(true); //fade using the far path on the colorcircle (if both are set, this path is chosen) - pixelbrush2->setBounce(true); //bounce this brush at the end of the strip - } - neopixels->clear(); - pixelbrush->paint(); //apply the paint of the first brush to the canvas (and update the brush) - pixelbrush2->paint(); //apply the paint of the second brush to the canvas (and update the brush) - pixelcanvas->transfer(); //transfer the canvas to the neopixels - neopixels->show(); + static unsigned int lastposition = 0; + if (pixelbrush->getPosition() == 0 && lastposition > 0) initialized = false; + lastposition = pixelbrush->getPosition(); + if (initialized == false) { + initialized = true; + Debug.println(F("huefader init")); + + HSV brushcolor; + + brushcolor.h = random(255); //random color + brushcolor.s = 255; //full saturation + brushcolor.v = 130; //medium brightness + + pixelbrush->setSpeed(random(150) + 150); //random movement speed + pixelbrush->setFadeSpeed(random(10) + 20); //set random fading speed + pixelbrush->setColor(brushcolor); //update the color of the brush + pixelbrush->setFadeHueNear(true); //fade using the near path on the colorcircle + + //second brush paints on the same canvas + brushcolor.h = random(255); + pixelbrush2->setSpeed(random(150) + 150); + pixelbrush2->setFadeSpeed(random(10) + 20); + pixelbrush2->setColor(brushcolor); + pixelbrush2->setFadeHueNear(true); //fade using the near path on the colorcircle + //pixelbrush->setFadeHueFar(true); //fade using the far path on the colorcircle (if both are set, this path is chosen) + pixelbrush2->setBounce(true); //bounce this brush at the end of the strip + } + neopixels->clear(); + pixelbrush->paint(); //apply the paint of the first brush to the canvas (and update the brush) + pixelbrush2->paint(); //apply the paint of the second brush to the canvas (and update the brush) + pixelcanvas->transfer(); //transfer the canvas to the neopixels + pixelsShow = true; } void speedtrails() { - // int brushspeed = 900; - // HSV brushcolor; - if (initialized == false) { - initialized = true; - Debug.println(F("speedtrails init")); - int brushspeed = 900; - brushcolor.h = 0; - brushcolor.s = 0; //make it white - brushcolor.v = 150; //medium brightness - pixelbrush->setColor(brushcolor); - pixelbrush->setSpeed(brushspeed); - pixelbrush->setFadeSpeed(250); //fast fading (255 is max.) - pixelbrush->setFadeHueNear(false); //deactivate hue fading, was activated in last animation - pixelbrush->setFadeout(true); - pixelbrush->moveTo(0); //move brush to zero - - //second brush - brushcolor.h = 0; //red - brushcolor.s = 250; - brushcolor.v = 150; - pixelbrush2->setSpeed(brushspeed); - pixelbrush2->setFadeSpeed(220); - pixelbrush2->setFadeout(true); - pixelbrush2->setColor(brushcolor); - pixelbrush2->moveTo(numberLeds / 3); //move it up one third of the strip - - //third brush - brushcolor.h = 28; //yellow - brushcolor.s = 255; - brushcolor.v = 100; - pixelbrush3->setSpeed(brushspeed); - pixelbrush3->setFadeSpeed(190); - pixelbrush3->setFadeout(true); - pixelbrush3->setColor(brushcolor); - pixelbrush3->moveTo(2 * numberLeds / 3); //move it up two thirds of the strip - } - - neopixels->clear(); - pixelbrush->paint(); //apply the paint of the first brush to the canvas (and update the brush) - pixelbrush2->paint(); //apply the paint of the second brush to the canvas (and update the brush) - pixelbrush3->paint(); //apply the paint of the third brush to the canvas (and update the brush) - pixelcanvas->transfer(); //transfer the canvas to the neopixels (and update i.e. fade pixels) - neopixels->show(); + if (initialized == false) { + initialized = true; + Debug.println(F("speedtrails init")); + int brushspeed = 900; + brushcolor.h = 0; + brushcolor.s = 0; //make it white + brushcolor.v = 150; //medium brightness + pixelbrush->setColor(brushcolor); + pixelbrush->setSpeed(brushspeed); + pixelbrush->setFadeSpeed(250); //fast fading (255 is max.) + pixelbrush->setFadeHueNear(false); //deactivate hue fading, was activated in last animation + pixelbrush->setFadeout(true); + pixelbrush->moveTo(0); //move brush to zero + + //second brush + brushcolor.h = 0; //red + brushcolor.s = 250; + brushcolor.v = 150; + pixelbrush2->setSpeed(brushspeed); + pixelbrush2->setFadeSpeed(220); + pixelbrush2->setFadeout(true); + pixelbrush2->setColor(brushcolor); + pixelbrush2->moveTo(numberLeds / 3); //move it up one third of the strip + + //third brush + brushcolor.h = 28; //yellow + brushcolor.s = 255; + brushcolor.v = 100; + pixelbrush3->setSpeed(brushspeed); + pixelbrush3->setFadeSpeed(190); + pixelbrush3->setFadeout(true); + pixelbrush3->setColor(brushcolor); + pixelbrush3->moveTo(2 * numberLeds / 3); //move it up two thirds of the strip + } + + neopixels->clear(); + pixelbrush->paint(); //apply the paint of the first brush to the canvas (and update the brush) + pixelbrush2->paint(); //apply the paint of the second brush to the canvas (and update the brush) + pixelbrush3->paint(); //apply the paint of the third brush to the canvas (and update the brush) + pixelcanvas->transfer(); //transfer the canvas to the neopixels (and update i.e. fade pixels) + pixelsShow = true; } void bouncyballs() { - // byte skipper = 0; - if (initialized == false) { - initialized = true; - Debug.println(F("bouncyballs init")); - // HSV brushcolor; - - brushcolor.h = 20; //orange - brushcolor.s = 240; //almost full saturation - brushcolor.v = 150; //medium brightness - - //first brush - pixelbrush->setSpeed(0); //zero initial speed - pixelbrush->setFadeSpeed(150); - pixelbrush->setFadeout(true); - pixelbrush->setColor(brushcolor); - pixelbrush->moveTo(numberLeds - 1); //move to end of the strip - pixelbrush->setBounce(true); //bounce if either end of the strip is reached - - //second brush - brushcolor.h = 220; //pink - pixelbrush2->setSpeed(0); //zero initial speed - pixelbrush2->setFadeSpeed(190); - pixelbrush2->setFadeout(true); - pixelbrush2->setColor(brushcolor); - pixelbrush2->moveTo(numberLeds / 3); //move to one third of the strip - pixelbrush2->setBounce(true); - - //third brush - brushcolor.h = 70; //green-ish (pure green is 85 or 255/3) - pixelbrush3->setSpeed(0); - pixelbrush3->setFadeSpeed(220); - pixelbrush3->setFadeout(true); - pixelbrush3->setColor(brushcolor); - pixelbrush3->moveTo(2 * numberLeds / 3); - pixelbrush3->setBounce(true); - - } - //apply some gravity force that accelerates the painters (i.e. add speed in negative direction = towards zero pixel) - // if (skipper % 5 == 0) //only apply gravity at some interval to make it slower on fast processors - // { - //read current speed of each brush and speed it up in negative direction (towards pixel zero) - pixelbrush->setSpeed(pixelbrush->getSpeed() - 10); - pixelbrush2->setSpeed(pixelbrush2->getSpeed() - 10); - pixelbrush3->setSpeed(pixelbrush3->getSpeed() - 10); - - // } - // skipper++; - neopixels->clear(); - pixelbrush->paint(); //apply the paint of the first brush to the canvas (and update the brush) - pixelbrush2->paint(); //apply the paint of the second brush to the canvas (and update the brush) - pixelbrush3->paint(); //apply the paint of the third brush to the canvas (and update the brush) - pixelcanvas->transfer(); //transfer the canvas to the neopixels (and update i.e. fade pixels) - neopixels->show(); + static byte skipper = 0; + if (initialized == false) { + initialized = true; + Debug.println(F("bouncyballs init")); + brushcolor.h = 20; //orange + brushcolor.s = 240; //almost full saturation + brushcolor.v = 150; //medium brightness + + //first brush + pixelbrush->setSpeed(0); //zero initial speed + pixelbrush->setFadeSpeed(150); + pixelbrush->setFadeout(true); + pixelbrush->setColor(brushcolor); + pixelbrush->moveTo(numberLeds - 1); //move to end of the strip + pixelbrush->setBounce(true); //bounce if either end of the strip is reached + + //second brush + brushcolor.h = 220; //pink + pixelbrush2->setSpeed(0); //zero initial speed + pixelbrush2->setFadeSpeed(190); + pixelbrush2->setFadeout(true); + pixelbrush2->setColor(brushcolor); + pixelbrush2->moveTo(numberLeds / 3); //move to one third of the strip + pixelbrush2->setBounce(true); + + //third brush + brushcolor.h = 70; //green-ish (pure green is 85 or 255/3) + pixelbrush3->setSpeed(0); + pixelbrush3->setFadeSpeed(220); + pixelbrush3->setFadeout(true); + pixelbrush3->setColor(brushcolor); + pixelbrush3->moveTo(2 * numberLeds / 3); + pixelbrush3->setBounce(true); + + } + //apply some gravity force that accelerates the painters (i.e. add speed in negative direction = towards zero pixel) + if (skipper % 5 == 0) //only apply gravity at some interval to make it slower on fast processors + { + //read current speed of each brush and speed it up in negative direction (towards pixel zero) + pixelbrush->setSpeed(pixelbrush->getSpeed() - 10); + pixelbrush2->setSpeed(pixelbrush2->getSpeed() - 10); + pixelbrush3->setSpeed(pixelbrush3->getSpeed() - 10); + + } + skipper++; + neopixels->clear(); + pixelbrush->paint(); //apply the paint of the first brush to the canvas (and update the brush) + pixelbrush2->paint(); //apply the paint of the second brush to the canvas (and update the brush) + pixelbrush3->paint(); //apply the paint of the third brush to the canvas (and update the brush) + pixelcanvas->transfer(); //transfer the canvas to the neopixels (and update i.e. fade pixels) + pixelsShow = true; } void twobrushcolormixing() { - // static bool firstrun = true; - - - if (initialized == false) { - initialized = true; - - brushcolor.s = 255; //full color saturation - brushcolor.v = 100; //medium-low brightness - brushcolor.h = 8; - - //setup the first brush - pixelbrush->setSpeed(-750); - pixelbrush->setSpeedlimit(1000); - pixelbrush->setFadeSpeed(random(80) + 50); - pixelbrush->setFadeout(true); - pixelbrush->setFadein(true); - pixelbrush->setColor(brushcolor); - pixelbrush->moveTo(random(numberLeds)); - pixelbrush->setBounce(true); - - //setup the second brush - brushcolor.h = 160; - pixelbrush4on2->setSpeed(600); - pixelbrush4on2->setSpeedlimit(1000); - pixelbrush4on2->setFadeSpeed(random(80) + 50); - pixelbrush4on2->setFadeout(true); - pixelbrush4on2->setFadein(true); - pixelbrush4on2->setColor(brushcolor); - pixelbrush4on2->moveTo(random(numberLeds)); - pixelbrush4on2->setBounce(true); - } - - - if (rand() % 10) { - brushcolor = pixelbrush->getColor(); - brushcolor.h += random(3) - 1; //randomly change hue a little ( ± random(1)) - pixelbrush->setColor(brushcolor); - - brushcolor = pixelbrush4on2->getColor(); - brushcolor.h += random(3) - 1; //randomly change hue a little ( ± random(1)) - pixelbrush4on2->setColor(brushcolor); - } - - //slowly change speed of both brushes - pixelbrush->setSpeed(pixelbrush->getSpeed() + random(6) - 3); //means speed = currentspeed ± random(3) - pixelbrush4on2->setSpeed(pixelbrush4on2->getSpeed() + random(6) - 3); //means speed = currentspeed ± random(3) - - neopixels->clear(); //remove any previously applied paint - pixelbrush->paint(); //apply the paint of the first brush to its assigned canvas (and update the brush) - pixelbrush4on2->paint(); //apply the paint of the second brush to its assigned canvas (and update the brush) - pixelcanvas->transfer(); //transfer the first canvas to the neopixels - pixelcanvas2->transfer(); //transfer the sedonc canvas to the neopixels (adding colors, rather than overwriting colors) - neopixels->show(); + if (initialized == false) { + initialized = true; + + brushcolor.s = 255; //full color saturation + brushcolor.v = 100; //medium-low brightness + brushcolor.h = 8; + + //setup the first brush + pixelbrush->setSpeed(-750); + pixelbrush->setSpeedlimit(1000); + pixelbrush->setFadeSpeed(random(80) + 50); + pixelbrush->setFadeout(true); + pixelbrush->setFadein(true); + pixelbrush->setColor(brushcolor); + pixelbrush->moveTo(random(numberLeds)); + pixelbrush->setBounce(true); + + //setup the second brush + brushcolor.h = 160; + pixelbrush4on2->setSpeed(600); + pixelbrush4on2->setSpeedlimit(1000); + pixelbrush4on2->setFadeSpeed(random(80) + 50); + pixelbrush4on2->setFadeout(true); + pixelbrush4on2->setFadein(true); + pixelbrush4on2->setColor(brushcolor); + pixelbrush4on2->moveTo(random(numberLeds)); + pixelbrush4on2->setBounce(true); + } + + + if (rand() % 10) { + brushcolor = pixelbrush->getColor(); + brushcolor.h += random(3) - 1; //randomly change hue a little ( ± random(1)) + pixelbrush->setColor(brushcolor); + + brushcolor = pixelbrush4on2->getColor(); + brushcolor.h += random(3) - 1; //randomly change hue a little ( ± random(1)) + pixelbrush4on2->setColor(brushcolor); + } + + //slowly change speed of both brushes + pixelbrush->setSpeed(pixelbrush->getSpeed() + random(6) - 3); //means speed = currentspeed ± random(3) + pixelbrush4on2->setSpeed(pixelbrush4on2->getSpeed() + random(6) - 3); //means speed = currentspeed ± random(3) + + neopixels->clear(); //remove any previously applied paint + pixelbrush->paint(); //apply the paint of the first brush to its assigned canvas (and update the brush) + pixelbrush4on2->paint(); //apply the paint of the second brush to its assigned canvas (and update the brush) + pixelcanvas->transfer(); //transfer the first canvas to the neopixels + pixelcanvas2->transfer(); //transfer the sedonc canvas to the neopixels (adding colors, rather than overwriting colors) + pixelsShow = true; } diff --git a/defines.h b/defines.h new file mode 100644 index 0000000..03e4874 --- /dev/null +++ b/defines.h @@ -0,0 +1,61 @@ +//DPT3.007 stuff +#define DPT3_007_MASK_DIRECTION B1000 +#define DPT3_007_INCREASE B1000 +#define DPT3_007_DECREASE B0000 +#define DPT3_007_MASK_STEP B0111 +#define DPT3_007_STOP B0000 + + + +//Scene 1 .. 9 +#define ALL_OFF 0x00 //1 +#define WHITE 0x01 //2 +#define RED 0x02 //3 +#define YELLOW 0x03 //4 +#define GREEN 0x04 //5 +#define CYAN 0x05 //6 +#define BLUE 0x06 //7 +#define PURPLE 0x07 //8 +#define ORANGE 0x08 //9 + +//Scenes 21 .. 25 +#define USER_COLOR_1 0x14 //21 +#define USER_COLOR_2 0x15 //22 +#define USER_COLOR_3 0x16 //23 +#define USER_COLOR_4 0x17 //24 +#define USER_COLOR_5 0x18 //25 + +//Scenes 41 .. 52 +#define RAINBOW 0x28 //41 +#define SINGLERGB 0x29 //42 +#define SPARKLER 0x2A //43 +#define TWINKYSTARS 0x2B //44 +#define CHASER 0x2C //45 +#define HUEFADER 0x2D //46 +#define SPEEDTRAILS 0x2E //47 +#define BOUNCYBALLS 0x2F //48 +#define TWOBRUSHCOLORMIXING 0x30 //49 + +#define WHIREMIDDLEON 0x32 //51 +#define WHIREMIDDLEOFF 0x33 //52 + +//Scene 61 .. 64 +#define TASK_RGB 0x3C +#define TASK_RGBW 0x3D +#define TASK_HSV 0x3E +#define TASK_DIMMER 0x3F + +#define TASK_IDLE 0xFE + +#define USERCOLORS 5 +#define R 0 +#define G 1 +#define B 2 +#define W 3 + +#define DEBOUNCE 80 //ms + +#define M_OFF 0 +#define M_OFF_WAIT 2 +#define M_ON 1 +#define M_ON_WAIT 3 diff --git a/fakeEEPROM.h b/fakeEEPROM.h index 50e7efc..e8e5979 100644 --- a/fakeEEPROM.h +++ b/fakeEEPROM.h @@ -20,104 +20,189 @@ void commitMemory() { } void initFakeEeprom(){ -writeMemory(0,0x7F); -writeMemory(1,0x11); -writeMemory(2,0xE0); -writeMemory(3,0xFF); -writeMemory(4,0xFF); -writeMemory(5,0xFF); -writeMemory(6,0xFF); -writeMemory(7,0xFF); -writeMemory(8,0xFF); -writeMemory(9,0xFF); -writeMemory(10,0x3E); -writeMemory(11,0x00); -writeMemory(12,0x80); -writeMemory(13,0x3E); -writeMemory(14,0x01); -writeMemory(15,0x80); -writeMemory(16,0x3E); -writeMemory(17,0x02); -writeMemory(18,0x80); -writeMemory(19,0x3E); -writeMemory(20,0x04); -writeMemory(21,0x80); -writeMemory(22,0x3E); -writeMemory(23,0x05); -writeMemory(24,0x80); -writeMemory(25,0x3E); -writeMemory(26,0x03); -writeMemory(27,0x80); -writeMemory(28,0x3E); -writeMemory(29,0x0A); -writeMemory(30,0x80); -writeMemory(31,0x3E); -writeMemory(32,0x0B); -writeMemory(33,0x80); -writeMemory(34,0x3E); -writeMemory(35,0x0C); -writeMemory(36,0x80); -writeMemory(37,0x3E); -writeMemory(38,0x0D); -writeMemory(39,0x80); -writeMemory(40,0x3E); -writeMemory(41,0x14); -writeMemory(42,0x80); -writeMemory(43,0x3E); -writeMemory(44,0x15); -writeMemory(45,0x80); -writeMemory(46,0x3E); -writeMemory(47,0x0E); -writeMemory(48,0x80); -writeMemory(49,0x3E); -writeMemory(50,0x0F); -writeMemory(51,0x80); -writeMemory(52,0x3E); -writeMemory(53,0x10); -writeMemory(54,0x80); -writeMemory(55,0x3E); -writeMemory(56,0x16); -writeMemory(57,0x80); -writeMemory(58,0x3E); -writeMemory(59,0x17); -writeMemory(60,0x80); -writeMemory(61,0xD2); -writeMemory(62,0x00); -writeMemory(63,0x1E); -writeMemory(64,0xFF); -writeMemory(65,0xFF); -writeMemory(66,0xFF); -writeMemory(67,0xFF); -writeMemory(68,0x1C); -writeMemory(69,0xFF); -writeMemory(70,0xFA); -writeMemory(71,0xE0); -writeMemory(72,0x02); -writeMemory(73,0x03); -writeMemory(74,0x00); -writeMemory(75,0xFF); -writeMemory(76,0x00); -writeMemory(77,0xFF); -writeMemory(78,0x00); -writeMemory(79,0x00); -writeMemory(80,0x00); -writeMemory(81,0x00); -writeMemory(82,0x00); -writeMemory(83,0x00); -writeMemory(84,0x00); -writeMemory(85,0x00); -writeMemory(86,0x00); -writeMemory(87,0x00); -writeMemory(88,0x00); -writeMemory(89,0x00); -writeMemory(90,0x00); -writeMemory(91,0x00); -writeMemory(92,0x00); -writeMemory(93,0x00); -writeMemory(94,0x00); -writeMemory(95,0x00); -writeMemory(96,0x00); -writeMemory(97,0x00); - + writeMemory(0,0xFF); + writeMemory(1,0xFF); + writeMemory(2,0xFF); + writeMemory(3,0xFF); + writeMemory(4,0xFF); + writeMemory(5,0xFF); + writeMemory(6,0xFF); + writeMemory(7,0xFF); + writeMemory(8,0xFF); + writeMemory(9,0xFF); + writeMemory(10,0xFF); + writeMemory(11,0xFF); + writeMemory(12,0xFF); + writeMemory(13,0xFF); + writeMemory(14,0xFF); + writeMemory(15,0xFF); + writeMemory(16,0xFF); + writeMemory(17,0xFF); + writeMemory(18,0xFF); + writeMemory(19,0xFF); + writeMemory(20,0xFF); + writeMemory(21,0xFF); + writeMemory(22,0xFF); + writeMemory(23,0xFF); + writeMemory(24,0xFF); + writeMemory(25,0xFF); + writeMemory(26,0xFF); + writeMemory(27,0xFF); + writeMemory(28,0xFF); + writeMemory(29,0xFF); + writeMemory(30,0xFF); + writeMemory(31,0xFF); + writeMemory(32,0xFF); + writeMemory(33,0xFF); + writeMemory(34,0xFF); + writeMemory(35,0xFF); + writeMemory(36,0xFF); + writeMemory(37,0xFF); + writeMemory(38,0xFF); + writeMemory(39,0xFF); + writeMemory(40,0xFF); + writeMemory(41,0xFF); + writeMemory(42,0xFF); + writeMemory(43,0xFF); + writeMemory(44,0xFF); + writeMemory(45,0xFF); + writeMemory(46,0xFF); + writeMemory(47,0xFF); + writeMemory(48,0xFF); + writeMemory(49,0xFF); + writeMemory(50,0xFF); + writeMemory(51,0xFF); + writeMemory(52,0xFF); + writeMemory(53,0xFF); + writeMemory(54,0xFF); + writeMemory(55,0xFF); + writeMemory(56,0xFF); + writeMemory(57,0xFF); + writeMemory(58,0xFF); + writeMemory(59,0xFF); + writeMemory(60,0xFF); + writeMemory(61,0xFF); + writeMemory(62,0xFF); + writeMemory(63,0xFF); + writeMemory(64,0xFF); + writeMemory(65,0xFF); + writeMemory(66,0xFF); + writeMemory(67,0xFF); + writeMemory(68,0xFF); + writeMemory(69,0xFF); + writeMemory(70,0xFF); + writeMemory(71,0xFF); + writeMemory(72,0xFF); + writeMemory(73,0xFF); + writeMemory(74,0xFF); + writeMemory(75,0xFF); + writeMemory(76,0xFF); + writeMemory(77,0xFF); + writeMemory(78,0xFF); + writeMemory(79,0xFF); + writeMemory(80,0xFF); + writeMemory(81,0xFF); + writeMemory(82,0xFF); + writeMemory(83,0xFF); + writeMemory(84,0xFF); + writeMemory(85,0xFF); + writeMemory(86,0xFF); + writeMemory(87,0xFF); + writeMemory(88,0xFF); + writeMemory(89,0xFF); + writeMemory(90,0xFF); + writeMemory(91,0xFF); + writeMemory(92,0xFF); + writeMemory(93,0xFF); + writeMemory(94,0xFF); + writeMemory(95,0xFF); + writeMemory(96,0xFF); + writeMemory(97,0xFF); + writeMemory(98,0xFF); + writeMemory(99,0xFF); + writeMemory(100,0xFF); + writeMemory(101,0xFF); + writeMemory(102,0xFF); + writeMemory(103,0xFF); + writeMemory(104,0xFF); + writeMemory(105,0xFF); + writeMemory(106,0xFF); + writeMemory(107,0xFF); + writeMemory(108,0xFF); + writeMemory(109,0xFF); + writeMemory(110,0xFF); + writeMemory(111,0xFF); + writeMemory(112,0xFF); + writeMemory(113,0xFF); + writeMemory(114,0xFF); + writeMemory(115,0xFF); + writeMemory(116,0xFF); + writeMemory(117,0xFF); + writeMemory(118,0xFF); + writeMemory(119,0xFF); + writeMemory(120,0xFF); + writeMemory(121,0xFF); + writeMemory(122,0xFF); + writeMemory(123,0xFF); + writeMemory(124,0xFF); + writeMemory(125,0xFF); + writeMemory(126,0xFF); + writeMemory(127,0xFF); + writeMemory(128,0xFF); + writeMemory(129,0xFF); + writeMemory(130,0xFF); + writeMemory(131,0xFF); + writeMemory(132,0xFF); + writeMemory(133,0xFF); + writeMemory(134,0xFF); + writeMemory(135,0xFF); + writeMemory(136,0xFF); + writeMemory(137,0xFF); + writeMemory(138,0xFF); + writeMemory(139,0xFF); + writeMemory(140,0xFF); + writeMemory(141,0xFF); + writeMemory(142,0xFF); + writeMemory(143,0xFF); + writeMemory(144,0xFF); + writeMemory(145,0xFF); + writeMemory(146,0xFF); + writeMemory(147,0xFF); + writeMemory(148,0xFF); + writeMemory(149,0xFF); + writeMemory(150,0xFF); + writeMemory(151,0xFF); + writeMemory(152,0xFF); + writeMemory(153,0xFF); + writeMemory(154,0xFF); + writeMemory(155,0xFF); + writeMemory(156,0xFF); + writeMemory(157,0xFF); + writeMemory(158,0xFF); + writeMemory(159,0xFF); + writeMemory(160,0xFF); + writeMemory(161,0xFF); + writeMemory(162,0xFF); + writeMemory(163,0xFF); + writeMemory(164,0xFF); + writeMemory(165,0xFF); + writeMemory(166,0xFF); + writeMemory(167,0xFF); + writeMemory(168,0xFF); + writeMemory(169,0xFF); + writeMemory(170,0xFF); + writeMemory(171,0xFF); + writeMemory(172,0xFF); + writeMemory(173,0xFF); + writeMemory(174,0xFF); + writeMemory(175,0xFF); + writeMemory(176,0xFF); + writeMemory(177,0xFF); + writeMemory(178,0xFF); + writeMemory(179,0xFF); + writeMemory(180,0xFF); + writeMemory(181,0xFF); + writeMemory(182,0xFF); + writeMemory(183,0xFF); } #endif diff --git a/kdevice_ALEDD1.h b/kdevice_ALEDD1.h index beba51c..d887785 100644 --- a/kdevice_ALEDD1.h +++ b/kdevice_ALEDD1.h @@ -1,6 +1,6 @@ #define MANUFACTURER_ID 7070 #define DEVICE_ID 50 -#define REVISION 0 +#define REVISION 1 #define COMOBJ_dim_sw 0 #define COMOBJ_dim_rel 1 @@ -19,42 +19,86 @@ #define COMOBJ_v 14 #define COMOBJ_HSV 15 #define COMOBJ_scene_state 16 +#define COMOBJ_m1sw 17 +#define COMOBJ_m1perc 18 +#define COMOBJ_m1rgb 19 +#define COMOBJ_m1rgbw 20 +#define COMOBJ_m2sw 21 +#define COMOBJ_m2perc 22 +#define COMOBJ_m2rgb 23 +#define COMOBJ_m2rgbw 24 +#define COMOBJ_m3sw 25 +#define COMOBJ_m3perc 26 +#define COMOBJ_m3rgb 27 +#define COMOBJ_m3rgbw 28 +#define COMOBJ_m4sw 29 +#define COMOBJ_m4perc 30 +#define COMOBJ_m4rgb 31 +#define COMOBJ_m4rgbw 32 +#define COMOBJ_power_supply 33 #define PARAM_led_type 0 #define PARAM_number_leds_strip 1 -#define PARAM_r_correction 2 -#define PARAM_g_correction 3 -#define PARAM_b_correction 4 -#define PARAM_w_correction 5 -#define PARAM_gamma_correction 6 -#define PARAM_wr 7 -#define PARAM_wg 8 -#define PARAM_wb 9 -#define PARAM_time_soft 10 -#define PARAM_time_rel 11 -#define PARAM_day_min 12 -#define PARAM_day_max 13 -#define PARAM_night_min 14 -#define PARAM_night_max 15 -#define PARAM_uc1r 16 -#define PARAM_uc1g 17 -#define PARAM_uc1b 18 -#define PARAM_uc1w 19 -#define PARAM_uc2r 20 -#define PARAM_uc2g 21 -#define PARAM_uc2b 22 -#define PARAM_uc2w 23 -#define PARAM_uc3r 24 -#define PARAM_uc3g 25 -#define PARAM_uc3b 26 -#define PARAM_uc3w 27 -#define PARAM_uc4r 28 -#define PARAM_uc4g 29 -#define PARAM_uc4b 30 -#define PARAM_uc4w 31 -#define PARAM_uc5r 32 -#define PARAM_uc5g 33 -#define PARAM_uc5b 34 -#define PARAM_uc5w 35 +#define PARAM_first_on_value 2 +#define PARAM_r_correction 3 +#define PARAM_g_correction 4 +#define PARAM_b_correction 5 +#define PARAM_w_correction 6 +#define PARAM_gamma_correction 7 +#define PARAM_wr 8 +#define PARAM_wg 9 +#define PARAM_wb 10 +#define PARAM_time_soft 11 +#define PARAM_time_rel 12 +#define PARAM_day_min 13 +#define PARAM_day_max 14 +#define PARAM_night_min 15 +#define PARAM_night_max 16 +#define PARAM_uc1r 17 +#define PARAM_uc1g 18 +#define PARAM_uc1b 19 +#define PARAM_uc1w 20 +#define PARAM_uc2r 21 +#define PARAM_uc2g 22 +#define PARAM_uc2b 23 +#define PARAM_uc2w 24 +#define PARAM_uc3r 25 +#define PARAM_uc3g 26 +#define PARAM_uc3b 27 +#define PARAM_uc3w 28 +#define PARAM_uc4r 29 +#define PARAM_uc4g 30 +#define PARAM_uc4b 31 +#define PARAM_uc4w 32 +#define PARAM_uc5r 33 +#define PARAM_uc5g 34 +#define PARAM_uc5b 35 +#define PARAM_uc5w 36 +#define PARAM_m1first 37 +#define PARAM_m1last 38 +#define PARAM_m1r 39 +#define PARAM_m1g 40 +#define PARAM_m1b 41 +#define PARAM_m1w 42 +#define PARAM_m2first 43 +#define PARAM_m2last 44 +#define PARAM_m2r 45 +#define PARAM_m2g 46 +#define PARAM_m2b 47 +#define PARAM_m2w 48 +#define PARAM_m3first 49 +#define PARAM_m3last 50 +#define PARAM_m3r 51 +#define PARAM_m3g 52 +#define PARAM_m3b 53 +#define PARAM_m3w 54 +#define PARAM_m4first 55 +#define PARAM_m4last 56 +#define PARAM_m4r 57 +#define PARAM_m4g 58 +#define PARAM_m4b 59 +#define PARAM_m4w 60 +#define PARAM_ps_control 61 +#define PARAM_ps_delay_off 62 KnxComObject KnxDevice::_comObjectsList[] = { /* Index 0 - dim_sw */ KnxComObject(KNX_DPT_1_001, 0x2b), @@ -73,46 +117,90 @@ KnxComObject KnxDevice::_comObjectsList[] = { /* Index 13 - s */ KnxComObject(KNX_DPT_5_004, 0x2a), /* Index 14 - v */ KnxComObject(KNX_DPT_5_004, 0x2a), /* Index 15 - HSV */ KnxComObject(KNX_DPT_232_600, 0x2a), - /* Index 16 - scene_state */ KnxComObject(KNX_DPT_17_001, 0x34) + /* Index 16 - scene_state */ KnxComObject(KNX_DPT_17_001, 0x34), + /* Index 17 - m1sw */ KnxComObject(KNX_DPT_1_001, 0x2a), + /* Index 18 - m1perc */ KnxComObject(KNX_DPT_5_001, 0x2a), + /* Index 19 - m1rgb */ KnxComObject(KNX_DPT_232_600, 0x2a), + /* Index 20 - m1rgbw */ KnxComObject(KNX_DPT_251_600, 0x2a), + /* Index 21 - m2sw */ KnxComObject(KNX_DPT_1_001, 0x2a), + /* Index 22 - m2perc */ KnxComObject(KNX_DPT_5_001, 0x2a), + /* Index 23 - m2rgb */ KnxComObject(KNX_DPT_232_600, 0x2a), + /* Index 24 - m2rgbw */ KnxComObject(KNX_DPT_251_600, 0x2a), + /* Index 25 - m3sw */ KnxComObject(KNX_DPT_1_001, 0x2a), + /* Index 26 - m3perc */ KnxComObject(KNX_DPT_5_001, 0x2a), + /* Index 27 - m3rgb */ KnxComObject(KNX_DPT_232_600, 0x2a), + /* Index 28 - m3rgbw */ KnxComObject(KNX_DPT_251_600, 0x2a), + /* Index 29 - m4sw */ KnxComObject(KNX_DPT_1_001, 0x2a), + /* Index 30 - m4perc */ KnxComObject(KNX_DPT_5_001, 0x2a), + /* Index 31 - m4rgb */ KnxComObject(KNX_DPT_232_600, 0x2a), + /* Index 32 - m4rgbw */ KnxComObject(KNX_DPT_251_600, 0x2a), + /* Index 33 - power_supply */ KnxComObject(KNX_DPT_1_001, 0x34) }; const byte KnxDevice::_numberOfComObjects = sizeof (_comObjectsList) / sizeof (KnxComObject); // do not change this code byte KonnektingDevice::_paramSizeList[] = { /* Index 0 - led_type */ PARAM_UINT8, /* Index 1 - number_leds_strip */ PARAM_UINT16, - /* Index 2 - r_correction */ PARAM_UINT8, - /* Index 3 - g_correction */ PARAM_UINT8, - /* Index 4 - b_correction */ PARAM_UINT8, - /* Index 5 - w_correction */ PARAM_UINT8, - /* Index 6 - gamma_correction */ PARAM_UINT8, - /* Index 7 - wr */ PARAM_UINT8, - /* Index 8 - wg */ PARAM_UINT8, - /* Index 9 - wb */ PARAM_UINT8, - /* Index 10 - time_soft */ PARAM_UINT8, - /* Index 11 - time_rel */ PARAM_UINT8, - /* Index 12 - day_min */ PARAM_UINT8, - /* Index 13 - day_max */ PARAM_UINT8, - /* Index 14 - night_min */ PARAM_UINT8, - /* Index 15 - night_max */ PARAM_UINT8, - /* Index 16 - uc1r */ PARAM_UINT8, - /* Index 17 - uc1g */ PARAM_UINT8, - /* Index 18 - uc1b */ PARAM_UINT8, - /* Index 19 - uc1w */ PARAM_UINT8, - /* Index 20 - uc2r */ PARAM_UINT8, - /* Index 21 - uc2g */ PARAM_UINT8, - /* Index 22 - uc2b */ PARAM_UINT8, - /* Index 23 - uc2w */ PARAM_UINT8, - /* Index 24 - uc3r */ PARAM_UINT8, - /* Index 25 - uc3g */ PARAM_UINT8, - /* Index 26 - uc3b */ PARAM_UINT8, - /* Index 27 - uc3w */ PARAM_UINT8, - /* Index 28 - uc4r */ PARAM_UINT8, - /* Index 29 - uc4g */ PARAM_UINT8, - /* Index 30 - uc4b */ PARAM_UINT8, - /* Index 31 - uc4w */ PARAM_UINT8, - /* Index 32 - uc5r */ PARAM_UINT8, - /* Index 33 - uc5g */ PARAM_UINT8, - /* Index 34 - uc5b */ PARAM_UINT8, - /* Index 35 - uc5w */ PARAM_UINT8 + /* Index 2 - first_on_value */ PARAM_UINT8, + /* Index 3 - r_correction */ PARAM_UINT8, + /* Index 4 - g_correction */ PARAM_UINT8, + /* Index 5 - b_correction */ PARAM_UINT8, + /* Index 6 - w_correction */ PARAM_UINT8, + /* Index 7 - gamma_correction */ PARAM_UINT8, + /* Index 8 - wr */ PARAM_UINT8, + /* Index 9 - wg */ PARAM_UINT8, + /* Index 10 - wb */ PARAM_UINT8, + /* Index 11 - time_soft */ PARAM_UINT8, + /* Index 12 - time_rel */ PARAM_UINT8, + /* Index 13 - day_min */ PARAM_UINT8, + /* Index 14 - day_max */ PARAM_UINT8, + /* Index 15 - night_min */ PARAM_UINT8, + /* Index 16 - night_max */ PARAM_UINT8, + /* Index 17 - uc1r */ PARAM_UINT8, + /* Index 18 - uc1g */ PARAM_UINT8, + /* Index 19 - uc1b */ PARAM_UINT8, + /* Index 20 - uc1w */ PARAM_UINT8, + /* Index 21 - uc2r */ PARAM_UINT8, + /* Index 22 - uc2g */ PARAM_UINT8, + /* Index 23 - uc2b */ PARAM_UINT8, + /* Index 24 - uc2w */ PARAM_UINT8, + /* Index 25 - uc3r */ PARAM_UINT8, + /* Index 26 - uc3g */ PARAM_UINT8, + /* Index 27 - uc3b */ PARAM_UINT8, + /* Index 28 - uc3w */ PARAM_UINT8, + /* Index 29 - uc4r */ PARAM_UINT8, + /* Index 30 - uc4g */ PARAM_UINT8, + /* Index 31 - uc4b */ PARAM_UINT8, + /* Index 32 - uc4w */ PARAM_UINT8, + /* Index 33 - uc5r */ PARAM_UINT8, + /* Index 34 - uc5g */ PARAM_UINT8, + /* Index 35 - uc5b */ PARAM_UINT8, + /* Index 36 - uc5w */ PARAM_UINT8, + /* Index 37 - m1first */ PARAM_UINT16, + /* Index 38 - m1last */ PARAM_UINT16, + /* Index 39 - m1r */ PARAM_UINT8, + /* Index 40 - m1g */ PARAM_UINT8, + /* Index 41 - m1b */ PARAM_UINT8, + /* Index 42 - m1w */ PARAM_UINT8, + /* Index 43 - m2first */ PARAM_UINT16, + /* Index 44 - m2last */ PARAM_UINT16, + /* Index 45 - m2r */ PARAM_UINT8, + /* Index 46 - m2g */ PARAM_UINT8, + /* Index 47 - m2b */ PARAM_UINT8, + /* Index 48 - m2w */ PARAM_UINT8, + /* Index 49 - m3first */ PARAM_UINT16, + /* Index 50 - m3last */ PARAM_UINT16, + /* Index 51 - m3r */ PARAM_UINT8, + /* Index 52 - m3g */ PARAM_UINT8, + /* Index 53 - m3b */ PARAM_UINT8, + /* Index 54 - m3w */ PARAM_UINT8, + /* Index 55 - m4first */ PARAM_UINT16, + /* Index 56 - m4last */ PARAM_UINT16, + /* Index 57 - m4r */ PARAM_UINT8, + /* Index 58 - m4g */ PARAM_UINT8, + /* Index 59 - m4b */ PARAM_UINT8, + /* Index 60 - m4w */ PARAM_UINT8, + /* Index 61 - ps_control */ PARAM_UINT8, + /* Index 62 - ps_delay_off */ PARAM_UINT8 }; const int KonnektingDevice::_numberOfParams = sizeof (_paramSizeList); // do not change this code diff --git a/knx_events.h b/knx_events.h new file mode 100644 index 0000000..c0a4f0a --- /dev/null +++ b/knx_events.h @@ -0,0 +1,293 @@ +void knxEvents(byte comObjIndex) { + Debug.println(F("knxEvents comObjIndex: %d"), comObjIndex); + lastTask = currentTask; + byte newTask = 0xFF; + byte tmpValue = 0; + bool tmpBool = false; + powerSupplyTurnOn = true; //dirty solution: if PS is off and LEDs are off and next command is "turn all off" PS will go on... and after timeout off. Is this a real use case?! + switch (comObjIndex) { + case COMOBJ_dim_sw: // Switch + newTask = TASK_DIMMER; + tmpBool = Knx.read(comObjIndex); + taskSoftOnOff(tmpBool); +// if(!tmpBool) powerSupplyTurnOn = false; + Debug.println(F("taskSoftOnOff: %d"), Knx.read(comObjIndex)); + break; + + case COMOBJ_dim_rel: // Relative dimming + newTask = TASK_DIMMER; + taskDimUpDownStop(Knx.read(comObjIndex)); + Debug.println(F("taskDimUpDownStop: %d"), Knx.read(comObjIndex)); + break; + + case COMOBJ_dim_abs: // Absolute dimming + newTask = TASK_DIMMER; + taskNewValue(Knx.read(comObjIndex)); + Debug.println(F("taskNewValue: %d"), Knx.read(comObjIndex)); + break; + + case COMOBJ_scene: // Scene + newTask = Knx.read(comObjIndex); + Debug.println(F("newTask: 0x%02X"), newTask); + + if (newTask != 0xFF) { + currentTask = newTask; + acceptNewRGBW = true; + initialized = false; + } + break; + case COMOBJ_RGB: // RGB 232.600 + acceptNewRGBW = true; + newTask = TASK_RGB; + Debug.println(F("newTask: 0x%02X"), newTask); + Knx.read(comObjIndex, new3Byte); + valuesRGBW[R] = new3Byte[R]; + valuesRGBW[G] = new3Byte[G]; + valuesRGBW[B] = new3Byte[B]; + valuesRGBW[W] = 0; + if (newTask != 0xFF) currentTask = newTask; + break; + case COMOBJ_RGBW: // RGBW 251.600 + acceptNewRGBW = true; + newTask = TASK_RGBW; + Debug.println(F("newTask: 0x%02X"), newTask); + Knx.read(comObjIndex, new6Byte); + valuesRGBW[R] = new6Byte[2]; + valuesRGBW[G] = new6Byte[3]; + valuesRGBW[B] = new6Byte[4]; + valuesRGBW[W] = new6Byte[5]; + Debug.println(F("valuesRGBW R: %d, G: %d, B: %d, W: %d \n"),valuesRGBW[R],valuesRGBW[G],valuesRGBW[B],valuesRGBW[W]); + + if (newTask != 0xFF) currentTask = newTask; + break; + case COMOBJ_HSV: // HSV 232.600 + acceptNewHSV = true; + newTask = TASK_HSV; + Debug.println(F("newTask: 0x%02X"), newTask); + Knx.read(comObjIndex, valuesHSV); + Debug.println(F("valuesHSV H: %d, S: %d, V: %d\n"),valuesHSV[0],valuesHSV[1],valuesHSV[2]); + + if (newTask != 0xFF) currentTask = newTask; + break; + + case COMOBJ_r: + rgbwChanged = true; + rgbwChangedMillis = millis(); + newRGBW[R] = Knx.read(comObjIndex); + Debug.println(F("new R: %d / 0x%02x"), newRGBW[R], newRGBW[R]); + newTask = TASK_RGBW; + if (newTask != 0xFF) currentTask = newTask; + break; + case COMOBJ_g: + rgbwChanged = true; + rgbwChangedMillis = millis(); + newRGBW[G] = Knx.read(comObjIndex); + Debug.println(F("new G: %d / 0x%02x"), newRGBW[G], newRGBW[G]); + newTask = TASK_RGBW; + if (newTask != 0xFF) currentTask = newTask; + break; + case COMOBJ_b: + rgbwChanged = true; + rgbwChangedMillis = millis(); + newRGBW[B] = Knx.read(comObjIndex); + Debug.println(F("new B: %d / 0x%02x"), newRGBW[B], newRGBW[B]); + newTask = TASK_RGBW; + if (newTask != 0xFF) currentTask = newTask; + break; + case COMOBJ_w: + rgbwChanged = true; + rgbwChangedMillis = millis(); + newRGBW[W] = Knx.read(comObjIndex); + Debug.println(F("new W: %d / 0x%02x"), newRGBW[W], newRGBW[W]); + newTask = TASK_RGBW; + if (newTask != 0xFF) currentTask = newTask; + break; + + case COMOBJ_h: + hsvChanged = true; + hsvChangedMillis = millis(); + newHSV[0] = Knx.read(comObjIndex); + Debug.println(F("new H"), newHSV[0]); + newTask = TASK_HSV; + if (newTask != 0xFF) currentTask = newTask; + break; + case COMOBJ_s: + hsvChanged = true; + hsvChangedMillis = millis(); + newHSV[1] = Knx.read(comObjIndex); + Debug.println(F("new S"), newHSV[1]); + newTask = TASK_HSV; + if (newTask != 0xFF) currentTask = newTask; + break; + case COMOBJ_v: + hsvChanged = true; + hsvChangedMillis = millis(); + newHSV[2] = Knx.read(comObjIndex); + Debug.println(F("new S"), newHSV[2]); + newTask = TASK_HSV; + if (newTask != 0xFF) currentTask = newTask; + break; + + case COMOBJ_m1sw: // Message 1 switch + if (Knx.read(comObjIndex)){ + newValueM1 = 255; + }else{ + newValueM1 = 0; + } + statusM1 = true; + break; + case COMOBJ_m1perc: // Message 1 percentage + newValueM1 = Knx.read(comObjIndex); + statusM1 = true; + break; + case COMOBJ_m1rgb: //Message 1 RGB + Knx.read(comObjIndex, new3Byte); + ledColorM1[R] = new3Byte[R]; + ledColorM1[G] = new3Byte[G]; + ledColorM1[B] = new3Byte[B]; + ledColorM1[W] = 0; + if(!ledColorM1[R] && !ledColorM1[G] && !ledColorM1[B]){ //RGBW = off + newValueM1 = 0; + }else{ + newValueM1 = 255; + } + statusM1 = true; + break; + case COMOBJ_m1rgbw: //Message 1 RGBW + Knx.read(comObjIndex, new6Byte); + ledColorM1[R] = new6Byte[2]; + ledColorM1[G] = new6Byte[3]; + ledColorM1[B] = new6Byte[4]; + ledColorM1[W] = new6Byte[5]; + if(!ledColorM1[R] && !ledColorM1[G] && !ledColorM1[B] && !ledColorM1[R]){ //RGBW = off + newValueM1 = 0; + }else{ + newValueM1 = 255; + } + statusM1 = true; + break; + + case COMOBJ_m2sw: // Message 2 switch + if (Knx.read(comObjIndex)){ + newValueM2 = 255; + }else{ + newValueM2 = 0; + } + statusM2 = true; + break; + case COMOBJ_m2perc: // Message 2 percentage + newValueM2 = Knx.read(comObjIndex); + statusM2 = true; + break; + case COMOBJ_m2rgb: //Message 2 RGB + Knx.read(comObjIndex, new3Byte); + ledColorM2[R] = new3Byte[R]; + ledColorM2[G] = new3Byte[G]; + ledColorM2[B] = new3Byte[B]; + ledColorM2[W] = 0; + if(!ledColorM2[R] && !ledColorM2[G] && !ledColorM2[B]){ //RGBW = off + newValueM2 = 0; + }else{ + newValueM2 = 255; + } + statusM1 = true; + break; + case COMOBJ_m2rgbw: //Message 2 RGBW + Knx.read(comObjIndex, new6Byte); + ledColorM2[R] = new6Byte[2]; + ledColorM2[G] = new6Byte[3]; + ledColorM2[B] = new6Byte[4]; + ledColorM2[W] = new6Byte[5]; + if(!ledColorM2[R] && !ledColorM2[G] && !ledColorM2[B] && !ledColorM2[W]){ //RGBW = off + newValueM2 = 0; + }else{ + newValueM2 = 255; + } + statusM2 = true; + break; + + case COMOBJ_m3sw: // Message 3 switch + if (Knx.read(comObjIndex)){ + newValueM3 = 255; + }else{ + newValueM3 = 0; + } + statusM3 = true; + break; + case COMOBJ_m3perc: // Message 3 percentage + newValueM3 = Knx.read(comObjIndex); + statusM3 = true; + break; + case COMOBJ_m3rgb: //Message 3 RGB + Knx.read(comObjIndex, new3Byte); + ledColorM3[R] = new3Byte[R]; + ledColorM3[G] = new3Byte[G]; + ledColorM3[B] = new3Byte[B]; + ledColorM3[W] = 0; + if(!ledColorM1[R] && !ledColorM1[G] && !ledColorM1[B]){ //RGBW = off + newValueM1 = 0; + }else{ + newValueM1 = 255; + } + statusM1 = true; + break; + case COMOBJ_m3rgbw: //Message 3 RGBW + Knx.read(comObjIndex, new6Byte); + ledColorM3[R] = new6Byte[2]; + ledColorM3[G] = new6Byte[3]; + ledColorM3[B] = new6Byte[4]; + ledColorM3[W] = new6Byte[5]; + if(!ledColorM3[R] && !ledColorM3[G] && !ledColorM3[B] && !ledColorM3[W]){ //RGBW = off + newValueM3 = 0; + }else{ + newValueM3 = 255; + } + statusM3 = true; + break; + + case COMOBJ_m4sw: // Message 4 switch + if (Knx.read(comObjIndex)){ + newValueM4 = 255; + }else{ + newValueM4 = 0; + } + statusM4 = true; + break; + case COMOBJ_m4perc: // Message 4 percentage + newValueM4 = Knx.read(comObjIndex); + statusM4 = true; + break; + case COMOBJ_m4rgb: //Message 4 RGB + Knx.read(comObjIndex, new3Byte); + ledColorM4[R] = new3Byte[R]; + ledColorM4[G] = new3Byte[G]; + ledColorM4[B] = new3Byte[B]; + ledColorM4[W] = 0; + if(!ledColorM4[R] && !ledColorM4[G] && !ledColorM4[B]){ //RGBW = off + newValueM4 = 0; + }else{ + newValueM4 = 255; + } + statusM1 = true; + break; + case COMOBJ_m4rgbw: //Message 1 RGBW + Knx.read(comObjIndex, new6Byte); + ledColorM4[R] = new6Byte[2]; + ledColorM4[G] = new6Byte[3]; + ledColorM4[B] = new6Byte[4]; + ledColorM4[W] = new6Byte[5]; + if(!ledColorM4[R] && !ledColorM4[G] && !ledColorM4[B] && !ledColorM4[R]){ //RGBW = off + newValueM4 = 0; + }else{ + newValueM4 = 255; + } + statusM4 = true; + break; + default: + break; + } + if(newTask != lastTask && newTask < 64){ + //0 .. 63 are KNX scenes, 64 .. 255 for internal use only! + sendSceneNumber = newTask; + } +} diff --git a/led_functions.h b/led_functions.h index 3998ef4..aa6c106 100644 --- a/led_functions.h +++ b/led_functions.h @@ -1,7 +1,9 @@ +/* byte mapByte(byte x, byte in_min, byte in_max, byte out_min, byte out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } +*/ word getLogValue(byte index, float gamma, byte startValue, word maxValue, word steps){ if (index >0){ @@ -19,10 +21,10 @@ word getLogValue(byte index, float gamma, byte startValue, word maxValue, word s void setDimmingCurves(){ word maxSteps = 256; for(word i = 0; i < maxSteps; i++){ - curveR[i] = getLogValue(i, gammaCorrection, 1, maxR, maxSteps); - curveG[i] = getLogValue(i, gammaCorrection, 1, maxG, maxSteps); - curveB[i] = getLogValue(i, gammaCorrection, 1, maxB, maxSteps); - curveW[i] = getLogValue(i, gammaCorrection, 1, maxW, maxSteps); + curveR[i] = getLogValue(i, gammaCorrection, firstOnValue, maxR, maxSteps); + curveG[i] = getLogValue(i, gammaCorrection, firstOnValue, maxG, maxSteps); + curveB[i] = getLogValue(i, gammaCorrection, firstOnValue, maxB, maxSteps); + curveW[i] = getLogValue(i, gammaCorrection, firstOnValue, maxW, maxSteps); } } @@ -42,27 +44,31 @@ void testStrip(){ //there are only 600 LEDs alowed -> hardcoded if(neopixels) delete neopixels; neopixels = new Adafruit_NeoPixel_ZeroDMA(600, LED_STRIP_PIN, NEO_RGBW); - neopixels->begin(&sercom4, SERCOM4, SERCOM4_DMAC_ID_TX, 22, 23, 24, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2, PIO_SERCOM_ALT); - neopixels->setPixelColor(0, 255,0,0,0); - neopixels->setPixelColor(1, 0,255,0,0); - neopixels->setPixelColor(2, 0,0,255,0); - neopixels->setPixelColor(3, 0,0,0,255); +#ifdef DEVELPMENT + neopixels->begin(&sercom5, SERCOM5, SERCOM5_DMAC_ID_TX, 6, 7, A5, SPI_PAD_2_SCK_3, SERCOM_RX_PAD_0, PIO_SERCOM); +#else + neopixels->begin(&sercom4, SERCOM4, SERCOM4_DMAC_ID_TX, 22, 23, 24, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2, PIO_SERCOM_ALT); +#endif + neopixels->setPixelColor(0, 255 , 0, 0, 0); + neopixels->setPixelColor(1, 0, 255, 0, 0); + neopixels->setPixelColor(2, 0, 0, 255, 0); + neopixels->setPixelColor(3, 0, 0, 0, 255); for(int i = 4; i < 600; i++){ - if((i % 10 == 0) && (i % 50 != 0)) neopixels->setPixelColor(i-1, 0,255,0,0); //each 10.(10,20,30,40,60,70...) is green - if(i % 50 == 0) neopixels->setPixelColor(i-1, 0,0,255,0); //each 50.(50,100,150...) is blue + if((i % 10 == 0) && (i % 50 != 0)) neopixels->setPixelColor(i-1, 0, 255, 0, 0); //each 10.(10,20,30,40,60,70...) is green + if(i % 50 == 0) neopixels->setPixelColor(i-1, 0, 0, 255, 0); //each 50.(50,100,150...) is blue } neopixels->setPixelColor(599, 255,0,0,0); //last one is red neopixels->show(); } void showProgrammedLeds(){ - neopixels->setPixelColor(0, 255,0,0,0); - neopixels->setPixelColor(1, 0,255,0,0); - neopixels->setPixelColor(2, 0,0,255,0); - neopixels->setPixelColor(3, 0,0,0,255); + neopixels->setPixelColor(0, 255, 0, 0, 0); + neopixels->setPixelColor(1, 0, 255, 0, 0); + neopixels->setPixelColor(2, 0, 0, 255, 0); + neopixels->setPixelColor(3, 0, 0, 0, 255); //each tens LED is red (10,20,30,40,60,70...) for(int i = 4; i < numberLeds; i++){ - if((i % 10 == 0) && (i % 50 != 0)) neopixels->setPixelColor(i-1, 0,255,0,0); //each 10. is red + if((i % 10 == 0) && (i % 50 != 0)) neopixels->setPixelColor(i-1, 0, 255, 0, 0); //each 10. is red if(i % 50 == 0) neopixels->setPixelColor(i - 1, 0, 0, 255, 0); //each 50. is blue } neopixels->setPixelColor(numberLeds - 1, 255, 0, 0, 0); //last one is green @@ -80,7 +86,11 @@ void initStrip(word pixel, byte type){ pixelbrush2 = new NeoPixelPainterBrush(pixelcanvas); pixelbrush3 = new NeoPixelPainterBrush(pixelcanvas); pixelbrush4on2 = new NeoPixelPainterBrush(pixelcanvas2); +#ifdef DEVELPMENT + neopixels->begin(&sercom5, SERCOM5, SERCOM5_DMAC_ID_TX, 6, 7, A5, SPI_PAD_2_SCK_3, SERCOM_RX_PAD_0, PIO_SERCOM); +#else neopixels->begin(&sercom4, SERCOM4, SERCOM4_DMAC_ID_TX, 22, 23, 24, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2, PIO_SERCOM_ALT); +#endif neopixels->show(); Debug.println(F("initPixel")); } @@ -98,10 +108,10 @@ void setDayNightValues(bool night){ } void taskSoftOnOff(byte value){ - if(value == 0) - dimmer.taskSoftOff(); - else + if(value) dimmer.taskSoftOn(); + else + dimmer.taskSoftOff(); } void taskDimUpDownStop(byte value){ @@ -125,7 +135,8 @@ void taskNewValue(byte value){ } void setAll(byte r, byte g, byte b, byte w){ - currentTask = 0xFE; //TASK_IDLE + currentTask = TASK_IDLE; //TASK_IDLE + //staticColorReady = true; //if we have RGB only, try to display mixed white if(!rgbw && w != 0 && r == 0 && g == 0 && b == 0){ r = getLogValue(w, gammaCorrection, 1, mixedWhite[0], 256); @@ -143,25 +154,158 @@ void setAll(byte r, byte g, byte b, byte w){ Debug.println(F("setAll log: R: %d, G: %d, B: %d, W: %d, HEX: 0x%02x 0x%02x 0x%02x 0x%02x"),r,g,b,w,r,g,b,w); #endif for(int i = 0; i < numberLeds; i++){ - neopixels->setPixelColor(i, r,g,b,w); + neopixels->setPixelColor(i, r, g, b, w); } - neopixels->show(); + //save color, we need it for messages + lastStaticColor[R] = r; + lastStaticColor[G] = g; + lastStaticColor[B] = b; + lastStaticColor[W] = w; + pixelsShow = true; } void setAllHsv(byte h, byte s, byte v){ Debug.println(F("setAllHsv H: %d, S: %d, V: %d"), h, s, v); - currentTask = 0xFE; //TASK_IDLE + currentTask = TASK_IDLE; //TASK_IDLE byte newRGB[3]; hsvToRgb(h, s, v, newRGB); for(int i = 0; i < numberLeds; i++){ neopixels->setPixelColor(i, newRGB[R], newRGB[G], newRGB[B]); - neopixels->show(); + pixelsShow = true; } } //function to set LED-Values -void setLeds(byte index){ - setAll(0, 0, 0, index); +void setLeds(byte value){ + setAll(0, 0, 0, value); // Debug.println(F("setLeds %d"),index); } + +//function to set LED-values via dimmer library +void setLeds(byte ch, byte value){ + new6Byte[2+ch] = value; +} + +/*neopixels->show() tranfers buffer data to physical LEDs +we can modify buffer before this step to show e.g. message-animation on top of normal animation +in addition we are setting ledsOn status. + +*/ + +void showPixels (){ + if(pixelsShow){ + pixelsShow = false; + neopixels->show(); + } +} + +/* +this function overrides selected pixels with specific color +attention: if message color matches current stripe color, it's not possible to identify message state +*/ + +void setMessageLeds(word firstLed, word lastLed, byte newValue, byte newColor[4]){ +/* + we can display up to 2 messages on a single strip + each message has it own stripe range + the range is defined in KONNEKTING Suite "from LED number x up to LED number y" + message 2 will override (or part of) message 1 if message 2 range overlaps message 1 range + +Examples: + +LED strip with 20 LEDs (0..19): + 0 1 2 3 4 +19 5 +18 6 +17 7 +16 8 +15 9 +14 13 12 11 10 + +Message 1 range: 10 - 4 => 7 LEDs (25%: 10,9; 50%: 10,9,8,7; 75%: 10,9,8,7,6) +Message 2 range: 14 - 0 => 7 LEDs, not possible in direct way. Please set LED 0 as LED 20, LED 1 as LED 21 and so on... (LED number from LED 0 + string length) + (25%: 14,15; 50%: 14,15,16,17; 75%: 14,15,16,17,18; 100%: 14,15,16,17,18,19,0) + if LED 0 will be set as 0, than the range will be 15 LEDs: 14,13,12...2,1,0 + +*/ + if(newValue){ //if 0, do nothing, we've allready wiped with animation or static color + if(lastLed >= firstLed){ + word amount = (lastLed - firstLed + 1) * newValue / 255; //round up //floor() + for(word led = firstLed; led < firstLed + amount; led++){ + if(led < numberLeds) { + neopixels->setPixelColor(led, newColor[R], newColor[G], newColor[B], newColor[W]); + }else{ + neopixels->setPixelColor(led - numberLeds, newColor[R], newColor[G], newColor[B], newColor[W]); //see examples + } + } + }else{//firstLed > lastLed + word amount = ceil((firstLed - lastLed + 1) * newValue / 255); //round up //floor() + for(word led = firstLed; led > firstLed - amount; led--){ + if(led < numberLeds) { + neopixels->setPixelColor(led, newColor[R], newColor[G], newColor[B], newColor[W]); + }else{ + neopixels->setPixelColor(led - numberLeds, newColor[R], newColor[G], newColor[B], newColor[W]); //see examples + } + } + } + } +} + +void showMessage(){ + //set color only if we are in NOT in WAIT state + if(statusM1 || statusM2 || statusM3 || statusM4){ + //just overlay with messages, animation will do "wipe" + if(RAINBOW <= currentTask && currentTask <= WHIREMIDDLEOFF){ + setMessageLeds(ledFirstM1, ledLastM1, newValueM1, ledColorM1); + lastValueM1 = newValueM1; + setMessageLeds(ledFirstM2, ledLastM2, newValueM2, ledColorM2); + lastValueM2 = newValueM2; + pixelsShow = true; //show result + } + //turn Message LEDs on/off if it's not an animation (static color) + if((ALL_OFF <= lastTaskBeforeMessage && lastTaskBeforeMessage <= USER_COLOR_5) || + (TASK_RGB <= lastTaskBeforeMessage && lastTaskBeforeMessage <= TASK_DIMMER )){ + //"wipe" messages if we will show less message LEDs as before + if(lastValueM1 > newValueM1 || lastValueM2 > newValueM2 || lastValueM3 > newValueM3 || lastValueM4 > newValueM4){ + setAll(lastStaticColor[R], lastStaticColor[G], lastStaticColor[B], lastStaticColor[W]); + Debug.println(F("Messages: set last color: R: %d, G: %d, B: %d, W: %d, statusM2: %d"), lastStaticColor[R], lastStaticColor[G], lastStaticColor[B], lastStaticColor[W], statusM2); + } + //and show messages on top of static color + setMessageLeds(ledFirstM1, ledLastM1, newValueM1, ledColorM1); + if(statusM1) { + statusM1 = false; //set message WAIT state +#ifdef KDEBUG + Debug.println(F("Message 1: pause routine and wait until TASK will be changed")); +#endif + lastValueM1 = newValueM1; + } + setMessageLeds(ledFirstM2, ledLastM2, newValueM2, ledColorM2); + if(statusM2) { + statusM2 = false; //set message WAIT state +#ifdef KDEBUG + Debug.println(F("Message 2: pause routine and wait until TASK will be changed")); +#endif + lastValueM2 = newValueM2; + } + setMessageLeds(ledFirstM3, ledLastM3, newValueM3, ledColorM3); + if(statusM3) { + statusM3 = false; //set message WAIT state +#ifdef KDEBUG + Debug.println(F("Message 3: pause routine and wait until TASK will be changed")); +#endif + lastValueM3 = newValueM3; + } + setMessageLeds(ledFirstM4, ledLastM4, newValueM4, ledColorM4); + if(statusM4) { + statusM4 = false; //set message WAIT state +#ifdef KDEBUG + Debug.println(F("Message 4: pause routine and wait until TASK will be changed")); +#endif + lastValueM4 = newValueM4; + } + pixelsShow = true; //show result + } +// + } +} diff --git a/scenes.h b/scenes.h index 3689198..e34c2a4 100644 --- a/scenes.h +++ b/scenes.h @@ -1,55 +1,15 @@ -//Scene 1 .. 9 -#define ALL_OFF 0x00 -#define WHITE 0x01 -#define RED 0x02 -#define YELLOW 0x03 -#define GREEN 0x04 -#define CYAN 0x05 -#define BLUE 0x06 -#define PURPLE 0x07 -#define ORANGE 0x08 - -//Scenes 21 .. 25 -#define USER_COLOR_1 0x14 -#define USER_COLOR_2 0x15 -#define USER_COLOR_3 0x16 -#define USER_COLOR_4 0x17 -#define USER_COLOR_5 0x18 - -//Scenes 41 .. 52 -#define RAINBOW 0x28 //41 -#define SINGLERGB 0x29 //42 -#define SPARKLER 0x2A //43 -#define TWINKYSTARS 0x2B //44 -#define CHASER 0x2C //45 -#define HUEFADER 0x2D //46 -#define SPEEDTRAILS 0x2E //47 -#define BOUNCYBALLS 0x2F //48 -#define TWOBRUSHCOLORMIXING 0x30 //49 - - -#define WHIREMIDDLEON 0x32 -#define WHIREMIDDLEOFF 0x33 - - - -//Scene 61 .. 64 -#define TASK_RGB 0x3C -#define TASK_RGBW 0x3D -#define TASK_HSV 0x3E -#define DIMMER 0x3F - - - - - - -#define TASK_IDLE 0xFE - - - void taskFunction(){ // Debug.println(F("currentTask: 0x%02X"), currentTask); + if(currentTask != TASK_IDLE) { + lastTaskBeforeMessage = currentTask; + //exit WAIT state + if(!statusM1) statusM1 = true; + if(!statusM2) statusM2 = true; + if(!statusM3) statusM3 = true; + if(!statusM4) statusM4 = true; + } + + switch(currentTask){ case ALL_OFF: setAll(0,0,0,0); @@ -135,7 +95,6 @@ void taskFunction(){ if(acceptNewRGBW){ // Debug.println(F("valuesRGBW R: %d, G: %d, B: %d, W: %d"),valuesRGBW[R],valuesRGBW[G],valuesRGBW[B],valuesRGBW[W]); setAll(valuesRGBW[R], valuesRGBW[G], valuesRGBW[B], valuesRGBW[W]); - acceptNewRGBW = false; rgbwChanged = false; //reset color because of time out (acceptNewRGBW) @@ -147,16 +106,11 @@ void taskFunction(){ break; case TASK_RGBW: if(acceptNewRGBW){ - //first 12 bits not defined, 4 bits ignored -// Debug.println(F("valuesRGBW R: %d, G: %d, B: %d, W: %d"), valuesRGBW[R], valuesRGBW[G], valuesRGBW[B], valuesRGBW[W]); + //first 12 bits are not defined, 4 bits ignored + Debug.println(F("valuesRGBW R: %d, G: %d, B: %d, W: %d"), valuesRGBW[R], valuesRGBW[G], valuesRGBW[B], valuesRGBW[W]); setAll(valuesRGBW[R], valuesRGBW[G], valuesRGBW[B], valuesRGBW[W]); acceptNewRGBW = false; rgbwChanged = false; - //reset color because of time out (acceptNewRGBW) -// new6Byte[2] = 0; -// new6Byte[3] = 0; -// new6Byte[4] = 0; -// new6Byte[5] = 0; Debug.println(F("TASK_RGBW done")); } break; @@ -164,22 +118,19 @@ void taskFunction(){ if(acceptNewHSV){ setAllHsv(valuesHSV[0], valuesHSV[1], valuesHSV[2]); acceptNewHSV = false; - hsvChanged = false; - //reset color because of time out (acceptNewRGBW) -// new3Byte[0] = 0; -// new3Byte[1] = 0; -// new3Byte[2] = 0; Debug.println(F("TASK_HSV done")); } break; - case DIMMER: + case TASK_DIMMER: setAll(0, 0, 0, lastDimmerValue); -// taskNewValue(lastDimmerValue); break; - - + case TASK_IDLE: default: break; } + showMessage(); + if(pixelsShow){ + showPixels(); + } }