From 04e2bf3de1b03f500dee311869386b31c1b2820b Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Sun, 12 Mar 2017 01:52:13 +0100 Subject: [PATCH] indentation + doc --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 211 ++++++++++---------- 1 file changed, 110 insertions(+), 101 deletions(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index cb1aa2d..cf9bb72 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -14,7 +14,7 @@ int brightness = LED_BRIGHTNESS_DEFAULT; int color = LED_COLOR_DEFAULT; int speed = LED_SPEED_DEFAULT; CRGB leds[LED_NUM]; -String ledEffect = LED_EFFECT_CYLON; +String ledEffect = LED_EFFECT_ERROR; boolean ledState = false; // WIFI @@ -45,21 +45,21 @@ void setup() Serial.println("Ready"); /* MQTT - * Il est important de faire un loop avant toute chose, - * afin de récupérer les valeurs provenant du broker mqtt - * et pas démarrer avec de vieilles infos. - */ - for (short int i = 0; i < 10; i++) { - delay(200); - client.loop(); - } + * Il est important de faire un loop avant toute chose, + * afin de récupérer les valeurs provenant du broker mqtt + * et pas démarrer avec de vieilles infos. + */ + for (short int i = 0; i < 10; i++) { + delay(200); + client.loop(); + } - //////////////////////////////// ColorPalette /////////////////////////////// - currentPalette = RainbowColors_p; - currentBlending = LINEARBLEND; - //////////////////////////////// ColorPalette /////////////////////////////// + //////////////////////////////// ColorPalette /////////////////////////////// + currentPalette = RainbowColors_p; + currentBlending = LINEARBLEND; + //////////////////////////////// ColorPalette /////////////////////////////// - Serial.println("End of setup"); + Serial.println("End of setup"); } // WIFI @@ -149,111 +149,120 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) } // LED +/** +* Coupe tout le strip de led. +*/ void ledBlackAll() { - FastLED.clear(); - FastLED.show(); + FastLED.clear(); + FastLED.show(); } +/** +* Effet Cylon : défilement d'une simple led sur le strip aller/retour. +* Pour faire plus sympas on ajoute une lueur autour, avec une lumière atténué. +*/ void ledCylon() { - // Effet cylon : on allume une led, on attends, on eteinds, on passe à la suivante - for(int i = 0; i < LED_NUM; i++) { - client.loop(); + for(int i = 0; i < LED_NUM; i++) { + client.loop(); - if (ledEffect != LED_EFFECT_CYLON) { - return; - } - - if ((i - 3) >= 0) { - leds[i - 3] = CRGB::Black; - } - if ((i - 2) >= 0) { - /* - * Se lit 128/256 d'intensité lumineuse actuelle - * https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors - */ - leds[i - 2].fadeLightBy(240); - } - if ((i - 1) >= 0) { - leds[i - 1].fadeLightBy(200); - } - - leds[i] = color; - - if ((i + 1) <= LED_NUM) { - leds[i + 1] = color; - // Je suis volontairement un peu moins puissant sur l'avant - // pour donner un effet de trainée sur l'arrière - leds[i + 1].fadeLightBy(220); - } - if ((i + 2) <= LED_NUM) { - leds[i + 2] = color; - leds[i + 2].fadeLightBy(240); - } - - FastLED.delay(1000 / speed); + if (ledEffect != LED_EFFECT_CYLON) { + return; } - // led[0] et led[255] sont gérées par la loop précédante - for(int i = LED_NUM - 1; i > 0; i--) { - client.loop(); - - if (ledEffect != LED_EFFECT_CYLON) { - return; - } - - if ((i - 2) >= 0) { - leds[i - 2] = color; - leds[i - 2].fadeLightBy(240); - } - if ((i - 1) >= 0) { - leds[i - 1] = color; - leds[i - 1].fadeLightBy(220); - } - - leds[i] = color; - - if ((i + 1) <= LED_NUM) { - leds[i + 1].fadeLightBy(200); - } - if ((i + 2) <= LED_NUM) { - leds[i + 2].fadeLightBy(240); - } - if ((i + 3) <= LED_NUM) { - leds[i + 3] = CRGB::Black; - } - - FastLED.delay(1000 / speed); + if ((i - 3) >= 0) { + leds[i - 3] = CRGB::Black; + } + if ((i - 2) >= 0) { + /* + * Se lit 128/256 d'intensité lumineuse actuelle + * https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors + */ + leds[i - 2].fadeLightBy(240); + } + if ((i - 1) >= 0) { + leds[i - 1].fadeLightBy(200); } -} -void ledError() -{ - for(int i = 0; i < LED_NUM; i++) { - if ((i % 2) == 0) { - leds[i] = CRGB::Black; - } else { - leds[i] = CRGB::Red; - } + leds[i] = color; + + if ((i + 1) <= LED_NUM) { + leds[i + 1] = color; + // Je suis volontairement un peu moins puissant sur l'avant + // pour donner un effet de trainée sur l'arrière + leds[i + 1].fadeLightBy(220); + } + if ((i + 2) <= LED_NUM) { + leds[i + 2] = color; + leds[i + 2].fadeLightBy(240); } FastLED.delay(1000 / speed); + } + + // led[0] et led[255] sont gérées par la loop précédante + for(int i = LED_NUM - 1; i > 0; i--) { + client.loop(); + + if (ledEffect != LED_EFFECT_CYLON) { + return; + } + + if ((i - 2) >= 0) { + leds[i - 2] = color; + leds[i - 2].fadeLightBy(240); + } + if ((i - 1) >= 0) { + leds[i - 1] = color; + leds[i - 1].fadeLightBy(220); + } + + leds[i] = color; + + if ((i + 1) <= LED_NUM) { + leds[i + 1].fadeLightBy(200); + } + if ((i + 2) <= LED_NUM) { + leds[i + 2].fadeLightBy(240); + } + if ((i + 3) <= LED_NUM) { + leds[i + 3] = CRGB::Black; + } + + FastLED.delay(1000 / speed); + } +} + +/** + * Utilise pour indiquer une erreur sur la reception de l'effet. + */ +void ledError() +{ + for(int i = 0; i < LED_NUM; i++) { + if ((i % 2) == 0) { + leds[i] = CRGB::Black; + } else { + leds[i] = CRGB::Red; + } + } + + FastLED.delay(1000 / speed); } void ledFullColor() { - fill_solid(leds, LED_NUM, color); - // TODO : il fadrait pas faire 0 -> 255 mais plutot 20 -> brightness - // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ - // Augmenter 2000 augmente la fréquence (c'est en fait sin((temps / 1000) * Pi/2) - // 0.36787944 ?? censé correspondre au minimum - // 108.4 ?? censé correspondre au maximum - int breath = (exp(sin(millis() / 2000.0 * PI)) - 0.3678794) * 108.4; - Serial.print(breath); - Serial.println(" / 255"); - FastLED.setBrightness(breath); - FastLED.delay(100 / speed); + fill_solid(leds, LED_NUM, color); + // TODO : il fadrait pas faire 0 -> 255 mais plutot 20 -> brightness + // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ + // Augmenter 2000 augmente la fréquence (c'est en fait sin((temps / 1000) * Pi/2) + // 0.36787944 ?? censé correspondre au minimum + // 108.4 ?? censé correspondre au maximum + int breath = (exp(sin(millis() / 2000.0 * PI)) - 0.3678794) * 108.4; + Serial.print(breath); + Serial.println(" / 255"); + FastLED.setBrightness(breath); + FastLED.delay(100 / speed); } ///////////////////// FastLED-3.1.5/examples/ColorPalette /////////////////////