From 5d07dbb73d5b0a34a0b54bcc2d25c5cc704bce76 Mon Sep 17 00:00:00 2001 From: Juergen Jung Date: Sun, 19 Feb 2017 21:43:23 +0100 Subject: [PATCH] Add documentation --- Readme.md | 80 +++++++++++++++++++++++++++ esp-wemos-schild/NeoPatterns.cpp | 7 +++ esp-wemos-schild/NeoPatterns.h | 3 + esp-wemos-schild/esp-wemos-schild.ino | 14 ++--- 4 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 Readme.md diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..4e5823d --- /dev/null +++ b/Readme.md @@ -0,0 +1,80 @@ +Homie Schild Firmware +===================== +## About +## Features +|Topic |Descriptions |settable |Values | +|---------|--------------|:---------:|---------| +|`device_id`/strip/pixel/|Range property from 0 - (number of pixels - 1)|ja|Color as uint32_t see [Color](#color)| +|`device_id`/strip/color|Range property to set the effects colors 1 & 2 see: [effect colors](#effect-colors)|ja|Color as uint32_t see [Color](#color)| +|`device_id`/strip/brightness|Sets the brightness of the pixel strip|ja|possible values: 0 - 255| +|`device_id`/strip/effect|Set effect|ja|see: [effects](#effects)| +|`device_id`/strip/clear|Clears the pixels strip|ja|any value is possible| +|`device_id`/strip/length|Set the strip length|ja|Possible values: 0 - length| + +## Color +To convert RGB value use the following bash code: +```bash +function rgbToColor { + echo $(( $(($1<<16)) + $(($2<<8)) + $(($3)) )); +} + +function colorToRGB { + echo "Red: $(($1>>16&0xff))" + echo "Green: $(($1>>8&0xff))" + echo "Blue: $(($1&0xff))" +} +``` +#### Example +RGB Value to color uint32_t +```bash + bash$ rgbToColor 155 230 32 + 10216992 + bash$ +``` +uint32_t to RGB values +```bash + bash$ colorToRGB 10216992 + Red: 155 + Green: 230 + Blue: 32 + bash$ +``` + +## Effects +* scanner +Shows the moving larson scanner eye known form *Battlestar Galactica* and *Knight Rider*. The used effect color can be specified by *color_0* +* randomscanner +This is the same scanner then the scanner above but uses an alternating color pattern +* rainbowcycle +Shows a cycling rainbown on the LED strip +* theaterchase +Shows an color chasing LED strip. +You can specify the color by set *color_0* and *color_1* +* fade +Fades from effect color_0 to effect_color_1 +* randomfade +Fades thru an alternating color pattern +* none +Stop all effects + +## Effect colors +You can set to different effect colors +* *color_0* (default R: 255, G: 0 B: 0) +* *color_1* (default R: 0, G: 0 B: 255) + +The effect color has to be set after the effect. +###### Example: +1. `homie/device_id/strip/effect/set -m "fade"` +2. `homie/device_id/strip/color_0/set -m "255"` +3. `homie/device_id/strip/color_1/set -m "10216992"` + +##### color_0 +This color will be used for the following effects: +* scanner +* theaterchase +* fade + +##### color_1 +This color will be used for the following effects: +* theaterchase +* fade diff --git a/esp-wemos-schild/NeoPatterns.cpp b/esp-wemos-schild/NeoPatterns.cpp index e51e81a..91cea44 100644 --- a/esp-wemos-schild/NeoPatterns.cpp +++ b/esp-wemos-schild/NeoPatterns.cpp @@ -228,6 +228,13 @@ void NeoPatterns::RandomFadeUpdate(){ Increment(); } +void NeoPatterns::SetColor1(uint32_t color){ + Color1 = color; +} +void NeoPatterns::SetColor2(uint32_t color){ + Color2 = color; +} + // Calculate 50% dimmed version of a color (used by ScannerUpdate) uint32_t NeoPatterns::DimColor(uint32_t color) { diff --git a/esp-wemos-schild/NeoPatterns.h b/esp-wemos-schild/NeoPatterns.h index 7168fed..68e470b 100644 --- a/esp-wemos-schild/NeoPatterns.h +++ b/esp-wemos-schild/NeoPatterns.h @@ -26,6 +26,9 @@ void Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, di void FadeUpdate(); void RandomFade(uint8_t interval = 100); void RandomFadeUpdate(); + +void SetColor1(uint32_t color); +void SetColor2(uint32_t color); //Utilities void ColorSet(uint32_t color); uint8_t Red(uint32_t color); diff --git a/esp-wemos-schild/esp-wemos-schild.ino b/esp-wemos-schild/esp-wemos-schild.ino index 5790312..3d8ff89 100644 --- a/esp-wemos-schild/esp-wemos-schild.ino +++ b/esp-wemos-schild/esp-wemos-schild.ino @@ -23,8 +23,6 @@ HomieNode stripNode("strip", "strip"); HomieNode sensorNode("sensor", "sensor"); Bounce debouncer = Bounce(); -uint32_t color1 = pixels.Color(255, 0, 0); -uint32_t color2 = pixels.Color(0, 0, 255); bool onSetColor(const HomieRange& range, const String& value){ if (!range.isRange || range.index < 0 || range.index > 1) { @@ -32,10 +30,10 @@ bool onSetColor(const HomieRange& range, const String& value){ } switch(range.index) { case 0: - color1 = value.toInt(); + pixels.SetColor1(value.toInt()); break; case 1: - color2 = value.toInt(); + pixels.SetColor2(value.toInt()); break; } stripNode.setProperty("color_" + String(range.index)).send(value); @@ -74,19 +72,19 @@ bool onSetEffect(const HomieRange& range, const String& value){ String effect = value; effect.toLowerCase(); if(effect == "scanner") { - pixels.Scanner(color1); + pixels.Scanner(pixels.Color(255, 0, 0)); } else if(effect == "randomscanner") { - pixels.Scanner(color1, 40, true); + pixels.Scanner(pixels.Color(255, 0, 0), 40, true); } else if(effect == "rainbowcycle") { pixels.RainbowCycle(50); } else if(effect == "theaterchase") { - pixels.TheaterChase(color1, color2, 100); + pixels.TheaterChase(pixels.Color(255, 0, 0), pixels.Color(0,0,255), 100); } else if(effect == "fade") { - pixels.Fade(color1, color2, 200, 100); + pixels.Fade(pixels.Color(255, 0, 0), pixels.Color(0,0,255), 200, 100); } else if(effect == "randomfade") { pixels.RandomFade();