Add support for HW proto V1
This commit is contained in:
parent
64e4e6f5e4
commit
d0a1ba647f
137
Claire.ino
137
Claire.ino
|
@ -1,4 +1,8 @@
|
|||
//#define DISABLE_WIFI
|
||||
#define HW_PROTO_PAPER 1
|
||||
#define HW_PROTO_V1 2
|
||||
#define HW HW_PROTO_PAPER
|
||||
//#define HW HW_PROTO_V1
|
||||
|
||||
#include <WiFiManager.h> // https://github.com/admarschoonen/WiFiManager
|
||||
#include <dESPatch.h>
|
||||
|
@ -9,32 +13,55 @@
|
|||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#if (HW == HW_PROTO_PAPER)
|
||||
#define NUM_LEDS 93
|
||||
#define DATA_PIN 5
|
||||
#elif (HW == HW_PROTO_V1)
|
||||
#define NUM_LEDS 29
|
||||
#define DATA_PIN 14
|
||||
#else
|
||||
#error "HW not set"
|
||||
#endif
|
||||
|
||||
#define NUM_LEDS 93
|
||||
//#define NUM_LEDS 10
|
||||
#define DATA_PIN 5
|
||||
|
||||
#define BUIENRADAR_START_LED 32
|
||||
#define BUIENRADAR_SKIP_LED 1
|
||||
#define BUIENRADAR_NUM_LEDS 12
|
||||
|
||||
#define PAQI_START_LED 72
|
||||
#define PAQI_SKIP_LED 0
|
||||
#define PAQI_NUM_LEDS 12
|
||||
|
||||
// #define UVI_LED 92 // LED in center
|
||||
#define UVI_LED 84 // LED above center
|
||||
#define AQI_LED 86 // LED to the right
|
||||
#define POLLEN_LED 90 // LED to the left
|
||||
#define IAQI_LED 88 // LED below center
|
||||
|
||||
#if (HW == HW_PROTO_PAPER)
|
||||
#define BUIENRADAR_START_LED 32
|
||||
#define BUIENRADAR_SKIP_LED 1
|
||||
#define BUIENRADAR_NUM_LEDS 12
|
||||
|
||||
#define PAQI_START_LED 72
|
||||
#define PAQI_SKIP_LED 0
|
||||
#define PAQI_NUM_LEDS 12
|
||||
|
||||
// #define UVI_LED 92 // LED in center
|
||||
#define UVI_LED 84 // LED above center
|
||||
#define AQI_LED 86 // LED to the right
|
||||
#define POLLEN_LED 90 // LED to the left
|
||||
#define IAQI_LED 88 // LED below center
|
||||
#elif (HW == HW_PROTO_V1)
|
||||
#define BUIENRADAR_START_LED 1
|
||||
#define BUIENRADAR_SKIP_LED 0
|
||||
#define BUIENRADAR_NUM_LEDS 12
|
||||
|
||||
#define PAQI_START_LED 13
|
||||
#define PAQI_SKIP_LED 0
|
||||
#define PAQI_NUM_LEDS 12
|
||||
|
||||
#define UVI_LED 28 // LED above center
|
||||
#define AQI_LED 25 // LED to the right
|
||||
#define POLLEN_LED 27 // LED to the left
|
||||
#define IAQI_LED 26 // LED below center
|
||||
#endif
|
||||
#define SHOW_AQI_LED
|
||||
#define SHOW_POLLEN_LED
|
||||
#define SHOW_UVI_LED
|
||||
|
||||
#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
|
||||
|
||||
Adafruit_NeoPixel leds(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
|
||||
#if (HW == HW_PROTO_PAPER)
|
||||
Adafruit_NeoPixel leds(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
|
||||
#elif (HW == HW_PROTO_V1)
|
||||
Adafruit_NeoPixel leds(NUM_LEDS, DATA_PIN, NEO_RGBW + NEO_KHZ800);
|
||||
#endif
|
||||
|
||||
static HTTPClient http;
|
||||
static const String baseUrlAQI = "http://target.luon.net:2356//forecast?&metrics=PAQI&metrics=AQI&metrics=pollen&metrics=UVI";
|
||||
|
@ -210,50 +237,6 @@ void setup() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void interpolateValues(Adafruit_NeoPixel * leds, int numLeds, int startLed, int skipLed, \
|
||||
int * colors, int numColors) {
|
||||
for (int led = 0; led < numLeds; led = led + skipLed + 1) {
|
||||
int idxColorLow, idxColorHigh;
|
||||
int idxLedLow, idxLedHigh;
|
||||
int r, g, b;
|
||||
|
||||
idxColorLow = (numColors * led) / numLeds;
|
||||
idxColorHigh = idxColorLow + 1;
|
||||
idxLedLow = (idxColorLow * numLeds) / numColors;
|
||||
idxLedHigh = (idxColorHigh * numLeds) / numColors;
|
||||
|
||||
if (idxColorHigh >= numColors) {
|
||||
idxColorHigh = numColors - 1;
|
||||
}
|
||||
|
||||
if (idxLedHigh >= numLeds) {
|
||||
idxLedHigh = numLeds - 1;
|
||||
}
|
||||
|
||||
int rgbLow = colors[idxColorLow];
|
||||
int rgbHigh = colors[idxColorHigh];
|
||||
|
||||
int rLow = (rgbLow & 0xFF0000) >> 16;
|
||||
int gLow = (rgbLow & 0x00FF00) >> 8;
|
||||
int bLow = (rgbLow & 0x0000FF);
|
||||
|
||||
int rHigh = (rgbHigh & 0xFF0000) >> 16;
|
||||
int gHigh = (rgbHigh & 0x00FF00) >> 8;
|
||||
int bHigh = (rgbHigh & 0x0000FF);
|
||||
|
||||
if (idxLedLow == idxLedHigh) {
|
||||
r = rLow;
|
||||
g = gLow;
|
||||
b = bLow;
|
||||
} else {
|
||||
r = ((rHigh - rLow) * (led - idxLedLow) + ((idxLedHigh - idxLedLow) >> 1)) / (idxLedHigh - idxLedLow) + rLow;
|
||||
g = ((gHigh - gLow) * (led - idxLedLow) + ((idxLedHigh - idxLedLow) >> 1)) / (idxLedHigh - idxLedLow) + gLow;
|
||||
b = ((bHigh - bLow) * (led - idxLedLow) + ((idxLedHigh - idxLedLow) >> 1)) / (idxLedHigh - idxLedLow) + bLow;
|
||||
}
|
||||
leds->setPixelColor(led + startLed, leds->Color(r, g, b));
|
||||
}
|
||||
}
|
||||
|
||||
// From https://circuits4you.com/2019/03/21/esp8266-url-encode-decode-example/
|
||||
String urlencode(String str)
|
||||
{
|
||||
|
@ -415,7 +398,11 @@ static int colormap(float x) {
|
|||
y = (0 << 16) | (0 << 8) | 0; // black (good)
|
||||
} else if (x < 2.0) {
|
||||
// 1.0 <= x < 2.0
|
||||
#if (HW == HW_PROTO_PAPER)
|
||||
y = (0 << 16) | (0 << 8) | 160; // blue (good)
|
||||
#elif (HW == HW_PROTO_V1)
|
||||
y = (0 << 16) | (0 << 8) | 255; // blue (good)
|
||||
#endif
|
||||
} else if (x < 3.0) {
|
||||
// 2.0 <= x < 3.0
|
||||
y = (0 << 16) | (255 << 8) | 255; // cyan (good)
|
||||
|
@ -481,6 +468,7 @@ static float buienradarMap(float x) {
|
|||
return y;
|
||||
}
|
||||
|
||||
#if (HW == HW_PROTO_PAPER)
|
||||
static void updateLedsNoWifi(void) {
|
||||
uint32_t ledIdx;
|
||||
uint32_t ledCount;
|
||||
|
@ -501,6 +489,29 @@ static void updateLedsNoWifi(void) {
|
|||
ledIdx = ledIdx + PAQI_SKIP_LED + 1;
|
||||
}
|
||||
}
|
||||
#elif (HW == HW_PROTO_V1)
|
||||
static void updateLedsNoWifi(void) {
|
||||
uint32_t ledIdx;
|
||||
uint32_t ledCount;
|
||||
uint32_t color;
|
||||
int r, g, b, w, n;
|
||||
|
||||
// Start by setting all leds to value of the first datapoint
|
||||
ledIdx = 0;
|
||||
ledCount = 0;
|
||||
for (ledCount = 0; ledCount < 11; ledCount++) {
|
||||
color = colormap(ledCount);
|
||||
|
||||
r = (color & 0xFF0000) >> 16;
|
||||
g = (color & 0x00FF00) >> 8;
|
||||
b = (color & 0x0000FF);
|
||||
w = (color & 0xFF000000) >> 24;
|
||||
|
||||
leds.setPixelColor(ledIdx, leds.Color(g, r, b, w));
|
||||
ledIdx = ledIdx + PAQI_SKIP_LED + 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void updateLeds(void) {
|
||||
uint32_t ledIdx;
|
||||
|
|
Loading…
Reference in New Issue