From d841cd66a747fa7393b3627ae8933bc1b2b76fd2 Mon Sep 17 00:00:00 2001 From: Adminius Date: Mon, 7 Oct 2019 22:45:08 +0200 Subject: [PATCH] new 0.2 version --- ALEDD1.ino | 227 +++++++++++++--------------- KONNEKTING_ALEDD1.kdevice.xml | 275 +--------------------------------- aledd1.h | 2 +- animations.h | 6 + button.h | 50 +++++++ fakeEEPROM.h | 125 ++++------------ hsvrgb.h | 68 +++++++++ kdevice_ALEDD1.h | 140 +---------------- led_functions.h | 25 ++-- scenes.h | 143 ++++++++++-------- 10 files changed, 367 insertions(+), 694 deletions(-) create mode 100644 button.h create mode 100644 hsvrgb.h diff --git a/ALEDD1.ino b/ALEDD1.ino index a3d05fe..f847a31 100644 --- a/ALEDD1.ino +++ b/ALEDD1.ino @@ -1,5 +1,5 @@ /* --------------------------------------------------------------------------------------------- -ALEDD 0.1 beta (work in progress) +ALEDD 0.2 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 */ @@ -50,10 +50,17 @@ KONNEKTING Device Library: http://librarymanager/All#Konnekting //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 sendSceneNumber = 0xFF; +byte lastDimmerValue = 0; byte curveR[256]; byte curveG[256]; @@ -93,9 +100,16 @@ byte ucBlue[USERCOLORS]; byte ucWhite[USERCOLORS]; byte new3Byte[3] = {0,0,0}; byte new6Byte[6] = {0,0,0,0,0,0}; -bool rgbwhsvChanged = false; -bool acceptNewValues = false; -unsigned long rgbwhsvChangedMillis = 0; +byte newRGBW[4] = {0,0,0,0}; +byte valuesRGBW[4] = {0,0,0,0}; +byte newHSV[3] = {0,0,0}; +byte valuesHSV[3] = {0,0,0}; +bool rgbwChanged = false; +bool hsvChanged = false; +bool acceptNewRGBW = false; +bool acceptNewHSV = false; +unsigned long rgbwChangedMillis = 0; +unsigned long hsvChangedMillis = 0; word rgbwhsvChangedDelay = 50; @@ -118,65 +132,16 @@ NeoPixelPainterBrush *pixelbrush4on2; //brush 4 on cancas 2 HSV brushcolor; DimmerControl dimmer; +#include "hsvrgb.h" #include "animations.h" #include "led_functions.h" #include "scenes.h" +#include "button.h" -void progButtonPressed(){ - bool btnState = !digitalRead(PROG_BUTTON_PIN); - //button pressed - if(btnState){ - if(!buttonPressed){ - clickMillis = millis(); - } - buttonPressed = true; - } - //button released - if(!btnState){ - unsigned long clickDuration = millis() - clickMillis; - buttonPressed = false; - if(clickDuration >= DEBOUNCE) - if(clickDuration > longClickDurationBtn){ - taskOnLongClick(); - }else{ - taskOnShortClick(); - } - } - -} -void taskOnShortClick(){ - //toggle ProgMode - Konnekting.setProgState(!Konnekting.isProgState()); - - //if already programmed, show LED settings - if(!Konnekting.isFactorySetting() && !ledTestMode){ - if(Konnekting.isProgState()) - showProgrammedLeds(); - else - neopixels->clear(); - neopixels->show(); - } - Debug.println(F("free ram: %d bytes"), Debug.freeRam()); -} -void taskOnLongClick(){ - //ATTENTION: we creating a new neopixel object with 600(!) LED that consumes alot of RAM! - //MCU will be reseted after this test! - ledTestMode = !ledTestMode; - if(ledTestMode){ - Debug.println(F("free ram before testStrip(): %d bytes"), Debug.freeRam()); - testStrip(); - Debug.println(F("free ram after testStrip(): %d bytes"), Debug.freeRam()); - }else{ - Debug.println(F("reboot!")); - NVIC_SystemReset() ; - while (true); - } - -} void setup() { pinMode(PROG_LED_PIN, OUTPUT); - pinMode(PROG_BUTTON_PIN, INPUT); + pinMode(PROG_BUTTON_PIN, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(PROG_BUTTON_PIN), progButtonPressed, CHANGE); #ifdef KDEBUG SerialUSB.begin(115200); @@ -220,14 +185,7 @@ 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: scenes - for (byte sc = 0; sc < 64; sc++) { - scene[sc] = Konnekting.getUINT8Param(PARAM_scene01 + sc); - } + //XML group: User colors for (byte uc = 0; uc < USERCOLORS; uc++) { ucRed[uc] = Konnekting.getUINT8Param(PARAM_uc1r + 4 * uc); @@ -262,10 +220,27 @@ void loop() { if (Konnekting.isReadyForApplication()) { dimmer.task(); taskFunction(); - if(rgbwhsvChanged){ - if(millis() - rgbwhsvChangedMillis > rgbwhsvChangedDelay && !acceptNewValues){ - Debug.println(F("apply new rgb(w) / hsv values")); - acceptNewValues = true; + 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]); + + valuesRGBW[R] = newRGBW[R]; + valuesRGBW[G] = newRGBW[G]; + valuesRGBW[B] = newRGBW[B]; + valuesRGBW[W] = newRGBW[W]; + acceptNewRGBW = true; + } + } + if(hsvChanged){ + if(millis() - hsvChangedMillis > rgbwhsvChangedDelay && !acceptNewHSV){ + Debug.println(F("apply new hsv values")); + + valuesHSV[0] = newHSV[0]; + valuesHSV[1] = newHSV[1]; + valuesHSV[2] = newHSV[2]; + acceptNewHSV = true; } } if (dimmer.updateAvailable()) { @@ -279,11 +254,18 @@ 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 } Knx.write(COMOBJ_dim_value, dimmer.getCurrentValue()); Debug.println(F("Send to Obj: %d value: %d"), COMOBJ_dim_value, 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; + } } } @@ -318,103 +300,106 @@ void knxEvents(byte comObjIndex) { break; case COMOBJ_scene : // Scene - newTask = scene[Knx.read(comObjIndex)]; + newTask = Knx.read(comObjIndex); Debug.println(F("newTask: 0x%02X"), newTask); - if (newTask != 0xFF) currentTask = newTask; + + if (newTask != 0xFF) { + currentTask = newTask; + acceptNewRGBW = true; + } // powerSupplyTask(); break; case COMOBJ_RGB : // RGB 232.600 - acceptNewValues = true; + acceptNewRGBW = true; newTask = TASK_RGB; Debug.println(F("newTask: 0x%02X"), newTask); - Knx.read(comObjIndex,new3Byte); + 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 - acceptNewValues = true; + acceptNewRGBW = true; newTask = TASK_RGBW; Debug.println(F("newTask: 0x%02X"), newTask); - Knx.read(comObjIndex,new6Byte); + 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 - acceptNewValues = true; + acceptNewHSV = true; newTask = TASK_HSV; Debug.println(F("newTask: 0x%02X"), newTask); - Knx.read(comObjIndex,new3Byte); + 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 : -// if(!rgbwhsvChanged) { - rgbwhsvChanged = true; - rgbwhsvChangedMillis = millis(); -// } - new6Byte[2] = Knx.read(comObjIndex); - Debug.println(F("new R: %d"), new6Byte[2]); + 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 : -// if(!rgbwhsvChanged) { - rgbwhsvChanged = true; - rgbwhsvChangedMillis = millis(); -// } - new6Byte[3] = Knx.read(comObjIndex); - Debug.println(F("new G: %d"), new6Byte[3]); + 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 : -// if(!rgbwhsvChanged) { - rgbwhsvChanged = true; - rgbwhsvChangedMillis = millis(); -// } - new6Byte[4] = Knx.read(comObjIndex); - Debug.println(F("new B: %d"), new6Byte[4]); + 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 : -// if(!rgbwhsvChanged) { - rgbwhsvChanged = true; - rgbwhsvChangedMillis = millis(); -// } - new6Byte[5] = Knx.read(comObjIndex); - Debug.println(F("new W: %d"), new6Byte[5]); + 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 : -// if(!rgbwhsvChanged) { - rgbwhsvChanged = true; - rgbwhsvChangedMillis = millis(); -// } - new3Byte[0] = Knx.read(comObjIndex); - Debug.println(F("new H"), new3Byte[0]); + 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 : -// if(!rgbwhsvChanged) { - rgbwhsvChanged = true; - rgbwhsvChangedMillis = millis(); -// } - new3Byte[1] = Knx.read(comObjIndex); - Debug.println(F("new S"), new3Byte[1]); + 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 : -// if(!rgbwhsvChanged) { - rgbwhsvChanged = true; - rgbwhsvChangedMillis = millis(); -// } - new3Byte[2] = Knx.read(comObjIndex); - Debug.println(F("new S"), new3Byte[2]); + 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; @@ -422,6 +407,8 @@ void knxEvents(byte comObjIndex) { default: break; } + 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 0800a7b..3ca7d2d 100644 --- a/KONNEKTING_ALEDD1.kdevice.xml +++ b/KONNEKTING_ALEDD1.kdevice.xml @@ -162,274 +162,6 @@ - - - Scene 1 - - - - Scene 2 - - - - Scene 3 - - - - Scene 4 - - - - Scene 5 - - - - Scene 6 - - - - Scene 7 - - - - Scene 8 - - - - Scene 9 - - - - Scene 10 - - - - Scene 11 - - - - Scene 12 - - - - Scene 13 - - - - Scene 14 - - - - Scene 15 - - - - Scene 16 - - - - Scene 17 - - - - Scene 18 - - - - Scene 19 - - - - Scene 20 - - - - Scene 21 - - - - Scene 22 - - - - Scene 23 - - - - Scene 24 - - - - Scene 25 - - - - Scene 26 - - - - Scene 27 - - - - Scene 28 - - - - Scene 29 - - - - Scene 30 - - - - Scene 31 - - - - Scene 32 - - - - Scene 33 - - - - Scene 34 - - - - Scene 35 - - - - Scene 36 - - - - Scene 37 - - - - Scene 38 - - - - Scene 39 - - - - Scene 40 - - - - Scene 41 - - - - Scene 42 - - - - Scene 43 - - - - Scene 44 - - - - Scene 45 - - - - Scene 46 - - - - Scene 47 - - - - Scene 48 - - - - Scene 49 - - - - Scene 50 - - - - Scene 51 - - - - Scene 52 - - - - Scene 53 - - - - Scene 54 - - - - Scene 55 - - - - Scene 56 - - - - Scene 57 - - - - Scene 58 - - - - Scene 59 - - - - Scene 60 - - - - Scene 61 - - - - Scene 62 - - - - Scene 63 - - - - Scene 64 - - - - - - Automatic powersupply control - - - - Power supply off after [0..180min] - - - @@ -527,6 +259,12 @@ 3 byte 232.600 42 + + + Scene Status + Value + 17.001 + 52 @@ -535,7 +273,6 @@ - diff --git a/aledd1.h b/aledd1.h index 3d9656f..7929be2 100644 --- a/aledd1.h +++ b/aledd1.h @@ -3,7 +3,7 @@ Uart SerialKNX (&sercom2, 3, 1, SERCOM_RX_PAD_1, UART_TX_PAD_2); //+pinPeriphera //Interrupt handler for SerialKNX void SERCOM2_Handler() { - SerialKNX.IrqHandler(); + SerialKNX.IrqHandler(); } //Hardware settings diff --git a/animations.h b/animations.h index 82da217..5bed61f 100644 --- a/animations.h +++ b/animations.h @@ -28,6 +28,12 @@ void rainbow() { } +void singlergb(){ + //let set single RGB color to whole strip and go though hue disk + //ToDo +} + + void sparkler() { // HSV brushcolor; diff --git a/button.h b/button.h new file mode 100644 index 0000000..2926ce1 --- /dev/null +++ b/button.h @@ -0,0 +1,50 @@ +void taskOnShortClick(){ + //toggle ProgMode + Konnekting.setProgState(!Konnekting.isProgState()); + + //if already programmed, show LED settings + if(!Konnekting.isFactorySetting() && !ledTestMode){ + if(Konnekting.isProgState()) + showProgrammedLeds(); + else + neopixels->clear(); + neopixels->show(); + } + Debug.println(F("free ram: %d bytes"), Debug.freeRam()); +} +void taskOnLongClick(){ + //ATTENTION: we creating a new neopixel object with 600(!) LED that consumes alot of RAM! + //MCU will be reseted after this test! + ledTestMode = !ledTestMode; + if(ledTestMode){ + Debug.println(F("free ram before testStrip(): %d bytes"), Debug.freeRam()); + testStrip(); + Debug.println(F("free ram after testStrip(): %d bytes"), Debug.freeRam()); + }else{ + Debug.println(F("reboot!")); + NVIC_SystemReset() ; + while (true); + } +} + +void progButtonPressed(){ + bool btnState = !digitalRead(PROG_BUTTON_PIN); + //button pressed + if(btnState){ + if(!buttonPressed){ + clickMillis = millis(); + } + buttonPressed = true; + } + //button released + if(!btnState){ + unsigned long clickDuration = millis() - clickMillis; + buttonPressed = false; + if(clickDuration >= DEBOUNCE) + if(clickDuration > longClickDurationBtn){ + taskOnLongClick(); + }else{ + taskOnShortClick(); + } + } +} diff --git a/fakeEEPROM.h b/fakeEEPROM.h index 52b2535..50e7efc 100644 --- a/fakeEEPROM.h +++ b/fakeEEPROM.h @@ -78,109 +78,46 @@ writeMemory(54,0x80); writeMemory(55,0x3E); writeMemory(56,0x16); writeMemory(57,0x80); -writeMemory(58,0x06);//type -writeMemory(59,0x00); -writeMemory(60,0x64);//ledNumber -writeMemory(61,0xFF); -writeMemory(62,0xFF); -writeMemory(63,0xFF); +writeMemory(58,0x3E); +writeMemory(59,0x17); +writeMemory(60,0x80); +writeMemory(61,0xD2); +writeMemory(62,0x00); +writeMemory(63,0x1E); writeMemory(64,0xFF); -writeMemory(65,0x00); +writeMemory(65,0xFF); writeMemory(66,0xFF); -writeMemory(67,0xFA); -writeMemory(68,0xE0); -writeMemory(69,0x02); -writeMemory(70,0x03); -writeMemory(71,0x00); -writeMemory(72,0xFF); -writeMemory(73,0x00); -writeMemory(74,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,0x93); -writeMemory(77,0x29); +writeMemory(76,0x00); +writeMemory(77,0xFF); writeMemory(78,0x00); -writeMemory(79,0xFF); -writeMemory(80,0xC5); -writeMemory(81,0x8F); +writeMemory(79,0x00); +writeMemory(80,0x00); +writeMemory(81,0x00); writeMemory(82,0x00); -writeMemory(83,0xFF); -writeMemory(84,0xF1); -writeMemory(85,0xE0); +writeMemory(83,0x00); +writeMemory(84,0x00); +writeMemory(85,0x00); writeMemory(86,0x00); -writeMemory(87,0xFF); -writeMemory(88,0xFA); -writeMemory(89,0xF4); +writeMemory(87,0x00); +writeMemory(88,0x00); +writeMemory(89,0x00); writeMemory(90,0x00); -writeMemory(91,0xC9); -writeMemory(92,0xE2); -writeMemory(93,0xFF); +writeMemory(91,0x00); +writeMemory(92,0x00); +writeMemory(93,0x00); writeMemory(94,0x00); -writeMemory(95,0xFF); +writeMemory(95,0x00); writeMemory(96,0x00); -writeMemory(97,0x01); -writeMemory(98,0x02); -writeMemory(99,0x03); -writeMemory(100,0x04); -writeMemory(101,0x05); -writeMemory(102,0x06); -writeMemory(103,0x07); -writeMemory(104,0x08); -writeMemory(105,0x1F); -writeMemory(106,0x20); -writeMemory(107,0x21); -writeMemory(108,0x22); -writeMemory(109,0x23); -writeMemory(110,0x32); -writeMemory(111,0x33); -writeMemory(112,0x34); -writeMemory(113,0x35); -writeMemory(114,0x36); -writeMemory(115,0x37); -writeMemory(116,0x38); -writeMemory(117,0x39); -writeMemory(118,0x3C); -writeMemory(119,0x3D); -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,0x00); -writeMemory(160,0x1E); +writeMemory(97,0x00); } #endif diff --git a/hsvrgb.h b/hsvrgb.h new file mode 100644 index 0000000..1aa6b40 --- /dev/null +++ b/hsvrgb.h @@ -0,0 +1,68 @@ +void hsvToRgb(byte h, byte s, byte v, byte rgbColor[]){ + if(s){ + byte i = h / 43; + byte f = (h - (i * 43)) * 6; + byte p = (v * (255 - s)) >> 8; + byte q = (v * (255 - ((s * f) >> 8))) >> 8; + byte t = (v * (255 - ((s * (255 - f)) >> 8))) >> 8; + switch (i){ + case 0: + rgbColor[0] = v; + rgbColor[1] = t; + rgbColor[2] = p; + break; + case 1: + rgbColor[0] = q; + rgbColor[1] = v; + rgbColor[2] = p; + break; + case 2: + rgbColor[0] = p; + rgbColor[1] = v; + rgbColor[2] = t; + break; + case 3: + rgbColor[0] = p; + rgbColor[1] = q; + rgbColor[2] = v; + break; + case 4: + rgbColor[0] = t; + rgbColor[1] = p; + rgbColor[2] = v; + break; + default: + rgbColor[0] = v; + rgbColor[1] = p; + rgbColor[2] = q; + break; + } + }else{ + rgbColor[0] = v; + rgbColor[1] = v; + rgbColor[2] = v; + } +} + +void rgbToHsv(byte r, byte g, byte b, byte hsvColor[]){ + byte min = min(min(r,g),b); + byte max = max(max(r,g),b); + byte diff = max - min; + hsvColor[2] = max; + if (hsvColor[2] == 0){ + hsvColor[0] = 0; + hsvColor[1] = 0; + }else{ + hsvColor[1] = 255 * (word)diff / hsvColor[2]; + if (hsvColor[1] == 0){ + hsvColor[0] = 0; + }else{ + if (r == max) + hsvColor[0] = 0 + ((g - b) * 43) / diff; + else if (g == max) + hsvColor[0] = 85 + ((b - r) * 43) / diff; + else + hsvColor[0] = 171 + ((r - g) * 43) / diff; + } + } +} diff --git a/kdevice_ALEDD1.h b/kdevice_ALEDD1.h index c6164d5..beba51c 100644 --- a/kdevice_ALEDD1.h +++ b/kdevice_ALEDD1.h @@ -18,6 +18,7 @@ #define COMOBJ_s 13 #define COMOBJ_v 14 #define COMOBJ_HSV 15 +#define COMOBJ_scene_state 16 #define PARAM_led_type 0 #define PARAM_number_leds_strip 1 #define PARAM_r_correction 2 @@ -54,72 +55,6 @@ #define PARAM_uc5g 33 #define PARAM_uc5b 34 #define PARAM_uc5w 35 -#define PARAM_scene01 36 -#define PARAM_scene02 37 -#define PARAM_scene03 38 -#define PARAM_scene04 39 -#define PARAM_scene05 40 -#define PARAM_scene06 41 -#define PARAM_scene07 42 -#define PARAM_scene08 43 -#define PARAM_scene09 44 -#define PARAM_scene10 45 -#define PARAM_scene11 46 -#define PARAM_scene12 47 -#define PARAM_scene13 48 -#define PARAM_scene14 49 -#define PARAM_scene15 50 -#define PARAM_scene16 51 -#define PARAM_scene17 52 -#define PARAM_scene18 53 -#define PARAM_scene19 54 -#define PARAM_scene20 55 -#define PARAM_scene21 56 -#define PARAM_scene22 57 -#define PARAM_scene23 58 -#define PARAM_scene24 59 -#define PARAM_scene25 60 -#define PARAM_scene26 61 -#define PARAM_scene27 62 -#define PARAM_scene28 63 -#define PARAM_scene29 64 -#define PARAM_scene30 65 -#define PARAM_scene31 66 -#define PARAM_scene32 67 -#define PARAM_scene33 68 -#define PARAM_scene34 69 -#define PARAM_scene35 70 -#define PARAM_scene36 71 -#define PARAM_scene37 72 -#define PARAM_scene38 73 -#define PARAM_scene39 74 -#define PARAM_scene40 75 -#define PARAM_scene41 76 -#define PARAM_scene42 77 -#define PARAM_scene43 78 -#define PARAM_scene44 79 -#define PARAM_scene45 80 -#define PARAM_scene46 81 -#define PARAM_scene47 82 -#define PARAM_scene48 83 -#define PARAM_scene49 84 -#define PARAM_scene50 85 -#define PARAM_scene51 86 -#define PARAM_scene52 87 -#define PARAM_scene53 88 -#define PARAM_scene54 89 -#define PARAM_scene55 90 -#define PARAM_scene56 91 -#define PARAM_scene57 92 -#define PARAM_scene58 93 -#define PARAM_scene59 94 -#define PARAM_scene60 95 -#define PARAM_scene61 96 -#define PARAM_scene62 97 -#define PARAM_scene63 98 -#define PARAM_scene64 99 -#define PARAM_ps_control 100 -#define PARAM_ps_delay_off 101 KnxComObject KnxDevice::_comObjectsList[] = { /* Index 0 - dim_sw */ KnxComObject(KNX_DPT_1_001, 0x2b), @@ -137,7 +72,8 @@ KnxComObject KnxDevice::_comObjectsList[] = { /* Index 12 - h */ KnxComObject(KNX_DPT_5_004, 0x2a), /* 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 15 - HSV */ KnxComObject(KNX_DPT_232_600, 0x2a), + /* Index 16 - scene_state */ KnxComObject(KNX_DPT_17_001, 0x34) }; const byte KnxDevice::_numberOfComObjects = sizeof (_comObjectsList) / sizeof (KnxComObject); // do not change this code @@ -148,7 +84,7 @@ byte KonnektingDevice::_paramSizeList[] = { /* Index 3 - g_correction */ PARAM_UINT8, /* Index 4 - b_correction */ PARAM_UINT8, /* Index 5 - w_correction */ PARAM_UINT8, - /* Index 6 - w_type */ PARAM_UINT8, + /* Index 6 - gamma_correction */ PARAM_UINT8, /* Index 7 - wr */ PARAM_UINT8, /* Index 8 - wg */ PARAM_UINT8, /* Index 9 - wb */ PARAM_UINT8, @@ -177,72 +113,6 @@ byte KonnektingDevice::_paramSizeList[] = { /* Index 32 - uc5r */ PARAM_UINT8, /* Index 33 - uc5g */ PARAM_UINT8, /* Index 34 - uc5b */ PARAM_UINT8, - /* Index 35 - uc5w */ PARAM_UINT8, - /* Index 36 - scene01 */ PARAM_UINT8, - /* Index 37 - scene02 */ PARAM_UINT8, - /* Index 38 - scene03 */ PARAM_UINT8, - /* Index 39 - scene04 */ PARAM_UINT8, - /* Index 40 - scene05 */ PARAM_UINT8, - /* Index 41 - scene06 */ PARAM_UINT8, - /* Index 42 - scene07 */ PARAM_UINT8, - /* Index 43 - scene08 */ PARAM_UINT8, - /* Index 44 - scene09 */ PARAM_UINT8, - /* Index 45 - scene10 */ PARAM_UINT8, - /* Index 46 - scene11 */ PARAM_UINT8, - /* Index 47 - scene12 */ PARAM_UINT8, - /* Index 48 - scene13 */ PARAM_UINT8, - /* Index 49 - scene14 */ PARAM_UINT8, - /* Index 50 - scene15 */ PARAM_UINT8, - /* Index 51 - scene16 */ PARAM_UINT8, - /* Index 52 - scene17 */ PARAM_UINT8, - /* Index 53 - scene18 */ PARAM_UINT8, - /* Index 54 - scene19 */ PARAM_UINT8, - /* Index 55 - scene20 */ PARAM_UINT8, - /* Index 56 - scene21 */ PARAM_UINT8, - /* Index 57 - scene22 */ PARAM_UINT8, - /* Index 58 - scene23 */ PARAM_UINT8, - /* Index 59 - scene24 */ PARAM_UINT8, - /* Index 60 - scene25 */ PARAM_UINT8, - /* Index 61 - scene26 */ PARAM_UINT8, - /* Index 62 - scene27 */ PARAM_UINT8, - /* Index 63 - scene28 */ PARAM_UINT8, - /* Index 64 - scene29 */ PARAM_UINT8, - /* Index 65 - scene30 */ PARAM_UINT8, - /* Index 66 - scene31 */ PARAM_UINT8, - /* Index 67 - scene32 */ PARAM_UINT8, - /* Index 68 - scene33 */ PARAM_UINT8, - /* Index 69 - scene34 */ PARAM_UINT8, - /* Index 70 - scene35 */ PARAM_UINT8, - /* Index 71 - scene36 */ PARAM_UINT8, - /* Index 72 - scene37 */ PARAM_UINT8, - /* Index 73 - scene38 */ PARAM_UINT8, - /* Index 74 - scene39 */ PARAM_UINT8, - /* Index 75 - scene40 */ PARAM_UINT8, - /* Index 76 - scene41 */ PARAM_UINT8, - /* Index 77 - scene42 */ PARAM_UINT8, - /* Index 78 - scene43 */ PARAM_UINT8, - /* Index 79 - scene44 */ PARAM_UINT8, - /* Index 80 - scene45 */ PARAM_UINT8, - /* Index 81 - scene46 */ PARAM_UINT8, - /* Index 82 - scene47 */ PARAM_UINT8, - /* Index 83 - scene48 */ PARAM_UINT8, - /* Index 84 - scene49 */ PARAM_UINT8, - /* Index 85 - scene50 */ PARAM_UINT8, - /* Index 86 - scene51 */ PARAM_UINT8, - /* Index 87 - scene52 */ PARAM_UINT8, - /* Index 88 - scene53 */ PARAM_UINT8, - /* Index 89 - scene54 */ PARAM_UINT8, - /* Index 90 - scene55 */ PARAM_UINT8, - /* Index 91 - scene56 */ PARAM_UINT8, - /* Index 92 - scene57 */ PARAM_UINT8, - /* Index 93 - scene58 */ PARAM_UINT8, - /* Index 94 - scene59 */ PARAM_UINT8, - /* Index 95 - scene60 */ PARAM_UINT8, - /* Index 96 - scene61 */ PARAM_UINT8, - /* Index 97 - scene62 */ PARAM_UINT8, - /* Index 98 - scene63 */ PARAM_UINT8, - /* Index 99 - scene64 */ PARAM_UINT8, - /* Index 100 - ps_control */ PARAM_UINT8, - /* Index 101 - ps_delay_off */ PARAM_UINT8 + /* Index 35 - uc5w */ PARAM_UINT8 }; const int KonnektingDevice::_numberOfParams = sizeof (_paramSizeList); // do not change this code diff --git a/led_functions.h b/led_functions.h index 5957fa6..3998ef4 100644 --- a/led_functions.h +++ b/led_functions.h @@ -63,9 +63,9 @@ void showProgrammedLeds(){ //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 % 50 == 0) neopixels->setPixelColor(i-1, 0,0,255,0); //each 50. is blue + 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 + neopixels->setPixelColor(numberLeds - 1, 255, 0, 0, 0); //last one is green neopixels->show(); } @@ -80,7 +80,7 @@ void initStrip(word pixel, byte type){ pixelbrush2 = new NeoPixelPainterBrush(pixelcanvas); pixelbrush3 = new NeoPixelPainterBrush(pixelcanvas); pixelbrush4on2 = new NeoPixelPainterBrush(pixelcanvas2); - neopixels->begin(&sercom4, SERCOM4, SERCOM4_DMAC_ID_TX, 22, 23, 24, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2, PIO_SERCOM_ALT); + neopixels->begin(&sercom4, SERCOM4, SERCOM4_DMAC_ID_TX, 22, 23, 24, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_2, PIO_SERCOM_ALT); neopixels->show(); Debug.println(F("initPixel")); } @@ -109,7 +109,7 @@ void taskDimUpDownStop(byte value){ byte step = value & DPT3_007_MASK_STEP; //true = increase, false = decrease bool direction = value & DPT3_007_MASK_DIRECTION; - Debug.println(F("value: %d, step: %d, direction: %d"),value,step,direction); + Debug.println(F("value: %d, step: %d, direction: %d"), value, step, direction); //if step == B?????000 then stop if(step == DPT3_007_STOP) dimmer.taskStop(); @@ -126,7 +126,7 @@ void taskNewValue(byte value){ void setAll(byte r, byte g, byte b, byte w){ currentTask = 0xFE; //TASK_IDLE - //if we only have RGB, try to display mixed white + //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); g = getLogValue(w, gammaCorrection, 1, mixedWhite[1], 256); @@ -140,29 +140,28 @@ void setAll(byte r, byte g, byte b, byte w){ w = curveW[w]; } #ifdef KDEBUG - Debug.println(F("setAll R: %d, G: %d, B: %d, W: %d"),r,g,b,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->show(); } void setAllHsv(byte h, byte s, byte v){ - Debug.println(F("setAllHsv H: %d, S: %d, V: %d"),h,s,v); + Debug.println(F("setAllHsv H: %d, S: %d, V: %d"), h, s, v); currentTask = 0xFE; //TASK_IDLE - RGB newColor; -// pixelcanvas->HSVtoRGB(h,s,v); - + byte newRGB[3]; + hsvToRgb(h, s, v, newRGB); + for(int i = 0; i < numberLeds; i++){ - neopixels->setPixelColor(i, newColor.r,newColor.g,newColor.b,0); + neopixels->setPixelColor(i, newRGB[R], newRGB[G], newRGB[B]); neopixels->show(); } } //function to set LED-Values void setLeds(byte index){ - setAll(0,0,0,index); + setAll(0, 0, 0, index); // Debug.println(F("setLeds %d"),index); } diff --git a/scenes.h b/scenes.h index fdf1e69..3689198 100644 --- a/scenes.h +++ b/scenes.h @@ -1,71 +1,84 @@ +//Scene 1 .. 9 #define ALL_OFF 0x00 -#define RED 0x01 -#define GREEN 0x02 -#define BLUE 0x03 -#define CYAN 0x04 -#define YELLOW 0x05 -#define ORANGE 0x06 +#define WHITE 0x01 +#define RED 0x02 +#define YELLOW 0x03 +#define GREEN 0x04 +#define CYAN 0x05 +#define BLUE 0x06 #define PURPLE 0x07 -#define WHITE 0x08 +#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 USER_COLOR_1 0x1F -#define USER_COLOR_2 0x20 -#define USER_COLOR_3 0x21 -#define USER_COLOR_4 0x22 -#define USER_COLOR_5 0x23 -#define RAINBOW 0x32 -#define SPARKLER 0x33 -#define TWINKYSTARS 0x34 -#define CHASER 0x35 -#define HUEFADER 0x36 -#define SPEEDTRAILS 0x37 -#define BOUNCYBALLS 0x38 -#define TWOBRUSHCOLORMIXING 0x39 -#define WHIREMIDDLEON 0x3C -#define WHIREMIDDLEOFF 0x3D -#define TASK_RGB 0xF0 -#define TASK_RGBW 0xF1 -#define TASK_HSV 0xF2 -#define DIMMER 0xFA #define TASK_IDLE 0xFE void taskFunction(){ +// Debug.println(F("currentTask: 0x%02X"), currentTask); switch(currentTask){ case ALL_OFF: setAll(0,0,0,0); dimmer.taskOff(); break; + case WHITE: + setAll(0,0,0,255); + dimmer.taskOn(); + break; case RED: setAll(255,0,0,0); break; + case YELLOW: + setAll(255,255,0,0); + break; case GREEN: setAll(0,255,0,0); break; + case CYAN: + setAll(0,255,255,0); + break; case BLUE: setAll(0,0,255,0); break; - case YELLOW: - setAll(255,255,0,0); - break; - case ORANGE: - setAll(255,81,0,0); - break; case PURPLE: setAll(255,0,255,0); break; - case CYAN: - setAll(0,255,255,0); - break; - case WHITE: - setAll(0,0,0,255); - dimmer.taskOn(); + case ORANGE: + setAll(255,81,0,0); break; case USER_COLOR_1: @@ -86,6 +99,9 @@ void taskFunction(){ case RAINBOW: rainbow(); + break; + case SINGLERGB: + singlergb(); break; case TWINKYSTARS: twinkystars(); @@ -116,11 +132,13 @@ void taskFunction(){ break; case TASK_RGB: - if(acceptNewValues){ - setAll(new3Byte[0],new3Byte[1],new3Byte[2],0); - acceptNewValues = false; - rgbwhsvChanged = false; - //reset color because of time out (acceptNewValues) + 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) new3Byte[0] = 0; new3Byte[1] = 0; new3Byte[2] = 0; @@ -128,33 +146,35 @@ void taskFunction(){ } break; case TASK_RGBW: - if(acceptNewValues){ + if(acceptNewRGBW){ //first 12 bits not defined, 4 bits ignored - setAll(new6Byte[2],new6Byte[3],new6Byte[4],new6Byte[5]); - acceptNewValues = false; - rgbwhsvChanged = false; - //reset color because of time out (acceptNewValues) - new6Byte[2] = 0; - new6Byte[3] = 0; - new6Byte[4] = 0; - new6Byte[5] = 0; +// 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; case TASK_HSV: - if(acceptNewValues){ - setAllHsv(new3Byte[0],new3Byte[1],new3Byte[2]); - acceptNewValues = false; - rgbwhsvChanged = false; - //reset color because of time out (acceptNewValues) - new3Byte[0] = 0; - new3Byte[1] = 0; - new3Byte[2] = 0; + 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: - + setAll(0, 0, 0, lastDimmerValue); +// taskNewValue(lastDimmerValue); break; @@ -163,4 +183,3 @@ void taskFunction(){ break; } } -