Commit db24118b authored by Andrea Trentini's avatar Andrea Trentini

inversione

parent 42cb0b0c
......@@ -14,7 +14,7 @@
* TODO: visualizzare solo quelli che cambiano? (e rimanere sull'ultimo cambiato)
* TODO: standardizzare nomi variabili e costanti (Klingon?)
* TODO: ssid broadcast coi dati letti
*
*
Copyright (C) 2018 HackLabCormano (http://hacklabcormano.it)
......@@ -29,7 +29,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.*
along with this program. If not, see <http://www.gnu.org/licenses/>.*
*/
......@@ -97,23 +97,6 @@ void statusMqtt() {
}
/** visualizzare qualcosa ogni secondo?
*/
int current=0;
void seconds() {
Serial.print(current);
Serial.print(" ");
//TODO spostare (creando una funzione apposita) in LED.h, portare colore in define
uint32_t prev=strip.getPixelColor(current);
strip.setPixelColor(current,strip.Color(0,0,250));
strip.show();
strip.setPixelColor(current,prev);
current--;
if(current>=NUM_LEDS) current=0;
if(current<0) current=NUM_LEDS-1;
//animate();
}
/**
* per buttar fuori qualcosa e vedere se va, controlla anche wifi
......@@ -123,9 +106,9 @@ void statusAndNtp() {
if (WiFi.status() != WL_CONNECTED) {
Serial.println("no wifi!");
delay(10000);
delay(5000);
impulse(strip.Color(150,0,0)); // segnala reboot
delay(10000);
delay(5000);
ESP.reset();
}
......
#include <ArduinoJson.h>
// https://frassino.comperio.it/kpi/clavis-csbno.json
void getAndShow() {
......@@ -38,7 +39,7 @@ void getAndShow() {
}
const size_t bufferSize = JSON_OBJECT_SIZE(6) + 1000; //120;
DynamicJsonBuffer jsonBuffer(bufferSize);
DynamicJsonBuffer jsonBuffer(bufferSize); //TODO: non più compatibile con versione 6 della lib, quando esce dalla beta va cambiato
//const char* json = "{\"dbName\":\"clavis-csbno\",\"utenti\":\"327980\",\"prestiti\":\"158367\",\"prestiti_oggi\":\"2010\",\"utentiplus\":\"6731\",\"utenti_attivi\":\"89353\"}";
//JsonObject& root = jsonBuffer.parseObject(json);
......
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#include <avr/power.h>
#endif
#define IMPULSE_DELAY 20
// per invertire il verso della barra (ora appesa al contrario, con lo 0 in alto)
#define INVERTED
//#define BRIANZA
#ifdef BRIANZA
......@@ -42,7 +45,7 @@ const uint32_t C_PRESTITI=strip.Color(0,100,100); // CRGB::Yellow
const uint32_t C_PRESTITI_OGGI=strip.Color(150,0,0); // era CRGB::Blue
const uint32_t C_UTENTI_PLUS=strip.Color(150,150,0); // CRGB::Brown
const uint32_t C_UTENTI_ATTIVI=strip.Color(150,100,0); // CRGB::Magenta
const uint32_t colori[]={C_UTENTI,C_PRESTITI,C_PRESTITI_OGGI,C_UTENTI_PLUS,C_UTENTI_ATTIVI};
const uint32_t colori[]= {C_UTENTI,C_PRESTITI,C_PRESTITI_OGGI,C_UTENTI_PLUS,C_UTENTI_ATTIVI};
const uint32_t vuoto=strip.Color(80,80,80); // CRGB::Red; // TODO: bianco o spento?
//CRGB vuoto=CRGB::White; // TODO: bianco o spento?
......@@ -60,26 +63,48 @@ void led_setup() {
//FastLED.setBrightness(10);
#endif
/*
/*
for(int i=0; i<NUM_LEDS; i++) {
leds[i].b=0; //random(255);
}
*/
strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
Serial.println("NeoPixel initialized...");
}
uint16_t ledIndex(uint16_t n) {
#ifdef INVERTED
return NUM_LEDS-n-1;
#else
return n;
#endif
}
uint32_t getPixelColor(uint16_t n) {
return strip.getPixelColor(ledIndex(n));
}
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) {
strip.setPixelColor(ledIndex(n),r,g,b);
}
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
strip.setPixelColor(ledIndex(n),r,g,b,w);
}
void setPixelColor(uint16_t n, uint32_t c) {
strip.setPixelColor(ledIndex(n), c);
}
void impulse(uint32_t col) {
for(int nr=0; nr<NUM_LEDS; nr++) {
uint32_t prec=strip.getPixelColor(nr);
strip.setPixelColor(nr,col);
uint32_t prec=getPixelColor(nr);
setPixelColor(nr,col);
strip.show();
delay(IMPULSE_DELAY);
strip.setPixelColor(nr,prec);
setPixelColor(nr,prec);
strip.show();
}
}
......@@ -98,16 +123,16 @@ void setAll() {
void bar(uint32_t col,int len) {
for(int nr=0; nr<NUM_LEDS; nr++) {
if(nr<=len) {
strip.setPixelColor(nr,col);
setPixelColor(nr,col);
strip.show();
delay(STEP);
} else {
strip.setPixelColor(nr,vuoto);
setPixelColor(nr,vuoto);
strip.show();
}
if(nr!=len && LOWENERGY) {
strip.setPixelColor(nr,vuoto);
setPixelColor(nr,vuoto);
strip.show();
}
}
......@@ -116,11 +141,11 @@ void bar(uint32_t col,int len) {
void barFlash(uint32_t col,int len, int flashes) {
bar(col,len);
for(int c=0; c<flashes; c++) {
strip.setPixelColor(len,vuoto);
setPixelColor(len,vuoto);
strip.show();
delay(MICROSTEP);
strip.setPixelColor(len,col);
setPixelColor(len,col);
strip.show();
delay(MICROSTEP);
}
......@@ -156,3 +181,21 @@ void animate() {
}
*/
}
/** visualizzare qualcosa ogni secondo?
*/
int current=0;
void seconds() {
Serial.print(current);
Serial.print(" ");
uint32_t prev=getPixelColor(current);
setPixelColor(current,strip.Color(0,0,250));
strip.show();
setPixelColor(current,prev);
current--;
if(current>=NUM_LEDS) current=0;
if(current<0) current=NUM_LEDS-1;
//animate();
}
......@@ -67,6 +67,7 @@ boolean wifi_setup() {
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
bar(strip.Color(0,0,200),ledIndex(NUM_LEDS*progress/total));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("OTA Error[%u]: ", error);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment