diff --git a/gemma_fire_v3/gemma_fire_v3.ino b/gemma_fire_v3/gemma_fire_v3.ino new file mode 100644 index 0000000..7e86bff --- /dev/null +++ b/gemma_fire_v3/gemma_fire_v3.ino @@ -0,0 +1,164 @@ +// Low power NeoPixel earrings example. Makes a nice blinky display +// with just a few LEDs on at any time...uses MUCH less juice than +// rainbow display! + +#include +#include + +#define PIN 0 +#define FIRE_SIZE 15 +#define RED_SIZE 12 +#define LIGHTNING_SIZE 14 + +Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, PIN); + +uint8_t mode = 0, // Current animation effect + offset = 0; // Position of spinny eyes +uint32_t color = 0xffffff; // Start red +uint32_t prevTime; +uint32_t prevChange; +uint8_t m = 0; +uint32_t waiting = 8000; +uint32_t changeTime = 120000; +uint8_t colourMode = 0; + + +const uint32_t mix[] = { 0xff00ff, 0x8f00ff, 0xf000ff }; +const uint32_t breathe[] = {7, 7, 15, 23, 30, 38, 45, 52, 58, 64, 70, 76, 80, 85, 89, 92, 95, 97, 98, 99, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 99, 98, 97, 95, 92, 89, 85, 80, 76, 70, 64, 58, 52, 45, 38, 30, 23, 15, 7 }; +const uint32_t fire[] = { 0xff2426, 0xfe3223, 0xfe4121, 0xfd4f1f, 0xfd5e1d, 0xfc6d1b, 0xfc7b18, 0xfb8a16, 0xfb9814, 0xfaa712, 0xfab610, 0xffc20d, 0xffd30b, 0xffe309, 0xfff407, 0xf7ff05 }; +const uint32_t lightning[] = { 0xffffff, 0x2436ff, 0x2e43fe, 0x3950fe, 0x4354fe, 0x4e6bfe, 0xffffff, 0x5879fe, 0x6386fe, 0x6d93fe, 0x78a1fe, 0x82aefe, 0x8dbcfe, 0x97c9fe, 0xa2d6fe, 0xace4fe }; // ,0xc2fffe, , , , , , , , , , }; +const uint32_t reds[] = { 0xf4c262, 0xff6961 , 0xff5c5c, 0xff1c00, 0xff0800, 0xff0000, 0xcd5c5c, 0xe34234, 0xd73b3e, 0xce1620, 0xcc0000, 0xb22222 }; //, , , , , , , , , , , 0xb31b1b}; + +const uint32_t clu_red_yellow[] = { 0xff0000, 0xff1100, 0xff2200, 0xff3300, 0xff4400, 0xff5500, 0xff6600, 0xff7700, 0xff8800, 0xff9900, 0xffaa00, 0xffbb00, 0xffcc00, 0xffdd00, 0xffee00, 0xffff00 }; +const uint32_t clu_blue_red[] = {0x0000ff, 0x2200ff, 0x4400ff, 0x6600ff, 0x8800ff, 0xaa00ff, 0xcc00ff, 0xee00ff, 0xff00ee, 0xff00cc, 0xff00aa, 0xff0088, 0xff0066, 0xff0044, 0xff0022, 0xff0000}; +const uint32_t clu_teal_purple[] = {0x00ffff, 0x00ddff, 0x00bbff, 0x0099ff, 0x0077ff, 0x0055ff, 0x0033ff, 0x0011ff, 0x1100ff, 0x3300ff, 0x5500ff, 0x7700ff, 0x9900ff, 0xbb00ff, 0xdd00ff, 0xff00ff}; +const uint32_t clu_red_orange[] = { 0xff0000, 0xff0c00, 0xff1700, 0xff2300, 0xff2f00, 0xff3a00, 0xff4600, 0xff5200, 0xff5d00, 0xff6900, 0xff7500, 0xff8000, 0xff8c00, 0xff9800, 0xffa300, 0xffaf00 }; +const uint32_t clu_teal_blue[] = { 0x00ffff, 0x00eeff, 0x00ddff, 0x00ccff, 0x00bbff, 0x00aaff, 0x0099ff, 0x0088ff, 0x0077ff, 0x0066ff, 0x0055ff, 0x0044ff, 0x0033ff, 0x0022ff, 0x0011ff, 0x0000ff }; +const uint32_t clu_red_black[] = { 0xff0000, 0xee0000, 0xdd0000, 0xcc0000, 0xbb0000, 0xaa0000, 0x990000, 0x880000, 0x770000, 0x660000, 0x550000, 0x440000, 0x330000, 0x220000, 0x080000, 0x000000 }; +const uint32_t clu_purple_yellow[] = { 0xff00ff, 0xff00dd, 0xff00bb, 0xff0099, 0xff0077, 0xff0055, 0xff0033, 0xff0011, 0xff1100, 0xff3300, 0xff5500, 0xff7700, 0xff9900, 0xffbb00, 0xffdd00, 0xffff00}; +const uint32_t clu_yellow_green[] = { 0xffff00, 0xeeff00, 0xddff00, 0xccff00, 0xbbff00, 0xaaff00, 0x99ff00, 0x88ff00, 0x77ff00, 0x66ff00, 0x55ff00, 0x44ff00, 0x33ff00, 0x22ff00, 0x11ff00, 0x00ff00 }; +const uint32_t clu_orange_green[] = { 0xff5300, 0xff6f00, 0xff8c00, 0xffa800, 0xffc500, 0xffe100, 0xfffe00, 0xe4ff00, 0xc7ff00, 0xabff00, 0x8eff00, 0x72ff00, 0x55ff00, 0x39ff00, 0x1cff00, 0x00ff00 }; + +const uint32_t clu[32]; + + +void setup() { + pixels.begin(); + pixels.setBrightness(10); // 1/3 brightness + prevTime = millis(); + prevChange = millis(); + + // colourMode = 1; + // initclu(); +} + +void initclu() { + + memcpy(clu, clu_blue_red, sizeof clu_blue_red ); +} + + +void loop() { + uint8_t i; + uint32_t t; + uint8_t B; + + + + switch (mode) { + + case 0: // Random sparks - just one LED on at a time! + + // + pixels.setPixelColor(0, color); + pixels.show(); + delay(1000); + break; + + case 1: // Spinny wheels (8 LEDs on at a time) + B = breathe[m]; + + // color = fire[random(FIRE_SIZE)]; + // color = lightning[random(LIGHTNING_SIZE)]; + color = 0xff0000; + pixels.setPixelColor(0, color); + pixels.setBrightness(B); + pixels.show(); + + m++; + if (m > 49) { + m = 0; + } + + delay(60); + break; + + case 2: + if (colourMode == 0) { + color = clu_red_yellow[random(FIRE_SIZE)]; + } + if (colourMode == 1) { + color = clu_blue_red[random(FIRE_SIZE)]; + } + if (colourMode == 2) { + color = clu_teal_purple[random(FIRE_SIZE)]; + } + if (colourMode == 3) { + color = clu_red_orange[random(FIRE_SIZE)]; + } + if (colourMode == 4) { + color = clu_purple_yellow[random(FIRE_SIZE)]; + } + + // color = lightning[random(LIGHTNING_SIZE)]; + + pixels.setPixelColor(0, color); + + pixels.show(); + + delay(120); + break; + } + + t = millis(); + + + + if ((t - prevTime) > waiting) { + + // color = fire[random(FIRE_SIZE)]; + mode++; + m = 0; + + if (mode > 2) { + mode = 0; + } + switch (mode) { + case 0: + waiting = 8000; + color = 0xff0000; + // color = 0x007fff; + break; + case 1: + waiting = 30000; + break; + case 2: + waiting = 30000; + pixels.setBrightness(60); + break; + } + + if (mode == 2) { + //++colourMode; + //if (colourMode > 3) { + // colourMode = 0; + //} + } + //color = rgb[random(3)]; + prevTime = millis(); + } + + + + +} diff --git a/libraries/Adafruit_Circuit_Playground/library.properties b/libraries/Adafruit_Circuit_Playground/library.properties index 3c64086..b848239 100644 --- a/libraries/Adafruit_Circuit_Playground/library.properties +++ b/libraries/Adafruit_Circuit_Playground/library.properties @@ -1,5 +1,5 @@ name=Adafruit Circuit Playground -version=1.8.0 +version=1.8.1 author=Adafruit maintainer=Adafruit sentence=All in one library to control Adafruit's Circuit Playground board. diff --git a/libraries/Adafruit_Circuit_Playground/utility/ffft.S b/libraries/Adafruit_Circuit_Playground/utility/ffft.S index 291ae60..24a6be8 100644 --- a/libraries/Adafruit_Circuit_Playground/utility/ffft.S +++ b/libraries/Adafruit_Circuit_Playground/utility/ffft.S @@ -431,3 +431,8 @@ fmuls_f: .endfunc #endif // __AVR__ + +#ifdef __SAMD21G18A__ +.cpu cortex-m0plus +.fpu softvfp +#endif \ No newline at end of file diff --git a/libraries/Adafruit_IO_Arduino/README.md b/libraries/Adafruit_IO_Arduino/README.md index 6b9b956..fc5bf4d 100644 --- a/libraries/Adafruit_IO_Arduino/README.md +++ b/libraries/Adafruit_IO_Arduino/README.md @@ -4,7 +4,7 @@ ![AIOArduino](https://cdn-learn.adafruit.com/assets/assets/000/057/496/original/adafruit_io_AIOA.png?1531335660) -This library provides a simple device independent interface for interacting with [Adafruit IO](https://io.adafruit.com) using Arduino. It allows you to switch between WiFi (ESP8266, M0 WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing) +This library provides a simple device independent interface for interacting with [Adafruit IO](https://io.adafruit.com) using Arduino. It allows you to switch between WiFi (ESP8266, ESP32, M0 WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing) ## Documentation diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_00_publish/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_00_publish/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_00_publish/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_00_publish/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_01_subscribe/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_01_subscribe/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_01_subscribe/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_01_subscribe/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_02_pubsub/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_02_pubsub/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_02_pubsub/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_02_pubsub/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_03_multiple_feeds/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_03_multiple_feeds/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_03_multiple_feeds/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_03_multiple_feeds/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_04_location/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_04_location/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_04_location/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_04_location/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_05_type_conversion/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_05_type_conversion/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_05_type_conversion/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_05_type_conversion/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_06_digital_in/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_06_digital_in/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_06_digital_in/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_06_digital_in/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_07_digital_out/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_07_digital_out/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_07_digital_out/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_07_digital_out/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_08_analog_in/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_08_analog_in/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_08_analog_in/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_08_analog_in/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_09_analog_out/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_09_analog_out/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_09_analog_out/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_09_analog_out/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_10_dashboard_creation/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_10_dashboard_creation/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_10_dashboard_creation/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_10_dashboard_creation/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_11_group_pub/adafruitio_11_group_pub.ino b/libraries/Adafruit_IO_Arduino/examples/adafruitio_11_group_pub/adafruitio_11_group_pub.ino index 83c0973..5573e45 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_11_group_pub/adafruitio_11_group_pub.ino +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_11_group_pub/adafruitio_11_group_pub.ino @@ -69,7 +69,7 @@ void loop() { // increment the count_1 by 1 count_1 += 1; // increment the count_2 by 2 - count_2 *= 2; + count_2 += 2; // wait four seconds (1000 milliseconds == 1 second) delay(4000); diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_11_group_pub/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_11_group_pub/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_11_group_pub/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_11_group_pub/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_12_group_sub/adafruitio_12_group_sub.ino b/libraries/Adafruit_IO_Arduino/examples/adafruitio_12_group_sub/adafruitio_12_group_sub.ino index fb31e53..36760ca 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_12_group_sub/adafruitio_12_group_sub.ino +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_12_group_sub/adafruitio_12_group_sub.ino @@ -5,7 +5,7 @@ // products from Adafruit! // // Written by Todd Treece for Adafruit Industries -// Copyright (c) 2016 Adafruit Industries +// Copyright (c) 2018 Adafruit Industries // Licensed under the MIT license. // // All text above must be included in any redistribution. @@ -34,8 +34,8 @@ void setup() { Serial.print("Connecting to Adafruit IO"); io.connect(); - group->onMessage("count-1", one); - group->onMessage("count-2", two); + group->onMessage("example.count-1", one); + group->onMessage("example.count-2", two); // wait for a connection while(io.status() < AIO_CONNECTED) { @@ -47,6 +47,8 @@ void setup() { Serial.println(); Serial.println(io.statusText()); + // force IO to update our MQTT subscription with the current values of all feeds + group->get(); } void loop() { diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_12_group_sub/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_12_group_sub/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_12_group_sub/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_12_group_sub/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_13_rgb/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_13_rgb/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_13_rgb/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_13_rgb/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_14_neopixel/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_14_neopixel/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_14_neopixel/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_14_neopixel/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_15_temp_humidity/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_15_temp_humidity/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_15_temp_humidity/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_15_temp_humidity/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_16_servo/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_16_servo/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_16_servo/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_16_servo/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_17_time_subscribe/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_17_time_subscribe/config.h index 5756181..e62e9c9 100644 --- a/libraries/Adafruit_IO_Arduino/examples/adafruitio_17_time_subscribe/config.h +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_17_time_subscribe/config.h @@ -10,6 +10,7 @@ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_18_device_info/adafruitio_18_device_info.ino b/libraries/Adafruit_IO_Arduino/examples/adafruitio_18_device_info/adafruitio_18_device_info.ino new file mode 100644 index 0000000..0d286aa --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_18_device_info/adafruitio_18_device_info.ino @@ -0,0 +1,82 @@ +// Adafruit IO Device Information +// desc: Displays Device, WiFi, and Adafruit IO connection information +// +// Adafruit invests time and resources providing this open source code. +// Please support Adafruit and open source hardware by purchasing +// products from Adafruit! +// +// Written by Brent Rubell for Adafruit Industries +// Copyright (c) 2018 Adafruit Industries +// Licensed under the MIT license. +// +// All text above must be included in any redistribution. + +/************************** Configuration ***********************************/ + +// edit the config.h tab and enter your Adafruit IO credentials +// and any additional configuration needed for WiFi, cellular, +// or ethernet clients. +#include "config.h" + +/************************ Example Starts Here *******************************/ +// device mac address +byte mac[6]; + +void setup() { + + // start the serial connection + Serial.begin(115200); + + // wait for serial monitor to open + while(! Serial); + + Serial.print("Connecting to Adafruit IO..."); + + // connect to io.adafruit.com + io.connect(); + + // wait for a connection + while(io.status() < AIO_CONNECTED) { + Serial.print("."); + delay(500); + } + Serial.println(); + + // Device Info + Serial.println("----DEVICE INFO----"); + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + WiFi.macAddress(mac); + Serial.print("MAC Address: "); + for(int i=0;i<6;i++) { + Serial.print(mac[i], HEX); + } + Serial.println(); + + // Network Info + Serial.println("----ROUTER INFO----"); + Serial.print("WIFI SSID: "); + Serial.println(WIFI_SSID); + Serial.print("WIFI Pass: "); + Serial.println(WIFI_PASS); + long rssi = WiFi.RSSI(); + Serial.print("RSSI:"); + Serial.println(rssi); + + // Adafruit IO Info + Serial.println("----ADAFRUIT IO INFO----"); + Serial.print("IO User: "); + Serial.println(IO_USERNAME); + Serial.print("IO Key: "); + Serial.println(IO_KEY); + Serial.print("IO Status: "); + Serial.println(io.statusText()); + +} + +void loop(){ + +} + diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_18_device_info/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_18_device_info/config.h new file mode 100644 index 0000000..fcc17be --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_18_device_info/config.h @@ -0,0 +1,44 @@ +/************************ Adafruit IO Config *******************************/ + +// visit io.adafruit.com if you need to create an account, +// or if you need your Adafruit IO key. +#define IO_USERNAME "AIO_USERNAME" +#define IO_KEY "AIO_KEY" + +/******************************* WIFI **************************************/ + +// the AdafruitIO_WiFi client will work with the following boards: +// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 +// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 +// - Feather M0 WiFi -> https://www.adafruit.com/products/3010 +// - Feather WICED -> https://www.adafruit.com/products/3056 + +#define WIFI_SSID "your_ssid" +#define WIFI_PASS "your_pass" + +// comment out the following two lines if you are using fona or ethernet +#include "AdafruitIO_WiFi.h" +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); + + +/******************************* FONA **************************************/ + +// the AdafruitIO_FONA client will work with the following boards: +// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 + +// uncomment the following two lines for 32u4 FONA, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_FONA.h" +// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); + + +/**************************** ETHERNET ************************************/ + +// the AdafruitIO_Ethernet client will work with the following boards: +// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 + +// uncomment the following two lines for ethernet, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_Ethernet.h" +// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_19_deepsleep/.zero.test.skip b/libraries/Adafruit_IO_Arduino/examples/adafruitio_19_deepsleep/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_19_deepsleep/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_19_deepsleep/adafruitio_19_deepsleep.ino b/libraries/Adafruit_IO_Arduino/examples/adafruitio_19_deepsleep/adafruitio_19_deepsleep.ino new file mode 100644 index 0000000..6458a71 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_19_deepsleep/adafruitio_19_deepsleep.ino @@ -0,0 +1,71 @@ +// Adafruit IO DeepSleep Example (HUZZAH8266) +// +// Adafruit invests time and resources providing this open source code. +// Please support Adafruit and open source hardware by purchasing +// products from Adafruit! +// +// Written by Brent Rubell for Adafruit Industries +// Copyright (c) 2018 Adafruit Industries +// Licensed under the MIT license. +// +// All text above must be included in any redistribution. + +/************************** Configuration ***********************************/ + +// edit the config.h tab and enter your Adafruit IO credentials +// and any additional configuration needed for WiFi, cellular, +// or ethernet clients. +#include "config.h" + +/************************ Example Starts Here *******************************/ +#define DEEPSLEEP_DURATION 20e6 + +void setup() { + // start the serial connection + Serial.begin(115200); + + // wait for serial monitor to open + while (!Serial); + Serial.println("Adafruit IO + DeepSleep"); + + // connect to the Adafruit IO Library + connectAIO(); + + // set up and write to deepsleep feed + feedWrite(); + + // let's go back to sleep for DEEPSLEEP_DURATION seconds... + Serial.println("sleeping..."); + // Put the Huzzah into deepsleep for DEEPSLEEP_DURATION + // NOTE: Make sure Pin 16 is connected to RST + ESP.deepSleep(1000000 * 2); +} + +// NOOP +void loop() { +} + + +void feedWrite(){ + // set up `deepsleep` feed + AdafruitIO_Feed *deepsleep = io.feed("deepsleep"); + Serial.println("sending value to feed 'deepsleep"); + // send data to deepsleep feed + deepsleep->save(1); + // write data to AIO + io.run(); +} +void connectAIO() { + Serial.println("Connecting to Adafruit IO..."); + io.connect(); + + // wait for a connection + while (io.status() < AIO_CONNECTED) { + Serial.print("."); + delay(500); + } + + // we are connected + Serial.println(); + Serial.println(io.statusText()); +} diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_19_deepsleep/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_19_deepsleep/config.h new file mode 100644 index 0000000..ff00627 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_19_deepsleep/config.h @@ -0,0 +1,44 @@ +/************************ Adafruit IO Config *******************************/ + +// visit io.adafruit.com if you need to create an account, +// or if you need your Adafruit IO key. +#define IO_USERNAME "AIO_USERNAME" +#define IO_KEY "AIO_KEY" + +/******************************* WIFI **************************************/ + +// the AdafruitIO_WiFi client will work with the following boards: +// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 +// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather M0 WiFi -> https://www.adafruit.com/products/3010 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 +// - Feather WICED -> https://www.adafruit.com/products/3056 + +#define WIFI_SSID "your_ssid" +#define WIFI_PASS "your_pass" + +// comment out the following two lines if you are using fona or ethernet +#include "AdafruitIO_WiFi.h" +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); + + +/******************************* FONA **************************************/ + +// the AdafruitIO_FONA client will work with the following boards: +// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 + +// uncomment the following two lines for 32u4 FONA, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_FONA.h" +// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); + + +/**************************** ETHERNET ************************************/ + +// the AdafruitIO_Ethernet client will work with the following boards: +// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 + +// uncomment the following two lines for ethernet, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_Ethernet.h" +// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_20_shared_feed_write/adafruitio_20_shared_feed_write.ino b/libraries/Adafruit_IO_Arduino/examples/adafruitio_20_shared_feed_write/adafruitio_20_shared_feed_write.ino new file mode 100644 index 0000000..046bcbc --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_20_shared_feed_write/adafruitio_20_shared_feed_write.ino @@ -0,0 +1,94 @@ +// Adafruit IO Shared Feeds Write Example +// desc: Example of writing a button value to a shared feed. +// +// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed +// +// Adafruit invests time and resources providing this open source code. +// Please support Adafruit and open source hardware by purchasing +// products from Adafruit! +// +// Written by Brent Rubell for Adafruit Industries +// Copyright (c) 2018 Adafruit Industries +// Licensed under the MIT license. +// +// All text above must be included in any redistribution. + +/************************** Configuration ***********************************/ + +// edit the config.h tab and enter your Adafruit IO credentials +// and any additional configuration needed for WiFi, cellular, +// or ethernet clients. +#include "config.h" + +/************************ Example Starts Here *******************************/ + +// digital pin 5 +#define BUTTON_PIN 5 + +// the Adafruit IO username of whomever owns the feed +#define FEED_OWNER "AIO_FEED_OWNER" + +// set up a shared feed between you and the FEED_OWNER +// make sure you have both read AND write access to this feed +AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER); + +// button state +bool current = false; +bool last = false; + +void setup() { + + // set button pin as an input + pinMode(BUTTON_PIN, INPUT); + + // start the serial connection + Serial.begin(115200); + + // wait for serial monitor to open + while(! Serial); + + // connect to io.adafruit.com + Serial.print("Connecting to Adafruit IO"); + io.connect(); + + // wait for a connection + while(io.status() < AIO_CONNECTED) { + Serial.print("."); + delay(500); + } + + // we are connected + Serial.println(); + Serial.println(io.statusText()); + +} + +void loop() { + + // io.run(); is required for all sketches. + // it should always be present at the top of your loop + // function. it keeps the client connected to + // io.adafruit.com, and processes any incoming data. + io.run(); + + // grab the current state of the button. + // we have to flip the logic because we are + // using a pullup resistor. + if(digitalRead(BUTTON_PIN) == LOW) + current = true; + else + current = false; + + // return if the value hasn't changed + if(current == last) + return; + + // save the current state to the 'sharedFeed' feed on adafruit io + Serial.print("sending button -> "); + Serial.println(current); + sharedFeed->save(current); + + // store last button state + last = current; + +} diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_20_shared_feed_write/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_20_shared_feed_write/config.h new file mode 100644 index 0000000..e62e9c9 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_20_shared_feed_write/config.h @@ -0,0 +1,44 @@ +/************************ Adafruit IO Config *******************************/ + +// visit io.adafruit.com if you need to create an account, +// or if you need your Adafruit IO key. +#define IO_USERNAME "your_username" +#define IO_KEY "your_key" + +/******************************* WIFI **************************************/ + +// the AdafruitIO_WiFi client will work with the following boards: +// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 +// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 +// - Feather M0 WiFi -> https://www.adafruit.com/products/3010 +// - Feather WICED -> https://www.adafruit.com/products/3056 + +#define WIFI_SSID "your_ssid" +#define WIFI_PASS "your_pass" + +// comment out the following two lines if you are using fona or ethernet +#include "AdafruitIO_WiFi.h" +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); + + +/******************************* FONA **************************************/ + +// the AdafruitIO_FONA client will work with the following boards: +// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 + +// uncomment the following two lines for 32u4 FONA, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_FONA.h" +// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); + + +/**************************** ETHERNET ************************************/ + +// the AdafruitIO_Ethernet client will work with the following boards: +// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 + +// uncomment the following two lines for ethernet, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_Ethernet.h" +// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_21_feed_read/adafruitio_21_feed_read.ino b/libraries/Adafruit_IO_Arduino/examples/adafruitio_21_feed_read/adafruitio_21_feed_read.ino new file mode 100644 index 0000000..7004d72 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_21_feed_read/adafruitio_21_feed_read.ino @@ -0,0 +1,78 @@ +// Adafruit IO Feed Reading +// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed +// +// Adafruit invests time and resources providing this open source code. +// Please support Adafruit and open source hardware by purchasing +// products from Adafruit! +// +// Written by Brent Rubell for Adafruit Industries +// Copyright (c) 2018 Adafruit Industries +// Licensed under the MIT license. +// +// All text above must be included in any redistribution. + +/************************** Configuration ***********************************/ + +// edit the config.h tab and enter your Adafruit IO credentials +// and any additional configuration needed for WiFi, cellular, +// or ethernet clients. +#include "config.h" + +/************************ Example Starts Here *******************************/ + +// the Adafruit IO username of whomever owns the feed +#define FEED_OWNER "AIO_FEED_OWNER" + +// set up the `sharedFeed` +AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER); + +void setup() { + + // start the serial connection + Serial.begin(115200); + + // wait for serial monitor to open + while(! Serial); + + // connect to io.adafruit.com + Serial.print("Connecting to Adafruit IO"); + io.connect(); + + // set up a message handler for the 'sharedFeed' feed. + // the handleMessage function (defined below) + // will be called whenever a message is + // received from adafruit io. + sharedFeed->onMessage(handleMessage); + + // wait for a connection + while(io.status() < AIO_CONNECTED) { + Serial.print("."); + delay(500); + } + + // we are connected + Serial.println(); + Serial.println(io.statusText()); + sharedFeed->get(); + +} + +void loop() { + + // io.run(); is required for all sketches. + // it should always be present at the top of your loop + // function. it keeps the client connected to + // io.adafruit.com, and processes any incoming data. + io.run(); + +} + +// this function is called whenever an 'sharedFeed' feed message +// is received from Adafruit IO. it was attached to +// the 'digital' feed in the setup() function above. +void handleMessage(AdafruitIO_Data *data) { + + Serial.print("received <- "); + Serial.println(data->toInt()); + +} diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_21_feed_read/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_21_feed_read/config.h new file mode 100644 index 0000000..e62e9c9 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_21_feed_read/config.h @@ -0,0 +1,44 @@ +/************************ Adafruit IO Config *******************************/ + +// visit io.adafruit.com if you need to create an account, +// or if you need your Adafruit IO key. +#define IO_USERNAME "your_username" +#define IO_KEY "your_key" + +/******************************* WIFI **************************************/ + +// the AdafruitIO_WiFi client will work with the following boards: +// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 +// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 +// - Feather M0 WiFi -> https://www.adafruit.com/products/3010 +// - Feather WICED -> https://www.adafruit.com/products/3056 + +#define WIFI_SSID "your_ssid" +#define WIFI_PASS "your_pass" + +// comment out the following two lines if you are using fona or ethernet +#include "AdafruitIO_WiFi.h" +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); + + +/******************************* FONA **************************************/ + +// the AdafruitIO_FONA client will work with the following boards: +// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 + +// uncomment the following two lines for 32u4 FONA, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_FONA.h" +// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); + + +/**************************** ETHERNET ************************************/ + +// the AdafruitIO_Ethernet client will work with the following boards: +// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 + +// uncomment the following two lines for ethernet, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_Ethernet.h" +// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/.esp8266.test.skip b/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/.esp8266.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/.esp8266.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/.zero.test.skip b/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/adafruitio_22_environmental_monitor.ino b/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/adafruitio_22_environmental_monitor.ino new file mode 100644 index 0000000..592d402 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/adafruitio_22_environmental_monitor.ino @@ -0,0 +1,190 @@ +// Adafruit IO Environmental Data Logger +// Tutorial Link: https://learn.adafruit.com/adafruit-io-air-quality-monitor +// +// Adafruit invests time and resources providing this open source code. +// Please support Adafruit and open source hardware by purchasing +// products from Adafruit! +// +// Written by Brent Rubell for Adafruit Industries +// Copyright (c) 2018 Adafruit Industries +// Licensed under the MIT license. +// +// All text above must be included in any redistribution. + +/************************** Adafruit IO Configuration ***********************************/ + +// edit the config.h tab and enter your Adafruit IO credentials +// and any additional configuration needed for WiFi, cellular, +// or ethernet clients. +#include "config.h" + +/**************************** Sensor Configuration ***************************************/ +#include +#include +#include +#include "Adafruit_VEML6070.h" +#include "Adafruit_SGP30.h" + +// BME280 Sensor Definitions +#define BME_SCK 13 +#define BME_MISO 12 +#define BME_MOSI 11 +#define BME_CS 10 +#define SEALEVELPRESSURE_HPA (1013.25) + +// Instanciate the sensors +Adafruit_BME280 bme; +Adafruit_VEML6070 uv = Adafruit_VEML6070(); +Adafruit_SGP30 sgp; + +/**************************** Example ***************************************/ +// Delay between sensor reads, in seconds +#define READ_DELAY 10 + +// DHT22 Data +int temperatureReading; +int pressureReading; + +// SGP30 Data +int tvocReading = 0; +int ecO2Reading = 0; + +// BME280 Data +int altitudeReading = 0; +int humidityReading = 0; + +// VEML6070 Data +int uvReading = 0; + +// set up the feeds for the BME280 +AdafruitIO_Feed *temperatureFeed = io.feed("temperature"); +AdafruitIO_Feed *humidityFeed = io.feed("humidity"); +AdafruitIO_Feed *pressureFeed = io.feed("pressure"); +AdafruitIO_Feed *altitudeFeed = io.feed("altitude"); + +// set up feed for the VEML6070 +AdafruitIO_Feed *uvFeed = io.feed("uv"); + +// set up feeds for the SGP30 +AdafruitIO_Feed *tvocFeed = io.feed("tvoc"); +AdafruitIO_Feed *ecO2Feed = io.feed("ecO2"); + +void setup() { + // start the serial connection + Serial.begin(9600); + + // wait for serial monitor to open + while (!Serial); + + Serial.println("Adafruit IO Environmental Logger"); + + // set up BME280 + setupBME280(); + // set up SGP30 + setupSGP30(); + // setup VEML6070 + uv.begin(VEML6070_1_T); + + // connect to io.adafruit.com + Serial.print("Connecting to Adafruit IO"); + io.connect(); + + // wait for a connection + while (io.status() < AIO_CONNECTED) + { + Serial.print("."); + delay(500); + } + + // we are connected + Serial.println(); + Serial.println(io.statusText()); +} + +void loop() { + // io.run(); is required for all sketches. + // it should always be present at the top of your loop + // function. it keeps the client connected to + // io.adafruit.com, and processes any incoming data. + io.run(); + + Serial.println("Reading Sensors..."); + + // Read the temperature from the BME280 + temperatureReading = bme.readTemperature(); + + // convert from celsius to degrees fahrenheit + temperatureReading = temperatureReading * 1.8 + 32; + + Serial.print("Temperature = "); Serial.print(temperatureReading); Serial.println(" *F"); + + // Read the pressure from the BME280 + pressureReading = bme.readPressure() / 100.0F; + Serial.print("Pressure = "); Serial.print(pressureReading); Serial.println(" hPa"); + + // Read the altitude from the BME280 + altitudeReading = bme.readAltitude(SEALEVELPRESSURE_HPA); + Serial.print("Approx. Altitude = "); Serial.print(altitudeReading); Serial.println(" m"); + + // Read the humidity from the BME280 + humidityReading = bme.readHumidity(); + Serial.print("Humidity = "); Serial.print(humidityReading); Serial.println("%"); + + // VEML6070 + uvReading = uv.readUV(); + Serial.print("UV Light Level: "); Serial.println(uvReading); + + if(! sgp.IAQmeasure()){ + tvocReading = -1; + ecO2Reading = -1; + } + else + { + tvocReading = sgp.TVOC; + ecO2Reading = sgp.eCO2; + } + + Serial.print("TVOC: "); Serial.print(tvocReading); Serial.print(" ppb\t"); + Serial.print("eCO2: "); Serial.print(ecO2Reading); Serial.println(" ppm"); + + // send data to Adafruit IO feeds + temperatureFeed->save(temperatureReading); + humidityFeed->save(humidityReading); + altitudeFeed->save(altitudeReading); + pressureFeed->save(pressureReading); + uvFeed->save(uvReading); + ecO2Feed->save(ecO2Reading); + tvocFeed->save(tvocReading); + + // delay the polled loop + delay(READ_DELAY * 1000); +} + +// Set up the SGP30 sensor +void setupSGP30() { + if (!sgp.begin()) + { + Serial.println("Sensor not found :("); + while (1); + } + Serial.print("Found SGP30 serial #"); + Serial.print(sgp.serialnumber[0], HEX); + Serial.print(sgp.serialnumber[1], HEX); + Serial.println(sgp.serialnumber[2], HEX); + + // If you previously calibrated the sensor in this environment, + // you can assign it to self-calibrate (replace the values with your baselines): + // sgp.setIAQBaseline(0x8E68, 0x8F41); +} + +// Set up the BME280 sensor +void setupBME280() { + bool status; + status = bme.begin(); + if (!status) + { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + while (1); + } + Serial.println("BME Sensor is set up!"); +} diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/config.h new file mode 100644 index 0000000..e62e9c9 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_22_environmental_monitor/config.h @@ -0,0 +1,44 @@ +/************************ Adafruit IO Config *******************************/ + +// visit io.adafruit.com if you need to create an account, +// or if you need your Adafruit IO key. +#define IO_USERNAME "your_username" +#define IO_KEY "your_key" + +/******************************* WIFI **************************************/ + +// the AdafruitIO_WiFi client will work with the following boards: +// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 +// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 +// - Feather M0 WiFi -> https://www.adafruit.com/products/3010 +// - Feather WICED -> https://www.adafruit.com/products/3056 + +#define WIFI_SSID "your_ssid" +#define WIFI_PASS "your_pass" + +// comment out the following two lines if you are using fona or ethernet +#include "AdafruitIO_WiFi.h" +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); + + +/******************************* FONA **************************************/ + +// the AdafruitIO_FONA client will work with the following boards: +// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 + +// uncomment the following two lines for 32u4 FONA, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_FONA.h" +// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); + + +/**************************** ETHERNET ************************************/ + +// the AdafruitIO_Ethernet client will work with the following boards: +// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 + +// uncomment the following two lines for ethernet, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_Ethernet.h" +// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_23_ifttt/adafruitio_23_ifttt.ino b/libraries/Adafruit_IO_Arduino/examples/adafruitio_23_ifttt/adafruitio_23_ifttt.ino new file mode 100644 index 0000000..1d9426f --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_23_ifttt/adafruitio_23_ifttt.ino @@ -0,0 +1,109 @@ +// Adafruit IO IFTTT Example - Gmailbox +// Tutorial Link: https://learn.adafruit.com/gmailbox +// +// Adafruit invests time and resources providing this open source code. +// Please support Adafruit and open source hardware by purchasing +// products from Adafruit! +// +// Written by Brent Rubell for Adafruit Industries +// Copyright (c) 2018 Adafruit Industries +// Licensed under the MIT license. +// +// All text above must be included in any redistribution. + +/************************** Configuration ***********************************/ + +// edit the config.h tab and enter your Adafruit IO credentials +// and any additional configuration needed for WiFi, cellular, +// or ethernet clients. +#include "config.h" + +// Import Servo Libraries +#if defined(ARDUINO_ARCH_ESP32) + // ESP32Servo Library (https://github.com/madhephaestus/ESP32Servo) + // installation: library manager -> search -> "ESP32Servo" + #include +#else + #include +#endif + +/************************ Example Starts Here *******************************/ + +// pin used to control the servo +#define SERVO_PIN 14 + +// Flag's up position, in degrees +#define FLAG_UP 0 + +// Flag's down position, in degrees +#define FLAG_DOWN 180 + +// How long to hold the flag up, in seconds +#define FLAG_DELAY 2 + +// create an instance of the servo class +Servo servo; + +// set up the 'servo' feed +AdafruitIO_Feed *gmail_feed = io.feed("gmail"); + +void setup() { + + // start the serial connection + Serial.begin(115200); + + // wait for serial monitor to open + while(! Serial); + + Serial.print("IFTTT Gmailbox"); + + // tell the servo class which pin we are using + servo.attach(SERVO_PIN); + + // connect to io.adafruit.com + Serial.print("Connecting to Adafruit IO"); + io.connect(); + + // set up a message handler for the 'servo' feed. + // the handleMessage function (defined below) + // will be called whenever a message is + // received from adafruit io. + gmail_feed->onMessage(handleMessage); + + // wait for a connection + while(io.status() < AIO_CONNECTED) { + Serial.print("."); + delay(500); + } + + // we are connected + Serial.println(); + Serial.println(io.statusText()); + gmail_feed->get(); + + // write flag to down position + servo.write(FLAG_DOWN); + +} + +void loop() { + + // io.run(); is required for all sketches. + // it should always be present at the top of your loop + // function. it keeps the client connected to + // io.adafruit.com, and processes any incoming data. + io.run(); + +} + +// this function is called whenever a 'gmail' message +// is received from Adafruit IO. it was attached to +// the gmail feed in the setup() function above. +void handleMessage(AdafruitIO_Data *data) { + + Serial.println("You've got mail!"); + servo.write(FLAG_UP); + // wait FLAG_DELAY seconds + delay(FLAG_DELAY * 1000); + servo.write(FLAG_DOWN); +} diff --git a/libraries/Adafruit_IO_Arduino/examples/adafruitio_23_ifttt/config.h b/libraries/Adafruit_IO_Arduino/examples/adafruitio_23_ifttt/config.h new file mode 100644 index 0000000..e62e9c9 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/adafruitio_23_ifttt/config.h @@ -0,0 +1,44 @@ +/************************ Adafruit IO Config *******************************/ + +// visit io.adafruit.com if you need to create an account, +// or if you need your Adafruit IO key. +#define IO_USERNAME "your_username" +#define IO_KEY "your_key" + +/******************************* WIFI **************************************/ + +// the AdafruitIO_WiFi client will work with the following boards: +// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 +// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 +// - Feather M0 WiFi -> https://www.adafruit.com/products/3010 +// - Feather WICED -> https://www.adafruit.com/products/3056 + +#define WIFI_SSID "your_ssid" +#define WIFI_PASS "your_pass" + +// comment out the following two lines if you are using fona or ethernet +#include "AdafruitIO_WiFi.h" +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); + + +/******************************* FONA **************************************/ + +// the AdafruitIO_FONA client will work with the following boards: +// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 + +// uncomment the following two lines for 32u4 FONA, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_FONA.h" +// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); + + +/**************************** ETHERNET ************************************/ + +// the AdafruitIO_Ethernet client will work with the following boards: +// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 + +// uncomment the following two lines for ethernet, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_Ethernet.h" +// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); diff --git a/libraries/Adafruit_IO_Arduino/examples/io_home_series/io_home_security/config.h b/libraries/Adafruit_IO_Arduino/examples/io_home_series/io_home_security/config.h new file mode 100644 index 0000000..7b326f9 --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/io_home_series/io_home_security/config.h @@ -0,0 +1,43 @@ +/************************ Adafruit IO Config *******************************/ + +// visit io.adafruit.com if you need to create an account, +// or if you need your Adafruit IO key. +#define IO_USERNAME "YOUR_AIO_USERNAME" +#define IO_KEY "YOUR_AIO_KEY" + +/******************************* WIFI **************************************/ + +// the AdafruitIO_WiFi client will work with the following boards: +// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 +// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather M0 WiFi -> https://www.adafruit.com/products/3010 +// - Feather WICED -> https://www.adafruit.com/products/3056 + +#define WIFI_SSID "YOUR_WIFI_SSID" +#define WIFI_PASS "YOUR_WIFI_PASS" + +// comment out the following two lines if you are using fona or ethernet +#include "AdafruitIO_WiFi.h" +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); + + +/******************************* FONA **************************************/ + +// the AdafruitIO_FONA client will work with the following boards: +// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 + +// uncomment the following two lines for 32u4 FONA, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_FONA.h" +// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); + + +/**************************** ETHERNET ************************************/ + +// the AdafruitIO_Ethernet client will work with the following boards: +// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 + +// uncomment the following two lines for ethernet, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_Ethernet.h" +// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); diff --git a/libraries/Adafruit_IO_Arduino/examples/io_home_series/io_home_security/io_home_security.ino b/libraries/Adafruit_IO_Arduino/examples/io_home_series/io_home_security/io_home_security.ino new file mode 100644 index 0000000..c1de41f --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/io_home_series/io_home_security/io_home_security.ino @@ -0,0 +1,298 @@ +// Adafruit IO House: Security System +// +// Learn Guide: https://learn.adafruit.com/adafruit-io-home-security +// +// Adafruit invests time and resources providing this open source code. +// Please support Adafruit and open source hardware by purchasing +// products from Adafruit! +// +// Written by Brent Rubell for Adafruit Industries +// Copyright (c) 2018 Adafruit Industries +// Licensed under the MIT license. +// +// All text above must be included in any redistribution. + +/************************** Configuration ***********************************/ + +// edit the config.h tab and enter your Adafruit IO credentials +// and any additional configuration needed for WiFi, cellular, +// or ethernet clients. +#include "config.h" + +// include the NeoPixel library +#include "Adafruit_NeoPixel.h" + +// include the SGP30 library +#include +#include "Adafruit_SGP30.h" + +/************************ Example Starts Here *******************************/ + +// delay the main `io.run()` loop +#define LOOP_DELAY 3000 +// delay for each sensor send to adafruit io +#define SENSOR_DELAY 1000 + +// PIR sensor input pin +#define pirPin 13 +// reed switch input pin +#define doorPin 2 +// piezo (alarm) buzzer +#define piezoPin 14 + +/**** Time Setup ****/ +// set the hour to start at +int startingHour = 1; +// set the second to start at +int seconds = 56; +// set the minutes to start at +int minutes = 56; +// set the hour at which the motion alarm should trigger +int alarmHour = 16; + +unsigned long currentTime = 0; +unsigned long prevTime = 0; +int currentHour = startingHour; + + +/*********NeoPixel Setup*********/ +// pin the NeoPixel strip and jewel are connected to +#define NEOPIXEL_PIN 12 +// amount of neopixels on the NeoPixel strip +#define STRIP_PIXEL_COUNT 60 +#define JEWEL_PIXEL_COUNT 7 +// type of neopixels used by the NeoPixel strip and jewel. +#define PIXEL_TYPE NEO_GRB + NEO_KHZ800 +// init. neoPixel Strip +Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, NEOPIXEL_PIN, PIXEL_TYPE); + +// sketch starts assuming no motion is detected +int pirState = LOW; +// sketch starts assuming the the door is closed +int doorState = LOW; +// alarm state +bool isAlarm = false; +// variable for reading the pin status +int pirRead = 0; +// SGP30 Sensor Object +Adafruit_SGP30 sgp; + +/*** Adafruit IO Feed Setup ***/ +// 'indoor-lights' feed +AdafruitIO_Feed *indoorLights = io.feed("indoor-lights"); +// `outdoor-lights` feed +AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights"); +// `front-door` feed +AdafruitIO_Feed *frontDoor = io.feed("front-door"); +// `motion-detector` feed +AdafruitIO_Feed *motionFeed = io.feed("motion-detector"); +// `home-alarm` feed +AdafruitIO_Feed *alarm = io.feed("home-alarm"); +// 'tvoc' feed +AdafruitIO_Feed *tvocFeed = io.feed("tvoc"); +// 'eco2' feed +AdafruitIO_Feed *eco2Feed = io.feed("eco2"); + +void setup() { + // start the serial connection + Serial.begin(115200); + + // wait for serial monitor to open + while(! Serial); + Serial.println("Adafruit IO Home: Security"); + + Serial.println("Connecting to Adafruit IO"); + // start MQTT connection to io.adafruit.com + io.connect(); + + // attach a message handler for the `home-alarm` feed + alarm->onMessage(handleAlarm); + // subscribe to lighting feeds and register message handlers + indoorLights->onMessage(indoorLightHandler); + outdoorLights->onMessage(outdoorLightHandler); + + // wait for an MQTT connection + // NOTE: when blending the HTTP and MQTT API, always use the mqttStatus + // method to check on MQTT connection status specifically + while(io.mqttStatus() < AIO_CONNECTED) { + Serial.print("."); + delay(500); + } + // we are connected + Serial.println(); + Serial.println(io.statusText()); + + // declare PIR sensor as input + pinMode(pirPin, INPUT); + // declare reed switch as input + pinMode(doorPin, INPUT); + // set up the SGP30 sensor + setupSGP30(); + // init the neopixel strip and set to `off` + strip.begin(); + strip.show(); +} + +void loop(){ + // io.run(); is required for all sketches. + // it should always be present at the top of your loop + // function. it keeps the client connected to + // io.adafruit.com, and processes any incoming data. + io.run(); + + getTime(); + Serial.println("* read door sensor..."); + readDoorSensor(); + Serial.println("* read motion detector"); + readPIR(); + Serial.println("* reading SGP30..."); + readSGP30(); + + // check if the alarm toggle is armed from the dashboard + if (isAlarm == true) { + if (doorState == HIGH || (currentHour>alarmHour && pirState == HIGH)) { + playAlarmAnimation(); + } + } +} + +void playAlarmAnimation() { +// plays the alarm piezo buzzer and turn on/off neopixels + Serial.println("ALARM TRIGGERED!"); + tone(piezoPin, 220, 2); + for(int i=0; isave(1); + } else { + Serial.println("* Door Open"); + frontDoor->save(3); + } + delay(SENSOR_DELAY); +} + +void readPIR() { + // check if motion is detected in front of the home + pirRead = digitalRead(pirPin); + if (pirRead == HIGH) { + if (pirState == LOW) { + // we have just turned on + Serial.println("* Motion detected in front of home!"); + motionFeed->save(3); + pirState = HIGH; + } + } + else { + if (pirState == HIGH) { + Serial.println("* Motion ended."); + motionFeed->save(0); + pirState = LOW; + } + } + delay(SENSOR_DELAY); +} + +void readSGP30() { +// reads the SGP30 sensor and sends data to Adafruit IO + if (! sgp.IAQmeasure()) { + Serial.println("Measurement failed"); + return; + } + Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t"); + Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm"); + tvocFeed->save(int(sgp.TVOC)); + delay(SENSOR_DELAY/2); + eco2Feed->save(int(sgp.eCO2)); + delay(SENSOR_DELAY/2); +} + +/*** MQTT messageHandlers ***/ +void handleAlarm(AdafruitIO_Data *data) { +// handle the alarm toggle on the Adafruit IO Dashboard + String toggleValue = data->toString(); + Serial.print("> rcv alarm: "); + Serial.println(toggleValue); + if(toggleValue == String("ON")) { + Serial.println("* Alarm Set: ON"); + isAlarm = true; + } else { + Serial.println("* Alarm Set: OFF"); + isAlarm = false; + } +} + +// handles the indoor light colorpicker on the Adafruit IO Dashboard +void indoorLightHandler(AdafruitIO_Data *data) { + Serial.print("-> indoor light HEX: "); + Serial.println(data->value()); + long color = data->toNeoPixel(); + // set the color of each NeoPixel in the jewel + for(int i=0; i outdoor light HEX: "); + Serial.println(data->value()); + long color = data->toNeoPixel(); + // set the color of each NeoPixel in the strip + for(int i=JEWEL_PIXEL_COUNT; i https://www.adafruit.com/products/2471 +// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 +// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 +// - Feather M0 WiFi -> https://www.adafruit.com/products/3010 +// - Feather WICED -> https://www.adafruit.com/products/3056 + +#define WIFI_SSID "your_ssid" +#define WIFI_PASS "your_pass" + +// comment out the following two lines if you are using fona or ethernet +#include "AdafruitIO_WiFi.h" +AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); + + +/******************************* FONA **************************************/ + +// the AdafruitIO_FONA client will work with the following boards: +// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027 + +// uncomment the following two lines for 32u4 FONA, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_FONA.h" +// AdafruitIO_FONA io(IO_USERNAME, IO_KEY); + + +/**************************** ETHERNET ************************************/ + +// the AdafruitIO_Ethernet client will work with the following boards: +// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201 + +// uncomment the following two lines for ethernet, +// and comment out the AdafruitIO_WiFi client in the WIFI section +// #include "AdafruitIO_Ethernet.h" +// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY); diff --git a/libraries/Adafruit_IO_Arduino/examples/io_home_series/neopixel_and_thermometer/neopixel_and_thermometer.ino b/libraries/Adafruit_IO_Arduino/examples/io_home_series/neopixel_and_thermometer/neopixel_and_thermometer.ino new file mode 100644 index 0000000..67996fb --- /dev/null +++ b/libraries/Adafruit_IO_Arduino/examples/io_home_series/neopixel_and_thermometer/neopixel_and_thermometer.ino @@ -0,0 +1,156 @@ +// Adafruit IO House: Lights and Temperature +// +// Learn Guide: https://learn.adafruit.com/adafruit-io-house-lights-and-temperature +// +// Adafruit invests time and resources providing this open source code. +// Please support Adafruit and open source hardware by purchasing +// products from Adafruit! +// +// Written by Brent Rubell for Adafruit Industries +// Copyright (c) 2018 Adafruit Industries +// Licensed under the MIT license. +// +// All text above must be included in any redistribution. + +/************************** Configuration ***********************************/ + +// edit the config.h tab and enter your Adafruit IO credentials +// and any additional configuration needed for WiFi, cellular, +// or ethernet clients. +#include "config.h" + +// include the NeoPixel library +#include "Adafruit_NeoPixel.h" + +// include the si7021 library +#include "Adafruit_Si7021.h" +/************************ Example Starts Here *******************************/ + +// pin the NeoPixel strip is connected to +#define STRIP_PIN 12 +// pin the NeoPixel Jewel is connected to +#define JEWEL_PIN 2 + +// amount of neopixels on the NeoPixel strip +#define STRIP_PIXEL_COUNT 34 +// amount of neopixels on the NeoPixel jewel +#define JEWEL_PIXEL_COUNT 7 + +// type of neopixels used by the NeoPixel strip and jewel. +#define PIXEL_TYPE NEO_GRB + NEO_KHZ800 + +// main loop() delay, in seconds +#define TEMP_DELAY 7 + +// Temperature and Humidity: Si7021 Sensor +int temperatureData; +int humidityData; + +// initalize neopixel strip +Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, STRIP_PIN, PIXEL_TYPE); +// initalize neopixel jewel +Adafruit_NeoPixel jewel = Adafruit_NeoPixel(JEWEL_PIXEL_COUNT, JEWEL_PIN, PIXEL_TYPE); + +// initalize the sensor object +Adafruit_Si7021 sensor = Adafruit_Si7021(); + +// set up the Adafruit IO feeds +AdafruitIO_Feed *indoorLights = io.feed("indoor-lights"); +AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights"); +AdafruitIO_Feed *humidity = io.feed("humidity"); +AdafruitIO_Feed *temperature = io.feed("temperature"); + +void setup() { + + // start the serial connection + Serial.begin(115200); + + // wait for serial monitor to open + while(! Serial); + + // connect to io.adafruit.com + Serial.print("Connecting to Adafruit IO"); + io.connect(); + + // subscribe to lighting feeds and register message handlers + indoorLights->onMessage(indoorLightHandler); + outdoorLights->onMessage(outdoorLightHandler); + + + // wait for a connection + while(io.status() < AIO_CONNECTED) { + Serial.print("."); + delay(500); + } + + // we are connected + Serial.println(); + Serial.println(io.statusText()); + + // initalize the Si7021 sensor + if (!sensor.begin()) { + Serial.println("Did not find Si7021 sensor!"); + while (true); + } + Serial.println("Si7021 sensor set up!"); + + // initalize the neopixel strip and jewel. + strip.begin(); + jewel.begin(); + + // set all neopixels on the strip and jewel to `off`. + strip.show(); + jewel.show(); +} + +void loop() { + // io.run(); is required for all sketches. + // it should always be present at the top of your loop + // function. it keeps the client connected to + // io.adafruit.com, and processes any incoming data. + io.run(); + + temperatureData = sensor.readTemperature() * 1.8 + 32; + humidityData = sensor.readHumidity(); + + + Serial.print("-> Sending Temperature to Adafruit IO: "); + Serial.println(temperatureData); + Serial.print("-> Sending Humidity to Adafruit IO: "); + Serial.println(humidityData); + + // send the state of the feed to adafruit io + temperature->save(temperatureData); + humidity->save(humidityData); + + // delay the loop to avoid flooding Adafruit IO + delay(1000*TEMP_DELAY); +} + +void indoorLightHandler(AdafruitIO_Data *data) { + Serial.print("-> indoor light HEX: "); + Serial.println(data->value()); + + long color = data->toNeoPixel(); + + // set the color of each NeoPixel in the jewel + for(int i=0; i outdoor light HEX: "); + Serial.println(data->value()); + + long color = data->toNeoPixel(); + + // set the color of each NeoPixel in the strip + for(int i=0; i +maintainer=Adafruit sentence=Arduino library to access Adafruit IO. paragraph=Arduino library to access Adafruit IO using the Adafruit ESP8266, ESP32, M0 WINC1500, WICED, MKR1000, Ethernet, or FONA hardware. category=Communication diff --git a/libraries/Adafruit_IO_Arduino/src/AdafruitIO.cpp b/libraries/Adafruit_IO_Arduino/src/AdafruitIO.cpp index 34cbdb6..318715f 100644 --- a/libraries/Adafruit_IO_Arduino/src/AdafruitIO.cpp +++ b/libraries/Adafruit_IO_Arduino/src/AdafruitIO.cpp @@ -78,6 +78,11 @@ AdafruitIO_Feed* AdafruitIO::feed(const char* name) return new AdafruitIO_Feed(this, name); } +AdafruitIO_Feed* AdafruitIO::feed(const char* name, const char* owner) +{ + return new AdafruitIO_Feed(this, name, owner); +} + AdafruitIO_Time* AdafruitIO::time(aio_time_format_t format) { return new AdafruitIO_Time(this, format); diff --git a/libraries/Adafruit_IO_Arduino/src/AdafruitIO.h b/libraries/Adafruit_IO_Arduino/src/AdafruitIO.h index 70e8f9c..4399de9 100644 --- a/libraries/Adafruit_IO_Arduino/src/AdafruitIO.h +++ b/libraries/Adafruit_IO_Arduino/src/AdafruitIO.h @@ -49,6 +49,7 @@ class AdafruitIO { void run(uint16_t busywait_ms = 0); AdafruitIO_Feed* feed(const char *name); + AdafruitIO_Feed* feed(const char *name, const char *owner); AdafruitIO_Group* group(const char *name); AdafruitIO_Dashboard* dashboard(const char *name); AdafruitIO_Time* time(aio_time_format_t format); diff --git a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Data.cpp b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Data.cpp index 941e977..38617f0 100644 --- a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Data.cpp +++ b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Data.cpp @@ -337,46 +337,56 @@ unsigned long AdafruitIO_Data::toUnsignedLong() int AdafruitIO_Data::toRed() { - if(! _value) - return 0; - - char r[] = "0x"; - strncat(r, toChar() + 1, 2); - - return (int)strtol(r, NULL, 0); + // Convert 0xRRGGBB to red. + if (! _value) + { + return 0; + } + char r[5]; + strcpy(r, "0x"); + strncpy(&r[2], toChar() + 1, 2); + r[4] = '\x00'; + return (int)strtol(r, NULL, 0); } int AdafruitIO_Data::toGreen() { - if(! _value) - return 0; - - char g[] = "0x"; - strncat(g, toChar() + 3, 2); - - return (int)strtol(g, NULL, 0); + // Convert 0xRRGGBB to green. + if (! _value) + { + return 0; + } + char g[5]; + strcpy(g, "0x"); + strncpy(&g[2], toChar() + 3, 2); + g[4] = '\x00'; + return (int)strtol(g, NULL, 0); } int AdafruitIO_Data::toBlue() { - if(! _value) - return 0; - - char b[] = "0x"; - strncat(b, toChar() + 5, 2); - - return (int)strtol(b, NULL, 0); + // Convert 0xRRGGBB to blue. + if (! _value) + { + return 0; + } + char b[5]; + strcpy(b, "0x"); + strncpy(&b[2], toChar() + 5, 2); + b[4] = '\x00'; + return (int)strtol(b, NULL, 0); } long AdafruitIO_Data::toNeoPixel() { - if(! _value) - return 0; - - char rgb_string[9] = "0x"; - strncat(rgb_string, toChar() + 1, 6); - - return strtol(rgb_string, NULL, 0); + if (! _value) + { + return 0; + } + char rgb[9]; + strcpy(rgb, "0x"); + strncpy(&rgb[2], toChar() + 1, 6); + return strtol(rgb, NULL, 0); } char* AdafruitIO_Data::toCSV() diff --git a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Feed.cpp b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Feed.cpp index 495207a..92eabb0 100644 --- a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Feed.cpp +++ b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Feed.cpp @@ -16,10 +16,16 @@ AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n):AdafruitIO_MQTT( { _io = io; name = n; - _sub = 0; - _pub = 0; - _get_pub = 0; - _dataCallback = 0; + owner = _io->_username; + + _init(); +} + +AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n, const char *un):AdafruitIO_MQTT() +{ + _io = io; + name = n; + owner = un; _init(); } @@ -33,7 +39,7 @@ AdafruitIO_Feed::~AdafruitIO_Feed() delete _pub; if(_get_pub) - delete _pub; + delete _get_pub; if(data) delete data; @@ -159,7 +165,7 @@ AdafruitIO_Data* AdafruitIO_Feed::lastValue() { // 15 extra for api path, 12 for /data/retain, 1 for null String url = "/api/v2/"; - url += _io->_username; + url += owner; url += "/feeds/"; url += name; url += "/data/retain"; @@ -181,6 +187,8 @@ AdafruitIO_Data* AdafruitIO_Feed::lastValue() return new AdafruitIO_Data(this, body.c_str()); } + return NULL; + } else { AIO_ERROR_PRINT("error retrieving lastValue, status: "); @@ -209,12 +217,16 @@ void AdafruitIO_Feed::subCallback(char *val, uint16_t len) void AdafruitIO_Feed::_init() { + _sub = 0; + _pub = 0; + _get_pub = 0; + _dataCallback = 0; // dynamically allocate memory for mqtt topic and REST URLs - _topic = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 8)); // 8 extra chars for /f/, /csv & null termination - _get_topic = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 12)); // 12 extra chars for /f/, /csv/get & null termination - _feed_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 16)); // 16 extra for api path & null term - _create_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + 15)); // 15 extra for api path & null term + _topic = (char *) malloc(sizeof(char) * (strlen(owner) + strlen(name) + 8)); // 8 extra chars for /f/, /csv & null termination + _get_topic = (char *) malloc(sizeof(char) * (strlen(owner) + strlen(name) + 12)); // 12 extra chars for /f/, /csv/get & null termination + _feed_url = (char *) malloc(sizeof(char) * (strlen(owner) + strlen(name) + 16)); // 16 extra for api path & null term + _create_url = (char *) malloc(sizeof(char) * (strlen(owner) + 15)); // 15 extra for api path & null term // init feed data data = new AdafruitIO_Data(this); @@ -222,24 +234,24 @@ void AdafruitIO_Feed::_init() if(_topic && _create_url && _feed_url) { // build topic string - strcpy(_topic, _io->_username); + strcpy(_topic, owner); strcat(_topic, "/f/"); strcat(_topic, name); strcat(_topic, "/csv"); // build feed url string strcpy(_feed_url, "/api/v2/"); - strcat(_feed_url, _io->_username); + strcat(_feed_url, owner); strcat(_feed_url, "/feeds/"); strcat(_feed_url, name); // build create url string strcpy(_create_url, "/api/v2/"); - strcat(_create_url, _io->_username); + strcat(_create_url, owner); strcat(_create_url, "/feeds"); // build /get topic string - strcpy(_get_topic, _io->_username); + strcpy(_get_topic, owner); strcat(_get_topic, "/f/"); strcat(_get_topic, name); strcat(_get_topic, "/csv/get"); @@ -256,6 +268,7 @@ void AdafruitIO_Feed::_init() // malloc failed _topic = 0; + _get_topic = 0; _create_url = 0; _feed_url = 0; _sub = 0; diff --git a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Feed.h b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Feed.h index 7fdfeed..c7b1c15 100644 --- a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Feed.h +++ b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Feed.h @@ -25,6 +25,8 @@ class AdafruitIO_Feed : public AdafruitIO_MQTT { public: AdafruitIO_Feed(AdafruitIO *io, const char *name); + AdafruitIO_Feed(AdafruitIO *io, const char *name, const char *owner); + ~AdafruitIO_Feed(); bool save(char *value, double lat=0, double lon=0, double ele=0); @@ -48,6 +50,7 @@ class AdafruitIO_Feed : public AdafruitIO_MQTT { void subCallback(char *val, uint16_t len); const char *name; + const char *owner; AdafruitIO_Data *lastValue(); AdafruitIO_Data *data; diff --git a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Group.cpp b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Group.cpp index 654af99..1c26a22 100644 --- a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Group.cpp +++ b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Group.cpp @@ -16,6 +16,7 @@ AdafruitIO_Group::AdafruitIO_Group(AdafruitIO *io, const char *n):AdafruitIO_MQT { _io = io; name = n; + owner = _io->_username; _init(); } @@ -28,12 +29,18 @@ AdafruitIO_Group::~AdafruitIO_Group() if(_pub) delete _pub; + if(_get_pub) + delete _get_pub; + if(data) delete data; if(_topic) free(_topic); + if (_get_topic) + free(_get_topic); + if(_group_url) free(_group_url); @@ -121,9 +128,14 @@ bool AdafruitIO_Group::save() } +bool AdafruitIO_Group::get() +{ + return _get_pub->publish("\0"); +} + AdafruitIO_Data* AdafruitIO_Group::getFeed(const char *feed) { - uint8_t i; + // uint8_t i; if(data == NULL) { data = new AdafruitIO_Data(feed); @@ -147,11 +159,13 @@ AdafruitIO_Data* AdafruitIO_Group::getFeed(const char *feed) } + return NULL; + } void AdafruitIO_Group::onMessage(AdafruitIODataCallbackType cb) { - uint8_t i; + // uint8_t i; if(_groupCallback == NULL) { _groupCallback = new AdafruitIOGroupCallback(cb); @@ -175,7 +189,7 @@ void AdafruitIO_Group::onMessage(AdafruitIODataCallbackType cb) void AdafruitIO_Group::onMessage(const char *feed, AdafruitIODataCallbackType cb) { - uint8_t i; + // uint8_t i; if(_groupCallback == NULL) { _groupCallback = new AdafruitIOGroupCallback(feed, cb); @@ -203,7 +217,7 @@ void AdafruitIO_Group::onMessage(const char *feed, AdafruitIODataCallbackType cb void AdafruitIO_Group::call(AdafruitIO_Data *d) { - uint8_t i; + // uint8_t i; if(_groupCallback == NULL) { return; @@ -266,7 +280,7 @@ void AdafruitIO_Group::subCallback(char *val, uint16_t len) void AdafruitIO_Group::setLocation(double lat, double lon, double ele) { - uint8_t i; + // uint8_t i; if(data == NULL) { return; @@ -323,34 +337,42 @@ void AdafruitIO_Group::_init() { // dynamically allocate memory for mqtt topic and REST URLs - _topic = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 8)); // 8 extra chars for /g/, /csv & null termination - _group_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 16)); // 16 extra for api path & null term - _create_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + 15)); // 15 extra for api path & null term + _topic = (char *) malloc(sizeof(char) * (strlen(owner) + strlen(name) + 8)); // 8 extra chars for /g/, /csv & null termination + _get_topic = (char *) malloc(sizeof(char) * (strlen(owner) + strlen(name) + 12)); // 12 extra chars for /f/, /csv/get & null termination + _group_url = (char *) malloc(sizeof(char) * (strlen(owner) + strlen(name) + 16)); // 16 extra for api path & null term + _create_url = (char *) malloc(sizeof(char) * (strlen(owner) + 15)); // 15 extra for api path & null term data = 0; if(_topic && _create_url && _group_url) { // build topic string - strcpy(_topic, _io->_username); + strcpy(_topic, owner); strcat(_topic, "/g/"); strcat(_topic, name); strcat(_topic, "/csv"); // build feed url string strcpy(_group_url, "/api/v2/"); - strcat(_group_url, _io->_username); + strcat(_group_url, owner); strcat(_group_url, "/groups/"); strcat(_group_url, name); // build create url string strcpy(_create_url, "/api/v2/"); - strcat(_create_url, _io->_username); + strcat(_create_url, owner); strcat(_create_url, "/groups"); + // build /get topic string + strcpy(_get_topic, owner); + strcat(_get_topic, "/g/"); + strcat(_get_topic, name); + strcat(_get_topic, "/csv/get"); + // setup subscription _sub = new Adafruit_MQTT_Subscribe(_io->_mqtt, _topic); _pub = new Adafruit_MQTT_Publish(_io->_mqtt, _topic); + _get_pub = new Adafruit_MQTT_Publish(_io->_mqtt, _get_topic); _io->_mqtt->subscribe(_sub); _sub->setCallback(this, &AdafruitIO_MQTT::subCallback); @@ -359,10 +381,12 @@ void AdafruitIO_Group::_init() // malloc failed _topic = 0; + _get_topic = 0; _create_url = 0; _group_url = 0; _sub = 0; _pub = 0; + _get_pub = 0; } diff --git a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Group.h b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Group.h index 7749846..02f4e23 100644 --- a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Group.h +++ b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Group.h @@ -38,6 +38,7 @@ class AdafruitIO_Group : public AdafruitIO_MQTT { void set(const char *feed, double value); bool save(); + bool get(); void setLocation(double lat=0, double lon=0, double ele=0); @@ -51,6 +52,7 @@ class AdafruitIO_Group : public AdafruitIO_MQTT { void call(AdafruitIO_Data *d); const char *name; + const char *owner; AdafruitIO_Data *data; AdafruitIO_Data* getFeed(const char *feed); @@ -59,11 +61,13 @@ class AdafruitIO_Group : public AdafruitIO_MQTT { void _init(); char *_topic; + char *_get_topic; char *_create_url; char *_group_url; Adafruit_MQTT_Subscribe *_sub; Adafruit_MQTT_Publish *_pub; + Adafruit_MQTT_Publish *_get_pub; AdafruitIO *_io; AdafruitIOGroupCallback *_groupCallback; diff --git a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Time.cpp b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Time.cpp index 880cb10..669d8ff 100644 --- a/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Time.cpp +++ b/libraries/Adafruit_IO_Arduino/src/AdafruitIO_Time.cpp @@ -53,6 +53,7 @@ void AdafruitIO_Time::_init() // dynamically allocate memory for mqtt topic and REST URLs const char *formatString; + switch (format) { case AIO_TIME_SECONDS: formatString = "seconds"; @@ -63,6 +64,9 @@ void AdafruitIO_Time::_init() case AIO_TIME_ISO: formatString = "ISO-8601"; break; + default: + formatString = "seconds"; + break; } _topic = (char *) malloc(sizeof(char) * (strlen(formatString) + 6)); // 6 extra chars for "time/" and null termination diff --git a/libraries/Adafruit_IO_Arduino/src/blocks/GaugeBlock.cpp b/libraries/Adafruit_IO_Arduino/src/blocks/GaugeBlock.cpp index 42e0c3a..bfe38a8 100644 --- a/libraries/Adafruit_IO_Arduino/src/blocks/GaugeBlock.cpp +++ b/libraries/Adafruit_IO_Arduino/src/blocks/GaugeBlock.cpp @@ -24,8 +24,8 @@ GaugeBlock::~GaugeBlock(){} String GaugeBlock::properties() { int w = 0; - - if(ringWidth == "thin") { + + if (strcmp(ringWidth, "thin")) { w = 25; } else { w = 50; diff --git a/libraries/Adafruit_IO_Arduino/src/blocks/MapBlock.cpp b/libraries/Adafruit_IO_Arduino/src/blocks/MapBlock.cpp index 275a0cf..dc5e896 100644 --- a/libraries/Adafruit_IO_Arduino/src/blocks/MapBlock.cpp +++ b/libraries/Adafruit_IO_Arduino/src/blocks/MapBlock.cpp @@ -13,24 +13,25 @@ MapBlock::MapBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f) { - historyHours = 0; - tile = "contrast"; + historyHours = 0; + tile = "contrast"; } -MapBlock::~MapBlock(){} +MapBlock::~MapBlock() {} String MapBlock::properties() { - if(tile != "contrast" && tile != "street" && tile != "sat") { - tile = "contrast"; - } + if ((strcmp(tile, "contrast") != 0) && (strcmp(tile, "street") != 0) && (strcmp(tile, "sat") != 0)) + { + tile = "contrast"; + } - String props = "{\"historyHours\":\""; - props += historyHours; - props += "\",\"tile\":\""; - props += tile; - props += "\"}"; + props = "{\"historyHours\":\""; + props += historyHours; + props += "\",\"tile\":\""; + props += tile; + props += "\"}"; - return props; + return props; } diff --git a/libraries/Adafruit_IO_Arduino/src/blocks/MapBlock.h b/libraries/Adafruit_IO_Arduino/src/blocks/MapBlock.h index 6ca37a7..8de7fc9 100644 --- a/libraries/Adafruit_IO_Arduino/src/blocks/MapBlock.h +++ b/libraries/Adafruit_IO_Arduino/src/blocks/MapBlock.h @@ -19,7 +19,8 @@ class MapBlock : public AdafruitIO_Block { public: MapBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f); ~MapBlock(); - + + String props; int historyHours; const char *tile; diff --git a/libraries/Adafruit_IO_Arduino/src/blocks/StreamBlock.cpp b/libraries/Adafruit_IO_Arduino/src/blocks/StreamBlock.cpp index 184a612..b73e642 100644 --- a/libraries/Adafruit_IO_Arduino/src/blocks/StreamBlock.cpp +++ b/libraries/Adafruit_IO_Arduino/src/blocks/StreamBlock.cpp @@ -13,38 +13,40 @@ StreamBlock::StreamBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f) { - fontSize = "small"; - fontColor = "green"; - showErrors = true; - showTimestamp = true; - showName = true; + fontSize = "small"; + fontColor = "green"; + showErrors = true; + showTimestamp = true; + showName = true; } -StreamBlock::~StreamBlock(){} +StreamBlock::~StreamBlock() {} String StreamBlock::properties() { - int s = 0; + int s = 0; - if(fontSize == "small") { - s = 12; - } else if(fontSize == "medium") { - s = 18; - } else { - s = 24; - } + if (strcmp(fontSize, "small") == 0) { + s = 12; + } + if (strcmp(fontSize, "medium") == 0) { + s = 18; + } + else { + s = 24; + } - String props = "{\"fontSize\":\""; - props += s; - props += "\",\"fontColor\":\""; - props += fontColor == "white" ? "#ffffff" : "#63de00"; - props += "\",\"errors\":\""; - props += showErrors ? "yes" : "no"; - props += "\",\"showTimestamp\":\""; - props += showTimestamp ? "yes" : "no"; - props += "\",\"showName\":\""; - props += showName ? "yes" : "no"; - props += "\"}"; + String props = "{\"fontSize\":\""; + props += s; + props += "\",\"fontColor\":\""; + props += (strcmp(fontColor, "white") == 0) ? "#ffffff" : "#63de00"; + props += "\",\"errors\":\""; + props += showErrors ? "yes" : "no"; + props += "\",\"showTimestamp\":\""; + props += showTimestamp ? "yes" : "no"; + props += "\",\"showName\":\""; + props += showName ? "yes" : "no"; + props += "\"}"; - return props; + return props; } diff --git a/libraries/Adafruit_IO_Arduino/src/blocks/TextBlock.cpp b/libraries/Adafruit_IO_Arduino/src/blocks/TextBlock.cpp index 980d85a..de18d1a 100644 --- a/libraries/Adafruit_IO_Arduino/src/blocks/TextBlock.cpp +++ b/libraries/Adafruit_IO_Arduino/src/blocks/TextBlock.cpp @@ -13,26 +13,31 @@ TextBlock::TextBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f) { - fontSize = "small"; + fontSize = "small"; } -TextBlock::~TextBlock(){} +TextBlock::~TextBlock() {} String TextBlock::properties() { - int s = 0; + int s = 0; - if(fontSize == "small") { - s = 12; - } else if(fontSize == "medium") { - s = 18; - } else { - s = 24; - } + if ((strcmp(fontSize, "small") == 0)) + { + s = 12; + } + else if ((strcmp(fontSize, "medium") == 0)) + { + s = 18; + } + else + { + s = 24; + } - String props = "{\"fontSize\":\""; - props += s; - props += "\"}"; + String props = "{\"fontSize\":\""; + props += s; + props += "\"}"; - return props; + return props; } diff --git a/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.cpp b/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.cpp index 40f4610..6855f84 100644 --- a/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.cpp +++ b/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.cpp @@ -189,7 +189,6 @@ int8_t Adafruit_MQTT::connect() { success = true; break; } - //Serial.println("\t**failed, retrying!"); } if (! success) return -2; // failed to sub for some reason } @@ -206,15 +205,20 @@ int8_t Adafruit_MQTT::connect(const char *user, const char *pass) uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer, uint8_t waitforpackettype, uint16_t timeout) { uint16_t len; - while (len = readFullPacket(buffer, MAXBUFFERSIZE, timeout)) { - //DEBUG_PRINT("Packet read size: "); DEBUG_PRINTLN(len); - // TODO: add subscription reading & call back processing here + while(true) { + len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); - if ((buffer[0] >> 4) == waitforpackettype) { - //DEBUG_PRINTLN(F("Found right packet")); + if(len == 0){ + break; + } + + if ((buffer[0] >> 4) == waitforpackettype) + { return len; - } else { + } + else + { ERROR_PRINTLN(F("Dropped a packet")); } } @@ -407,7 +411,6 @@ bool Adafruit_MQTT::unsubscribe(Adafruit_MQTT_Subscribe *sub) { } void Adafruit_MQTT::processPackets(int16_t timeout) { - uint16_t len; uint32_t elapsed = 0, endtime, starttime = millis(); @@ -482,7 +485,7 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) { if (i==MAXSUBSCRIPTIONS) return NULL; // matching sub not found ??? uint8_t packet_id_len = 0; - uint16_t packetid; + uint16_t packetid = 0; // Check if it is QoS 1, TODO: we dont support QoS 2 if ((buffer[0] & 0x6) == 0x2) { packet_id_len = 2; diff --git a/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.h b/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.h index 2d7066b..dc229df 100644 --- a/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.h +++ b/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.h @@ -105,14 +105,13 @@ #define MQTT_CONN_WILLFLAG 0x04 #define MQTT_CONN_CLEANSESSION 0x02 -// how many subscriptions we want to be able to track -#define MAXSUBSCRIPTIONS 5 - // how much data we save in a subscription object -// eg max-subscription-payload-size +// and how many subscriptions we want to be able to track. #if defined (__AVR_ATmega32U4__) || defined(__AVR_ATmega328P__) + #define MAXSUBSCRIPTIONS 5 #define SUBSCRIPTIONDATALEN 20 #else + #define MAXSUBSCRIPTIONS 15 #define SUBSCRIPTIONDATALEN 100 #endif diff --git a/libraries/Adafruit_MQTT_Library/Adafruit_MQTT_Client.cpp b/libraries/Adafruit_MQTT_Library/Adafruit_MQTT_Client.cpp index e2ecc82..0a4312e 100644 --- a/libraries/Adafruit_MQTT_Library/Adafruit_MQTT_Client.cpp +++ b/libraries/Adafruit_MQTT_Library/Adafruit_MQTT_Client.cpp @@ -53,6 +53,7 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen, uint16_t len = 0; int16_t t = timeout; + while (client->connected() && (timeout >= 0)) { //DEBUG_PRINT('.'); while (client->available()) { @@ -62,6 +63,11 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen, buffer[len] = c; //DEBUG_PRINTLN((uint8_t)c, HEX); len++; + + if (maxlen == 0) { // handle zero-length packets + return 0; + } + if (len == maxlen) { // we read all we want, bail DEBUG_PRINT(F("Read data:\t")); DEBUG_PRINTBUFFER(buffer, len); diff --git a/libraries/Adafruit_MQTT_Library/examples/adafruitio_anon_time_esp8266/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/adafruitio_anon_time_esp8266/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/adafruitio_anon_time_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/adafruitio_errors_esp8266/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/adafruitio_errors_esp8266/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/adafruitio_errors_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/adafruitio_secure_esp8266/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/adafruitio_secure_esp8266/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/adafruitio_secure_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/adafruitio_time_esp8266/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/adafruitio_time_esp8266/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/adafruitio_time_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/mqtt_2subs_esp8266/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/mqtt_2subs_esp8266/.zero.test.skip index e69de29..8b13789 100644 --- a/libraries/Adafruit_MQTT_Library/examples/mqtt_2subs_esp8266/.zero.test.skip +++ b/libraries/Adafruit_MQTT_Library/examples/mqtt_2subs_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266/.zero.test.skip index e69de29..8b13789 100644 --- a/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266/.zero.test.skip +++ b/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266_callback/.esp8266.test.skip b/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266_callback/.esp8266.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266_callback/.esp8266.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266_callback/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266_callback/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/mqtt_esp8266_callback/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/mqtt_ethernet/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/mqtt_ethernet/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/mqtt_ethernet/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/mqtt_fona/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/mqtt_fona/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/mqtt_fona/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/mqtt_winc1500/.esp8266.test.skip b/libraries/Adafruit_MQTT_Library/examples/mqtt_winc1500/.esp8266.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/mqtt_winc1500/.esp8266.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/mqtt_yun/.esp8266.test.skip b/libraries/Adafruit_MQTT_Library/examples/mqtt_yun/.esp8266.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/libraries/Adafruit_MQTT_Library/examples/mqtt_yun/.esp8266.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/examples/mqtt_yun/.zero.test.skip b/libraries/Adafruit_MQTT_Library/examples/mqtt_yun/.zero.test.skip index e69de29..8b13789 100644 --- a/libraries/Adafruit_MQTT_Library/examples/mqtt_yun/.zero.test.skip +++ b/libraries/Adafruit_MQTT_Library/examples/mqtt_yun/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/libraries/Adafruit_MQTT_Library/library.properties b/libraries/Adafruit_MQTT_Library/library.properties index 2268792..6436b1a 100644 --- a/libraries/Adafruit_MQTT_Library/library.properties +++ b/libraries/Adafruit_MQTT_Library/library.properties @@ -1,5 +1,5 @@ name=Adafruit MQTT Library -version=0.20.1 +version=0.20.3 author=Adafruit maintainer=Adafruit sentence=MQTT library that supports the FONA, ESP8266, Yun, and generic Arduino Client hardware. diff --git a/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp b/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp index 3c0630d..e0b2a94 100644 --- a/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp +++ b/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp @@ -43,7 +43,7 @@ // Constructor when length, pin and type are known at compile-time: Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, uint8_t p, neoPixelType t) : - begun(false), brightness(0), pixels(NULL), endTime(0) + begun(false), brightness(0), pixels(NULL), endTime(0) { updateType(t); updateLength(n); @@ -110,7 +110,7 @@ void Adafruit_NeoPixel::updateType(neoPixelType t) { } } -#if defined(ESP8266) +#if defined(ESP8266) // ESP8266 show() is external to enforce ICACHE_RAM_ATTR execution extern "C" void ICACHE_RAM_ATTR espShow( uint8_t pin, uint8_t *pixels, uint32_t numBytes, uint8_t type); @@ -1207,12 +1207,12 @@ void Adafruit_NeoPixel::show(void) { // [[[Begin of the Neopixel NRF52 EasyDMA implementation // by the Hackerspace San Salvador]]] // This technique uses the PWM peripheral on the NRF52. The PWM uses the -// EasyDMA feature included on the chip. This technique loads the duty -// cycle configuration for each cycle when the PWM is enabled. For this +// EasyDMA feature included on the chip. This technique loads the duty +// cycle configuration for each cycle when the PWM is enabled. For this // to work we need to store a 16 bit configuration for each bit of the // RGB(W) values in the pixel buffer. // Comparator values for the PWM were hand picked and are guaranteed to -// be 100% organic to preserve freshness and high accuracy. Current +// be 100% organic to preserve freshness and high accuracy. Current // parameters are: // * PWM Clock: 16Mhz // * Minimum step time: 62.5ns @@ -1242,13 +1242,13 @@ void Adafruit_NeoPixel::show(void) { #define CTOPVAL_400KHz 40UL // 2.5us // ---------- END Constants for the EasyDMA implementation ------------- -// +// // If there is no device available an alternative cycle-counter // implementation is tried. // The nRF52832 runs with a fixed clock of 64Mhz. The alternative // implementation is the same as the one used for the Teensy 3.0/1/2 but // with the Nordic SDK HAL & registers syntax. -// The number of cycles was hand picked and is guaranteed to be 100% +// The number of cycles was hand picked and is guaranteed to be 100% // organic to preserve freshness and high accuracy. // ---------- BEGIN Constants for cycle counter implementation --------- #define CYCLES_800_T0H 18 // ~0.36 uS @@ -1289,7 +1289,7 @@ void Adafruit_NeoPixel::show(void) { break; } } - + // only malloc if there is PWM device available if ( pwm != NULL ) { #ifdef ARDUINO_FEATHER52 // use thread-safe malloc @@ -1970,7 +1970,7 @@ void Adafruit_NeoPixel::show(void) { } } -#else +#else #error Architecture not supported #endif @@ -2069,6 +2069,32 @@ void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint32_t c) { } } +// Fills all or a given start+length of strip. Arguments: +// Packed RGB color (0 if unspecified, effectively a strip clear operation). +// Index if first pixel (0 if unspecified - beginning of strip). +// Pixel count (if unspecified, fills to end of strip). +void Adafruit_NeoPixel::fill(uint32_t c, uint16_t first, uint16_t count) { + uint16_t i, end; + + if(first >= numLEDs) { + return; // If first LED is past end of strip, nothing to do + } + + // Calculate the index ONE AFTER the last pixel to fill + if(count == 0) { + // Fill to end of strip + end = numLEDs; + } else { + // Ensure that the loop won't go past the last pixel + end = first + count; + if(end > numLEDs) end = numLEDs; + } + + for(i = first; i < end; i++) { + this->setPixelColor(i, c); + } +} + // Convert separate R,G,B into packed 32-bit RGB color. // Packed format is always RGB, regardless of LED strand color order. uint32_t Adafruit_NeoPixel::Color(uint8_t r, uint8_t g, uint8_t b) { diff --git a/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.h b/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.h index 9fa35bc..5fde63f 100644 --- a/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.h +++ b/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.h @@ -50,43 +50,43 @@ // 0bRRRRGGBB for RGB // RGB NeoPixel permutations; white and red offsets are always same -// Offset: W R G B -#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) -#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) -#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) -#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) -#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) -#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) +// Offset: W R G B // HEX representation +#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) // 0x06 +#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) // 0x09 +#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) // 0x52 +#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) // 0xA1 +#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) // 0x58 +#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) // 0xA4 // RGBW NeoPixel permutations; all 4 offsets are distinct -// Offset: W R G B -#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) -#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) -#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) -#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) -#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) -#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) +// Offset: W R G B // HEX representation +#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) // 0x1B +#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) // 0x1E +#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) // 0x27 +#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) // 0x36 +#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) // 0x2D +#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) // 0x39 -#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) -#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) -#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) -#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) -#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) -#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) +#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) // 0x4B +#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) // 0x4E +#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) // 0x87 +#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) // 0xC6 +#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) // 0x8D +#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) // 0xC9 -#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) -#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) -#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) -#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) -#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) -#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) +#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) // 0x63 +#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) // 0x72 +#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) // 0x93 +#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) // 0xD2 +#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) // 0xB1 +#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) // 0xE1 -#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) -#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) -#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) -#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) -#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) -#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) +#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) // 0x6C +#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) // 0x78 +#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) // 0x9C +#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) // 0xD8 +#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) // 0xB4 +#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) // 0xE4 // Add NEO_KHZ400 to the color order value to indicate a 400 KHz // device. All but the earliest v1 NeoPixels expect an 800 KHz data @@ -129,6 +129,7 @@ class Adafruit_NeoPixel { setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b), setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w), setPixelColor(uint16_t n, uint32_t c), + fill(uint32_t c=0, uint16_t first=0, uint16_t count=0), setBrightness(uint8_t), clear(), updateLength(uint16_t n), diff --git a/libraries/Adafruit_NeoPixel/README.md b/libraries/Adafruit_NeoPixel/README.md index 356bb31..1356049 100644 --- a/libraries/Adafruit_NeoPixel/README.md +++ b/libraries/Adafruit_NeoPixel/README.md @@ -43,8 +43,7 @@ Things I'd Like To Do But There's No Official Timeline So Please Don't Count On * For the show() function (with all the delicate pixel timing stuff), break out each architecture into separate source files rather than the current unmaintainable tangle of #ifdef statements! * Really the only reason I've never incorporated an HSV color function is that I haven't settled on a type and range for the hue element (mathematically an integer from 0 to 1529 yields a "most correct" approach but it's weird to use and would probably annoy people). - * Add a fill function with the arguments: (color, first, count). Count, if unspecified, fills to end of strip. First, if unspecified, is zero. Color, if unspecified, is zero (effectively a strip clear operation). Do NOT then implement fifty billion minor variations (such as first, last). No. This argument sequence was very specifically chosen because reasons, and equivalents to such variations are trivially made in one's call. Just one fill function, please. - * At such time that the prior two items are settled, revisit the DotStar library (and maybe even LPD8806 or anything else we've got) and add the same functions and behaviors so there's a good degree of sketch compatibility across different pixel types. + * At such time that the prior item is settled (along with the recently-added fill() function in Adafruit_NeoPixel), revisit the DotStar library (and maybe even LPD8806 or anything else we've got) and add the same functions and behaviors so there's a good degree of sketch compatibility across different pixel types. * I wouldn't mind paring down strandtest a bit. More diagnostic, less Amiga demo. * Please don't use updateLength() or updateType() in new code. They should not have been implemented this way (use the C++ 'new' operator with the regular constructor instead) and are only sticking around because of the Prime Directive. setPin() is OK for now though, it's a trick we can use to 'recycle' pixel memory across multiple strips. * In the M0 and M4 code, use the hardware systick counter for bit timing rather than hand-tweaked NOPs (a temporary kludge at the time because I wasn't reading systick correctly). diff --git a/libraries/Adafruit_NeoPixel/examples/simple_new_operator/.esp8266.test.skip b/libraries/Adafruit_NeoPixel/examples/simple_new_operator/.esp8266.test.skip new file mode 100644 index 0000000..e69de29 diff --git a/libraries/Adafruit_NeoPixel/examples/simple_new_operator/simple_new_operator.ino b/libraries/Adafruit_NeoPixel/examples/simple_new_operator/simple_new_operator.ino new file mode 100644 index 0000000..4b6019f --- /dev/null +++ b/libraries/Adafruit_NeoPixel/examples/simple_new_operator/simple_new_operator.ino @@ -0,0 +1,55 @@ +// NeoPixel Ring simple sketch (c) 2013 Shae Erisson +// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library +// This sketch show how to use "new" operator with Adafruit_NeoPixel library +// It's helpful if you don't know NeoPixel settings at compile time or +// you just want to store this settings in EEPROM + +#include +#ifdef __AVR__ + #include +#endif + +// Which pin on the Arduino is connected to the NeoPixels? +// On a Trinket or Gemma we suggest changing this to 1 +#define PIN 6 + +// How many NeoPixels are attached to the Arduino? +int numPixel = 16; + +// Color order, for more information see https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.h +uint8_t colorOrder = 0x52; //or just use NEO_GBR + +// Define new pointer for NeoPixel +Adafruit_NeoPixel *pixels; + + +int delayval = 500; // delay for half a second + +void setup() { + // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket +#if defined (__AVR_ATtiny85__) + if (F_CPU == 16000000) clock_prescale_set(clock_div_1); +#endif + // End of trinket special code + + // Here is a good place to read numPixel & colorOrder from EEPROM or what ever. + // create a new NeoPixel instance with new values + pixels = new Adafruit_NeoPixel(numPixel, PIN, colorOrder); + pixels->begin(); // This initializes the NeoPixel library. +} + +void loop() { + + // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. + + for(int i=0;isetPixelColor(i, pixels->Color(0,150,0)); // Moderately bright green color. + + pixels->show(); // This sends the updated pixel color to the hardware. + + delay(delayval); // Delay for a period of time (in milliseconds). + + } +} diff --git a/libraries/Adafruit_NeoPixel/keywords.txt b/libraries/Adafruit_NeoPixel/keywords.txt index 2ad4532..38a65d6 100644 --- a/libraries/Adafruit_NeoPixel/keywords.txt +++ b/libraries/Adafruit_NeoPixel/keywords.txt @@ -19,10 +19,10 @@ Color KEYWORD2 show KEYWORD2 clear KEYWORD2 -updateLength KEYWORD2 -updateType KEYWORD2 -getPixels KEYWORD2 -getBrightness KEYWORD2 +updateLength KEYWORD2 +updateType KEYWORD2 +getPixels KEYWORD2 +getBrightness KEYWORD2 getPin KEYWORD2 canShow KEYWORD2 @@ -35,6 +35,34 @@ NEO_COLMASK LITERAL1 NEO_SPDMASK LITERAL1 NEO_KHZ800 LITERAL1 NEO_KHZ400 LITERAL1 -NEO_GRB LITERAL1 NEO_RGB LITERAL1 -NEO_RGBW LITERAL1 +NEO_RBG LITERAL1 +NEO_GRB LITERAL1 +NEO_GBR LITERAL1 +NEO_BRG LITERAL1 +NEO_BGR LITERAL1 +NEO_WRGB LITERAL1 +NEO_WRBG LITERAL1 +NEO_WGRB LITERAL1 +NEO_WGBR LITERAL1 +NEO_WBRG LITERAL1 +NEO_WBGR LITERAL1 +NEO_RWGB LITERAL1 +NEO_RWBG LITERAL1 +NEO_RGWB LITERAL1 +NEO_RGBW LITERAL1 +NEO_RBWG LITERAL1 +NEO_RBGW LITERAL1 +NEO_GWRB LITERAL1 +NEO_GWBR LITERAL1 +NEO_GRWB LITERAL1 +NEO_GRBW LITERAL1 +NEO_GBWR LITERAL1 +NEO_GBRW LITERAL1 +NEO_BWRG LITERAL1 +NEO_BWGR LITERAL1 +NEO_BRWG LITERAL1 +NEO_BRGW LITERAL1 +NEO_BGWR LITERAL1 +NEO_BGRW LITERAL1 + diff --git a/libraries/Adafruit_NeoPixel/library.properties b/libraries/Adafruit_NeoPixel/library.properties index c09be61..0db6e2b 100644 --- a/libraries/Adafruit_NeoPixel/library.properties +++ b/libraries/Adafruit_NeoPixel/library.properties @@ -1,5 +1,5 @@ name=Adafruit NeoPixel -version=1.1.6 +version=1.1.7 author=Adafruit maintainer=Adafruit sentence=Arduino library for controlling single-wire-based LED pixels and strip. diff --git a/libraries/ArduinoJson/CHANGELOG.md b/libraries/ArduinoJson/CHANGELOG.md index fa7bd65..b600582 100644 --- a/libraries/ArduinoJson/CHANGELOG.md +++ b/libraries/ArduinoJson/CHANGELOG.md @@ -1,10 +1,96 @@ ArduinoJson: change log ======================= -v6.2.0-beta +v6.5.0-beta (2018-10-13) +----------- + +* Added implicit conversion from `JsonArray` and `JsonObject` to `JsonVariant` +* Allow mixed configuration in compilation units (issue #809) +* Fixed object keys not being duplicated +* `JsonPair::key()` now returns a `JsonKey` +* Increased the default capacity of `DynamicJsonDocument` +* Fixed `JsonVariant::is()` (closes #763) +* Added `JsonArrayConst`, `JsonObjectConst`, and `JsonVariantConst` +* Added copy-constructor and copy-assignment-operator for `JsonDocument` (issue #827) + +v6.4.0-beta (2018-09-11) +----------- + +* Copy `JsonArray` and `JsonObject`, instead of storing pointers (issue #780) +* Added `JsonVariant::to()` and `JsonVariant::to()` + +v6.3.0-beta (2018-08-31) +----------- + +* Implemented reference semantics for `JsonVariant` +* Replaced `JsonPair`'s `key` and `value` with `key()` and `value()` +* Fixed `serializeJson(obj[key], dst)` (issue #794) + +> ### BREAKING CHANGES +> +> #### JsonVariant +> +> `JsonVariant` now has a semantic similar to `JsonObject` and `JsonArray`. +> It's a reference to a value stored in the `JsonDocument`. +> As a consequence, a `JsonVariant` cannot be used as a standalone variable anymore. +> +> Old code: +> +> ```c++ +> JsonVariant myValue = 42; +> ``` +> +> New code: +> +> ```c++ +> DynamicJsonDocument doc; +> JsonVariant myValue = doc.to(); +> myValue.set(42); +> ``` +> +> #### JsonPair +> +> Old code: +> +> ```c++ +> for(JsonPair p : myObject) { +> Serial.println(p.key); +> Serial.println(p.value.as()); +> } +> ``` +> +> New code: +> +> ```c++ +> for(JsonPair p : myObject) { +> Serial.println(p.key()); +> Serial.println(p.value().as()); +> } +> ``` +> +> CAUTION: the key is now read only! + +v6.2.3-beta (2018-07-19) +----------- + +* Fixed exception when using Flash strings as object keys (issue #784) + +v6.2.2-beta (2018-07-18) +----------- + +* Fixed `invalid application of 'sizeof' to incomplete type '__FlashStringHelper'` (issue #783) +* Fixed `char[]` not duplicated when passed to `JsonVariant::operator[]` + +v6.2.1-beta (2018-07-17) +----------- + +* Fixed `JsonObject` not inserting keys of type `String` (issue #782) + +v6.2.0-beta (2018-07-12) ----------- * Disabled lazy number deserialization (issue #772) +* Fixed `JsonVariant::is()` that returned true for empty strings * Improved float serialization when `-fsingle-precision-constant` is used * Renamed function `RawJson()` to `serialized()` * `serializeMsgPack()` now supports values marked with `serialized()` @@ -30,7 +116,7 @@ v6.2.0-beta > object["values"] = serialized("[1,2,3,4]"); > ``` -v6.1.0-beta +v6.1.0-beta (2018-07-02) ----------- * Return `JsonArray` and `JsonObject` by value instead of reference (issue #309) @@ -60,12 +146,12 @@ v6.1.0-beta > } > ``` -v6.0.1-beta +v6.0.1-beta (2018-06-11) ----------- * Fixed conflicts with `isnan()` and `isinf()` macros (issue #752) -v6.0.0-beta +v6.0.0-beta (2018-06-07) ----------- * Added `DynamicJsonDocument` and `StaticJsonDocument` diff --git a/libraries/ArduinoJson/README.md b/libraries/ArduinoJson/README.md index f15fae5..4bfea96 100644 --- a/libraries/ArduinoJson/README.md +++ b/libraries/ArduinoJson/README.md @@ -2,7 +2,7 @@ --- -[![Build status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/master?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/master) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=master)](https://travis-ci.org/bblanchon/ArduinoJson) [![Coverage Status](https://img.shields.io/coveralls/bblanchon/ArduinoJson.svg)](https://coveralls.io/r/bblanchon/ArduinoJson?branch=master) [![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson) +[![Build status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=6.x)](https://travis-ci.org/bblanchon/ArduinoJson) [![Coverage Status](https://img.shields.io/coveralls/bblanchon/ArduinoJson.svg)](https://coveralls.io/r/bblanchon/ArduinoJson?branch=6.x) [![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson) ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). diff --git a/libraries/ArduinoJson/appveyor.yml b/libraries/ArduinoJson/appveyor.yml index 572f2c5..e9de701 100644 --- a/libraries/ArduinoJson/appveyor.yml +++ b/libraries/ArduinoJson/appveyor.yml @@ -1,4 +1,4 @@ -version: 6.0.1.{build} +version: 6.4.0.{build} environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 diff --git a/libraries/ArduinoJson/library.json b/libraries/ArduinoJson/library.json index c4bd31e..53d820c 100644 --- a/libraries/ArduinoJson/library.json +++ b/libraries/ArduinoJson/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/bblanchon/ArduinoJson.git" }, - "version": "6.2.0-beta", + "version": "6.5.0-beta", "authors": { "name": "Benoit Blanchon", "url": "https://blog.benoitblanchon.fr" diff --git a/libraries/ArduinoJson/library.properties b/libraries/ArduinoJson/library.properties index a8c5281..2fb64f2 100644 --- a/libraries/ArduinoJson/library.properties +++ b/libraries/ArduinoJson/library.properties @@ -1,5 +1,5 @@ name=ArduinoJson -version=6.2.0-beta +version=6.5.0-beta author=Benoit Blanchon maintainer=Benoit Blanchon sentence=An efficient and elegant JSON library for Arduino. diff --git a/libraries/ArduinoJson/scripts/publish.sh b/libraries/ArduinoJson/scripts/publish.sh new file mode 100644 index 0000000..56695f9 --- /dev/null +++ b/libraries/ArduinoJson/scripts/publish.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -eu + +cd "$(dirname "$0")/.." + +VERSION="$1" +DATE=$(date +%F) +TAG="v$VERSION" + +update_version_in_source () { + IFS=".-" read MAJOR MINOR REVISION EXTRA < <(echo "$VERSION") + UNDERLINE=$(printf -- '-%.0s' $(seq 1 ${#TAG})) + + sed -i~ -bE "4s/HEAD/$TAG ($DATE)/; 5s/-+/$UNDERLINE/" CHANGELOG.md + rm CHANGELOG.md*~ + sed -i~ -bE "s/\"version\":.*$/\"version\": \"$VERSION\",/" library.json + rm library.json*~ + + sed -i~ -bE "s/version=.*$/version=$VERSION/" library.properties + rm library.properties*~ + + sed -i~ -bE \ + -e "s/ARDUINOJSON_VERSION .*$/ARDUINOJSON_VERSION \"$VERSION\"/" \ + -e "s/ARDUINOJSON_VERSION_MAJOR .*$/ARDUINOJSON_VERSION_MAJOR $MAJOR/" \ + -e "s/ARDUINOJSON_VERSION_MINOR .*$/ARDUINOJSON_VERSION_MINOR $MINOR/" \ + -e "s/ARDUINOJSON_VERSION_REVISION .*$/ARDUINOJSON_VERSION_REVISION $REVISION/" \ + src/ArduinoJson/version.hpp + rm src/ArduinoJson/version.hpp*~ +} + +commit_new_version () { + git add src/ArduinoJson/version.hpp CHANGELOG.md library.json library.properties + git commit -m "Set version to $VERSION" +} + +add_tag () { + CHANGES=$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' CHANGELOG.md) + git tag -m "ArduinoJson $VERSION"$'\n'"$CHANGES" "$TAG" +} + +push () { + git push --follow-tags +} + +update_version_in_source +commit_new_version +add_tag +push diff --git a/libraries/ArduinoJson/src/ArduinoJson.hpp b/libraries/ArduinoJson/src/ArduinoJson.hpp index 949e6c3..12d0e9d 100644 --- a/libraries/ArduinoJson/src/ArduinoJson.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson.hpp @@ -4,18 +4,17 @@ #pragma once -#include "ArduinoJson/version.hpp" - -#include "ArduinoJson/DynamicJsonDocument.hpp" -#include "ArduinoJson/StaticJsonDocument.hpp" - -#include "ArduinoJson/JsonObjectImpl.hpp" +#include "ArduinoJson/Namespace.hpp" #include "ArduinoJson/JsonArray.hpp" +#include "ArduinoJson/JsonDocument.hpp" #include "ArduinoJson/JsonObject.hpp" +#include "ArduinoJson/JsonVariant.hpp" +#include "ArduinoJson/Data/VariantAsImpl.hpp" #include "ArduinoJson/JsonArrayImpl.hpp" #include "ArduinoJson/JsonArraySubscript.hpp" +#include "ArduinoJson/JsonObjectImpl.hpp" #include "ArduinoJson/JsonObjectSubscript.hpp" #include "ArduinoJson/JsonVariantImpl.hpp" @@ -24,3 +23,21 @@ #include "ArduinoJson/Json/PrettyJsonSerializer.hpp" #include "ArduinoJson/MsgPack/MsgPackDeserializer.hpp" #include "ArduinoJson/MsgPack/MsgPackSerializer.hpp" + +namespace ArduinoJson { +using ARDUINOJSON_NAMESPACE::DeserializationError; +using ARDUINOJSON_NAMESPACE::DynamicJsonDocument; +using ARDUINOJSON_NAMESPACE::JsonArray; +using ARDUINOJSON_NAMESPACE::JsonArrayConst; +using ARDUINOJSON_NAMESPACE::JsonFloat; +using ARDUINOJSON_NAMESPACE::JsonInteger; +using ARDUINOJSON_NAMESPACE::JsonKey; +using ARDUINOJSON_NAMESPACE::JsonObject; +using ARDUINOJSON_NAMESPACE::JsonObjectConst; +using ARDUINOJSON_NAMESPACE::JsonPair; +using ARDUINOJSON_NAMESPACE::JsonUInt; +using ARDUINOJSON_NAMESPACE::JsonVariant; +using ARDUINOJSON_NAMESPACE::JsonVariantConst; +using ARDUINOJSON_NAMESPACE::serialized; +using ARDUINOJSON_NAMESPACE::StaticJsonDocument; +} // namespace ArduinoJson diff --git a/libraries/ArduinoJson/src/ArduinoJson/Configuration.hpp b/libraries/ArduinoJson/src/ArduinoJson/Configuration.hpp index af4ea0b..f8d2bd9 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Configuration.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Configuration.hpp @@ -4,6 +4,18 @@ #pragma once +#if defined(_MSC_VER) +#define ARDUINOJSON_HAS_INT64 1 +#else +#define ARDUINOJSON_HAS_INT64 0 +#endif + +#if __cplusplus >= 201103L +#define ARDUINOJSON_HAS_LONG_LONG 1 +#else +#define ARDUINOJSON_HAS_LONG_LONG 0 +#endif + // Small or big machine? #ifndef ARDUINOJSON_EMBEDDED_MODE #if defined(ARDUINO) || defined(__IAR_SYSTEMS_ICC__) || defined(__XC) || \ @@ -25,9 +37,6 @@ #ifndef ARDUINOJSON_USE_LONG_LONG #define ARDUINOJSON_USE_LONG_LONG 0 #endif -#ifndef ARDUINOJSON_USE_INT64 -#define ARDUINOJSON_USE_INT64 0 -#endif // Embedded systems usually don't have std::string #ifndef ARDUINOJSON_ENABLE_STD_STRING @@ -44,6 +53,11 @@ #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 #endif +// Default capacity for DynamicJsonDocument +#ifndef ARDUINOJSON_DEFAULT_POOL_SIZE +#define ARDUINOJSON_DEFAULT_POOL_SIZE 1024 +#endif + #else // ARDUINOJSON_EMBEDDED_MODE // On a computer we have plenty of memory so we can use doubles @@ -53,22 +67,13 @@ // Use long long when available #ifndef ARDUINOJSON_USE_LONG_LONG -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) +#if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64 #define ARDUINOJSON_USE_LONG_LONG 1 #else #define ARDUINOJSON_USE_LONG_LONG 0 #endif #endif -// Use _int64 on old versions of Visual Studio -#ifndef ARDUINOJSON_USE_INT64 -#if defined(_MSC_VER) && _MSC_VER <= 1700 -#define ARDUINOJSON_USE_INT64 1 -#else -#define ARDUINOJSON_USE_INT64 0 -#endif -#endif - // On a computer, we can use std::string #ifndef ARDUINOJSON_ENABLE_STD_STRING #define ARDUINOJSON_ENABLE_STD_STRING 1 @@ -84,6 +89,11 @@ #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 #endif +// Default capacity for DynamicJsonDocument +#ifndef ARDUINOJSON_DEFAULT_POOL_SIZE +#define ARDUINOJSON_DEFAULT_POOL_SIZE 16384 +#endif + #endif // ARDUINOJSON_EMBEDDED_MODE #ifdef ARDUINO @@ -141,10 +151,6 @@ #define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 #endif -#if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64 -#error ARDUINOJSON_USE_LONG_LONG and ARDUINOJSON_USE_INT64 cannot be set together -#endif - #ifndef ARDUINOJSON_LITTLE_ENDIAN #if defined(_MSC_VER) || \ (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/ArrayFunctions.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/ArrayFunctions.hpp new file mode 100644 index 0000000..3b680f4 --- /dev/null +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/ArrayFunctions.hpp @@ -0,0 +1,99 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "JsonVariantData.hpp" +#include "Slot.hpp" +#include "SlotFunctions.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +inline JsonVariantData* arrayAdd(JsonArrayData* arr, MemoryPool* pool) { + if (!arr) return 0; + + Slot* slot = new (pool) Slot(); + if (!slot) return 0; + + slot->next = 0; + + if (arr->tail) { + slot->prev = arr->tail; + arr->tail->next = slot; + arr->tail = slot; + } else { + slot->prev = 0; + arr->head = slot; + arr->tail = slot; + } + + return &slot->value; +} + +inline Slot* arrayGetSlot(const JsonArrayData* arr, size_t index) { + if (!arr) return 0; + return slotAdvance(arr->head, index); +} + +inline JsonVariantData* arrayGet(const JsonArrayData* arr, size_t index) { + Slot* slot = arrayGetSlot(arr, index); + return slot ? &slot->value : 0; +} + +inline void arrayRemove(JsonArrayData* arr, Slot* slot) { + if (!arr || !slot) return; + + if (slot->prev) + slot->prev->next = slot->next; + else + arr->head = slot->next; + if (slot->next) + slot->next->prev = slot->prev; + else + arr->tail = slot->prev; +} + +inline void arrayRemove(JsonArrayData* arr, size_t index) { + arrayRemove(arr, arrayGetSlot(arr, index)); +} + +inline void arrayClear(JsonArrayData* arr) { + if (!arr) return; + arr->head = 0; + arr->tail = 0; +} + +bool variantCopy(JsonVariantData*, const JsonVariantData*, MemoryPool*); + +inline bool arrayCopy(JsonArrayData* dst, const JsonArrayData* src, + MemoryPool* pool) { + if (!dst || !src) return false; + arrayClear(dst); + for (Slot* s = src->head; s; s = s->next) { + if (!variantCopy(arrayAdd(dst, pool), &s->value, pool)) return false; + } + return true; +} + +bool variantEquals(const JsonVariantData*, const JsonVariantData*); + +inline bool arrayEquals(const JsonArrayData* a1, const JsonArrayData* a2) { + if (a1 == a2) return true; + if (!a1 || !a2) return false; + Slot* s1 = a1->head; + Slot* s2 = a2->head; + for (;;) { + if (s1 == s2) return true; + if (!s1 || !s2) return false; + if (!variantEquals(&s1->value, &s2->value)) return false; + s1 = s1->next; + s2 = s2->next; + } +} + +inline size_t arraySize(const JsonArrayData* arr) { + if (!arr) return 0; + return slotSize(arr->head); +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/IsVariant.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/IsVariant.hpp deleted file mode 100644 index 2c54341..0000000 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/IsVariant.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "../Polyfills/type_traits.hpp" - -namespace ArduinoJson { -namespace Internals { - -class JsonVariantTag {}; - -template -struct IsVariant : is_base_of {}; -} // namespace Internals -} // namespace ArduinoJson diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonFloat.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonFloat.hpp index 0ed4214..2f6e957 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonFloat.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonFloat.hpp @@ -6,13 +6,11 @@ #include "../Configuration.hpp" -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { #if ARDUINOJSON_USE_DOUBLE typedef double JsonFloat; #else typedef float JsonFloat; #endif -} -} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonInteger.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonInteger.hpp index c8ddd00..9848b5b 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonInteger.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonInteger.hpp @@ -6,18 +6,15 @@ #include "../Configuration.hpp" -namespace ArduinoJson { -namespace Internals { +#include // int64_t + +namespace ARDUINOJSON_NAMESPACE { #if ARDUINOJSON_USE_LONG_LONG -typedef long long JsonInteger; -typedef unsigned long long JsonUInt; -#elif ARDUINOJSON_USE_INT64 -typedef __int64 JsonInteger; -typedef unsigned _int64 JsonUInt; +typedef int64_t JsonInteger; +typedef uint64_t JsonUInt; #else typedef long JsonInteger; typedef unsigned long JsonUInt; #endif -} -} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantAs.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantAs.hpp index a3a0847..2d0738d 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantAs.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantAs.hpp @@ -4,8 +4,14 @@ #pragma once -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { + +class JsonArray; +class JsonArrayConst; +class JsonObject; +class JsonObjectConst; +class JsonVariant; +class JsonVariantConst; // A metafunction that returns the type of the value returned by // JsonVariant::as() @@ -19,5 +25,25 @@ struct JsonVariantAs { typedef const char* type; }; -} // namespace Internals -} // namespace ArduinoJson +// A metafunction that returns the type of the value returned by +// JsonVariant::as() +template +struct JsonVariantConstAs { + typedef typename JsonVariantAs::type type; +}; + +template <> +struct JsonVariantConstAs { + typedef JsonVariantConst type; +}; + +template <> +struct JsonVariantConstAs { + typedef JsonObjectConst type; +}; + +template <> +struct JsonVariantConstAs { + typedef JsonArrayConst type; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantContent.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantContent.hpp deleted file mode 100644 index 97a84a0..0000000 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantContent.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "JsonFloat.hpp" -#include "JsonInteger.hpp" - -namespace ArduinoJson { -namespace Internals { -// Forward declarations -struct JsonArrayData; -struct JsonObjectData; - -// A union that defines the actual content of a JsonVariant. -// The enum JsonVariantType determines which member is in use. -union JsonVariantContent { - JsonFloat asFloat; // used for double and float - JsonUInt asInteger; // used for bool, char, short, int and longs - JsonArrayData* asArray; // asArray cannot be null - JsonObjectData* asObject; // asObject cannot be null - const char* asString; // asString can be null - struct { - const char* data; - size_t size; - } asRaw; -}; -} // namespace Internals -} // namespace ArduinoJson diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantData.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantData.hpp new file mode 100644 index 0000000..d00854c --- /dev/null +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantData.hpp @@ -0,0 +1,79 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include // ptrdiff_t, size_t + +#include "JsonFloat.hpp" +#include "JsonInteger.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +enum JsonVariantType { + JSON_NULL, + JSON_LINKED_RAW, + JSON_OWNED_RAW, + JSON_LINKED_STRING, + JSON_OWNED_STRING, + JSON_BOOLEAN, + JSON_POSITIVE_INTEGER, + JSON_NEGATIVE_INTEGER, + JSON_ARRAY, + JSON_OBJECT, + JSON_FLOAT +}; + +struct JsonObjectData { + struct Slot *head; + struct Slot *tail; +}; + +struct JsonArrayData { + struct Slot *head; + struct Slot *tail; +}; + +struct RawData { + const char *data; + size_t size; +}; + +// A union that defines the actual content of a JsonVariantData. +// The enum JsonVariantType determines which member is in use. +union JsonVariantContent { + JsonFloat asFloat; + JsonUInt asInteger; + JsonArrayData asArray; + JsonObjectData asObject; + const char *asString; + struct { + const char *data; + size_t size; + } asRaw; +}; + +// this struct must be a POD type to prevent error calling offsetof on clang +struct JsonVariantData { + bool keyIsStatic : 1; + JsonVariantType type : 7; + JsonVariantContent content; +}; + +inline JsonVariantData *getVariantData(JsonArrayData *arr) { + const ptrdiff_t offset = offsetof(JsonVariantData, content) - + offsetof(JsonVariantContent, asArray); + if (!arr) return 0; + return reinterpret_cast(reinterpret_cast(arr) - + offset); +} + +inline JsonVariantData *getVariantData(JsonObjectData *obj) { + const ptrdiff_t offset = offsetof(JsonVariantData, content) - + offsetof(JsonVariantContent, asObject); + if (!obj) return 0; + return reinterpret_cast(reinterpret_cast(obj) - + offset); +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantDefault.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantDefault.hpp deleted file mode 100644 index 57ecc83..0000000 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantDefault.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -namespace ArduinoJson { -namespace Internals { - -template -struct JsonVariantDefault { - static T get() { - return T(); - } -}; - -template -struct JsonVariantDefault : JsonVariantDefault {}; - -template -struct JsonVariantDefault : JsonVariantDefault {}; -} -} diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantTo.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantTo.hpp new file mode 100644 index 0000000..5b5d4f0 --- /dev/null +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantTo.hpp @@ -0,0 +1,30 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { +class JsonArray; +class JsonObject; +class JsonVariant; + +// A metafunction that returns the type of the value returned by +// JsonVariant::to() +template +struct JsonVariantTo {}; + +template <> +struct JsonVariantTo { + typedef JsonArray type; +}; +template <> +struct JsonVariantTo { + typedef JsonObject type; +}; +template <> +struct JsonVariantTo { + typedef JsonVariant type; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantType.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantType.hpp deleted file mode 100644 index 838460a..0000000 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/JsonVariantType.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -namespace ArduinoJson { - -namespace Internals { - -// Enumerated type to know the current type of a JsonVariant. -// The value determines which member of JsonVariantContent is used. -enum JsonVariantType { - JSON_UNDEFINED, // JsonVariant has not been initialized - JSON_UNPARSED, // JsonVariant contains an unparsed string - JSON_STRING, // JsonVariant stores a const char* - JSON_BOOLEAN, // JsonVariant stores a bool - JSON_POSITIVE_INTEGER, // JsonVariant stores an JsonUInt - JSON_NEGATIVE_INTEGER, // JsonVariant stores an JsonUInt that must be negated - JSON_ARRAY, // JsonVariant stores a pointer to a JsonArrayData - JSON_OBJECT, // JsonVariant stores a pointer to a JsonObjectData - JSON_FLOAT // JsonVariant stores a JsonFloat -}; -} // namespace Internals -} // namespace ArduinoJson diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/List.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/List.hpp deleted file mode 100644 index 0982c01..0000000 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/List.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "../Memory/JsonBuffer.hpp" -#include "ListConstIterator.hpp" -#include "ListIterator.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A singly linked list of T. -// The linked list is composed of ListNode. -// It is derived by JsonArrayData and JsonObjectData -template -class List { - public: - typedef T value_type; - typedef ListNode node_type; - typedef ListIterator iterator; - typedef ListConstIterator const_iterator; - - explicit List(JsonBuffer *buf) : _buffer(buf), _firstNode(NULL) {} - - // Returns the numbers of elements in the list. - // For a JsonObjectData, it would return the number of key-value pairs - size_t size() const { - size_t nodeCount = 0; - for (node_type *node = _firstNode; node; node = node->next) nodeCount++; - return nodeCount; - } - - iterator add() { - node_type *newNode = new (_buffer) node_type(); - - if (_firstNode) { - node_type *lastNode = _firstNode; - while (lastNode->next) lastNode = lastNode->next; - lastNode->next = newNode; - } else { - _firstNode = newNode; - } - - return iterator(newNode); - } - - iterator begin() { - return iterator(_firstNode); - } - iterator end() { - return iterator(NULL); - } - - const_iterator begin() const { - return const_iterator(_firstNode); - } - const_iterator end() const { - return const_iterator(NULL); - } - - void remove(iterator it) { - node_type *nodeToRemove = it._node; - if (!nodeToRemove) return; - if (nodeToRemove == _firstNode) { - _firstNode = nodeToRemove->next; - } else { - for (node_type *node = _firstNode; node; node = node->next) - if (node->next == nodeToRemove) node->next = nodeToRemove->next; - } - } - - JsonBuffer &buffer() const { - return *_buffer; - } - JsonBuffer *_buffer; // TODO!! - - protected: - void clear() { - _firstNode = 0; - } - - private: - node_type *_firstNode; -}; -} // namespace Internals -} // namespace ArduinoJson diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/ListConstIterator.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/ListConstIterator.hpp deleted file mode 100644 index a6af685..0000000 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/ListConstIterator.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "ListNode.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A read-only forward itertor for List -template -class ListConstIterator { - public: - explicit ListConstIterator(const ListNode *node = NULL) : _node(node) {} - - const T &operator*() const { - return _node->content; - } - const T *operator->() { - return &_node->content; - } - - bool operator==(const ListConstIterator &other) const { - return _node == other._node; - } - - bool operator!=(const ListConstIterator &other) const { - return _node != other._node; - } - - ListConstIterator &operator++() { - if (_node) _node = _node->next; - return *this; - } - - ListConstIterator &operator+=(size_t distance) { - while (_node && distance) { - _node = _node->next; - --distance; - } - return *this; - } - - private: - const ListNode *_node; -}; -} -} diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/ListIterator.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/ListIterator.hpp deleted file mode 100644 index 01fa287..0000000 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/ListIterator.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "ListConstIterator.hpp" -#include "ListNode.hpp" - -namespace ArduinoJson { -namespace Internals { - -template -class List; - -// A read-write forward iterator for List -template -class ListIterator { - friend class List; - - public: - explicit ListIterator(ListNode *node = NULL) : _node(node) {} - - T &operator*() const { - return _node->content; - } - T *operator->() { - return &_node->content; - } - - bool operator==(const ListIterator &other) const { - return _node == other._node; - } - - bool operator!=(const ListIterator &other) const { - return _node != other._node; - } - - ListIterator &operator++() { - if (_node) _node = _node->next; - return *this; - } - - ListIterator &operator+=(size_t distance) { - while (_node && distance) { - _node = _node->next; - --distance; - } - return *this; - } - - operator ListConstIterator() const { - return ListConstIterator(_node); - } - - private: - ListNode *_node; -}; -} -} diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/ListNode.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/ListNode.hpp deleted file mode 100644 index f6e2a5e..0000000 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/ListNode.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include // for NULL - -#include "../Memory/JsonBufferAllocated.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A node for a singly-linked list. -// Used by List and its iterators. -template -struct ListNode : public Internals::JsonBufferAllocated { - ListNode() throw() : next(NULL) {} - - ListNode *next; - T content; -}; -} // namespace Internals -} // namespace ArduinoJson diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/ObjectFunctions.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/ObjectFunctions.hpp new file mode 100644 index 0000000..cb5a345 --- /dev/null +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/ObjectFunctions.hpp @@ -0,0 +1,123 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "JsonVariantData.hpp" +#include "SlotFunctions.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +template +inline Slot* objectFindSlot(const JsonObjectData* obj, TKey key) { + if (!obj) return 0; + Slot* slot = obj->head; + while (slot) { + if (key.equals(slot->key)) break; + slot = slot->next; + } + return slot; +} + +template +inline bool objectContainsKey(const JsonObjectData* obj, const TKey& key) { + return objectFindSlot(obj, key) != 0; +} + +template +inline JsonVariantData* objectAdd(JsonObjectData* obj, TKey key, + MemoryPool* pool) { + Slot* slot = new (pool) Slot(); + if (!slot) return 0; + + slot->next = 0; + + if (obj->tail) { + slot->prev = obj->tail; + obj->tail->next = slot; + obj->tail = slot; + } else { + slot->prev = 0; + obj->head = slot; + obj->tail = slot; + } + + if (!slotSetKey(slot, key, pool)) return 0; + return &slot->value; +} + +template +inline JsonVariantData* objectSet(JsonObjectData* obj, TKey key, + MemoryPool* pool) { + if (!obj) return 0; + + // ignore null key + if (key.isNull()) return 0; + + // search a matching key + Slot* slot = objectFindSlot(obj, key); + if (slot) return &slot->value; + + return objectAdd(obj, key, pool); +} + +template +inline JsonVariantData* objectGet(const JsonObjectData* obj, TKey key) { + Slot* slot = objectFindSlot(obj, key); + return slot ? &slot->value : 0; +} + +inline void objectClear(JsonObjectData* obj) { + if (!obj) return; + obj->head = 0; + obj->tail = 0; +} + +inline void objectRemove(JsonObjectData* obj, Slot* slot) { + if (!obj) return; + if (!slot) return; + if (slot->prev) + slot->prev->next = slot->next; + else + obj->head = slot->next; + if (slot->next) + slot->next->prev = slot->prev; + else + obj->tail = slot->prev; +} + +inline size_t objectSize(const JsonObjectData* obj) { + if (!obj) return 0; + return slotSize(obj->head); +} + +// bool variantCopy(JsonVariantData*, const JsonVariantData*, MemoryPool*); + +inline bool objectCopy(JsonObjectData* dst, const JsonObjectData* src, + MemoryPool* pool) { + if (!dst || !src) return false; + objectClear(dst); + for (Slot* s = src->head; s; s = s->next) { + JsonVariantData* var; + if (s->value.keyIsStatic) + var = objectAdd(dst, ZeroTerminatedRamStringConst(s->key), pool); + else + var = objectAdd(dst, ZeroTerminatedRamString(s->key), pool); + if (!variantCopy(var, &s->value, pool)) return false; + } + return true; +} + +inline bool objectEquals(const JsonObjectData* o1, const JsonObjectData* o2) { + if (o1 == o2) return true; + if (!o1 || !o2) return false; + + for (Slot* s = o1->head; s; s = s->next) { + JsonVariantData* v1 = &s->value; + JsonVariantData* v2 = objectGet(o2, makeString(s->key)); + if (!variantEquals(v1, v2)) return false; + } + return true; +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/Slot.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/Slot.hpp new file mode 100644 index 0000000..db603b9 --- /dev/null +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/Slot.hpp @@ -0,0 +1,19 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "../Memory/AllocableInMemoryPool.hpp" +#include "JsonVariantData.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +struct Slot : AllocableInMemoryPool { + JsonVariantData value; + struct Slot* next; + struct Slot* prev; + const char* key; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/SlotFunctions.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/SlotFunctions.hpp new file mode 100644 index 0000000..9c3dc4a --- /dev/null +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/SlotFunctions.hpp @@ -0,0 +1,59 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "../Strings/StringTypes.hpp" +#include "JsonVariantData.hpp" +#include "Slot.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +template +inline bool slotSetKey(Slot* slot, TKey key, MemoryPool* pool) { + const char* dup = key.save(pool); + if (!dup) return false; + slot->key = dup; + slot->value.keyIsStatic = false; + return true; +} + +inline bool slotSetKey(Slot* slot, ZeroTerminatedRamStringConst key, + MemoryPool* pool) { + slot->key = key.save(pool); + slot->value.keyIsStatic = true; + return true; +} + +inline bool slotSetKey(Slot* slot, StringInMemoryPool key, MemoryPool* pool) { + slot->key = key.save(pool); + slot->value.keyIsStatic = false; + return true; +} + +inline const Slot* slotAdvance(const Slot* slot, size_t distance) { + while (distance && slot) { + slot = slot->next; + distance--; + } + return slot; +} + +inline Slot* slotAdvance(Slot* slot, size_t distance) { + while (distance && slot) { + slot = slot->next; + distance--; + } + return slot; +} + +inline size_t slotSize(const Slot* slot) { + size_t n = 0; + while (slot) { + n++; + slot = slot->next; + } + return n; +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/ValueSaver.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/ValueSaver.hpp deleted file mode 100644 index 5912629..0000000 --- a/libraries/ArduinoJson/src/ArduinoJson/Data/ValueSaver.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#pragma once - -#include "../JsonVariant.hpp" -#include "../Memory/JsonBuffer.hpp" -#include "../Polyfills/type_traits.hpp" -#include "../Strings/StringTypes.hpp" - -namespace ArduinoJson { -namespace Internals { - -template -struct ValueSaver { - template - static bool save(JsonBuffer*, Destination& destination, Source source) { - destination = source; - return true; - } -}; - -// We duplicate all strings except const char* -template -struct ValueSaver< - TString, typename enable_if::value && - !is_same::value>::type> { - template - static bool save(JsonBuffer* buffer, Destination& dest, TString source) { - const char* dup = makeString(source).save(buffer); - if (!dup) return false; - dest = dup; - return true; - } -}; - -// We duplicate all SerializedValue except SerializedValue -template -struct ValueSaver< - const SerializedValue&, - typename enable_if::value>::type> { - template - static bool save(JsonBuffer* buffer, Destination& dest, - const SerializedValue& source) { - const char* dup = makeString(source.data(), source.size()).save(buffer); - if (!dup) return false; - dest = SerializedValue(dup, source.size()); - return true; - } -}; -} // namespace Internals -} // namespace ArduinoJson diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/VariantAs.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/VariantAs.hpp new file mode 100644 index 0000000..9f3de6e --- /dev/null +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/VariantAs.hpp @@ -0,0 +1,48 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "../Serialization/DynamicStringWriter.hpp" +#include "VariantFunctions.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +class JsonVariantConst; + +template +inline typename enable_if::value, T>::type variantAs( + const JsonVariantData* _data) { + return variantAsIntegral(_data); +} + +template +inline typename enable_if::value, T>::type variantAs( + const JsonVariantData* _data) { + return variantAsBoolean(_data); +} + +template +inline typename enable_if::value, T>::type variantAs( + const JsonVariantData* _data) { + return variantAsFloat(_data); +} + +template +inline typename enable_if::value || + is_same::value, + const char*>::type +variantAs(const JsonVariantData* _data) { + return variantAsString(_data); +} + +template +inline typename enable_if::value, T>::type +variantAs(const JsonVariantData* _data); + +template +inline typename enable_if::value, T>::type variantAs( + const JsonVariantData* _data); + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/VariantAsImpl.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/VariantAsImpl.hpp new file mode 100644 index 0000000..6447160 --- /dev/null +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/VariantAsImpl.hpp @@ -0,0 +1,29 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "../JsonVariant.hpp" +#include "../Serialization/DynamicStringWriter.hpp" +#include "VariantFunctions.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +template +inline typename enable_if::value, T>::type +variantAs(const JsonVariantData* _data) { + return JsonVariantConst(_data); +} + +template +inline typename enable_if::value, T>::type variantAs( + const JsonVariantData* _data) { + const char* cstr = variantAsString(_data); + if (cstr) return T(cstr); + T s; + serializeJson(JsonVariantConst(_data), s); + return s; +} + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Data/VariantFunctions.hpp b/libraries/ArduinoJson/src/ArduinoJson/Data/VariantFunctions.hpp new file mode 100644 index 0000000..fba9abd --- /dev/null +++ b/libraries/ArduinoJson/src/ArduinoJson/Data/VariantFunctions.hpp @@ -0,0 +1,287 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "../Numbers/parseFloat.hpp" +#include "../Numbers/parseInteger.hpp" +#include "../SerializedValue.hpp" +#include "ArrayFunctions.hpp" +#include "JsonVariantData.hpp" +#include "ObjectFunctions.hpp" +#include "Slot.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +template +inline T variantAsIntegral(const JsonVariantData* var) { + if (!var) return 0; + switch (var->type) { + case JSON_POSITIVE_INTEGER: + case JSON_BOOLEAN: + return T(var->content.asInteger); + case JSON_NEGATIVE_INTEGER: + return T(~var->content.asInteger + 1); + case JSON_LINKED_STRING: + case JSON_OWNED_STRING: + return parseInteger(var->content.asString); + case JSON_FLOAT: + return T(var->content.asFloat); + default: + return 0; + } +} + +inline bool variantAsBoolean(const JsonVariantData* var) { + return variantAsIntegral(var) != 0; +} + +// T = float/double +template +inline T variantAsFloat(const JsonVariantData* var) { + if (!var) return 0; + switch (var->type) { + case JSON_POSITIVE_INTEGER: + case JSON_BOOLEAN: + return static_cast(var->content.asInteger); + case JSON_NEGATIVE_INTEGER: + return -static_cast(var->content.asInteger); + case JSON_LINKED_STRING: + case JSON_OWNED_STRING: + return parseFloat(var->content.asString); + case JSON_FLOAT: + return static_cast(var->content.asFloat); + default: + return 0; + } +} + +inline const char* variantAsString(const JsonVariantData* var) { + if (!var) return 0; + if (var && + (var->type == JSON_LINKED_STRING || var->type == JSON_OWNED_STRING)) + return var->content.asString; + else + return 0; +} + +inline JsonArrayData* variantAsArray(JsonVariantData* var) { + if (var && var->type == JSON_ARRAY) + return &var->content.asArray; + else + return 0; +} + +inline const JsonArrayData* variantAsArray(const JsonVariantData* var) { + if (var && var->type == JSON_ARRAY) + return &var->content.asArray; + else + return 0; +} + +inline JsonObjectData* variantAsObject(JsonVariantData* var) { + if (var && var->type == JSON_OBJECT) + return &var->content.asObject; + else + return 0; +} + +inline const JsonObjectData* variantAsObject(const JsonVariantData* var) { + if (var && var->type == JSON_OBJECT) + return &var->content.asObject; + else + return 0; +} + +inline bool variantSetBoolean(JsonVariantData* var, bool value) { + if (!var) return false; + var->type = JSON_BOOLEAN; + var->content.asInteger = static_cast(value); + return true; +} + +inline bool variantSetFloat(JsonVariantData* var, JsonFloat value) { + if (!var) return false; + var->type = JSON_FLOAT; + var->content.asFloat = value; + return true; +} + +template +inline bool variantSetSignedInteger(JsonVariantData* var, T value) { + if (!var) return false; + if (value >= 0) { + var->type = JSON_POSITIVE_INTEGER; + var->content.asInteger = static_cast(value); + } else { + var->type = JSON_NEGATIVE_INTEGER; + var->content.asInteger = ~static_cast(value) + 1; + } + return true; +} + +inline bool variantSetSignedInteger(JsonVariantData* var, JsonUInt value) { + if (!var) return false; + var->type = JSON_POSITIVE_INTEGER; + var->content.asInteger = static_cast(value); + return true; +} + +inline bool variantSetLinkedRaw(JsonVariantData* var, + SerializedValue value) { + if (!var) return false; + var->type = JSON_LINKED_RAW; + var->content.asRaw.data = value.data(); + var->content.asRaw.size = value.size(); + return true; +} + +template +inline bool variantSetOwnedRaw(JsonVariantData* var, SerializedValue value, + MemoryPool* pool) { + if (!var) return false; + const char* dup = makeString(value.data(), value.size()).save(pool); + if (dup) { + var->type = JSON_OWNED_RAW; + var->content.asRaw.data = dup; + var->content.asRaw.size = value.size(); + return true; + } else { + var->type = JSON_NULL; + return false; + } +} + +template +inline bool variantSetString(JsonVariantData* var, T value, MemoryPool* pool) { + if (!var) return false; + const char* dup = value.save(pool); + if (dup) { + var->type = JSON_OWNED_STRING; + var->content.asString = dup; + return true; + } else { + var->type = JSON_NULL; + return false; + } +} + +inline bool variantSetString(JsonVariantData* var, const char* value) { + if (!var) return false; + var->type = JSON_LINKED_STRING; + var->content.asString = value; + return true; +} + +inline bool variantSetString(JsonVariantData* var, const char* value, + MemoryPool* pool) { + return variantSetString(var, makeString(const_cast(value)), pool); +} + +inline void variantSetNull(JsonVariantData* var) { + if (var) var->type = JSON_NULL; +} + +inline JsonArrayData* variantToArray(JsonVariantData* var) { + if (!var) return 0; + var->type = JSON_ARRAY; + var->content.asArray.head = 0; + var->content.asArray.tail = 0; + return &var->content.asArray; +} + +inline JsonObjectData* variantToObject(JsonVariantData* var) { + if (!var) return 0; + var->type = JSON_OBJECT; + var->content.asObject.head = 0; + var->content.asObject.tail = 0; + return &var->content.asObject; +} + +inline bool variantCopy(JsonVariantData* dst, const JsonVariantData* src, + MemoryPool* pool) { + if (!dst) return false; + if (!src) { + dst->type = JSON_NULL; + return true; + } + switch (src->type) { + case JSON_ARRAY: + return arrayCopy(variantToArray(dst), &src->content.asArray, pool); + case JSON_OBJECT: + return objectCopy(variantToObject(dst), &src->content.asObject, pool); + case JSON_OWNED_STRING: + return variantSetString(dst, src->content.asString, pool); + case JSON_OWNED_RAW: + return variantSetOwnedRaw( + dst, + serialized(const_cast(src->content.asRaw.data), + src->content.asRaw.size), + pool); + default: + *dst = *src; + return true; + } +} + +inline bool variantIsInteger(const JsonVariantData* var) { + return var && (var->type == JSON_POSITIVE_INTEGER || + var->type == JSON_NEGATIVE_INTEGER); +} + +inline bool variantIsFloat(const JsonVariantData* var) { + return var && + (var->type == JSON_FLOAT || var->type == JSON_POSITIVE_INTEGER || + var->type == JSON_NEGATIVE_INTEGER); +} + +inline bool variantIsString(const JsonVariantData* var) { + return var && + (var->type == JSON_LINKED_STRING || var->type == JSON_OWNED_STRING); +} + +inline bool variantIsArray(const JsonVariantData* var) { + return var && var->type == JSON_ARRAY; +} + +inline bool variantIsObject(const JsonVariantData* var) { + return var && var->type == JSON_OBJECT; +} + +inline bool variantIsNull(const JsonVariantData* var) { + return var == 0 || var->type == JSON_NULL; +} + +inline bool variantEquals(const JsonVariantData* a, const JsonVariantData* b) { + if (a == b) return true; + if (!a || !b) return false; + if (a->type != b->type) return false; + + switch (a->type) { + case JSON_LINKED_RAW: + case JSON_OWNED_RAW: + case JSON_LINKED_STRING: + case JSON_OWNED_STRING: + return !strcmp(a->content.asString, b->content.asString); + + case JSON_BOOLEAN: + case JSON_POSITIVE_INTEGER: + case JSON_NEGATIVE_INTEGER: + return a->content.asInteger == b->content.asInteger; + + case JSON_ARRAY: + return arrayEquals(&a->content.asArray, &b->content.asArray); + + case JSON_OBJECT: + return objectEquals(&a->content.asObject, &b->content.asObject); + + case JSON_FLOAT: + return a->content.asFloat == b->content.asFloat; + + case JSON_NULL: + default: + return true; + } +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp index 5326065..9f12ddb 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp @@ -8,8 +8,7 @@ #include -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { struct ArduinoStreamReader { Stream& _stream; @@ -35,7 +34,6 @@ struct ArduinoStreamReader { inline ArduinoStreamReader makeReader(Stream& input) { return ArduinoStreamReader(input); } -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE #endif diff --git a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/CharPointerReader.hpp b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/CharPointerReader.hpp index 8414f84..56a09df 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/CharPointerReader.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/CharPointerReader.hpp @@ -4,8 +4,7 @@ #pragma once -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { template class UnsafeCharPointerReader { @@ -60,5 +59,4 @@ inline SafeCharPointerReader makeReader(const String& input) { } #endif -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp index 724f2ab..92a868b 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -8,7 +8,7 @@ #include #endif -namespace ArduinoJson { +namespace ARDUINOJSON_NAMESPACE { class DeserializationError { public: @@ -80,4 +80,4 @@ inline std::ostream& operator<<(std::ostream& s, DeserializationError::Code c) { } #endif -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/FlashStringReader.hpp b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/FlashStringReader.hpp index 2eabf79..e9fd57e 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/FlashStringReader.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/FlashStringReader.hpp @@ -6,8 +6,7 @@ #if ARDUINOJSON_ENABLE_PROGMEM -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { class UnsafeFlashStringReader { const char* _ptr; @@ -50,7 +49,6 @@ inline SafeFlashStringReader makeReader(const __FlashStringHelper* input, size_t size) { return SafeFlashStringReader(input, size); } -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE #endif diff --git a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/IteratorReader.hpp b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/IteratorReader.hpp index 7e01c21..ce33c3a 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/IteratorReader.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/IteratorReader.hpp @@ -4,8 +4,7 @@ #pragma once -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { template class IteratorReader { @@ -30,5 +29,4 @@ inline IteratorReader makeReader( return IteratorReader(input.begin(), input.end()); } -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE diff --git a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/StdStreamReader.hpp b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/StdStreamReader.hpp index 8ad841a..2db4419 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/StdStreamReader.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/StdStreamReader.hpp @@ -8,8 +8,7 @@ #include -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { class StdStreamReader { std::istream& _stream; @@ -34,7 +33,6 @@ class StdStreamReader { inline StdStreamReader makeReader(std::istream& input) { return StdStreamReader(input); } -} // namespace Internals -} // namespace ArduinoJson +} // namespace ARDUINOJSON_NAMESPACE #endif diff --git a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp index 25abe9d..fedea7f 100644 --- a/libraries/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp +++ b/libraries/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp @@ -12,15 +12,15 @@ #include "./IteratorReader.hpp" #include "./StdStreamReader.hpp" -namespace ArduinoJson { -namespace Internals { +namespace ARDUINOJSON_NAMESPACE { template