Fixed some issues. It now shows the time, but the offset is incorrect.
This commit is contained in:
BIN
ESP_Medicine_Indicator/.DS_Store
vendored
Normal file
BIN
ESP_Medicine_Indicator/.DS_Store
vendored
Normal file
Binary file not shown.
@ -1,25 +1,31 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <Adafruit_Sensor.h>
|
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <NTPClient.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <medicine_secrets.h>
|
|
||||||
|
|
||||||
#define NEO_PIN 14 // Pin for all the Neopixels
|
#define NEO_PIN 14 // Pin for all the Neopixels
|
||||||
#define SIG_PIX 2 // Number of temperature pixels
|
#define SIG_PIX 2 // Number of temperature pixels
|
||||||
#define BUTTON_FWD_PIN 2
|
#define BUTTON_FWD_PIN 4
|
||||||
#define mqtt_topic "home/medicine"
|
#define mqtt_topic "home/medicine"
|
||||||
|
|
||||||
const char* ssid = SECRET_SSID;
|
const char* ssid = "Saints&Strangers_";
|
||||||
const char* password = SECRET_WIFIPASS;
|
const char* password = "xYhnac-5mixdu";
|
||||||
const char* mqtt_server = SECRET_MQTT_SERVER;
|
const char* mqtt_server = "192.168.200.55";
|
||||||
const char* mqtt_user = SECRET_MQTT_USER;
|
const char* mqtt_user = "hass";
|
||||||
const char* mqtt_password = SECRET_MQTT_PASS;
|
const char* mqtt_password = "Over9+look*";
|
||||||
|
|
||||||
boolean oldState = HIGH;
|
boolean oldState = HIGH;
|
||||||
int mode = 0; // Active mode on startup
|
int mode = 0; // Active mode on startup
|
||||||
|
|
||||||
|
// NTP Definition
|
||||||
|
const long utcOffsetInSeconds = -18000;
|
||||||
|
//char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
|
||||||
|
WiFiUDP ntpUDP;
|
||||||
|
NTPClient timeClient(ntpUDP, "north-america.pool.ntp.org", utcOffsetInSeconds);
|
||||||
|
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient client(espClient);
|
PubSubClient client(espClient);
|
||||||
long lastMsg = 0;
|
long lastMsg = 0;
|
||||||
@ -120,6 +126,14 @@ void loop() {
|
|||||||
}
|
}
|
||||||
// Set the last-read button state to the old state (reset)
|
// Set the last-read button state to the old state (reset)
|
||||||
oldState = newState;
|
oldState = newState;
|
||||||
|
client.loop();
|
||||||
|
timeClient.update();
|
||||||
|
Serial.print(timeClient.getHours());
|
||||||
|
Serial.print(":");
|
||||||
|
Serial.print(timeClient.getMinutes());
|
||||||
|
Serial.print(":");
|
||||||
|
Serial.println(timeClient.getSeconds());
|
||||||
|
delay(200);
|
||||||
|
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
@ -127,7 +141,7 @@ void loop() {
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(1000);
|
delay(200);
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
reconnect();
|
reconnect();
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,412 @@
|
|||||||
|
/*!
|
||||||
|
* @file Adafruit_NeoPixel.h
|
||||||
|
*
|
||||||
|
* This is part of Adafruit's NeoPixel library for the Arduino platform,
|
||||||
|
* allowing a broad range of microcontroller boards (most AVR boards,
|
||||||
|
* many ARM devices, ESP8266 and ESP32, among others) to control Adafruit
|
||||||
|
* NeoPixels, FLORA RGB Smart Pixels and compatible devices -- WS2811,
|
||||||
|
* WS2812, WS2812B, SK6812, etc.
|
||||||
|
*
|
||||||
|
* Adafruit invests time and resources providing this open source code,
|
||||||
|
* please support Adafruit and open-source hardware by purchasing products
|
||||||
|
* from Adafruit!
|
||||||
|
*
|
||||||
|
* Written by Phil "Paint Your Dragon" Burgess for Adafruit Industries,
|
||||||
|
* with contributions by PJRC, Michael Miller and other members of the
|
||||||
|
* open source community.
|
||||||
|
*
|
||||||
|
* This file is part of the Adafruit_NeoPixel library.
|
||||||
|
*
|
||||||
|
* Adafruit_NeoPixel is free software: you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Adafruit_NeoPixel is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with NeoPixel. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADAFRUIT_NEOPIXEL_H
|
||||||
|
#define ADAFRUIT_NEOPIXEL_H
|
||||||
|
|
||||||
|
#ifdef ARDUINO
|
||||||
|
#if (ARDUINO >= 100)
|
||||||
|
#include <Arduino.h>
|
||||||
|
#else
|
||||||
|
#include <WProgram.h>
|
||||||
|
#include <pins_arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_TINYUSB // For Serial when selecting TinyUSB
|
||||||
|
#include <Adafruit_TinyUSB.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TARGET_LPC1768
|
||||||
|
#include <Arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_RP2040)
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "hardware/pio.h"
|
||||||
|
#include "hardware/clocks.h"
|
||||||
|
#include "rp2040_pio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// The order of primary colors in the NeoPixel data stream can vary among
|
||||||
|
// device types, manufacturers and even different revisions of the same
|
||||||
|
// item. The third parameter to the Adafruit_NeoPixel constructor encodes
|
||||||
|
// the per-pixel byte offsets of the red, green and blue primaries (plus
|
||||||
|
// white, if present) in the data stream -- the following #defines provide
|
||||||
|
// an easier-to-use named version for each permutation. e.g. NEO_GRB
|
||||||
|
// indicates a NeoPixel-compatible device expecting three bytes per pixel,
|
||||||
|
// with the first byte transmitted containing the green value, second
|
||||||
|
// containing red and third containing blue. The in-memory representation
|
||||||
|
// of a chain of NeoPixels is the same as the data-stream order; no
|
||||||
|
// re-ordering of bytes is required when issuing data to the chain.
|
||||||
|
// Most of these values won't exist in real-world devices, but it's done
|
||||||
|
// this way so we're ready for it (also, if using the WS2811 driver IC,
|
||||||
|
// one might have their pixels set up in any weird permutation).
|
||||||
|
|
||||||
|
// Bits 5,4 of this value are the offset (0-3) from the first byte of a
|
||||||
|
// pixel to the location of the red color byte. Bits 3,2 are the green
|
||||||
|
// offset and 1,0 are the blue offset. If it is an RGBW-type device
|
||||||
|
// (supporting a white primary in addition to R,G,B), bits 7,6 are the
|
||||||
|
// offset to the white byte...otherwise, bits 7,6 are set to the same value
|
||||||
|
// as 5,4 (red) to indicate an RGB (not RGBW) device.
|
||||||
|
// i.e. binary representation:
|
||||||
|
// 0bWWRRGGBB for RGBW devices
|
||||||
|
// 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)) ///< Transmit as R,G,B
|
||||||
|
#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) ///< Transmit as R,B,G
|
||||||
|
#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B
|
||||||
|
#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,R
|
||||||
|
#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) ///< Transmit as B,R,G
|
||||||
|
#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,R
|
||||||
|
|
||||||
|
// RGBW NeoPixel permutations; all 4 offsets are distinct
|
||||||
|
// Offset: W R G B
|
||||||
|
#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) ///< Transmit as W,R,G,B
|
||||||
|
#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) ///< Transmit as W,R,B,G
|
||||||
|
#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) ///< Transmit as W,G,R,B
|
||||||
|
#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) ///< Transmit as W,G,B,R
|
||||||
|
#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) ///< Transmit as W,B,R,G
|
||||||
|
#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) ///< Transmit as W,B,G,R
|
||||||
|
|
||||||
|
#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) ///< Transmit as R,W,G,B
|
||||||
|
#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) ///< Transmit as R,W,B,G
|
||||||
|
#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) ///< Transmit as R,G,W,B
|
||||||
|
#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) ///< Transmit as R,G,B,W
|
||||||
|
#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) ///< Transmit as R,B,W,G
|
||||||
|
#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) ///< Transmit as R,B,G,W
|
||||||
|
|
||||||
|
#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) ///< Transmit as G,W,R,B
|
||||||
|
#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) ///< Transmit as G,W,B,R
|
||||||
|
#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) ///< Transmit as G,R,W,B
|
||||||
|
#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B,W
|
||||||
|
#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,W,R
|
||||||
|
#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,R,W
|
||||||
|
|
||||||
|
#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) ///< Transmit as B,W,R,G
|
||||||
|
#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) ///< Transmit as B,W,G,R
|
||||||
|
#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) ///< Transmit as B,R,W,G
|
||||||
|
#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) ///< Transmit as B,R,G,W
|
||||||
|
#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,W,R
|
||||||
|
#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,R,W
|
||||||
|
|
||||||
|
// 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 stream, this is
|
||||||
|
// the default if unspecified. Because flash space is very limited on ATtiny
|
||||||
|
// devices (e.g. Trinket, Gemma), v1 NeoPixels aren't handled by default on
|
||||||
|
// those chips, though it can be enabled by removing the ifndef/endif below,
|
||||||
|
// but code will be bigger. Conversely, can disable the NEO_KHZ400 line on
|
||||||
|
// other MCUs to remove v1 support and save a little space.
|
||||||
|
|
||||||
|
#define NEO_KHZ800 0x0000 ///< 800 KHz data transmission
|
||||||
|
#ifndef __AVR_ATtiny85__
|
||||||
|
#define NEO_KHZ400 0x0100 ///< 400 KHz data transmission
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// If 400 KHz support is enabled, the third parameter to the constructor
|
||||||
|
// requires a 16-bit value (in order to select 400 vs 800 KHz speed).
|
||||||
|
// If only 800 KHz is enabled (as is default on ATtiny), an 8-bit value
|
||||||
|
// is sufficient to encode pixel color order, saving some space.
|
||||||
|
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
typedef uint16_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor
|
||||||
|
#else
|
||||||
|
typedef uint8_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// These two tables are declared outside the Adafruit_NeoPixel class
|
||||||
|
// because some boards may require oldschool compilers that don't
|
||||||
|
// handle the C++11 constexpr keyword.
|
||||||
|
|
||||||
|
/* A PROGMEM (flash mem) table containing 8-bit unsigned sine wave (0-255).
|
||||||
|
Copy & paste this snippet into a Python REPL to regenerate:
|
||||||
|
import math
|
||||||
|
for x in range(256):
|
||||||
|
print("{:3},".format(int((math.sin(x/128.0*math.pi)+1.0)*127.5+0.5))),
|
||||||
|
if x&15 == 15: print
|
||||||
|
*/
|
||||||
|
static const uint8_t PROGMEM _NeoPixelSineTable[256] = {
|
||||||
|
128, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 162, 165, 167, 170,
|
||||||
|
173, 176, 179, 182, 185, 188, 190, 193, 196, 198, 201, 203, 206, 208, 211,
|
||||||
|
213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 234, 235, 237, 238, 240,
|
||||||
|
241, 243, 244, 245, 246, 248, 249, 250, 250, 251, 252, 253, 253, 254, 254,
|
||||||
|
254, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 252, 251,
|
||||||
|
250, 250, 249, 248, 246, 245, 244, 243, 241, 240, 238, 237, 235, 234, 232,
|
||||||
|
230, 228, 226, 224, 222, 220, 218, 215, 213, 211, 208, 206, 203, 201, 198,
|
||||||
|
196, 193, 190, 188, 185, 182, 179, 176, 173, 170, 167, 165, 162, 158, 155,
|
||||||
|
152, 149, 146, 143, 140, 137, 134, 131, 128, 124, 121, 118, 115, 112, 109,
|
||||||
|
106, 103, 100, 97, 93, 90, 88, 85, 82, 79, 76, 73, 70, 67, 65,
|
||||||
|
62, 59, 57, 54, 52, 49, 47, 44, 42, 40, 37, 35, 33, 31, 29,
|
||||||
|
27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11, 10, 9, 7, 6,
|
||||||
|
5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, 10, 11,
|
||||||
|
12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, 37,
|
||||||
|
40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76,
|
||||||
|
79, 82, 85, 88, 90, 93, 97, 100, 103, 106, 109, 112, 115, 118, 121,
|
||||||
|
124};
|
||||||
|
|
||||||
|
/* Similar to above, but for an 8-bit gamma-correction table.
|
||||||
|
Copy & paste this snippet into a Python REPL to regenerate:
|
||||||
|
import math
|
||||||
|
gamma=2.6
|
||||||
|
for x in range(256):
|
||||||
|
print("{:3},".format(int(math.pow((x)/255.0,gamma)*255.0+0.5))),
|
||||||
|
if x&15 == 15: print
|
||||||
|
*/
|
||||||
|
static const uint8_t PROGMEM _NeoPixelGammaTable[256] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
|
||||||
|
1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3,
|
||||||
|
3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
|
||||||
|
6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10,
|
||||||
|
11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17,
|
||||||
|
17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
|
||||||
|
25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35,
|
||||||
|
36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 48,
|
||||||
|
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||||
|
64, 65, 66, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 80, 81,
|
||||||
|
82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96, 97, 99, 100, 102,
|
||||||
|
103, 105, 106, 108, 109, 111, 112, 114, 115, 117, 119, 120, 122, 124, 125,
|
||||||
|
127, 129, 130, 132, 134, 136, 137, 139, 141, 143, 145, 146, 148, 150, 152,
|
||||||
|
154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182,
|
||||||
|
184, 186, 188, 191, 193, 195, 197, 199, 202, 204, 206, 209, 211, 213, 215,
|
||||||
|
218, 220, 223, 225, 227, 230, 232, 235, 237, 240, 242, 245, 247, 250, 252,
|
||||||
|
255};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief Class that stores state and functions for interacting with
|
||||||
|
Adafruit NeoPixels and compatible devices.
|
||||||
|
*/
|
||||||
|
class Adafruit_NeoPixel {
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor: number of LEDs, pin number, LED type
|
||||||
|
Adafruit_NeoPixel(uint16_t n, int16_t pin = 6,
|
||||||
|
neoPixelType type = NEO_GRB + NEO_KHZ800);
|
||||||
|
Adafruit_NeoPixel(void);
|
||||||
|
~Adafruit_NeoPixel();
|
||||||
|
|
||||||
|
void begin(void);
|
||||||
|
void show(void);
|
||||||
|
void setPin(int16_t p);
|
||||||
|
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||||
|
void setPixelColor(uint16_t n, uint32_t c);
|
||||||
|
void fill(uint32_t c = 0, uint16_t first = 0, uint16_t count = 0);
|
||||||
|
void setBrightness(uint8_t);
|
||||||
|
void clear(void);
|
||||||
|
void updateLength(uint16_t n);
|
||||||
|
void updateType(neoPixelType t);
|
||||||
|
/*!
|
||||||
|
@brief Check whether a call to show() will start sending data
|
||||||
|
immediately or will 'block' for a required interval. NeoPixels
|
||||||
|
require a short quiet time (about 300 microseconds) after the
|
||||||
|
last bit is received before the data 'latches' and new data can
|
||||||
|
start being received. Usually one's sketch is implicitly using
|
||||||
|
this time to generate a new frame of animation...but if it
|
||||||
|
finishes very quickly, this function could be used to see if
|
||||||
|
there's some idle time available for some low-priority
|
||||||
|
concurrent task.
|
||||||
|
@return 1 or true if show() will start sending immediately, 0 or false
|
||||||
|
if show() would block (meaning some idle time is available).
|
||||||
|
*/
|
||||||
|
bool canShow(void) {
|
||||||
|
// It's normal and possible for endTime to exceed micros() if the
|
||||||
|
// 32-bit clock counter has rolled over (about every 70 minutes).
|
||||||
|
// Since both are uint32_t, a negative delta correctly maps back to
|
||||||
|
// positive space, and it would seem like the subtraction below would
|
||||||
|
// suffice. But a problem arises if code invokes show() very
|
||||||
|
// infrequently...the micros() counter may roll over MULTIPLE times in
|
||||||
|
// that interval, the delta calculation is no longer correct and the
|
||||||
|
// next update may stall for a very long time. The check below resets
|
||||||
|
// the latch counter if a rollover has occurred. This can cause an
|
||||||
|
// extra delay of up to 300 microseconds in the rare case where a
|
||||||
|
// show() call happens precisely around the rollover, but that's
|
||||||
|
// neither likely nor especially harmful, vs. other code that might
|
||||||
|
// stall for 30+ minutes, or having to document and frequently remind
|
||||||
|
// and/or provide tech support explaining an unintuitive need for
|
||||||
|
// show() calls at least once an hour.
|
||||||
|
uint32_t now = micros();
|
||||||
|
if (endTime > now) {
|
||||||
|
endTime = now;
|
||||||
|
}
|
||||||
|
return (now - endTime) >= 300L;
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@brief Get a pointer directly to the NeoPixel data buffer in RAM.
|
||||||
|
Pixel data is stored in a device-native format (a la the NEO_*
|
||||||
|
constants) and is not translated here. Applications that access
|
||||||
|
this buffer will need to be aware of the specific data format
|
||||||
|
and handle colors appropriately.
|
||||||
|
@return Pointer to NeoPixel buffer (uint8_t* array).
|
||||||
|
@note This is for high-performance applications where calling
|
||||||
|
setPixelColor() on every single pixel would be too slow (e.g.
|
||||||
|
POV or light-painting projects). There is no bounds checking
|
||||||
|
on the array, creating tremendous potential for mayhem if one
|
||||||
|
writes past the ends of the buffer. Great power, great
|
||||||
|
responsibility and all that.
|
||||||
|
*/
|
||||||
|
uint8_t *getPixels(void) const { return pixels; };
|
||||||
|
uint8_t getBrightness(void) const;
|
||||||
|
/*!
|
||||||
|
@brief Retrieve the pin number used for NeoPixel data output.
|
||||||
|
@return Arduino pin number (-1 if not set).
|
||||||
|
*/
|
||||||
|
int16_t getPin(void) const { return pin; };
|
||||||
|
/*!
|
||||||
|
@brief Return the number of pixels in an Adafruit_NeoPixel strip object.
|
||||||
|
@return Pixel count (0 if not set).
|
||||||
|
*/
|
||||||
|
uint16_t numPixels(void) const { return numLEDs; }
|
||||||
|
uint32_t getPixelColor(uint16_t n) const;
|
||||||
|
/*!
|
||||||
|
@brief An 8-bit integer sine wave function, not directly compatible
|
||||||
|
with standard trigonometric units like radians or degrees.
|
||||||
|
@param x Input angle, 0-255; 256 would loop back to zero, completing
|
||||||
|
the circle (equivalent to 360 degrees or 2 pi radians).
|
||||||
|
One can therefore use an unsigned 8-bit variable and simply
|
||||||
|
add or subtract, allowing it to overflow/underflow and it
|
||||||
|
still does the expected contiguous thing.
|
||||||
|
@return Sine result, 0 to 255, or -128 to +127 if type-converted to
|
||||||
|
a signed int8_t, but you'll most likely want unsigned as this
|
||||||
|
output is often used for pixel brightness in animation effects.
|
||||||
|
*/
|
||||||
|
static uint8_t sine8(uint8_t x) {
|
||||||
|
return pgm_read_byte(&_NeoPixelSineTable[x]); // 0-255 in, 0-255 out
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@brief An 8-bit gamma-correction function for basic pixel brightness
|
||||||
|
adjustment. Makes color transitions appear more perceptially
|
||||||
|
correct.
|
||||||
|
@param x Input brightness, 0 (minimum or off/black) to 255 (maximum).
|
||||||
|
@return Gamma-adjusted brightness, can then be passed to one of the
|
||||||
|
setPixelColor() functions. This uses a fixed gamma correction
|
||||||
|
exponent of 2.6, which seems reasonably okay for average
|
||||||
|
NeoPixels in average tasks. If you need finer control you'll
|
||||||
|
need to provide your own gamma-correction function instead.
|
||||||
|
*/
|
||||||
|
static uint8_t gamma8(uint8_t x) {
|
||||||
|
return pgm_read_byte(&_NeoPixelGammaTable[x]); // 0-255 in, 0-255 out
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@brief Convert separate red, green and blue values into a single
|
||||||
|
"packed" 32-bit RGB color.
|
||||||
|
@param r Red brightness, 0 to 255.
|
||||||
|
@param g Green brightness, 0 to 255.
|
||||||
|
@param b Blue brightness, 0 to 255.
|
||||||
|
@return 32-bit packed RGB value, which can then be assigned to a
|
||||||
|
variable for later use or passed to the setPixelColor()
|
||||||
|
function. Packed RGB format is predictable, regardless of
|
||||||
|
LED strand color order.
|
||||||
|
*/
|
||||||
|
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
|
return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@brief Convert separate red, green, blue and white values into a
|
||||||
|
single "packed" 32-bit WRGB color.
|
||||||
|
@param r Red brightness, 0 to 255.
|
||||||
|
@param g Green brightness, 0 to 255.
|
||||||
|
@param b Blue brightness, 0 to 255.
|
||||||
|
@param w White brightness, 0 to 255.
|
||||||
|
@return 32-bit packed WRGB value, which can then be assigned to a
|
||||||
|
variable for later use or passed to the setPixelColor()
|
||||||
|
function. Packed WRGB format is predictable, regardless of
|
||||||
|
LED strand color order.
|
||||||
|
*/
|
||||||
|
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||||
|
return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||||
|
}
|
||||||
|
static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255);
|
||||||
|
/*!
|
||||||
|
@brief A gamma-correction function for 32-bit packed RGB or WRGB
|
||||||
|
colors. Makes color transitions appear more perceptially
|
||||||
|
correct.
|
||||||
|
@param x 32-bit packed RGB or WRGB color.
|
||||||
|
@return Gamma-adjusted packed color, can then be passed in one of the
|
||||||
|
setPixelColor() functions. Like gamma8(), this uses a fixed
|
||||||
|
gamma correction exponent of 2.6, which seems reasonably okay
|
||||||
|
for average NeoPixels in average tasks. If you need finer
|
||||||
|
control you'll need to provide your own gamma-correction
|
||||||
|
function instead.
|
||||||
|
*/
|
||||||
|
static uint32_t gamma32(uint32_t x);
|
||||||
|
|
||||||
|
void rainbow(uint16_t first_hue = 0, int8_t reps = 1,
|
||||||
|
uint8_t saturation = 255, uint8_t brightness = 255,
|
||||||
|
bool gammify = true);
|
||||||
|
|
||||||
|
static neoPixelType str2order(const char *v);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if defined(ARDUINO_ARCH_RP2040)
|
||||||
|
void rp2040Init(uint8_t pin, bool is800KHz);
|
||||||
|
void rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
#ifdef NEO_KHZ400 // If 400 KHz NeoPixel support enabled...
|
||||||
|
bool is800KHz; ///< true if 800 KHz pixels
|
||||||
|
#endif
|
||||||
|
bool begun; ///< true if begin() previously called
|
||||||
|
uint16_t numLEDs; ///< Number of RGB LEDs in strip
|
||||||
|
uint16_t numBytes; ///< Size of 'pixels' buffer below
|
||||||
|
int16_t pin; ///< Output pin number (-1 if not yet set)
|
||||||
|
uint8_t brightness; ///< Strip brightness 0-255 (stored as +1)
|
||||||
|
uint8_t *pixels; ///< Holds LED color values (3 or 4 bytes each)
|
||||||
|
uint8_t rOffset; ///< Red index within each 3- or 4-byte pixel
|
||||||
|
uint8_t gOffset; ///< Index of green byte
|
||||||
|
uint8_t bOffset; ///< Index of blue byte
|
||||||
|
uint8_t wOffset; ///< Index of white (==rOffset if no white)
|
||||||
|
uint32_t endTime; ///< Latch timing reference
|
||||||
|
#ifdef __AVR__
|
||||||
|
volatile uint8_t *port; ///< Output PORT register
|
||||||
|
uint8_t pinMask; ///< Output PORT bitmask
|
||||||
|
#endif
|
||||||
|
#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32)
|
||||||
|
GPIO_TypeDef *gpioPort; ///< Output GPIO PORT
|
||||||
|
uint32_t gpioPin; ///< Output GPIO PIN
|
||||||
|
#endif
|
||||||
|
#if defined(ARDUINO_ARCH_RP2040)
|
||||||
|
PIO pio = pio0;
|
||||||
|
int sm = 0;
|
||||||
|
bool init = true;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADAFRUIT_NEOPIXEL_H
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
# Contribution Guidelines
|
||||||
|
|
||||||
|
This library is the culmination of the expertise of many members of the open source community who have dedicated their time and hard work. The best way to ask for help or propose a new idea is to [create a new issue](https://github.com/adafruit/Adafruit_NeoPixel/issues/new) while creating a Pull Request with your code changes allows you to share your own innovations with the rest of the community.
|
||||||
|
|
||||||
|
The following are some guidelines to observe when creating issues or PRs:
|
||||||
|
|
||||||
|
- Be friendly; it is important that we can all enjoy a safe space as we are all working on the same project and it is okay for people to have different ideas
|
||||||
|
|
||||||
|
- [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); it helps us help you when we can read your code! On that note also refrain from pasting more than 30 lines of code in a post, instead [create a gist](https://gist.github.com/) if you need to share large snippets
|
||||||
|
|
||||||
|
- Use reasonable titles; refrain from using overly long or capitalized titles as they are usually annoying and do little to encourage others to help :smile:
|
||||||
|
|
||||||
|
- Be detailed; refrain from mentioning code problems without sharing your source code and always give information regarding your board and version of the library
|
||||||
165
ESP_Medicine_Indicator/libraries/Adafruit_NeoPixel/COPYING
Normal file
165
ESP_Medicine_Indicator/libraries/Adafruit_NeoPixel/COPYING
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
||||||
|
This version of the GNU Lesser General Public License incorporates
|
||||||
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
|
0. Additional Definitions.
|
||||||
|
|
||||||
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
|
General Public License.
|
||||||
|
|
||||||
|
"The Library" refers to a covered work governed by this License,
|
||||||
|
other than an Application or a Combined Work as defined below.
|
||||||
|
|
||||||
|
An "Application" is any work that makes use of an interface provided
|
||||||
|
by the Library, but which is not otherwise based on the Library.
|
||||||
|
Defining a subclass of a class defined by the Library is deemed a mode
|
||||||
|
of using an interface provided by the Library.
|
||||||
|
|
||||||
|
A "Combined Work" is a work produced by combining or linking an
|
||||||
|
Application with the Library. The particular version of the Library
|
||||||
|
with which the Combined Work was made is also called the "Linked
|
||||||
|
Version".
|
||||||
|
|
||||||
|
The "Minimal Corresponding Source" for a Combined Work means the
|
||||||
|
Corresponding Source for the Combined Work, excluding any source code
|
||||||
|
for portions of the Combined Work that, considered in isolation, are
|
||||||
|
based on the Application, and not on the Linked Version.
|
||||||
|
|
||||||
|
The "Corresponding Application Code" for a Combined Work means the
|
||||||
|
object code and/or source code for the Application, including any data
|
||||||
|
and utility programs needed for reproducing the Combined Work from the
|
||||||
|
Application, but excluding the System Libraries of the Combined Work.
|
||||||
|
|
||||||
|
1. Exception to Section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
You may convey a covered work under sections 3 and 4 of this License
|
||||||
|
without being bound by section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
2. Conveying Modified Versions.
|
||||||
|
|
||||||
|
If you modify a copy of the Library, and, in your modifications, a
|
||||||
|
facility refers to a function or data to be supplied by an Application
|
||||||
|
that uses the facility (other than as an argument passed when the
|
||||||
|
facility is invoked), then you may convey a copy of the modified
|
||||||
|
version:
|
||||||
|
|
||||||
|
a) under this License, provided that you make a good faith effort to
|
||||||
|
ensure that, in the event an Application does not supply the
|
||||||
|
function or data, the facility still operates, and performs
|
||||||
|
whatever part of its purpose remains meaningful, or
|
||||||
|
|
||||||
|
b) under the GNU GPL, with none of the additional permissions of
|
||||||
|
this License applicable to that copy.
|
||||||
|
|
||||||
|
3. Object Code Incorporating Material from Library Header Files.
|
||||||
|
|
||||||
|
The object code form of an Application may incorporate material from
|
||||||
|
a header file that is part of the Library. You may convey such object
|
||||||
|
code under terms of your choice, provided that, if the incorporated
|
||||||
|
material is not limited to numerical parameters, data structure
|
||||||
|
layouts and accessors, or small macros, inline functions and templates
|
||||||
|
(ten or fewer lines in length), you do both of the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the object code that the
|
||||||
|
Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
4. Combined Works.
|
||||||
|
|
||||||
|
You may convey a Combined Work under terms of your choice that,
|
||||||
|
taken together, effectively do not restrict modification of the
|
||||||
|
portions of the Library contained in the Combined Work and reverse
|
||||||
|
engineering for debugging such modifications, if you also do each of
|
||||||
|
the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the Combined Work that
|
||||||
|
the Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
c) For a Combined Work that displays copyright notices during
|
||||||
|
execution, include the copyright notice for the Library among
|
||||||
|
these notices, as well as a reference directing the user to the
|
||||||
|
copies of the GNU GPL and this license document.
|
||||||
|
|
||||||
|
d) Do one of the following:
|
||||||
|
|
||||||
|
0) Convey the Minimal Corresponding Source under the terms of this
|
||||||
|
License, and the Corresponding Application Code in a form
|
||||||
|
suitable for, and under terms that permit, the user to
|
||||||
|
recombine or relink the Application with a modified version of
|
||||||
|
the Linked Version to produce a modified Combined Work, in the
|
||||||
|
manner specified by section 6 of the GNU GPL for conveying
|
||||||
|
Corresponding Source.
|
||||||
|
|
||||||
|
1) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (a) uses at run time
|
||||||
|
a copy of the Library already present on the user's computer
|
||||||
|
system, and (b) will operate properly with a modified version
|
||||||
|
of the Library that is interface-compatible with the Linked
|
||||||
|
Version.
|
||||||
|
|
||||||
|
e) Provide Installation Information, but only if you would otherwise
|
||||||
|
be required to provide such information under section 6 of the
|
||||||
|
GNU GPL, and only to the extent that such information is
|
||||||
|
necessary to install and execute a modified version of the
|
||||||
|
Combined Work produced by recombining or relinking the
|
||||||
|
Application with a modified version of the Linked Version. (If
|
||||||
|
you use option 4d0, the Installation Information must accompany
|
||||||
|
the Minimal Corresponding Source and Corresponding Application
|
||||||
|
Code. If you use option 4d1, you must provide the Installation
|
||||||
|
Information in the manner specified by section 6 of the GNU GPL
|
||||||
|
for conveying Corresponding Source.)
|
||||||
|
|
||||||
|
5. Combined Libraries.
|
||||||
|
|
||||||
|
You may place library facilities that are a work based on the
|
||||||
|
Library side by side in a single library together with other library
|
||||||
|
facilities that are not Applications and are not covered by this
|
||||||
|
License, and convey such a combined library under terms of your
|
||||||
|
choice, if you do both of the following:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work based
|
||||||
|
on the Library, uncombined with any other library facilities,
|
||||||
|
conveyed under the terms of this License.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library that part of it
|
||||||
|
is a work based on the Library, and explaining where to find the
|
||||||
|
accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
6. Revised Versions of the GNU Lesser General Public License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU Lesser General Public License from time to time. Such new
|
||||||
|
versions will be similar in spirit to the present version, but may
|
||||||
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Library as you received it specifies that a certain numbered version
|
||||||
|
of the GNU Lesser General Public License "or any later version"
|
||||||
|
applies to it, you have the option of following the terms and
|
||||||
|
conditions either of that published version or of any later version
|
||||||
|
published by the Free Software Foundation. If the Library as you
|
||||||
|
received it does not specify a version number of the GNU Lesser
|
||||||
|
General Public License, you may choose any version of the GNU Lesser
|
||||||
|
General Public License ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Library as you received it specifies that a proxy can decide
|
||||||
|
whether future versions of the GNU Lesser General Public License shall
|
||||||
|
apply, that proxy's public statement of acceptance of any version is
|
||||||
|
permanent authorization for you to choose that version for the
|
||||||
|
Library.
|
||||||
158
ESP_Medicine_Indicator/libraries/Adafruit_NeoPixel/README.md
Normal file
158
ESP_Medicine_Indicator/libraries/Adafruit_NeoPixel/README.md
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
# Adafruit NeoPixel Library [](https://github.com/adafruit/Adafruit_NeoPixel/actions)[](http://adafruit.github.io/Adafruit_NeoPixel/html/index.html)
|
||||||
|
|
||||||
|
Arduino library for controlling single-wire-based LED pixels and strip such as the [Adafruit 60 LED/meter Digital LED strip][strip], the [Adafruit FLORA RGB Smart Pixel][flora], the [Adafruit Breadboard-friendly RGB Smart Pixel][pixel], the [Adafruit NeoPixel Stick][stick], and the [Adafruit NeoPixel Shield][shield].
|
||||||
|
|
||||||
|
After downloading, rename folder to 'Adafruit_NeoPixel' and install in Arduino Libraries folder. Restart Arduino IDE, then open File->Sketchbook->Library->Adafruit_NeoPixel->strandtest sketch.
|
||||||
|
|
||||||
|
Compatibility notes: Port A is not supported on any AVR processors at this time
|
||||||
|
|
||||||
|
[flora]: http://adafruit.com/products/1060
|
||||||
|
[strip]: http://adafruit.com/products/1138
|
||||||
|
[pixel]: http://adafruit.com/products/1312
|
||||||
|
[stick]: http://adafruit.com/products/1426
|
||||||
|
[shield]: http://adafruit.com/products/1430
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### First Method
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries
|
||||||
|
1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.
|
||||||
|
1. Then search for Neopixel strip using the search bar.
|
||||||
|
1. Click on the text area and then select the specific version and install it.
|
||||||
|
|
||||||
|
### Second Method
|
||||||
|
|
||||||
|
1. Navigate to the [Releases page](https://github.com/adafruit/Adafruit_NeoPixel/releases).
|
||||||
|
1. Download the latest release.
|
||||||
|
1. Extract the zip file
|
||||||
|
1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- ### Simple to use
|
||||||
|
|
||||||
|
Controlling NeoPixels “from scratch” is quite a challenge, so we provide a library letting you focus on the fun and interesting bits.
|
||||||
|
|
||||||
|
- ### Give back
|
||||||
|
|
||||||
|
The library is free; you don’t have to pay for anything. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
|
||||||
|
|
||||||
|
- ### Supported Chipsets
|
||||||
|
|
||||||
|
We have included code for the following chips - sometimes these break for exciting reasons that we can't control in which case please open an issue!
|
||||||
|
|
||||||
|
- AVR ATmega and ATtiny (any 8-bit) - 8 MHz, 12 MHz and 16 MHz
|
||||||
|
- Teensy 3.x and LC
|
||||||
|
- Arduino Due
|
||||||
|
- Arduino 101
|
||||||
|
- ATSAMD21 (Arduino Zero/M0 and other SAMD21 boards) @ 48 MHz
|
||||||
|
- ATSAMD51 @ 120 MHz
|
||||||
|
- Adafruit STM32 Feather @ 120 MHz
|
||||||
|
- ESP8266 any speed
|
||||||
|
- ESP32 any speed
|
||||||
|
- Nordic nRF52 (Adafruit Feather nRF52), nRF51 (micro:bit)
|
||||||
|
- Infineon XMC1100 BootKit @ 32 MHz
|
||||||
|
- Infineon XMC1100 2Go @ 32 MHz
|
||||||
|
- Infineon XMC1300 BootKit @ 32 MHz
|
||||||
|
- Infineon XMC4700 RelaxKit, XMC4800 RelaxKit, XMC4800 IoT Amazon FreeRTOS Kit @ 144 MHz
|
||||||
|
|
||||||
|
Check forks for other architectures not listed here!
|
||||||
|
|
||||||
|
- ### GNU Lesser General Public License
|
||||||
|
|
||||||
|
Adafruit_NeoPixel is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
- begin()
|
||||||
|
- updateLength()
|
||||||
|
- updateType()
|
||||||
|
- show()
|
||||||
|
- delay_ns()
|
||||||
|
- setPin()
|
||||||
|
- setPixelColor()
|
||||||
|
- fill()
|
||||||
|
- ColorHSV()
|
||||||
|
- getPixelColor()
|
||||||
|
- setBrightness()
|
||||||
|
- getBrightness()
|
||||||
|
- clear()
|
||||||
|
- gamma32()
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
There are many examples implemented in this library. One of the examples is below. You can find other examples [here](https://github.com/adafruit/Adafruit_NeoPixel/tree/master/examples)
|
||||||
|
|
||||||
|
### Simple
|
||||||
|
|
||||||
|
```Cpp
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h>
|
||||||
|
#endif
|
||||||
|
#define PIN 6
|
||||||
|
#define NUMPIXELS 16
|
||||||
|
|
||||||
|
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
#define DELAYVAL 500
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pixels.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
pixels.clear();
|
||||||
|
|
||||||
|
for(int i=0; i<NUMPIXELS; i++) {
|
||||||
|
|
||||||
|
pixels.setPixelColor(i, pixels.Color(0, 150, 0));
|
||||||
|
pixels.show();
|
||||||
|
delay(DELAYVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
If you want to contribute to this project:
|
||||||
|
|
||||||
|
- Report bugs and errors
|
||||||
|
- Ask for enhancements
|
||||||
|
- Create issues and pull requests
|
||||||
|
- Tell others about this library
|
||||||
|
- Contribute new protocols
|
||||||
|
|
||||||
|
Please read [CONTRIBUTING.md](https://github.com/adafruit/Adafruit_NeoPixel/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
|
||||||
|
|
||||||
|
### Roadmap
|
||||||
|
|
||||||
|
The PRIME DIRECTIVE is to maintain backward compatibility with existing Arduino sketches -- many are hosted elsewhere and don't track changes here, some are in print and can never be changed!
|
||||||
|
|
||||||
|
Please don't reformat code for the sake of reformatting code. The resulting large "visual diff" makes it impossible to untangle actual bug fixes from merely rearranged lines. Also, don't bother with PRs for timing adjustments "to better match the datasheet," because the datasheet isn't really true to begin with.
|
||||||
|
|
||||||
|
Things I'd Like To Do But There's No Official Timeline So Please Don't Count On Any Of This Ever Being Canonical:
|
||||||
|
|
||||||
|
- 400 KHz support can be removed, turns out it was never actually necessary; even the earliest NeoPixels can ingest 800 KHz data. Of course the #defines should remain so old sketches still compile, but both can be set to 0 and would have no effect on anything.
|
||||||
|
- 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!
|
||||||
|
- 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). (As of 1.4.2, systick is used on M4 devices and it appears to be overclock-compatible. Not for M0 yet, which is why this item is still here.)
|
||||||
|
- As currently written, brightness scaling is still a "destructive" operation -- pixel values are altered in RAM and the original value as set can't be accurately read back, only approximated, which has been confusing and frustrating to users. It was done this way at the time because NeoPixel timing is strict, AVR microcontrollers (all we had at the time) are limited, and assembly language is hard. All the 32-bit architectures should have no problem handling nondestructive brightness scaling -- calculating each byte immediately before it's sent out the wire, maintaining the original set value in RAM -- the work just hasn't been done. There's a fair chance even the AVR code could manage it with some intense focus. (The DotStar library achieves nondestructive brightness scaling because it doesn't have to manage data timing so carefully...every architecture, even ATtiny, just takes whatever cycles it needs for the multiply/shift operations.)
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
This library is written by Phil "Paint Your Dragon" Burgess for Adafruit Industries, with contributions by PJRC, Michael Miller and other members of the open source community.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Adafruit_NeoPixel is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
Adafruit_NeoPixel is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.en.html) for more details.
|
||||||
|
You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see [this](https://www.gnu.org/licenses/)
|
||||||
178
ESP_Medicine_Indicator/libraries/Adafruit_NeoPixel/esp.c
Normal file
178
ESP_Medicine_Indicator/libraries/Adafruit_NeoPixel/esp.c
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
// Implements the RMT peripheral on Espressif SoCs
|
||||||
|
// Copyright (c) 2020 Lucian Copeland for Adafruit Industries
|
||||||
|
|
||||||
|
/* Uses code from Espressif RGB LED Strip demo and drivers
|
||||||
|
* Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "driver/rmt.h"
|
||||||
|
|
||||||
|
#if defined(ESP_IDF_VERSION)
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
|
||||||
|
#define HAS_ESP_IDF_4
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This code is adapted from the ESP-IDF v3.4 RMT "led_strip" example, altered
|
||||||
|
// to work with the Arduino version of the ESP-IDF (3.2)
|
||||||
|
|
||||||
|
#define WS2812_T0H_NS (400)
|
||||||
|
#define WS2812_T0L_NS (850)
|
||||||
|
#define WS2812_T1H_NS (800)
|
||||||
|
#define WS2812_T1L_NS (450)
|
||||||
|
|
||||||
|
#define WS2811_T0H_NS (500)
|
||||||
|
#define WS2811_T0L_NS (2000)
|
||||||
|
#define WS2811_T1H_NS (1200)
|
||||||
|
#define WS2811_T1L_NS (1300)
|
||||||
|
|
||||||
|
static uint32_t t0h_ticks = 0;
|
||||||
|
static uint32_t t1h_ticks = 0;
|
||||||
|
static uint32_t t0l_ticks = 0;
|
||||||
|
static uint32_t t1l_ticks = 0;
|
||||||
|
|
||||||
|
// Limit the number of RMT channels available for the Neopixels. Defaults to all
|
||||||
|
// channels (8 on ESP32, 4 on ESP32-S2 and S3). Redefining this value will free
|
||||||
|
// any channels with a higher number for other uses, such as IR send-and-recieve
|
||||||
|
// libraries. Redefine as 1 to restrict Neopixels to only a single channel.
|
||||||
|
#define ADAFRUIT_RMT_CHANNEL_MAX RMT_CHANNEL_MAX
|
||||||
|
|
||||||
|
#define RMT_LL_HW_BASE (&RMT)
|
||||||
|
|
||||||
|
bool rmt_reserved_channels[ADAFRUIT_RMT_CHANNEL_MAX];
|
||||||
|
|
||||||
|
static void IRAM_ATTR ws2812_rmt_adapter(const void *src, rmt_item32_t *dest, size_t src_size,
|
||||||
|
size_t wanted_num, size_t *translated_size, size_t *item_num)
|
||||||
|
{
|
||||||
|
if (src == NULL || dest == NULL) {
|
||||||
|
*translated_size = 0;
|
||||||
|
*item_num = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const rmt_item32_t bit0 = {{{ t0h_ticks, 1, t0l_ticks, 0 }}}; //Logical 0
|
||||||
|
const rmt_item32_t bit1 = {{{ t1h_ticks, 1, t1l_ticks, 0 }}}; //Logical 1
|
||||||
|
size_t size = 0;
|
||||||
|
size_t num = 0;
|
||||||
|
uint8_t *psrc = (uint8_t *)src;
|
||||||
|
rmt_item32_t *pdest = dest;
|
||||||
|
while (size < src_size && num < wanted_num) {
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
// MSB first
|
||||||
|
if (*psrc & (1 << (7 - i))) {
|
||||||
|
pdest->val = bit1.val;
|
||||||
|
} else {
|
||||||
|
pdest->val = bit0.val;
|
||||||
|
}
|
||||||
|
num++;
|
||||||
|
pdest++;
|
||||||
|
}
|
||||||
|
size++;
|
||||||
|
psrc++;
|
||||||
|
}
|
||||||
|
*translated_size = size;
|
||||||
|
*item_num = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
|
||||||
|
// Reserve channel
|
||||||
|
rmt_channel_t channel = ADAFRUIT_RMT_CHANNEL_MAX;
|
||||||
|
for (size_t i = 0; i < ADAFRUIT_RMT_CHANNEL_MAX; i++) {
|
||||||
|
if (!rmt_reserved_channels[i]) {
|
||||||
|
rmt_reserved_channels[i] = true;
|
||||||
|
channel = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (channel == ADAFRUIT_RMT_CHANNEL_MAX) {
|
||||||
|
// Ran out of channels!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(HAS_ESP_IDF_4)
|
||||||
|
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(pin, channel);
|
||||||
|
config.clk_div = 2;
|
||||||
|
#else
|
||||||
|
// Match default TX config from ESP-IDF version 3.4
|
||||||
|
rmt_config_t config = {
|
||||||
|
.rmt_mode = RMT_MODE_TX,
|
||||||
|
.channel = channel,
|
||||||
|
.gpio_num = pin,
|
||||||
|
.clk_div = 2,
|
||||||
|
.mem_block_num = 1,
|
||||||
|
.tx_config = {
|
||||||
|
.carrier_freq_hz = 38000,
|
||||||
|
.carrier_level = RMT_CARRIER_LEVEL_HIGH,
|
||||||
|
.idle_level = RMT_IDLE_LEVEL_LOW,
|
||||||
|
.carrier_duty_percent = 33,
|
||||||
|
.carrier_en = false,
|
||||||
|
.loop_en = false,
|
||||||
|
.idle_output_en = true,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
rmt_config(&config);
|
||||||
|
rmt_driver_install(config.channel, 0, 0);
|
||||||
|
|
||||||
|
// Convert NS timings to ticks
|
||||||
|
uint32_t counter_clk_hz = 0;
|
||||||
|
|
||||||
|
#if defined(HAS_ESP_IDF_4)
|
||||||
|
rmt_get_counter_clock(channel, &counter_clk_hz);
|
||||||
|
#else
|
||||||
|
// this emulates the rmt_get_counter_clock() function from ESP-IDF 3.4
|
||||||
|
if (RMT_LL_HW_BASE->conf_ch[config.channel].conf1.ref_always_on == RMT_BASECLK_REF) {
|
||||||
|
uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt;
|
||||||
|
uint32_t div = div_cnt == 0 ? 256 : div_cnt;
|
||||||
|
counter_clk_hz = REF_CLK_FREQ / (div);
|
||||||
|
} else {
|
||||||
|
uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt;
|
||||||
|
uint32_t div = div_cnt == 0 ? 256 : div_cnt;
|
||||||
|
counter_clk_hz = APB_CLK_FREQ / (div);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// NS to tick converter
|
||||||
|
float ratio = (float)counter_clk_hz / 1e9;
|
||||||
|
|
||||||
|
if (is800KHz) {
|
||||||
|
t0h_ticks = (uint32_t)(ratio * WS2812_T0H_NS);
|
||||||
|
t0l_ticks = (uint32_t)(ratio * WS2812_T0L_NS);
|
||||||
|
t1h_ticks = (uint32_t)(ratio * WS2812_T1H_NS);
|
||||||
|
t1l_ticks = (uint32_t)(ratio * WS2812_T1L_NS);
|
||||||
|
} else {
|
||||||
|
t0h_ticks = (uint32_t)(ratio * WS2811_T0H_NS);
|
||||||
|
t0l_ticks = (uint32_t)(ratio * WS2811_T0L_NS);
|
||||||
|
t1h_ticks = (uint32_t)(ratio * WS2811_T1H_NS);
|
||||||
|
t1l_ticks = (uint32_t)(ratio * WS2811_T1L_NS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize automatic timing translator
|
||||||
|
rmt_translator_init(config.channel, ws2812_rmt_adapter);
|
||||||
|
|
||||||
|
// Write and wait to finish
|
||||||
|
rmt_write_sample(config.channel, pixels, (size_t)numBytes, true);
|
||||||
|
rmt_wait_tx_done(config.channel, pdMS_TO_TICKS(100));
|
||||||
|
|
||||||
|
// Free channel again
|
||||||
|
rmt_driver_uninstall(config.channel);
|
||||||
|
rmt_reserved_channels[channel] = false;
|
||||||
|
|
||||||
|
gpio_set_direction(pin, GPIO_MODE_OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
86
ESP_Medicine_Indicator/libraries/Adafruit_NeoPixel/esp8266.c
Normal file
86
ESP_Medicine_Indicator/libraries/Adafruit_NeoPixel/esp8266.c
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
// This is a mash-up of the Due show() code + insights from Michael Miller's
|
||||||
|
// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus
|
||||||
|
// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution.
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#ifdef ESP8266
|
||||||
|
#include <eagle_soc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static uint32_t _getCycleCount(void) __attribute__((always_inline));
|
||||||
|
static inline uint32_t _getCycleCount(void) {
|
||||||
|
uint32_t ccount;
|
||||||
|
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
|
||||||
|
return ccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
IRAM_ATTR void espShow(
|
||||||
|
uint8_t pin, uint8_t *pixels, uint32_t numBytes, __attribute__((unused)) boolean is800KHz) {
|
||||||
|
#else
|
||||||
|
void espShow(
|
||||||
|
uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CYCLES_800_T0H (F_CPU / 2500001) // 0.4us
|
||||||
|
#define CYCLES_800_T1H (F_CPU / 1250001) // 0.8us
|
||||||
|
#define CYCLES_800 (F_CPU / 800001) // 1.25us per bit
|
||||||
|
#define CYCLES_400_T0H (F_CPU / 2000000) // 0.5uS
|
||||||
|
#define CYCLES_400_T1H (F_CPU / 833333) // 1.2us
|
||||||
|
#define CYCLES_400 (F_CPU / 400000) // 2.5us per bit
|
||||||
|
|
||||||
|
uint8_t *p, *end, pix, mask;
|
||||||
|
uint32_t t, time0, time1, period, c, startTime;
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
uint32_t pinMask;
|
||||||
|
pinMask = _BV(pin);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
p = pixels;
|
||||||
|
end = p + numBytes;
|
||||||
|
pix = *p++;
|
||||||
|
mask = 0x80;
|
||||||
|
startTime = 0;
|
||||||
|
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
if(is800KHz) {
|
||||||
|
#endif
|
||||||
|
time0 = CYCLES_800_T0H;
|
||||||
|
time1 = CYCLES_800_T1H;
|
||||||
|
period = CYCLES_800;
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
} else { // 400 KHz bitstream
|
||||||
|
time0 = CYCLES_400_T0H;
|
||||||
|
time1 = CYCLES_400_T1H;
|
||||||
|
period = CYCLES_400;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for(t = time0;; t = time0) {
|
||||||
|
if(pix & mask) t = time1; // Bit high duration
|
||||||
|
while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start
|
||||||
|
#ifdef ESP8266
|
||||||
|
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high
|
||||||
|
#else
|
||||||
|
gpio_set_level(pin, HIGH);
|
||||||
|
#endif
|
||||||
|
startTime = c; // Save start time
|
||||||
|
while(((c = _getCycleCount()) - startTime) < t); // Wait high duration
|
||||||
|
#ifdef ESP8266
|
||||||
|
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low
|
||||||
|
#else
|
||||||
|
gpio_set_level(pin, LOW);
|
||||||
|
#endif
|
||||||
|
if(!(mask >>= 1)) { // Next bit/byte
|
||||||
|
if(p >= end) break;
|
||||||
|
pix = *p++;
|
||||||
|
mask = 0x80;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while((_getCycleCount() - startTime) < period); // Wait for last bit
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ESP8266
|
||||||
@ -0,0 +1,177 @@
|
|||||||
|
// NeoPixel test program showing use of the WHITE channel for RGBW
|
||||||
|
// pixels only (won't look correct on regular RGB NeoPixel strips).
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
// On a Trinket or Gemma we suggest changing this to 1:
|
||||||
|
#define LED_PIN 6
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
#define LED_COUNT 60
|
||||||
|
|
||||||
|
// NeoPixel brightness, 0 (min) to 255 (max)
|
||||||
|
#define BRIGHTNESS 50 // Set BRIGHTNESS to about 1/5 (max = 255)
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = Pixel type flags, add together as needed:
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
|
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
strip.setBrightness(BRIGHTNESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Fill along the length of the strip in various colors...
|
||||||
|
colorWipe(strip.Color(255, 0, 0) , 50); // Red
|
||||||
|
colorWipe(strip.Color( 0, 255, 0) , 50); // Green
|
||||||
|
colorWipe(strip.Color( 0, 0, 255) , 50); // Blue
|
||||||
|
colorWipe(strip.Color( 0, 0, 0, 255), 50); // True white (not RGB white)
|
||||||
|
|
||||||
|
whiteOverRainbow(75, 5);
|
||||||
|
|
||||||
|
pulseWhite(5);
|
||||||
|
|
||||||
|
rainbowFade2White(3, 3, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void whiteOverRainbow(int whiteSpeed, int whiteLength) {
|
||||||
|
|
||||||
|
if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;
|
||||||
|
|
||||||
|
int head = whiteLength - 1;
|
||||||
|
int tail = 0;
|
||||||
|
int loops = 3;
|
||||||
|
int loopNum = 0;
|
||||||
|
uint32_t lastTime = millis();
|
||||||
|
uint32_t firstPixelHue = 0;
|
||||||
|
|
||||||
|
for(;;) { // Repeat forever (or until a 'break' or 'return')
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
if(((i >= tail) && (i <= head)) || // If between head & tail...
|
||||||
|
((tail > head) && ((i >= tail) || (i <= head)))) {
|
||||||
|
strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
|
||||||
|
} else { // else set rainbow
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
// There's no delay here, it just runs full-tilt until the timer and
|
||||||
|
// counter combination below runs out.
|
||||||
|
|
||||||
|
firstPixelHue += 40; // Advance just a little along the color wheel
|
||||||
|
|
||||||
|
if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?
|
||||||
|
if(++head >= strip.numPixels()) { // Advance head, wrap around
|
||||||
|
head = 0;
|
||||||
|
if(++loopNum >= loops) return;
|
||||||
|
}
|
||||||
|
if(++tail >= strip.numPixels()) { // Advance tail, wrap around
|
||||||
|
tail = 0;
|
||||||
|
}
|
||||||
|
lastTime = millis(); // Save time of last movement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pulseWhite(uint8_t wait) {
|
||||||
|
for(int j=0; j<256; j++) { // Ramp up from 0 to 255
|
||||||
|
// Fill entire strip with white at gamma-corrected brightness level 'j':
|
||||||
|
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int j=255; j>=0; j--) { // Ramp down from 255 to 0
|
||||||
|
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
|
||||||
|
int fadeVal=0, fadeMax=100;
|
||||||
|
|
||||||
|
// Hue of first pixel runs 'rainbowLoops' complete loops through the color
|
||||||
|
// wheel. Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to rainbowLoops*65536, using steps of 256 so we
|
||||||
|
// advance around the wheel at a decent clip.
|
||||||
|
for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536;
|
||||||
|
firstPixelHue += 256) {
|
||||||
|
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the three-argument variant, though the
|
||||||
|
// second value (saturation) is a constant 255.
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
|
||||||
|
255 * fadeVal / fadeMax)));
|
||||||
|
}
|
||||||
|
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
|
||||||
|
if(firstPixelHue < 65536) { // First loop,
|
||||||
|
if(fadeVal < fadeMax) fadeVal++; // fade in
|
||||||
|
} else if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { // Last loop,
|
||||||
|
if(fadeVal > 0) fadeVal--; // fade out
|
||||||
|
} else {
|
||||||
|
fadeVal = fadeMax; // Interim loop, make sure fade is at max
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int k=0; k<whiteLoops; k++) {
|
||||||
|
for(int j=0; j<256; j++) { // Ramp up 0 to 255
|
||||||
|
// Fill entire strip with white at gamma-corrected brightness level 'j':
|
||||||
|
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
|
||||||
|
strip.show();
|
||||||
|
}
|
||||||
|
delay(1000); // Pause 1 second
|
||||||
|
for(int j=255; j>=0; j--) { // Ramp down 255 to 0
|
||||||
|
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
|
||||||
|
strip.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(500); // Pause 1/2 second
|
||||||
|
}
|
||||||
@ -0,0 +1,231 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This example is based on StrandtestBLE example and adapts it to use
|
||||||
|
* the new ArduinoBLE library.
|
||||||
|
*
|
||||||
|
* https://github.com/arduino-libraries/ArduinoBLE
|
||||||
|
*
|
||||||
|
* Supported boards:
|
||||||
|
* Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
|
||||||
|
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
|
||||||
|
*
|
||||||
|
* You can use a generic BLE central app, like LightBlue (iOS and Android) or
|
||||||
|
* nRF Connect (Android), to interact with the services and characteristics
|
||||||
|
* created in this sketch.
|
||||||
|
*
|
||||||
|
* This example code is in the public domain.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define PIN 15 // Pin where NeoPixels are connected
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = Pixel type flags, add together as needed:
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
|
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
uint8_t rgb_values[3];
|
||||||
|
|
||||||
|
#include <ArduinoBLE.h>
|
||||||
|
|
||||||
|
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
|
||||||
|
|
||||||
|
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
|
||||||
|
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Hello World!");
|
||||||
|
|
||||||
|
// custom services and characteristics can be added as well
|
||||||
|
// begin initialization
|
||||||
|
if (!BLE.begin())
|
||||||
|
{
|
||||||
|
Serial.println("starting BLE failed!");
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Peripheral address: ");
|
||||||
|
Serial.println(BLE.address());
|
||||||
|
|
||||||
|
// set advertised local name and service UUID:
|
||||||
|
BLE.setLocalName("LED");
|
||||||
|
BLE.setAdvertisedService(ledService);
|
||||||
|
|
||||||
|
// add the characteristic to the service
|
||||||
|
ledService.addCharacteristic(switchCharacteristic);
|
||||||
|
|
||||||
|
// add service
|
||||||
|
BLE.addService(ledService);
|
||||||
|
|
||||||
|
// set the initial value for the characeristic:
|
||||||
|
switchCharacteristic.writeValue(0);
|
||||||
|
|
||||||
|
// start advertising
|
||||||
|
BLE.advertise();
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
|
||||||
|
pinMode(PIN, OUTPUT);
|
||||||
|
digitalWrite(PIN, LOW);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
BLEDevice central = BLE.central();
|
||||||
|
|
||||||
|
// if a central is connected to peripheral:
|
||||||
|
if (central)
|
||||||
|
{
|
||||||
|
Serial.print("Connected to central: ");
|
||||||
|
// print the central's MAC address:
|
||||||
|
Serial.println(central.address());
|
||||||
|
|
||||||
|
// while the central is still connected to peripheral:
|
||||||
|
while (central.connected())
|
||||||
|
{
|
||||||
|
// if the remote device wrote to the characteristic,
|
||||||
|
// use the value to control the LED:
|
||||||
|
if (switchCharacteristic.written())
|
||||||
|
{
|
||||||
|
switch (switchCharacteristic.value())
|
||||||
|
{
|
||||||
|
case 'a':
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
colorWipe(strip.Color(0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
colorWipe(strip.Color(0, 0, 255), 20); // Blue
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
theaterChase(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
theaterChase(strip.Color(0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
theaterChase(strip.Color(255, 0, 255), 20); // Cyan
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
theaterChaseRainbow(20);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strip.numPixels(); i++)
|
||||||
|
{ // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait)
|
||||||
|
{
|
||||||
|
for (int a = 0; a < 10; a++)
|
||||||
|
{ // Repeat 10 times...
|
||||||
|
for (int b = 0; b < 3; b++)
|
||||||
|
{ // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for (int c = b; c < strip.numPixels(); c += 3)
|
||||||
|
{
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait)
|
||||||
|
{
|
||||||
|
// Hue of first pixel runs 5 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
|
||||||
|
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strip.numPixels(); i++)
|
||||||
|
{ // For each pixel in strip...
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the single-argument hue variant. The result
|
||||||
|
// is passed through strip.gamma32() to provide 'truer' colors
|
||||||
|
// before assigning to each pixel:
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait)
|
||||||
|
{
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for (int a = 0; a < 30; a++)
|
||||||
|
{ // Repeat 30 times...
|
||||||
|
for (int b = 0; b < 3; b++)
|
||||||
|
{ // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for (int c = b; c < strip.numPixels(); c += 3)
|
||||||
|
{
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,239 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This example is based on StrandtestArduinoBLE example to make use of
|
||||||
|
* callbacks features of the ArduinoBLE library.
|
||||||
|
*
|
||||||
|
* https://github.com/arduino-libraries/ArduinoBLE
|
||||||
|
*
|
||||||
|
* Supported boards:
|
||||||
|
* Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
|
||||||
|
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
|
||||||
|
*
|
||||||
|
* You can use a generic BLE central app, like LightBlue (iOS and Android) or
|
||||||
|
* nRF Connect (Android), to interact with the services and characteristics
|
||||||
|
* created in this sketch.
|
||||||
|
*
|
||||||
|
* This example code is in the public domain.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define PIN 15 // Pin where NeoPixels are connected
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = Pixel type flags, add together as needed:
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
|
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
uint8_t rgb_values[3];
|
||||||
|
|
||||||
|
#include <ArduinoBLE.h>
|
||||||
|
|
||||||
|
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
|
||||||
|
|
||||||
|
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
|
||||||
|
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Hello World!");
|
||||||
|
|
||||||
|
// custom services and characteristics can be added as well
|
||||||
|
// begin initialization
|
||||||
|
if (!BLE.begin())
|
||||||
|
{
|
||||||
|
Serial.println("starting BLE failed!");
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Peripheral address: ");
|
||||||
|
Serial.println(BLE.address());
|
||||||
|
|
||||||
|
// set advertised local name and service UUID:
|
||||||
|
BLE.setLocalName("LEDCallback");
|
||||||
|
BLE.setAdvertisedService(ledService);
|
||||||
|
|
||||||
|
// add the characteristic to the service
|
||||||
|
ledService.addCharacteristic(switchCharacteristic);
|
||||||
|
|
||||||
|
// add service
|
||||||
|
BLE.addService(ledService);
|
||||||
|
// assign event handlers for connected, disconnected to peripheral
|
||||||
|
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
|
||||||
|
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
|
||||||
|
|
||||||
|
// assign event handlers for characteristic
|
||||||
|
switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten);
|
||||||
|
// set the initial value for the characeristic:
|
||||||
|
switchCharacteristic.writeValue(0);
|
||||||
|
|
||||||
|
// start advertising
|
||||||
|
BLE.advertise();
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
|
||||||
|
pinMode(PIN, OUTPUT);
|
||||||
|
digitalWrite(PIN, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// poll for BLE events
|
||||||
|
BLE.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
void blePeripheralConnectHandler(BLEDevice central)
|
||||||
|
{
|
||||||
|
// central connected event handler
|
||||||
|
Serial.print("Connected event, central: ");
|
||||||
|
Serial.println(central.address());
|
||||||
|
}
|
||||||
|
|
||||||
|
void blePeripheralDisconnectHandler(BLEDevice central)
|
||||||
|
{
|
||||||
|
// central disconnected event handler
|
||||||
|
Serial.print("Disconnected event, central: ");
|
||||||
|
Serial.println(central.address());
|
||||||
|
}
|
||||||
|
|
||||||
|
void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic)
|
||||||
|
{
|
||||||
|
// central wrote new value to characteristic, update LED
|
||||||
|
Serial.print("Characteristic event, written: ");
|
||||||
|
|
||||||
|
switch (switchCharacteristic.value())
|
||||||
|
{
|
||||||
|
case 'a':
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
colorWipe(strip.Color(0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
colorWipe(strip.Color(0, 0, 255), 20); // Blue
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
theaterChase(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
theaterChase(strip.Color(0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
theaterChase(strip.Color(255, 0, 255), 20); // Cyan
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
theaterChaseRainbow(20);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strip.numPixels(); i++)
|
||||||
|
{ // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait)
|
||||||
|
{
|
||||||
|
for (int a = 0; a < 10; a++)
|
||||||
|
{ // Repeat 10 times...
|
||||||
|
for (int b = 0; b < 3; b++)
|
||||||
|
{ // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for (int c = b; c < strip.numPixels(); c += 3)
|
||||||
|
{
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait)
|
||||||
|
{
|
||||||
|
// Hue of first pixel runs 5 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
|
||||||
|
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strip.numPixels(); i++)
|
||||||
|
{ // For each pixel in strip...
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the single-argument hue variant. The result
|
||||||
|
// is passed through strip.gamma32() to provide 'truer' colors
|
||||||
|
// before assigning to each pixel:
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait)
|
||||||
|
{
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for (int a = 0; a < 30; a++)
|
||||||
|
{ // Repeat 30 times...
|
||||||
|
for (int b = 0; b < 3; b++)
|
||||||
|
{ // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for (int c = b; c < strip.numPixels(); c += 3)
|
||||||
|
{
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,133 @@
|
|||||||
|
#include "BLESerial.h"
|
||||||
|
|
||||||
|
// #define BLE_SERIAL_DEBUG
|
||||||
|
|
||||||
|
BLESerial* BLESerial::_instance = NULL;
|
||||||
|
|
||||||
|
BLESerial::BLESerial(unsigned char req, unsigned char rdy, unsigned char rst) :
|
||||||
|
BLEPeripheral(req, rdy, rst)
|
||||||
|
{
|
||||||
|
this->_txCount = 0;
|
||||||
|
this->_rxHead = this->_rxTail = 0;
|
||||||
|
this->_flushed = 0;
|
||||||
|
BLESerial::_instance = this;
|
||||||
|
|
||||||
|
addAttribute(this->_uartService);
|
||||||
|
addAttribute(this->_uartNameDescriptor);
|
||||||
|
setAdvertisedServiceUuid(this->_uartService.uuid());
|
||||||
|
addAttribute(this->_rxCharacteristic);
|
||||||
|
addAttribute(this->_rxNameDescriptor);
|
||||||
|
this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received);
|
||||||
|
addAttribute(this->_txCharacteristic);
|
||||||
|
addAttribute(this->_txNameDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::begin(...) {
|
||||||
|
BLEPeripheral::begin();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.println(F("BLESerial::begin()"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::poll() {
|
||||||
|
if (millis() < this->_flushed + 100) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
} else {
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::end() {
|
||||||
|
this->_rxCharacteristic.setEventHandler(BLEWritten, NULL);
|
||||||
|
this->_rxHead = this->_rxTail = 0;
|
||||||
|
flush();
|
||||||
|
BLEPeripheral::disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::available(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer);
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::available() = "));
|
||||||
|
Serial.println(retval);
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::peek(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_rxTail == this->_rxHead) return -1;
|
||||||
|
uint8_t byte = this->_rxBuffer[this->_rxTail];
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::peek() = "));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.println(byte, HEX);
|
||||||
|
#endif
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::read(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_rxTail == this->_rxHead) return -1;
|
||||||
|
this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer);
|
||||||
|
uint8_t byte = this->_rxBuffer[this->_rxTail];
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::read() = "));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.println(byte, HEX);
|
||||||
|
#endif
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::flush(void) {
|
||||||
|
if (this->_txCount == 0) return;
|
||||||
|
this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount);
|
||||||
|
this->_flushed = millis();
|
||||||
|
this->_txCount = 0;
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.println(F("BLESerial::flush()"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t BLESerial::write(uint8_t byte) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_txCharacteristic.subscribed() == false) return 0;
|
||||||
|
this->_txBuffer[this->_txCount++] = byte;
|
||||||
|
if (this->_txCount == sizeof(this->_txBuffer)) flush();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::write("));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.print(byte, HEX);
|
||||||
|
Serial.println(F(") = 1"));
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BLESerial::operator bool() {
|
||||||
|
bool retval = BLEPeripheral::connected();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::operator bool() = "));
|
||||||
|
Serial.println(retval);
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::_received(const uint8_t* data, size_t size) {
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer);
|
||||||
|
this->_rxBuffer[this->_rxHead] = data[i];
|
||||||
|
}
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::received("));
|
||||||
|
for (int i = 0; i < size; i++) Serial.print((char) data[i]);
|
||||||
|
Serial.println(F(")"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) {
|
||||||
|
BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength());
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef _BLE_SERIAL_H_
|
||||||
|
#define _BLE_SERIAL_H_
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <BLEPeripheral.h>
|
||||||
|
|
||||||
|
class BLESerial : public BLEPeripheral, public Stream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BLESerial(unsigned char req, unsigned char rdy, unsigned char rst);
|
||||||
|
|
||||||
|
void begin(...);
|
||||||
|
void poll();
|
||||||
|
void end();
|
||||||
|
|
||||||
|
virtual int available(void);
|
||||||
|
virtual int peek(void);
|
||||||
|
virtual int read(void);
|
||||||
|
virtual void flush(void);
|
||||||
|
virtual size_t write(uint8_t byte);
|
||||||
|
using Print::write;
|
||||||
|
virtual operator bool();
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long _flushed;
|
||||||
|
static BLESerial* _instance;
|
||||||
|
|
||||||
|
size_t _rxHead;
|
||||||
|
size_t _rxTail;
|
||||||
|
size_t _rxCount() const;
|
||||||
|
uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
|
||||||
|
size_t _txCount;
|
||||||
|
uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
|
||||||
|
|
||||||
|
BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
|
||||||
|
BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART");
|
||||||
|
BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
|
||||||
|
BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)");
|
||||||
|
BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
|
||||||
|
BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)");
|
||||||
|
|
||||||
|
void _received(const uint8_t* data, size_t size);
|
||||||
|
static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -0,0 +1,192 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This example was developed by the Hackerspace San Salvador to demonstrate
|
||||||
|
* the simultaneous use of the NeoPixel library and the Bluetooth SoftDevice.
|
||||||
|
* To compile this example you'll need to add support for the NRF52 based
|
||||||
|
* following the instructions at:
|
||||||
|
* https://github.com/sandeepmistry/arduino-nRF5
|
||||||
|
* Or adding the following URL to the board manager URLs on Arduino preferences:
|
||||||
|
* https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json
|
||||||
|
* Then you can install the BLEPeripheral library avaiable at:
|
||||||
|
* https://github.com/sandeepmistry/arduino-BLEPeripheral
|
||||||
|
* To test it, compile this example and use the UART module from the nRF
|
||||||
|
* Toolbox App for Android. Edit the interface and send the characters
|
||||||
|
* 'a' to 'i' to switch the animation.
|
||||||
|
* There is a delay because this example blocks the thread of execution but
|
||||||
|
* the change will be shown after the current animation ends. (This might
|
||||||
|
* take a couple of seconds)
|
||||||
|
* For more info write us at: info _at- teubi.co
|
||||||
|
*/
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <BLEPeripheral.h>
|
||||||
|
#include "BLESerial.h"
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define PIN 15 // Pin where NeoPixels are connected
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = Pixel type flags, add together as needed:
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
|
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
// define pins (varies per shield/board)
|
||||||
|
#define BLE_REQ 10
|
||||||
|
#define BLE_RDY 2
|
||||||
|
#define BLE_RST 9
|
||||||
|
|
||||||
|
// create ble serial instance, see pinouts above
|
||||||
|
BLESerial BLESerial(BLE_REQ, BLE_RDY, BLE_RST);
|
||||||
|
|
||||||
|
uint8_t current_state = 0;
|
||||||
|
uint8_t rgb_values[3];
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Hello World!");
|
||||||
|
// custom services and characteristics can be added as well
|
||||||
|
BLESerial.setLocalName("UART_HS");
|
||||||
|
BLESerial.begin();
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
|
||||||
|
//pinMode(PIN, OUTPUT);
|
||||||
|
//digitalWrite(PIN, LOW);
|
||||||
|
|
||||||
|
current_state = 'a';
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
while(BLESerial.available()) {
|
||||||
|
uint8_t character = BLESerial.read();
|
||||||
|
switch(character) {
|
||||||
|
case 'a':
|
||||||
|
case 'b':
|
||||||
|
case 'c':
|
||||||
|
case 'd':
|
||||||
|
case 'e':
|
||||||
|
case 'f':
|
||||||
|
case 'g':
|
||||||
|
case 'h':
|
||||||
|
current_state = character;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
switch(current_state) {
|
||||||
|
case 'a':
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
colorWipe(strip.Color( 0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
colorWipe(strip.Color( 0, 0, 255), 20); // Blue
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
theaterChase(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
theaterChase(strip.Color( 0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
theaterChase(strip.Color(255, 0, 255), 20); // Cyan
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
theaterChaseRainbow(20);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
for(int a=0; a<10; a++) { // Repeat 10 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait) {
|
||||||
|
// Hue of first pixel runs 5 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
|
||||||
|
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the single-argument hue variant. The result
|
||||||
|
// is passed through strip.gamma32() to provide 'truer' colors
|
||||||
|
// before assigning to each pixel:
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait) {
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for(int a=0; a<30; a++) { // Repeat 30 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,133 @@
|
|||||||
|
#include "BLESerial.h"
|
||||||
|
|
||||||
|
// #define BLE_SERIAL_DEBUG
|
||||||
|
|
||||||
|
BLESerial* BLESerial::_instance = NULL;
|
||||||
|
|
||||||
|
BLESerial::BLESerial(unsigned char req, unsigned char rdy, unsigned char rst) :
|
||||||
|
BLEPeripheral(req, rdy, rst)
|
||||||
|
{
|
||||||
|
this->_txCount = 0;
|
||||||
|
this->_rxHead = this->_rxTail = 0;
|
||||||
|
this->_flushed = 0;
|
||||||
|
BLESerial::_instance = this;
|
||||||
|
|
||||||
|
addAttribute(this->_uartService);
|
||||||
|
addAttribute(this->_uartNameDescriptor);
|
||||||
|
setAdvertisedServiceUuid(this->_uartService.uuid());
|
||||||
|
addAttribute(this->_rxCharacteristic);
|
||||||
|
addAttribute(this->_rxNameDescriptor);
|
||||||
|
this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received);
|
||||||
|
addAttribute(this->_txCharacteristic);
|
||||||
|
addAttribute(this->_txNameDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::begin(...) {
|
||||||
|
BLEPeripheral::begin();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.println(F("BLESerial::begin()"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::poll() {
|
||||||
|
if (millis() < this->_flushed + 100) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
} else {
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::end() {
|
||||||
|
this->_rxCharacteristic.setEventHandler(BLEWritten, NULL);
|
||||||
|
this->_rxHead = this->_rxTail = 0;
|
||||||
|
flush();
|
||||||
|
BLEPeripheral::disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::available(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer);
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::available() = "));
|
||||||
|
Serial.println(retval);
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::peek(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_rxTail == this->_rxHead) return -1;
|
||||||
|
uint8_t byte = this->_rxBuffer[this->_rxTail];
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::peek() = "));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.println(byte, HEX);
|
||||||
|
#endif
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLESerial::read(void) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_rxTail == this->_rxHead) return -1;
|
||||||
|
this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer);
|
||||||
|
uint8_t byte = this->_rxBuffer[this->_rxTail];
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::read() = "));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.println(byte, HEX);
|
||||||
|
#endif
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::flush(void) {
|
||||||
|
if (this->_txCount == 0) return;
|
||||||
|
this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount);
|
||||||
|
this->_flushed = millis();
|
||||||
|
this->_txCount = 0;
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.println(F("BLESerial::flush()"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t BLESerial::write(uint8_t byte) {
|
||||||
|
BLEPeripheral::poll();
|
||||||
|
if (this->_txCharacteristic.subscribed() == false) return 0;
|
||||||
|
this->_txBuffer[this->_txCount++] = byte;
|
||||||
|
if (this->_txCount == sizeof(this->_txBuffer)) flush();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::write("));
|
||||||
|
Serial.print((char) byte);
|
||||||
|
Serial.print(F(" 0x"));
|
||||||
|
Serial.print(byte, HEX);
|
||||||
|
Serial.println(F(") = 1"));
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BLESerial::operator bool() {
|
||||||
|
bool retval = BLEPeripheral::connected();
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::operator bool() = "));
|
||||||
|
Serial.println(retval);
|
||||||
|
#endif
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::_received(const uint8_t* data, size_t size) {
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer);
|
||||||
|
this->_rxBuffer[this->_rxHead] = data[i];
|
||||||
|
}
|
||||||
|
#ifdef BLE_SERIAL_DEBUG
|
||||||
|
Serial.print(F("BLESerial::received("));
|
||||||
|
for (int i = 0; i < size; i++) Serial.print((char) data[i]);
|
||||||
|
Serial.println(F(")"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) {
|
||||||
|
BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength());
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef _BLE_SERIAL_H_
|
||||||
|
#define _BLE_SERIAL_H_
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <BLEPeripheral.h>
|
||||||
|
|
||||||
|
class BLESerial : public BLEPeripheral, public Stream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BLESerial(unsigned char req, unsigned char rdy, unsigned char rst);
|
||||||
|
|
||||||
|
void begin(...);
|
||||||
|
void poll();
|
||||||
|
void end();
|
||||||
|
|
||||||
|
virtual int available(void);
|
||||||
|
virtual int peek(void);
|
||||||
|
virtual int read(void);
|
||||||
|
virtual void flush(void);
|
||||||
|
virtual size_t write(uint8_t byte);
|
||||||
|
using Print::write;
|
||||||
|
virtual operator bool();
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long _flushed;
|
||||||
|
static BLESerial* _instance;
|
||||||
|
|
||||||
|
size_t _rxHead;
|
||||||
|
size_t _rxTail;
|
||||||
|
size_t _rxCount() const;
|
||||||
|
uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
|
||||||
|
size_t _txCount;
|
||||||
|
uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
|
||||||
|
|
||||||
|
BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
|
||||||
|
BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART");
|
||||||
|
BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
|
||||||
|
BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)");
|
||||||
|
BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
|
||||||
|
BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)");
|
||||||
|
|
||||||
|
void _received(const uint8_t* data, size_t size);
|
||||||
|
static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -0,0 +1,198 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This example was developed by the Hackerspace San Salvador to demonstrate
|
||||||
|
* the simultaneous use of the NeoPixel library and the Bluetooth SoftDevice.
|
||||||
|
* To compile this example you'll need to add support for the NRF52 based
|
||||||
|
* following the instructions at:
|
||||||
|
* https://github.com/sandeepmistry/arduino-nRF5
|
||||||
|
* Or adding the following URL to the board manager URLs on Arduino preferences:
|
||||||
|
* https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json
|
||||||
|
* Then you can install the BLEPeripheral library avaiable at:
|
||||||
|
* https://github.com/sandeepmistry/arduino-BLEPeripheral
|
||||||
|
* To test it, compile this example and use the UART module from the nRF
|
||||||
|
* Toolbox App for Android. Edit the interface and send the characters
|
||||||
|
* 'a' to 'i' to switch the animation.
|
||||||
|
* There is a no delay because this example does not block the threads execution
|
||||||
|
* so the change will be shown immediately and will not need to wait for the current
|
||||||
|
* animation to end.
|
||||||
|
* For more info write us at: info _at- teubi.co
|
||||||
|
*/
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <BLEPeripheral.h>
|
||||||
|
#include "BLESerial.h"
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define PIN 15 // Pin where NeoPixels are connected
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = Pixel type flags, add together as needed:
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
|
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
// define pins (varies per shield/board)
|
||||||
|
#define BLE_REQ 10
|
||||||
|
#define BLE_RDY 2
|
||||||
|
#define BLE_RST 9
|
||||||
|
|
||||||
|
// create ble serial instance, see pinouts above
|
||||||
|
BLESerial BLESerial(BLE_REQ, BLE_RDY, BLE_RST);
|
||||||
|
|
||||||
|
uint8_t current_state = 0;
|
||||||
|
uint8_t rgb_values[3];
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Hello World!");
|
||||||
|
// custom services and characteristics can be added as well
|
||||||
|
BLESerial.setLocalName("UART_HS");
|
||||||
|
BLESerial.begin();
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
|
||||||
|
//pinMode(PIN, OUTPUT);
|
||||||
|
//digitalWrite(PIN, LOW);
|
||||||
|
|
||||||
|
current_state = 'a';
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
while(BLESerial.available()) {
|
||||||
|
uint8_t character = BLESerial.read();
|
||||||
|
switch(character) {
|
||||||
|
case 'a':
|
||||||
|
case 'b':
|
||||||
|
case 'c':
|
||||||
|
case 'd':
|
||||||
|
case 'e':
|
||||||
|
case 'f':
|
||||||
|
case 'g':
|
||||||
|
case 'h':
|
||||||
|
current_state = character;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
switch(current_state) {
|
||||||
|
case 'a':
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
colorWipe(strip.Color( 0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
colorWipe(strip.Color( 0, 0, 255), 20); // Blue
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
theaterChase(strip.Color(255, 0, 0), 20); // Red
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
theaterChase(strip.Color( 0, 255, 0), 20); // Green
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
theaterChase(strip.Color(255, 0, 255), 20); // Cyan
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
theaterChaseRainbow(20);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some functions of our own for creating animated effects -----------------
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
pixelCurrent++; // Advance current pixel
|
||||||
|
if(pixelCurrent >= pixelNumber) // Loop the pattern from the first LED
|
||||||
|
pixelCurrent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
for(int i = 0; i < pixelNumber; i++) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM)
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
for(int i=0; i < pixelNumber; i+3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM)
|
||||||
|
}
|
||||||
|
pixelQueue++; // Advance current pixel
|
||||||
|
if(pixelQueue >= 3)
|
||||||
|
pixelQueue = 0; // Loop the pattern from the first LED
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(uint8_t wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait;
|
||||||
|
for(uint16_t i=0; i < pixelNumber; i++) {
|
||||||
|
strip.setPixelColor(i, Wheel((i + pixelCycle) & 255)); // Update delay time
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
pixelCycle++; // Advance current cycle
|
||||||
|
if(pixelCycle >= 256)
|
||||||
|
pixelCycle = 0; // Loop the cycle back to the begining
|
||||||
|
}
|
||||||
|
|
||||||
|
//Theatre-style crawling lights with rainbow effect
|
||||||
|
void theaterChaseRainbow(uint8_t wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
for(int i=0; i < pixelNumber; i+3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, Wheel((i + pixelCycle) % 255)); // Update delay time
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
for(int i=0; i < pixelNumber; i+3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Update delay time
|
||||||
|
}
|
||||||
|
pixelQueue++; // Advance current queue
|
||||||
|
pixelCycle++; // Advance current cycle
|
||||||
|
if(pixelQueue >= 3)
|
||||||
|
pixelQueue = 0; // Loop
|
||||||
|
if(pixelCycle >= 256)
|
||||||
|
pixelCycle = 0; // Loop
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input a value 0 to 255 to get a color value.
|
||||||
|
// The colours are a transition r - g - b - back to r.
|
||||||
|
uint32_t Wheel(byte WheelPos) {
|
||||||
|
WheelPos = 255 - WheelPos;
|
||||||
|
if(WheelPos < 85) {
|
||||||
|
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||||
|
}
|
||||||
|
if(WheelPos < 170) {
|
||||||
|
WheelPos -= 85;
|
||||||
|
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||||
|
}
|
||||||
|
WheelPos -= 170;
|
||||||
|
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||||
|
}
|
||||||
@ -0,0 +1,164 @@
|
|||||||
|
// Simple demonstration on using an input device to trigger changes on your
|
||||||
|
// NeoPixels. Wire a momentary push button to connect from ground to a
|
||||||
|
// digital IO pin. When the button is pressed it will change to a new pixel
|
||||||
|
// animation. Initial state has all pixels off -- press the button once to
|
||||||
|
// start the first animation. As written, the button does not interrupt an
|
||||||
|
// animation in-progress, it works only when idle.
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Digital IO pin connected to the button. This will be driven with a
|
||||||
|
// pull-up resistor so the switch pulls the pin to ground momentarily.
|
||||||
|
// On a high -> low transition the button press logic will execute.
|
||||||
|
#define BUTTON_PIN 2
|
||||||
|
|
||||||
|
#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
|
||||||
|
|
||||||
|
#define PIXEL_COUNT 16 // Number of NeoPixels
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = Pixel type flags, add together as needed:
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
|
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
boolean oldState = HIGH;
|
||||||
|
int mode = 0; // Currently-active animation mode, 0-9
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Initialize all pixels to 'off'
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Get current button state.
|
||||||
|
boolean newState = digitalRead(BUTTON_PIN);
|
||||||
|
|
||||||
|
// Check if state changed from high to low (button press).
|
||||||
|
if((newState == LOW) && (oldState == HIGH)) {
|
||||||
|
// Short delay to debounce button.
|
||||||
|
delay(20);
|
||||||
|
// Check if button is still low after debounce.
|
||||||
|
newState = digitalRead(BUTTON_PIN);
|
||||||
|
if(newState == LOW) { // Yes, still low
|
||||||
|
if(++mode > 8) mode = 0; // Advance to next mode, wrap around after #8
|
||||||
|
switch(mode) { // Start the new animation...
|
||||||
|
case 0:
|
||||||
|
colorWipe(strip.Color( 0, 0, 0), 50); // Black/off
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
colorWipe(strip.Color( 0, 255, 0), 50); // Green
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
colorWipe(strip.Color( 0, 0, 255), 50); // Blue
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
theaterChase(strip.Color(127, 127, 127), 50); // White
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
theaterChase(strip.Color(127, 0, 0), 50); // Red
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
theaterChase(strip.Color( 0, 0, 127), 50); // Blue
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
rainbow(10);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
theaterChaseRainbow(50);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the last-read button state to the old state.
|
||||||
|
oldState = newState;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
for(int a=0; a<10; a++) { // Repeat 10 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait) {
|
||||||
|
// Hue of first pixel runs 3 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 3*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 3*65536/256 = 768 passes through this outer loop:
|
||||||
|
for(long firstPixelHue = 0; firstPixelHue < 3*65536; firstPixelHue += 256) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
// Offset pixel hue by an amount to make one full revolution of the
|
||||||
|
// color wheel (range of 65536) along the length of the strip
|
||||||
|
// (strip.numPixels() steps):
|
||||||
|
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
|
||||||
|
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
|
||||||
|
// optionally add saturation and value (brightness) (each 0 to 255).
|
||||||
|
// Here we're using just the single-argument hue variant. The result
|
||||||
|
// is passed through strip.gamma32() to provide 'truer' colors
|
||||||
|
// before assigning to each pixel:
|
||||||
|
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait) {
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for(int a=0; a<30; a++) { // Repeat 30 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
|
||||||
|
// Released under the GPLv3 license to match the rest of the
|
||||||
|
// Adafruit NeoPixel library
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
#define NUMPIXELS 16 // Popular NeoPixel ring size
|
||||||
|
|
||||||
|
// When setting up the NeoPixel library, we tell it how many pixels,
|
||||||
|
// and which pin to use to send signals. Note that for older NeoPixel
|
||||||
|
// strips you might need to change the third parameter -- see the
|
||||||
|
// strandtest example for more information on possible values.
|
||||||
|
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
pixels.clear(); // Set all pixel colors to 'off'
|
||||||
|
|
||||||
|
// The first NeoPixel in a strand is #0, second is 1, all the way up
|
||||||
|
// to the count of pixels minus one.
|
||||||
|
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
|
||||||
|
|
||||||
|
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
|
||||||
|
// Here we're using a moderately bright green color:
|
||||||
|
pixels.setPixelColor(i, pixels.Color(0, 150, 0));
|
||||||
|
|
||||||
|
pixels.show(); // Send the updated pixel colors to the hardware.
|
||||||
|
|
||||||
|
delay(DELAYVAL); // Pause before next pass through loop
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
|
||||||
|
// Released under the GPLv3 license to match the rest of the
|
||||||
|
// Adafruit NeoPixel library
|
||||||
|
// This sketch shows use of the "new" operator with Adafruit_NeoPixel.
|
||||||
|
// It's helpful if you don't know NeoPixel settings at compile time or
|
||||||
|
// just want to store this settings in EEPROM or a file on an SD card.
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
int pin = 6; // On Trinket or Gemma, suggest changing this to 1
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
int numPixels = 16; // Popular NeoPixel ring size
|
||||||
|
|
||||||
|
// NeoPixel color format & data rate. See the strandtest example for
|
||||||
|
// information on possible values.
|
||||||
|
int pixelFormat = NEO_GRB + NEO_KHZ800;
|
||||||
|
|
||||||
|
// Rather than declaring the whole NeoPixel object here, we just create
|
||||||
|
// a pointer for one, which we'll then allocate later...
|
||||||
|
Adafruit_NeoPixel *pixels;
|
||||||
|
|
||||||
|
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
// Right about here is where we could read 'pin', 'numPixels' and/or
|
||||||
|
// 'pixelFormat' from EEPROM or a file on SD or whatever. This is a simple
|
||||||
|
// example and doesn't do that -- those variables are just set to fixed
|
||||||
|
// values at the top of this code -- but this is where it would happen.
|
||||||
|
|
||||||
|
// Then create a new NeoPixel object dynamically with these values:
|
||||||
|
pixels = new Adafruit_NeoPixel(numPixels, pin, pixelFormat);
|
||||||
|
|
||||||
|
// Going forward from here, code works almost identically to any other
|
||||||
|
// NeoPixel example, but instead of the dot operator on function calls
|
||||||
|
// (e.g. pixels.begin()), we instead use pointer indirection (->) like so:
|
||||||
|
pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
// You'll see more of this in the loop() function below.
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
pixels->clear(); // Set all pixel colors to 'off'
|
||||||
|
|
||||||
|
// The first NeoPixel in a strand is #0, second is 1, all the way up
|
||||||
|
// to the count of pixels minus one.
|
||||||
|
for(int i=0; i<numPixels; i++) { // For each pixel...
|
||||||
|
|
||||||
|
// pixels->Color() takes RGB values, from 0,0,0 up to 255,255,255
|
||||||
|
// Here we're using a moderately bright green color:
|
||||||
|
pixels->setPixelColor(i, pixels->Color(0, 150, 0));
|
||||||
|
|
||||||
|
pixels->show(); // Send the updated pixel colors to the hardware.
|
||||||
|
|
||||||
|
delay(DELAYVAL); // Pause before next pass through loop
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,143 @@
|
|||||||
|
// A basic everyday NeoPixel strip test program.
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
// On a Trinket or Gemma we suggest changing this to 1:
|
||||||
|
#define LED_PIN 6
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
#define LED_COUNT 60
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = Pixel type flags, add together as needed:
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
|
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
|
||||||
|
// setup() function -- runs once at startup --------------------------------
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// loop() function -- runs repeatedly as long as board is on ---------------
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Fill along the length of the strip in various colors...
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||||
|
colorWipe(strip.Color( 0, 255, 0), 50); // Green
|
||||||
|
colorWipe(strip.Color( 0, 0, 255), 50); // Blue
|
||||||
|
|
||||||
|
// Do a theater marquee effect in various colors...
|
||||||
|
theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
|
||||||
|
theaterChase(strip.Color(127, 0, 0), 50); // Red, half brightness
|
||||||
|
theaterChase(strip.Color( 0, 0, 127), 50); // Blue, half brightness
|
||||||
|
|
||||||
|
rainbow(10); // Flowing rainbow cycle along the whole strip
|
||||||
|
theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Some functions of our own for creating animated effects -----------------
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
||||||
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
for(int a=0; a<10; a++) { // Repeat 10 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in steps of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(int wait) {
|
||||||
|
// Hue of first pixel runs 5 complete loops through the color wheel.
|
||||||
|
// Color wheel has a range of 65536 but it's OK if we roll over, so
|
||||||
|
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
|
||||||
|
// means we'll make 5*65536/256 = 1280 passes through this loop:
|
||||||
|
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
|
||||||
|
// strip.rainbow() can take a single argument (first pixel hue) or
|
||||||
|
// optionally a few extras: number of rainbow repetitions (default 1),
|
||||||
|
// saturation and value (brightness) (both 0-255, similar to the
|
||||||
|
// ColorHSV() function, default 255), and a true/false flag for whether
|
||||||
|
// to apply gamma correction to provide 'truer' colors (default true).
|
||||||
|
strip.rainbow(firstPixelHue);
|
||||||
|
// Above line is equivalent to:
|
||||||
|
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
|
||||||
|
void theaterChaseRainbow(int wait) {
|
||||||
|
int firstPixelHue = 0; // First pixel starts at red (hue 0)
|
||||||
|
for(int a=0; a<30; a++) { // Repeat 30 times...
|
||||||
|
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
|
||||||
|
strip.clear(); // Set all pixels in RAM to 0 (off)
|
||||||
|
// 'c' counts up from 'b' to end of strip in increments of 3...
|
||||||
|
for(int c=b; c<strip.numPixels(); c += 3) {
|
||||||
|
// hue of pixel 'c' is offset by an amount to make one full
|
||||||
|
// revolution of the color wheel (range 65536) along the length
|
||||||
|
// of the strip (strip.numPixels() steps):
|
||||||
|
int hue = firstPixelHue + c * 65536L / strip.numPixels();
|
||||||
|
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
|
||||||
|
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip with new contents
|
||||||
|
delay(wait); // Pause for a moment
|
||||||
|
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,186 @@
|
|||||||
|
// A non-blocking everyday NeoPixel strip test program.
|
||||||
|
|
||||||
|
// NEOPIXEL BEST PRACTICES for most reliable operation:
|
||||||
|
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
|
||||||
|
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
|
||||||
|
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
|
||||||
|
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
|
||||||
|
// connect GROUND (-) first, then +, then data.
|
||||||
|
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
|
||||||
|
// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
|
||||||
|
// (Skipping these may work OK on your workbench but can fail in the field)
|
||||||
|
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Which pin on the Arduino is connected to the NeoPixels?
|
||||||
|
// On a Trinket or Gemma we suggest changing this to 1:
|
||||||
|
#ifdef ESP32
|
||||||
|
// Cannot use 6 as output for ESP. Pins 6-11 are connected to SPI flash. Use 16 instead.
|
||||||
|
#define LED_PIN 16
|
||||||
|
#else
|
||||||
|
#define LED_PIN 6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// How many NeoPixels are attached to the Arduino?
|
||||||
|
#define LED_COUNT 60
|
||||||
|
|
||||||
|
// Declare our NeoPixel strip object:
|
||||||
|
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
// Argument 1 = Number of pixels in NeoPixel strip
|
||||||
|
// Argument 2 = Arduino pin number (most are valid)
|
||||||
|
// Argument 3 = Pixel type flags, add together as needed:
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
|
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
|
||||||
|
unsigned long pixelPrevious = 0; // Previous Pixel Millis
|
||||||
|
unsigned long patternPrevious = 0; // Previous Pattern Millis
|
||||||
|
int patternCurrent = 0; // Current Pattern Number
|
||||||
|
int patternInterval = 5000; // Pattern Interval (ms)
|
||||||
|
int pixelInterval = 50; // Pixel Interval (ms)
|
||||||
|
int pixelQueue = 0; // Pattern Pixel Queue
|
||||||
|
int pixelCycle = 0; // Pattern Pixel Cycle
|
||||||
|
uint16_t pixelCurrent = 0; // Pattern Current Pixel Number
|
||||||
|
uint16_t pixelNumber = LED_COUNT; // Total Number of Pixels
|
||||||
|
|
||||||
|
// setup() function -- runs once at startup --------------------------------
|
||||||
|
void setup() {
|
||||||
|
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
|
||||||
|
// Any other board, you can remove this part (but no harm leaving it):
|
||||||
|
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
|
||||||
|
clock_prescale_set(clock_div_1);
|
||||||
|
#endif
|
||||||
|
// END of Trinket-specific code.
|
||||||
|
|
||||||
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||||
|
strip.show(); // Turn OFF all pixels ASAP
|
||||||
|
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop() function -- runs repeatedly as long as board is on ---------------
|
||||||
|
void loop() {
|
||||||
|
unsigned long currentMillis = millis(); // Update current time
|
||||||
|
if((currentMillis - patternPrevious) >= patternInterval) { // Check for expired time
|
||||||
|
patternPrevious = currentMillis;
|
||||||
|
patternCurrent++; // Advance to next pattern
|
||||||
|
if(patternCurrent >= 7)
|
||||||
|
patternCurrent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currentMillis - pixelPrevious >= pixelInterval) { // Check for expired time
|
||||||
|
pixelPrevious = currentMillis; // Run current frame
|
||||||
|
switch (patternCurrent) {
|
||||||
|
case 7:
|
||||||
|
theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
rainbow(10); // Flowing rainbow cycle along the whole strip
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
theaterChase(strip.Color(0, 0, 127), 50); // Blue
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
theaterChase(strip.Color(127, 0, 0), 50); // Red
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
theaterChase(strip.Color(127, 127, 127), 50); // White
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
colorWipe(strip.Color(0, 0, 255), 50); // Blue
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
colorWipe(strip.Color(0, 255, 0), 50); // Green
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some functions of our own for creating animated effects -----------------
|
||||||
|
|
||||||
|
// Fill strip pixels one after another with a color. Strip is NOT cleared
|
||||||
|
// first; anything there will be covered pixel by pixel. Pass in color
|
||||||
|
// (as a single 'packed' 32-bit value, which you can get by calling
|
||||||
|
// strip.Color(red, green, blue) as shown in the loop() function above),
|
||||||
|
// and a delay time (in milliseconds) between pixels.
|
||||||
|
void colorWipe(uint32_t color, int wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
pixelCurrent++; // Advance current pixel
|
||||||
|
if(pixelCurrent >= pixelNumber) // Loop the pattern from the first LED
|
||||||
|
pixelCurrent = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
|
||||||
|
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
|
||||||
|
// between frames.
|
||||||
|
void theaterChase(uint32_t color, int wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
for(int i = 0; i < pixelNumber; i++) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM)
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
for(int i=0; i < pixelNumber; i+=3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM)
|
||||||
|
}
|
||||||
|
pixelQueue++; // Advance current pixel
|
||||||
|
if(pixelQueue >= 3)
|
||||||
|
pixelQueue = 0; // Loop the pattern from the first LED
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
|
||||||
|
void rainbow(uint8_t wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait;
|
||||||
|
for(uint16_t i=0; i < pixelNumber; i++) {
|
||||||
|
strip.setPixelColor(i, Wheel((i + pixelCycle) & 255)); // Update delay time
|
||||||
|
}
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
pixelCycle++; // Advance current cycle
|
||||||
|
if(pixelCycle >= 256)
|
||||||
|
pixelCycle = 0; // Loop the cycle back to the begining
|
||||||
|
}
|
||||||
|
|
||||||
|
//Theatre-style crawling lights with rainbow effect
|
||||||
|
void theaterChaseRainbow(uint8_t wait) {
|
||||||
|
if(pixelInterval != wait)
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
for(int i=0; i < pixelNumber; i+=3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, Wheel((i + pixelCycle) % 255)); // Update delay time
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
for(int i=0; i < pixelNumber; i+=3) {
|
||||||
|
strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Update delay time
|
||||||
|
}
|
||||||
|
pixelQueue++; // Advance current queue
|
||||||
|
pixelCycle++; // Advance current cycle
|
||||||
|
if(pixelQueue >= 3)
|
||||||
|
pixelQueue = 0; // Loop
|
||||||
|
if(pixelCycle >= 256)
|
||||||
|
pixelCycle = 0; // Loop
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input a value 0 to 255 to get a color value.
|
||||||
|
// The colours are a transition r - g - b - back to r.
|
||||||
|
uint32_t Wheel(byte WheelPos) {
|
||||||
|
WheelPos = 255 - WheelPos;
|
||||||
|
if(WheelPos < 85) {
|
||||||
|
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||||
|
}
|
||||||
|
if(WheelPos < 170) {
|
||||||
|
WheelPos -= 85;
|
||||||
|
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||||
|
}
|
||||||
|
WheelPos -= 170;
|
||||||
|
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||||
|
}
|
||||||
@ -0,0 +1,134 @@
|
|||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PIN 6
|
||||||
|
|
||||||
|
// Parameter 1 = number of pixels in strip
|
||||||
|
// Parameter 2 = Arduino pin number (most are valid)
|
||||||
|
// Parameter 3 = pixel type flags, add together as needed:
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||||
|
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||||
|
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||||
|
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
|
||||||
|
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
|
||||||
|
// and minimize distance between Arduino and first pixel. Avoid connecting
|
||||||
|
// on a live circuit...if you must, connect GND first.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
strip.begin();
|
||||||
|
strip.setBrightness(50);
|
||||||
|
strip.show(); // Initialize all pixels to 'off'
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Some example procedures showing how to display to the pixels:
|
||||||
|
colorWipe(strip.Color(255, 0, 0), 50); // Red
|
||||||
|
colorWipe(strip.Color(0, 255, 0), 50); // Green
|
||||||
|
colorWipe(strip.Color(0, 0, 255), 50); // Blue
|
||||||
|
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
|
||||||
|
// Send a theater pixel chase in...
|
||||||
|
theaterChase(strip.Color(127, 127, 127), 50); // White
|
||||||
|
theaterChase(strip.Color(127, 0, 0), 50); // Red
|
||||||
|
theaterChase(strip.Color(0, 0, 127), 50); // Blue
|
||||||
|
|
||||||
|
rainbow(20);
|
||||||
|
rainbowCycle(20);
|
||||||
|
theaterChaseRainbow(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill the dots one after the other with a color
|
||||||
|
void colorWipe(uint32_t c, uint8_t wait) {
|
||||||
|
for(uint16_t i=0; i<strip.numPixels(); i++) {
|
||||||
|
strip.setPixelColor(i, c);
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rainbow(uint8_t wait) {
|
||||||
|
uint16_t i, j;
|
||||||
|
|
||||||
|
for(j=0; j<256; j++) {
|
||||||
|
for(i=0; i<strip.numPixels(); i++) {
|
||||||
|
strip.setPixelColor(i, Wheel((i+j) & 255));
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slightly different, this makes the rainbow equally distributed throughout
|
||||||
|
void rainbowCycle(uint8_t wait) {
|
||||||
|
uint16_t i, j;
|
||||||
|
|
||||||
|
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
|
||||||
|
for(i=0; i< strip.numPixels(); i++) {
|
||||||
|
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
delay(wait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Theatre-style crawling lights.
|
||||||
|
void theaterChase(uint32_t c, uint8_t wait) {
|
||||||
|
for (int j=0; j<10; j++) { //do 10 cycles of chasing
|
||||||
|
for (int q=0; q < 3; q++) {
|
||||||
|
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||||
|
strip.setPixelColor(i+q, c); //turn every third pixel on
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
|
||||||
|
delay(wait);
|
||||||
|
|
||||||
|
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||||
|
strip.setPixelColor(i+q, 0); //turn every third pixel off
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Theatre-style crawling lights with rainbow effect
|
||||||
|
void theaterChaseRainbow(uint8_t wait) {
|
||||||
|
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
|
||||||
|
for (int q=0; q < 3; q++) {
|
||||||
|
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||||
|
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
|
||||||
|
delay(wait);
|
||||||
|
|
||||||
|
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
|
||||||
|
strip.setPixelColor(i+q, 0); //turn every third pixel off
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input a value 0 to 255 to get a color value.
|
||||||
|
// The colours are a transition r - g - b - back to r.
|
||||||
|
uint32_t Wheel(byte WheelPos) {
|
||||||
|
WheelPos = 255 - WheelPos;
|
||||||
|
if(WheelPos < 85) {
|
||||||
|
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||||
|
}
|
||||||
|
if(WheelPos < 170) {
|
||||||
|
WheelPos -= 85;
|
||||||
|
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||||
|
}
|
||||||
|
WheelPos -= 170;
|
||||||
|
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
// This is a mash-up of the Due show() code + insights from Michael Miller's
|
||||||
|
// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus
|
||||||
|
// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution.
|
||||||
|
#if defined(K210)
|
||||||
|
#define KENDRYTE_K210 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(KENDRYTE_K210)
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "sysctl.h"
|
||||||
|
|
||||||
|
void k210Show(
|
||||||
|
uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz)
|
||||||
|
{
|
||||||
|
|
||||||
|
#define CYCLES_800_T0H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 2500000) // 0.4us
|
||||||
|
#define CYCLES_800_T1H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 1250000) // 0.8us
|
||||||
|
#define CYCLES_800 (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 800000) // 1.25us per bit
|
||||||
|
#define CYCLES_400_T0H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 2000000) // 0.5uS
|
||||||
|
#define CYCLES_400_T1H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 833333) // 1.2us
|
||||||
|
#define CYCLES_400 (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 400000) // 2.5us per bit
|
||||||
|
|
||||||
|
uint8_t *p, *end, pix, mask;
|
||||||
|
uint32_t t, time0, time1, period, c, startTime;
|
||||||
|
|
||||||
|
p = pixels;
|
||||||
|
end = p + numBytes;
|
||||||
|
pix = *p++;
|
||||||
|
mask = 0x80;
|
||||||
|
startTime = 0;
|
||||||
|
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
if (is800KHz)
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
time0 = CYCLES_800_T0H;
|
||||||
|
time1 = CYCLES_800_T1H;
|
||||||
|
period = CYCLES_800;
|
||||||
|
#ifdef NEO_KHZ400
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // 400 KHz bitstream
|
||||||
|
time0 = CYCLES_400_T0H;
|
||||||
|
time1 = CYCLES_400_T1H;
|
||||||
|
period = CYCLES_400;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (t = time0;; t = time0)
|
||||||
|
{
|
||||||
|
if (pix & mask)
|
||||||
|
t = time1; // Bit high duration
|
||||||
|
while (((c = read_cycle()) - startTime) < period)
|
||||||
|
; // Wait for bit start
|
||||||
|
digitalWrite(pin, HIGH);
|
||||||
|
startTime = c; // Save start time
|
||||||
|
while (((c = read_cycle()) - startTime) < t)
|
||||||
|
; // Wait high duration
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
|
||||||
|
if (!(mask >>= 1))
|
||||||
|
{ // Next bit/byte
|
||||||
|
if (p >= end)
|
||||||
|
break;
|
||||||
|
pix = *p++;
|
||||||
|
mask = 0x80;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while ((read_cycle() - startTime) < period)
|
||||||
|
; // Wait for last bit
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // KENDRYTE_K210
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
#######################################
|
||||||
|
# Syntax Coloring Map For Adafruit_NeoPixel
|
||||||
|
#######################################
|
||||||
|
# Class
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
Adafruit_NeoPixel KEYWORD1
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Methods and Functions
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
begin KEYWORD2
|
||||||
|
show KEYWORD2
|
||||||
|
setPin KEYWORD2
|
||||||
|
setPixelColor KEYWORD2
|
||||||
|
fill KEYWORD2
|
||||||
|
setBrightness KEYWORD2
|
||||||
|
clear KEYWORD2
|
||||||
|
updateLength KEYWORD2
|
||||||
|
updateType KEYWORD2
|
||||||
|
canShow KEYWORD2
|
||||||
|
getPixels KEYWORD2
|
||||||
|
getBrightness KEYWORD2
|
||||||
|
getPin KEYWORD2
|
||||||
|
numPixels KEYWORD2
|
||||||
|
getPixelColor KEYWORD2
|
||||||
|
sine8 KEYWORD2
|
||||||
|
gamma8 KEYWORD2
|
||||||
|
Color KEYWORD2
|
||||||
|
ColorHSV KEYWORD2
|
||||||
|
gamma32 KEYWORD2
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Constants
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
NEO_COLMASK LITERAL1
|
||||||
|
NEO_SPDMASK LITERAL1
|
||||||
|
NEO_KHZ800 LITERAL1
|
||||||
|
NEO_KHZ400 LITERAL1
|
||||||
|
NEO_RGB 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
|
||||||
|
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
name=Adafruit NeoPixel
|
||||||
|
version=1.11.0
|
||||||
|
author=Adafruit
|
||||||
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
|
sentence=Arduino library for controlling single-wire-based LED pixels and strip.
|
||||||
|
paragraph=Arduino library for controlling single-wire-based LED pixels and strip.
|
||||||
|
category=Display
|
||||||
|
url=https://github.com/adafruit/Adafruit_NeoPixel
|
||||||
|
architectures=*
|
||||||
|
includes=Adafruit_NeoPixel.h
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
// -------------------------------------------------- //
|
||||||
|
// This file is autogenerated by pioasm; do not edit! //
|
||||||
|
// -------------------------------------------------- //
|
||||||
|
|
||||||
|
// Unless you know what you are doing...
|
||||||
|
// Lines 47 and 52 have been edited to set transmit bit count
|
||||||
|
|
||||||
|
#if !PICO_NO_HARDWARE
|
||||||
|
#include "hardware/pio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ------ //
|
||||||
|
// ws2812 //
|
||||||
|
// ------ //
|
||||||
|
|
||||||
|
#define ws2812_wrap_target 0
|
||||||
|
#define ws2812_wrap 3
|
||||||
|
|
||||||
|
#define ws2812_T1 2
|
||||||
|
#define ws2812_T2 5
|
||||||
|
#define ws2812_T3 3
|
||||||
|
|
||||||
|
static const uint16_t ws2812_program_instructions[] = {
|
||||||
|
// .wrap_target
|
||||||
|
0x6221, // 0: out x, 1 side 0 [2]
|
||||||
|
0x1123, // 1: jmp !x, 3 side 1 [1]
|
||||||
|
0x1400, // 2: jmp 0 side 1 [4]
|
||||||
|
0xa442, // 3: nop side 0 [4]
|
||||||
|
// .wrap
|
||||||
|
};
|
||||||
|
|
||||||
|
#if !PICO_NO_HARDWARE
|
||||||
|
static const struct pio_program ws2812_program = {
|
||||||
|
.instructions = ws2812_program_instructions,
|
||||||
|
.length = 4,
|
||||||
|
.origin = -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline pio_sm_config ws2812_program_get_default_config(uint offset) {
|
||||||
|
pio_sm_config c = pio_get_default_sm_config();
|
||||||
|
sm_config_set_wrap(&c, offset + ws2812_wrap_target, offset + ws2812_wrap);
|
||||||
|
sm_config_set_sideset(&c, 1, false, false);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "hardware/clocks.h"
|
||||||
|
static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin,
|
||||||
|
float freq, uint bits) {
|
||||||
|
pio_gpio_init(pio, pin);
|
||||||
|
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
|
||||||
|
pio_sm_config c = ws2812_program_get_default_config(offset);
|
||||||
|
sm_config_set_sideset_pins(&c, pin);
|
||||||
|
sm_config_set_out_shift(&c, false, true,
|
||||||
|
bits); // <----<<< Length changed to "bits"
|
||||||
|
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
|
||||||
|
int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3;
|
||||||
|
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
|
||||||
|
sm_config_set_clkdiv(&c, div);
|
||||||
|
pio_sm_init(pio, sm, offset, &c);
|
||||||
|
pio_sm_set_enabled(pio, sm, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -0,0 +1,117 @@
|
|||||||
|
#include "Adafruit_Sensor.h"
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Prints sensor information to serial console
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
void Adafruit_Sensor::printSensorDetails(void) {
|
||||||
|
sensor_t sensor;
|
||||||
|
getSensor(&sensor);
|
||||||
|
Serial.println(F("------------------------------------"));
|
||||||
|
Serial.print(F("Sensor: "));
|
||||||
|
Serial.println(sensor.name);
|
||||||
|
Serial.print(F("Type: "));
|
||||||
|
switch ((sensors_type_t)sensor.type) {
|
||||||
|
case SENSOR_TYPE_ACCELEROMETER:
|
||||||
|
Serial.print(F("Acceleration (m/s2)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_MAGNETIC_FIELD:
|
||||||
|
Serial.print(F("Magnetic (uT)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_ORIENTATION:
|
||||||
|
Serial.print(F("Orientation (degrees)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_GYROSCOPE:
|
||||||
|
Serial.print(F("Gyroscopic (rad/s)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_LIGHT:
|
||||||
|
Serial.print(F("Light (lux)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_PRESSURE:
|
||||||
|
Serial.print(F("Pressure (hPa)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_PROXIMITY:
|
||||||
|
Serial.print(F("Distance (cm)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_GRAVITY:
|
||||||
|
Serial.print(F("Gravity (m/s2)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_LINEAR_ACCELERATION:
|
||||||
|
Serial.print(F("Linear Acceleration (m/s2)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_ROTATION_VECTOR:
|
||||||
|
Serial.print(F("Rotation vector"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_RELATIVE_HUMIDITY:
|
||||||
|
Serial.print(F("Relative Humidity (%)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_AMBIENT_TEMPERATURE:
|
||||||
|
Serial.print(F("Ambient Temp (C)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_OBJECT_TEMPERATURE:
|
||||||
|
Serial.print(F("Object Temp (C)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_VOLTAGE:
|
||||||
|
Serial.print(F("Voltage (V)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_CURRENT:
|
||||||
|
Serial.print(F("Current (mA)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_COLOR:
|
||||||
|
Serial.print(F("Color (RGBA)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_TVOC:
|
||||||
|
Serial.print(F("Total Volatile Organic Compounds (ppb)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_VOC_INDEX:
|
||||||
|
Serial.print(F("Volatile Organic Compounds (Index)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_NOX_INDEX:
|
||||||
|
Serial.print(F("Nitrogen Oxides (Index)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_CO2:
|
||||||
|
Serial.print(F("Carbon Dioxide (ppm)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_ECO2:
|
||||||
|
Serial.print(F("Equivalent/estimated CO2 (ppm)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_PM10_STD:
|
||||||
|
Serial.print(F("Standard Particulate Matter 1.0 (ppm)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_PM25_STD:
|
||||||
|
Serial.print(F("Standard Particulate Matter 2.5 (ppm)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_PM100_STD:
|
||||||
|
Serial.print(F("Standard Particulate Matter 10.0 (ppm)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_PM10_ENV:
|
||||||
|
Serial.print(F("Environmental Particulate Matter 1.0 (ppm)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_PM25_ENV:
|
||||||
|
Serial.print(F("Environmental Particulate Matter 2.5 (ppm)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_PM100_ENV:
|
||||||
|
Serial.print(F("Environmental Particulate Matter 10.0 (ppm)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_GAS_RESISTANCE:
|
||||||
|
Serial.print(F("Gas Resistance (ohms)"));
|
||||||
|
break;
|
||||||
|
case SENSOR_TYPE_UNITLESS_PERCENT:
|
||||||
|
Serial.print(F("Unitless Percent (%)"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
Serial.print(F("Driver Ver: "));
|
||||||
|
Serial.println(sensor.version);
|
||||||
|
Serial.print(F("Unique ID: "));
|
||||||
|
Serial.println(sensor.sensor_id);
|
||||||
|
Serial.print(F("Min Value: "));
|
||||||
|
Serial.println(sensor.min_value);
|
||||||
|
Serial.print(F("Max Value: "));
|
||||||
|
Serial.println(sensor.max_value);
|
||||||
|
Serial.print(F("Resolution: "));
|
||||||
|
Serial.println(sensor.resolution);
|
||||||
|
Serial.println(F("------------------------------------\n"));
|
||||||
|
}
|
||||||
@ -0,0 +1,221 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software< /span>
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and
|
||||||
|
* extended sensor support to include color, voltage and current */
|
||||||
|
|
||||||
|
#ifndef _ADAFRUIT_SENSOR_H
|
||||||
|
#define _ADAFRUIT_SENSOR_H
|
||||||
|
|
||||||
|
#ifndef ARDUINO
|
||||||
|
#include <stdint.h>
|
||||||
|
#elif ARDUINO >= 100
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Print.h"
|
||||||
|
#else
|
||||||
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Constants */
|
||||||
|
#define SENSORS_GRAVITY_EARTH (9.80665F) /**< Earth's gravity in m/s^2 */
|
||||||
|
#define SENSORS_GRAVITY_MOON (1.6F) /**< The moon's gravity in m/s^2 */
|
||||||
|
#define SENSORS_GRAVITY_SUN (275.0F) /**< The sun's gravity in m/s^2 */
|
||||||
|
#define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH)
|
||||||
|
#define SENSORS_MAGFIELD_EARTH_MAX \
|
||||||
|
(60.0F) /**< Maximum magnetic field on Earth's surface */
|
||||||
|
#define SENSORS_MAGFIELD_EARTH_MIN \
|
||||||
|
(30.0F) /**< Minimum magnetic field on Earth's surface */
|
||||||
|
#define SENSORS_PRESSURE_SEALEVELHPA \
|
||||||
|
(1013.25F) /**< Average sea level pressure is 1013.25 hPa */
|
||||||
|
#define SENSORS_DPS_TO_RADS \
|
||||||
|
(0.017453293F) /**< Degrees/s to rad/s multiplier \
|
||||||
|
*/
|
||||||
|
#define SENSORS_RADS_TO_DPS \
|
||||||
|
(57.29577793F) /**< Rad/s to degrees/s multiplier */
|
||||||
|
#define SENSORS_GAUSS_TO_MICROTESLA \
|
||||||
|
(100) /**< Gauss to micro-Tesla multiplier */
|
||||||
|
|
||||||
|
/** Sensor types */
|
||||||
|
typedef enum {
|
||||||
|
SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */
|
||||||
|
SENSOR_TYPE_MAGNETIC_FIELD = (2),
|
||||||
|
SENSOR_TYPE_ORIENTATION = (3),
|
||||||
|
SENSOR_TYPE_GYROSCOPE = (4),
|
||||||
|
SENSOR_TYPE_LIGHT = (5),
|
||||||
|
SENSOR_TYPE_PRESSURE = (6),
|
||||||
|
SENSOR_TYPE_PROXIMITY = (8),
|
||||||
|
SENSOR_TYPE_GRAVITY = (9),
|
||||||
|
SENSOR_TYPE_LINEAR_ACCELERATION =
|
||||||
|
(10), /**< Acceleration not including gravity */
|
||||||
|
SENSOR_TYPE_ROTATION_VECTOR = (11),
|
||||||
|
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
|
||||||
|
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
|
||||||
|
SENSOR_TYPE_OBJECT_TEMPERATURE = (14),
|
||||||
|
SENSOR_TYPE_VOLTAGE = (15),
|
||||||
|
SENSOR_TYPE_CURRENT = (16),
|
||||||
|
SENSOR_TYPE_COLOR = (17),
|
||||||
|
SENSOR_TYPE_TVOC = (18),
|
||||||
|
SENSOR_TYPE_VOC_INDEX = (19),
|
||||||
|
SENSOR_TYPE_NOX_INDEX = (20),
|
||||||
|
SENSOR_TYPE_CO2 = (21),
|
||||||
|
SENSOR_TYPE_ECO2 = (22),
|
||||||
|
SENSOR_TYPE_PM10_STD = (23),
|
||||||
|
SENSOR_TYPE_PM25_STD = (24),
|
||||||
|
SENSOR_TYPE_PM100_STD = (25),
|
||||||
|
SENSOR_TYPE_PM10_ENV = (26),
|
||||||
|
SENSOR_TYPE_PM25_ENV = (27),
|
||||||
|
SENSOR_TYPE_PM100_ENV = (28),
|
||||||
|
SENSOR_TYPE_GAS_RESISTANCE = (29),
|
||||||
|
SENSOR_TYPE_UNITLESS_PERCENT = (30)
|
||||||
|
} sensors_type_t;
|
||||||
|
|
||||||
|
/** struct sensors_vec_s is used to return a vector in a common format. */
|
||||||
|
typedef struct {
|
||||||
|
union {
|
||||||
|
float v[3]; ///< 3D vector elements
|
||||||
|
struct {
|
||||||
|
float x; ///< X component of vector
|
||||||
|
float y; ///< Y component of vector
|
||||||
|
float z; ///< Z component of vector
|
||||||
|
}; ///< Struct for holding XYZ component
|
||||||
|
/* Orientation sensors */
|
||||||
|
struct {
|
||||||
|
float roll; /**< Rotation around the longitudinal axis (the plane body, 'X
|
||||||
|
axis'). Roll is positive and increasing when moving
|
||||||
|
downward. -90 degrees <= roll <= 90 degrees */
|
||||||
|
float pitch; /**< Rotation around the lateral axis (the wing span, 'Y
|
||||||
|
axis'). Pitch is positive and increasing when moving
|
||||||
|
upwards. -180 degrees <= pitch <= 180 degrees) */
|
||||||
|
float heading; /**< Angle between the longitudinal axis (the plane body)
|
||||||
|
and magnetic north, measured clockwise when viewing from
|
||||||
|
the top of the device. 0-359 degrees */
|
||||||
|
}; ///< Struct for holding roll/pitch/heading
|
||||||
|
}; ///< Union that can hold 3D vector array, XYZ components or
|
||||||
|
///< roll/pitch/heading
|
||||||
|
int8_t status; ///< Status byte
|
||||||
|
uint8_t reserved[3]; ///< Reserved
|
||||||
|
} sensors_vec_t;
|
||||||
|
|
||||||
|
/** struct sensors_color_s is used to return color data in a common format. */
|
||||||
|
typedef struct {
|
||||||
|
union {
|
||||||
|
float c[3]; ///< Raw 3-element data
|
||||||
|
/* RGB color space */
|
||||||
|
struct {
|
||||||
|
float r; /**< Red component */
|
||||||
|
float g; /**< Green component */
|
||||||
|
float b; /**< Blue component */
|
||||||
|
}; ///< RGB data in floating point notation
|
||||||
|
}; ///< Union of various ways to describe RGB colorspace
|
||||||
|
uint32_t rgba; /**< 24-bit RGBA value */
|
||||||
|
} sensors_color_t;
|
||||||
|
|
||||||
|
/* Sensor event (36 bytes) */
|
||||||
|
/** struct sensor_event_s is used to provide a single sensor event in a common
|
||||||
|
* format. */
|
||||||
|
typedef struct {
|
||||||
|
int32_t version; /**< must be sizeof(struct sensors_event_t) */
|
||||||
|
int32_t sensor_id; /**< unique sensor identifier */
|
||||||
|
int32_t type; /**< sensor type */
|
||||||
|
int32_t reserved0; /**< reserved */
|
||||||
|
int32_t timestamp; /**< time is in milliseconds */
|
||||||
|
union {
|
||||||
|
float data[4]; ///< Raw data */
|
||||||
|
sensors_vec_t acceleration; /**< acceleration values are in meter per second
|
||||||
|
per second (m/s^2) */
|
||||||
|
sensors_vec_t
|
||||||
|
magnetic; /**< magnetic vector values are in micro-Tesla (uT) */
|
||||||
|
sensors_vec_t orientation; /**< orientation values are in degrees */
|
||||||
|
sensors_vec_t gyro; /**< gyroscope values are in rad/s */
|
||||||
|
float temperature; /**< temperature is in degrees centigrade (Celsius) */
|
||||||
|
float distance; /**< distance in centimeters */
|
||||||
|
float light; /**< light in SI lux units */
|
||||||
|
float pressure; /**< pressure in hectopascal (hPa) */
|
||||||
|
float relative_humidity; /**< relative humidity in percent */
|
||||||
|
float current; /**< current in milliamps (mA) */
|
||||||
|
float voltage; /**< voltage in volts (V) */
|
||||||
|
float tvoc; /**< Total Volatile Organic Compounds, in ppb */
|
||||||
|
float voc_index; /**< VOC (Volatile Organic Compound) index where 100 is
|
||||||
|
normal (unitless) */
|
||||||
|
float nox_index; /**< NOx (Nitrogen Oxides) index where 100 is normal
|
||||||
|
(unitless) */
|
||||||
|
float CO2; /**< Measured CO2 in parts per million (ppm) */
|
||||||
|
float eCO2; /**< equivalent/estimated CO2 in parts per million (ppm
|
||||||
|
estimated from some other measurement) */
|
||||||
|
float pm10_std; /**< Standard Particulate Matter <=1.0 in parts per million
|
||||||
|
(ppm) */
|
||||||
|
float pm25_std; /**< Standard Particulate Matter <=2.5 in parts per million
|
||||||
|
(ppm) */
|
||||||
|
float pm100_std; /**< Standard Particulate Matter <=10.0 in parts per
|
||||||
|
million (ppm) */
|
||||||
|
float pm10_env; /**< Environmental Particulate Matter <=1.0 in parts per
|
||||||
|
million (ppm) */
|
||||||
|
float pm25_env; /**< Environmental Particulate Matter <=2.5 in parts per
|
||||||
|
million (ppm) */
|
||||||
|
float pm100_env; /**< Environmental Particulate Matter <=10.0 in parts per
|
||||||
|
million (ppm) */
|
||||||
|
float gas_resistance; /**< Proportional to the amount of VOC particles in
|
||||||
|
the air (Ohms) */
|
||||||
|
float unitless_percent; /**<Percentage, unit-less (%) */
|
||||||
|
sensors_color_t color; /**< color in RGB component values */
|
||||||
|
}; ///< Union for the wide ranges of data we can carry
|
||||||
|
} sensors_event_t;
|
||||||
|
|
||||||
|
/* Sensor details (40 bytes) */
|
||||||
|
/** struct sensor_s is used to describe basic information about a specific
|
||||||
|
* sensor. */
|
||||||
|
typedef struct {
|
||||||
|
char name[12]; /**< sensor name */
|
||||||
|
int32_t version; /**< version of the hardware + driver */
|
||||||
|
int32_t sensor_id; /**< unique sensor identifier */
|
||||||
|
int32_t type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */
|
||||||
|
float max_value; /**< maximum value of this sensor's value in SI units */
|
||||||
|
float min_value; /**< minimum value of this sensor's value in SI units */
|
||||||
|
float resolution; /**< smallest difference between two values reported by this
|
||||||
|
sensor */
|
||||||
|
int32_t min_delay; /**< min delay in microseconds between events. zero = not a
|
||||||
|
constant rate */
|
||||||
|
} sensor_t;
|
||||||
|
|
||||||
|
/** @brief Common sensor interface to unify various sensors.
|
||||||
|
* Intentionally modeled after sensors.h in the Android API:
|
||||||
|
* https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h
|
||||||
|
*/
|
||||||
|
class Adafruit_Sensor {
|
||||||
|
public:
|
||||||
|
// Constructor(s)
|
||||||
|
Adafruit_Sensor() {}
|
||||||
|
virtual ~Adafruit_Sensor() {}
|
||||||
|
|
||||||
|
// These must be defined by the subclass
|
||||||
|
|
||||||
|
/*! @brief Whether we should automatically change the range (if possible) for
|
||||||
|
higher precision
|
||||||
|
@param enabled True if we will try to autorange */
|
||||||
|
virtual void enableAutoRange(bool enabled) {
|
||||||
|
(void)enabled; /* suppress unused warning */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*! @brief Get the latest sensor event
|
||||||
|
@returns True if able to fetch an event */
|
||||||
|
virtual bool getEvent(sensors_event_t *) = 0;
|
||||||
|
/*! @brief Get info about the sensor itself */
|
||||||
|
virtual void getSensor(sensor_t *) = 0;
|
||||||
|
|
||||||
|
void printSensorDetails(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@ -0,0 +1,268 @@
|
|||||||
|
# Adafruit Unified Sensor Driver #
|
||||||
|
|
||||||
|
Many small embedded systems exist to collect data from sensors, analyse the data, and either take an appropriate action or send that sensor data to another system for processing.
|
||||||
|
|
||||||
|
One of the many challenges of embedded systems design is the fact that parts you used today may be out of production tomorrow, or system requirements may change and you may need to choose a different sensor down the road.
|
||||||
|
|
||||||
|
Creating new drivers is a relatively easy task, but integrating them into existing systems is both error prone and time consuming since sensors rarely use the exact same units of measurement.
|
||||||
|
|
||||||
|
By reducing all data to a single **sensors\_event\_t** 'type' and settling on specific, **standardised SI units** for each sensor family the same sensor types return values that are comparable with any other similar sensor. This enables you to switch sensor models with very little impact on the rest of the system, which can help mitigate some of the risks and problems of sensor availability and code reuse.
|
||||||
|
|
||||||
|
The unified sensor abstraction layer is also useful for data-logging and data-transmission since you only have one well-known type to log or transmit over the air or wire.
|
||||||
|
|
||||||
|
## Unified Sensor Drivers ##
|
||||||
|
|
||||||
|
The following drivers are based on the Adafruit Unified Sensor Driver:
|
||||||
|
|
||||||
|
**Accelerometers**
|
||||||
|
- [Adafruit\_ADXL345](https://github.com/adafruit/Adafruit_ADXL345)
|
||||||
|
- [Adafruit\_LSM303DLHC](https://github.com/adafruit/Adafruit_LSM303DLHC)
|
||||||
|
- [Adafruit\_MMA8451\_Library](https://github.com/adafruit/Adafruit_MMA8451_Library)
|
||||||
|
|
||||||
|
**Gyroscope**
|
||||||
|
- [Adafruit\_L3GD20\_U](https://github.com/adafruit/Adafruit_L3GD20_U)
|
||||||
|
|
||||||
|
**Light**
|
||||||
|
- [Adafruit\_TSL2561](https://github.com/adafruit/Adafruit_TSL2561)
|
||||||
|
- [Adafruit\_TSL2591\_Library](https://github.com/adafruit/Adafruit_TSL2591_Library)
|
||||||
|
|
||||||
|
**Magnetometers**
|
||||||
|
- [Adafruit\_LSM303DLHC](https://github.com/adafruit/Adafruit_LSM303DLHC)
|
||||||
|
- [Adafruit\_HMC5883\_Unified](https://github.com/adafruit/Adafruit_HMC5883_Unified)
|
||||||
|
|
||||||
|
**Barometric Pressure**
|
||||||
|
- [Adafruit\_BMP085\_Unified](https://github.com/adafruit/Adafruit_BMP085_Unified)
|
||||||
|
- [Adafruit\_BMP183\_Unified\_Library](https://github.com/adafruit/Adafruit_BMP183_Unified_Library)
|
||||||
|
|
||||||
|
**Humidity & Temperature**
|
||||||
|
- [DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library)
|
||||||
|
|
||||||
|
**Humidity, Temperature, & Barometric Pressure**
|
||||||
|
- [Adafruit_BME280_Library](https://github.com/adafruit/Adafruit_BME280_Library/)
|
||||||
|
|
||||||
|
**Orientation**
|
||||||
|
- [Adafruit_BNO055](https://github.com/adafruit/Adafruit_BNO055)
|
||||||
|
|
||||||
|
**All in one device**
|
||||||
|
- [Adafruit_LSM9DS0](https://github.com/adafruit/Adafruit_LSM9DS0_Library) (accelerometer, gyroscope, magnetometer)
|
||||||
|
- [Adafruit_LSM9DS1](https://github.com/adafruit/Adafruit_LSM9DS1/) (accelerometer, gyroscope, magnetometer)
|
||||||
|
|
||||||
|
|
||||||
|
## How Does it Work? ##
|
||||||
|
|
||||||
|
Any driver that supports the Adafruit unified sensor abstraction layer will implement the Adafruit\_Sensor base class. There are two main typedefs and one enum defined in Adafruit_Sensor.h that are used to 'abstract' away the sensor details and values:
|
||||||
|
|
||||||
|
## Sensor Types (`sensors_type_t`)
|
||||||
|
|
||||||
|
These pre-defined sensor types are used to properly handle the two related typedefs below, and allows us determine what types of units the sensor uses, etc.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
/** Sensor types */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SENSOR_TYPE_ACCELEROMETER = (1),
|
||||||
|
SENSOR_TYPE_MAGNETIC_FIELD = (2),
|
||||||
|
SENSOR_TYPE_ORIENTATION = (3),
|
||||||
|
SENSOR_TYPE_GYROSCOPE = (4),
|
||||||
|
SENSOR_TYPE_LIGHT = (5),
|
||||||
|
SENSOR_TYPE_PRESSURE = (6),
|
||||||
|
SENSOR_TYPE_PROXIMITY = (8),
|
||||||
|
SENSOR_TYPE_GRAVITY = (9),
|
||||||
|
SENSOR_TYPE_LINEAR_ACCELERATION = (10),
|
||||||
|
SENSOR_TYPE_ROTATION_VECTOR = (11),
|
||||||
|
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
|
||||||
|
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
|
||||||
|
SENSOR_TYPE_VOLTAGE = (15),
|
||||||
|
SENSOR_TYPE_CURRENT = (16),
|
||||||
|
SENSOR_TYPE_COLOR = (17),
|
||||||
|
SENSOR_TYPE_TVOC = (18),
|
||||||
|
SENSOR_TYPE_VOC_INDEX = (19),
|
||||||
|
SENSOR_TYPE_NOX_INDEX = (20),
|
||||||
|
SENSOR_TYPE_CO2 = (21),
|
||||||
|
SENSOR_TYPE_ECO2 = (22),
|
||||||
|
SENSOR_TYPE_PM10_STD = (23),
|
||||||
|
SENSOR_TYPE_PM25_STD = (24),
|
||||||
|
SENSOR_TYPE_PM100_STD = (25),
|
||||||
|
SENSOR_TYPE_PM10_ENV = (26),
|
||||||
|
SENSOR_TYPE_PM25_ENV = (27),
|
||||||
|
SENSOR_TYPE_PM100_ENV = (28),
|
||||||
|
SENSOR_TYPE_GAS_RESISTANCE = (29),
|
||||||
|
SENSOR_TYPE_UNITLESS_PERCENT = (30)
|
||||||
|
} sensors_type_t;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sensor Details (`sensor_t`)
|
||||||
|
|
||||||
|
This typedef describes the specific capabilities of this sensor, and allows us to know what sensor we are using beneath the abstraction layer.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
/* Sensor details (40 bytes) */
|
||||||
|
/** struct sensor_s is used to describe basic information about a specific sensor. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char name[12];
|
||||||
|
int32_t version;
|
||||||
|
int32_t sensor_id;
|
||||||
|
int32_t type;
|
||||||
|
float max_value;
|
||||||
|
float min_value;
|
||||||
|
float resolution;
|
||||||
|
int32_t min_delay;
|
||||||
|
} sensor_t;
|
||||||
|
```
|
||||||
|
|
||||||
|
The individual fields are intended to be used as follows:
|
||||||
|
|
||||||
|
- **name**: The sensor name or ID, up to a maximum of twelve characters (ex. "MPL115A2")
|
||||||
|
- **version**: The version of the sensor HW and the driver to allow us to differentiate versions of the board or driver
|
||||||
|
- **sensor\_id**: A unique sensor identifier that is used to differentiate this specific sensor instance from any others that are present on the system or in the sensor network
|
||||||
|
- **type**: The sensor type, based on **sensors\_type\_t** in sensors.h
|
||||||
|
- **max\_value**: The maximum value that this sensor can return (in the appropriate SI unit)
|
||||||
|
- **min\_value**: The minimum value that this sensor can return (in the appropriate SI unit)
|
||||||
|
- **resolution**: The smallest difference between two values that this sensor can report (in the appropriate SI unit)
|
||||||
|
- **min\_delay**: The minimum delay in microseconds between two sensor events, or '0' if there is no constant sensor rate
|
||||||
|
|
||||||
|
## Sensor Data/Events (`sensors_event_t`)
|
||||||
|
|
||||||
|
This typedef is used to return sensor data from any sensor supported by the abstraction layer, using standard SI units and scales.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
/* Sensor event (36 bytes) */
|
||||||
|
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int32_t version;
|
||||||
|
int32_t sensor_id;
|
||||||
|
int32_t type;
|
||||||
|
int32_t reserved0;
|
||||||
|
int32_t timestamp;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
float data[4];
|
||||||
|
sensors_vec_t acceleration;
|
||||||
|
sensors_vec_t magnetic;
|
||||||
|
sensors_vec_t orientation;
|
||||||
|
sensors_vec_t gyro;
|
||||||
|
float temperature;
|
||||||
|
float distance;
|
||||||
|
float light;
|
||||||
|
float pressure;
|
||||||
|
float relative_humidity;
|
||||||
|
float current;
|
||||||
|
float voltage;
|
||||||
|
float tvoc;
|
||||||
|
float voc_index;
|
||||||
|
float nox_index;
|
||||||
|
float CO2,
|
||||||
|
float eCO2,
|
||||||
|
float pm10_std,
|
||||||
|
float pm25_std,
|
||||||
|
float pm100_std,
|
||||||
|
float pm10_env,
|
||||||
|
float pm25_env,
|
||||||
|
float pm100_env,
|
||||||
|
float gas_resistance,
|
||||||
|
float unitless_percent,
|
||||||
|
sensors_color_t color;
|
||||||
|
};
|
||||||
|
} sensors_event_t;
|
||||||
|
```
|
||||||
|
It includes the following fields:
|
||||||
|
|
||||||
|
- **version**: Contain 'sizeof(sensors\_event\_t)' to identify which version of the API we're using in case this changes in the future
|
||||||
|
- **sensor\_id**: A unique sensor identifier that is used to differentiate this specific sensor instance from any others that are present on the system or in the sensor network (must match the sensor\_id value in the corresponding sensor\_t enum above!)
|
||||||
|
- **type**: the sensor type, based on **sensors\_type\_t** in sensors.h
|
||||||
|
- **timestamp**: time in milliseconds when the sensor value was read
|
||||||
|
- **data[4]**: An array of four 32-bit values that allows us to encapsulate any type of sensor data via a simple union (further described below)
|
||||||
|
|
||||||
|
## Required Functions
|
||||||
|
|
||||||
|
In addition to the two standard types and the sensor type enum, all drivers based on Adafruit_Sensor must also implement the following two functions:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
bool getEvent(sensors_event_t*);
|
||||||
|
```
|
||||||
|
Calling this function will populate the supplied sensors\_event\_t reference with the latest available sensor data. You should call this function as often as you want to update your data.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
void getSensor(sensor_t*);
|
||||||
|
```
|
||||||
|
Calling this function will provide some basic information about the sensor (the sensor name, driver version, min and max values, etc.
|
||||||
|
|
||||||
|
## Standardised SI values for `sensors_event_t`
|
||||||
|
|
||||||
|
A key part of the abstraction layer is the standardization of values on SI units of a particular scale, which is accomplished via the data[4] union in sensors\_event\_t above. This 16 byte union includes fields for each main sensor type, and uses the following SI units and scales:
|
||||||
|
|
||||||
|
- **acceleration**: values are in **meter per second per second** (m/s^2)
|
||||||
|
- **magnetic**: values are in **micro-Tesla** (uT)
|
||||||
|
- **orientation**: values are in **degrees**
|
||||||
|
- **gyro**: values are in **rad/s**
|
||||||
|
- **temperature**: values in **degrees centigrade** (Celsius)
|
||||||
|
- **distance**: values are in **centimeters**
|
||||||
|
- **light**: values are in **SI lux** units
|
||||||
|
- **pressure**: values are in **hectopascal** (hPa)
|
||||||
|
- **relative\_humidity**: values are in **percent**
|
||||||
|
- **current**: values are in **milliamps** (mA)
|
||||||
|
- **voltage**: values are in **volts** (V)
|
||||||
|
- **color**: values are in 0..1.0 RGB channel luminosity and 32-bit RGBA format
|
||||||
|
- **tvoc**: values are in **parts per billion** (ppb)
|
||||||
|
- **voc_index**: values are an **index** from 1-500 with 100 being normal
|
||||||
|
- **nox_index**: values are an **index** from 1-500 with 100 being normal
|
||||||
|
- **CO2**: values are in **parts per million** (ppm)
|
||||||
|
- **eCO2**: values are in **parts per million** (ppm)
|
||||||
|
- **pm10_std**: values are in **parts per million** (ppm)
|
||||||
|
- **pm25_std**: values are in **parts per million** (ppm)
|
||||||
|
- **pm100_std**: values are in **parts per million** (ppm)
|
||||||
|
- **pm10_env**: values are in **parts per million** (ppm)
|
||||||
|
- **pm25_env**: values are in **parts per million** (ppm)
|
||||||
|
- **pm100_env**: values are in **parts per million** (ppm)
|
||||||
|
- **gas_resistance**: values are in **ohms**
|
||||||
|
- **unitless_percent**: values are in **%**
|
||||||
|
|
||||||
|
## The Unified Driver Abstraction Layer in Practice ##
|
||||||
|
|
||||||
|
Using the unified sensor abstraction layer is relatively easy once a compliant driver has been created.
|
||||||
|
|
||||||
|
Every compliant sensor can now be read using a single, well-known 'type' (sensors\_event\_t), and there is a standardized way of interrogating a sensor about its specific capabilities (via sensor\_t).
|
||||||
|
|
||||||
|
An example of reading the [TSL2561](https://github.com/adafruit/Adafruit_TSL2561) light sensor can be seen below:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
Adafruit_TSL2561 tsl = Adafruit_TSL2561(TSL2561_ADDR_FLOAT, 12345);
|
||||||
|
...
|
||||||
|
/* Get a new sensor event */
|
||||||
|
sensors_event_t event;
|
||||||
|
tsl.getEvent(&event);
|
||||||
|
|
||||||
|
/* Display the results (light is measured in lux) */
|
||||||
|
if (event.light)
|
||||||
|
{
|
||||||
|
Serial.print(event.light); Serial.println(" lux");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* If event.light = 0 lux the sensor is probably saturated
|
||||||
|
and no reliable data could be generated! */
|
||||||
|
Serial.println("Sensor overload");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Similarly, we can get the basic technical capabilities of this sensor with the following code:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
sensor_t sensor;
|
||||||
|
|
||||||
|
sensor_t sensor;
|
||||||
|
tsl.getSensor(&sensor);
|
||||||
|
|
||||||
|
/* Display the sensor details */
|
||||||
|
Serial.println("------------------------------------");
|
||||||
|
Serial.print ("Sensor: "); Serial.println(sensor.name);
|
||||||
|
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
|
||||||
|
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
|
||||||
|
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux");
|
||||||
|
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux");
|
||||||
|
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux");
|
||||||
|
Serial.println("------------------------------------");
|
||||||
|
Serial.println("");
|
||||||
|
```
|
||||||
@ -0,0 +1,153 @@
|
|||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_Sensor.h>
|
||||||
|
#include <Adafruit_ADXL343.h>
|
||||||
|
|
||||||
|
/* Assign a unique ID to this sensor at the same time */
|
||||||
|
/* Uncomment following line for default Wire bus */
|
||||||
|
Adafruit_ADXL343 accel = Adafruit_ADXL343(12345);
|
||||||
|
|
||||||
|
/* NeoTrellis M4, etc. */
|
||||||
|
/* Uncomment following line for Wire1 bus */
|
||||||
|
//Adafruit_ADXL343 accel = Adafruit_ADXL343(12345, &Wire1);
|
||||||
|
|
||||||
|
void displaySensorDetails(void)
|
||||||
|
{
|
||||||
|
sensor_t sensor;
|
||||||
|
accel.getSensor(&sensor);
|
||||||
|
Serial.println("------------------------------------");
|
||||||
|
Serial.print ("Sensor: "); Serial.println(sensor.name);
|
||||||
|
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
|
||||||
|
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
|
||||||
|
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
|
||||||
|
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
|
||||||
|
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" m/s^2");
|
||||||
|
Serial.println("------------------------------------");
|
||||||
|
Serial.println("");
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayDataRate(void)
|
||||||
|
{
|
||||||
|
Serial.print ("Data Rate: ");
|
||||||
|
|
||||||
|
switch(accel.getDataRate())
|
||||||
|
{
|
||||||
|
case ADXL343_DATARATE_3200_HZ:
|
||||||
|
Serial.print ("3200 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_1600_HZ:
|
||||||
|
Serial.print ("1600 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_800_HZ:
|
||||||
|
Serial.print ("800 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_400_HZ:
|
||||||
|
Serial.print ("400 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_200_HZ:
|
||||||
|
Serial.print ("200 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_100_HZ:
|
||||||
|
Serial.print ("100 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_50_HZ:
|
||||||
|
Serial.print ("50 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_25_HZ:
|
||||||
|
Serial.print ("25 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_12_5_HZ:
|
||||||
|
Serial.print ("12.5 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_6_25HZ:
|
||||||
|
Serial.print ("6.25 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_3_13_HZ:
|
||||||
|
Serial.print ("3.13 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_1_56_HZ:
|
||||||
|
Serial.print ("1.56 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_0_78_HZ:
|
||||||
|
Serial.print ("0.78 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_0_39_HZ:
|
||||||
|
Serial.print ("0.39 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_0_20_HZ:
|
||||||
|
Serial.print ("0.20 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_DATARATE_0_10_HZ:
|
||||||
|
Serial.print ("0.10 ");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Serial.print ("???? ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Serial.println(" Hz");
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayRange(void)
|
||||||
|
{
|
||||||
|
Serial.print ("Range: +/- ");
|
||||||
|
|
||||||
|
switch(accel.getRange())
|
||||||
|
{
|
||||||
|
case ADXL343_RANGE_16_G:
|
||||||
|
Serial.print ("16 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_RANGE_8_G:
|
||||||
|
Serial.print ("8 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_RANGE_4_G:
|
||||||
|
Serial.print ("4 ");
|
||||||
|
break;
|
||||||
|
case ADXL343_RANGE_2_G:
|
||||||
|
Serial.print ("2 ");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Serial.print ("?? ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Serial.println(" g");
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(void)
|
||||||
|
{
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial);
|
||||||
|
Serial.println("Accelerometer Test"); Serial.println("");
|
||||||
|
|
||||||
|
/* Initialise the sensor */
|
||||||
|
if(!accel.begin())
|
||||||
|
{
|
||||||
|
/* There was a problem detecting the ADXL343 ... check your connections */
|
||||||
|
Serial.println("Ooops, no ADXL343 detected ... Check your wiring!");
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the range to whatever is appropriate for your project */
|
||||||
|
accel.setRange(ADXL343_RANGE_16_G);
|
||||||
|
// accel.setRange(ADXL343_RANGE_8_G);
|
||||||
|
// accel.setRange(ADXL343_RANGE_4_G);
|
||||||
|
// accel.setRange(ADXL343_RANGE_2_G);
|
||||||
|
|
||||||
|
/* Display some basic information on this sensor */
|
||||||
|
displaySensorDetails();
|
||||||
|
displayDataRate();
|
||||||
|
displayRange();
|
||||||
|
Serial.println("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(void)
|
||||||
|
{
|
||||||
|
/* Get a new sensor event */
|
||||||
|
sensors_event_t event;
|
||||||
|
accel.getEvent(&event);
|
||||||
|
|
||||||
|
/* Display the results (acceleration is measured in m/s^2) */
|
||||||
|
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
|
||||||
|
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
|
||||||
|
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");Serial.println("m/s^2 ");
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
name=Adafruit Unified Sensor
|
||||||
|
version=1.1.11
|
||||||
|
author=Adafruit <info@adafruit.com>
|
||||||
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
|
sentence=Required for all Adafruit Unified Sensor based libraries.
|
||||||
|
paragraph=A unified sensor abstraction layer used by many Adafruit sensor libraries.
|
||||||
|
category=Sensors
|
||||||
|
url=https://github.com/adafruit/Adafruit_Sensor
|
||||||
|
architectures=*
|
||||||
|
includes=Adafruit_Sensor.h
|
||||||
|
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#include "src/ArduinoJson.h"
|
||||||
854
ESP_Medicine_Indicator/libraries/ArduinoJson/CHANGELOG.md
Normal file
854
ESP_Medicine_Indicator/libraries/ArduinoJson/CHANGELOG.md
Normal file
@ -0,0 +1,854 @@
|
|||||||
|
ArduinoJson: change log
|
||||||
|
=======================
|
||||||
|
|
||||||
|
v6.21.3 (2023-07-23)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fix compatibility with the Blynk libary (issue #1914)
|
||||||
|
* Fix double lookup in `to<JsonVariant>()`
|
||||||
|
* Fix double call to `size()` in `serializeMsgPack()`
|
||||||
|
* Include `ARDUINOJSON_SLOT_OFFSET_SIZE` in the namespace name
|
||||||
|
* Show a link to the documentation when user passes an unsupported input type
|
||||||
|
|
||||||
|
v6.21.2 (2023-04-12)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fix compatibility with the Zephyr Project (issue #1905)
|
||||||
|
* Allow using PROGMEM outside of Arduino (issue #1903)
|
||||||
|
* Set default for `ARDUINOJSON_ENABLE_PROGMEM` to `1` on AVR
|
||||||
|
|
||||||
|
v6.21.1 (2023-03-27)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Double speed of `DynamicJsonDocument::garbageCollect()`
|
||||||
|
* Fix compatibility with GCC 5.2 (issue #1897)
|
||||||
|
|
||||||
|
v6.21.0 (2023-03-14)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Drop support for C++98/C++03. Minimum required is C++11.
|
||||||
|
* Remove `ARDUINOJSON_NAMESPACE`; use `ArduinoJson` instead.
|
||||||
|
* Make string support generic (issue #1807)
|
||||||
|
|
||||||
|
v6.20.1 (2023-02-08)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Remove explicit exclusion of `as<char*>()` and `as<char>()` (issue #1860)
|
||||||
|
If you try to call them, you'll now get the same error message as any unsupported type.
|
||||||
|
You could also add a custom converter for `char*` and `char`.
|
||||||
|
|
||||||
|
v6.20.0 (2022-12-26)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Add `JsonVariant::shallowCopy()` (issue #1343)
|
||||||
|
* Fix `9.22337e+18 is outside the range of representable values of type 'long'`
|
||||||
|
* Fix comparison operators for `JsonArray`, `JsonArrayConst`, `JsonObject`, and `JsonObjectConst`
|
||||||
|
* Fix lax parsing of `true`, `false`, and `null` (issue #1781)
|
||||||
|
* Remove undocumented `accept()` functions
|
||||||
|
* Rename `addElement()` to `add()`
|
||||||
|
* Remove `getElement()`, `getOrAddElement()`, `getMember()`, and `getOrAddMember()`
|
||||||
|
* Remove undocumented `JsonDocument::data()` and `JsonDocument::memoryPool()`
|
||||||
|
* Remove undocumented `JsonArrayIterator::internal()` and `JsonObjectIterator::internal()`
|
||||||
|
* Rename things in `ARDUINOJSON_NAMESPACE` to match the public names
|
||||||
|
* Add documentation to most public symbols
|
||||||
|
* Remove support for naked `char` (was deprecated since 6.18.0)
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> This release hides `JsonVariant`'s functions that were only intended for internal use.
|
||||||
|
> If you were using them in your programs, you must replace with `operator[]` and `to<JsonVariant>()`, like so:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> // before
|
||||||
|
> JsonVariant a = variant.getElement(idx);
|
||||||
|
> JsonVariant b = variant.getOrAddElement(idx);
|
||||||
|
> JsonVariant c = variant.getMember(key);
|
||||||
|
> JsonVariant d = variant.getOrAddMember(key);
|
||||||
|
>
|
||||||
|
> // after
|
||||||
|
> JsonVariant a = variant[idx];
|
||||||
|
> JsonVariant b = idx < variant.size() ? variant[idx] : variant[idx].to<JsonVariant>();
|
||||||
|
> JsonVariant c = variant[key];
|
||||||
|
> JsonVariant d = variant.containsKey(key) ? variant[key] : variant[key].to<JsonVariant>();
|
||||||
|
> ```
|
||||||
|
|
||||||
|
v6.19.4 (2022-04-05)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Add `ElementProxy::memoryUsage()`
|
||||||
|
* Add `MemberProxy::memoryUsage()` (issue #1730)
|
||||||
|
* Add implicit conversion from `JsonDocument` to `JsonVariant`
|
||||||
|
* Fix comparisons operators with `const JsonDocument&`
|
||||||
|
|
||||||
|
v6.19.3 (2022-03-08)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fix `call of overloaded 'String(const char*, int)' is ambiguous`
|
||||||
|
* Fix `JsonString` operator `==` and `!=` for non-zero-terminated string
|
||||||
|
* Fix `-Wsign-conversion` on GCC 8 (issue #1715)
|
||||||
|
* MessagePack: serialize round floats as integers (issue #1718)
|
||||||
|
|
||||||
|
v6.19.2 (2022-02-14)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fix `cannot convert 'pgm_p' to 'const void*'` (issue #1707)
|
||||||
|
|
||||||
|
v6.19.1 (2022-01-14)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fix crash when adding an object member in a too small `JsonDocument`
|
||||||
|
* Fix filter not working in zero-copy mode (issue #1697)
|
||||||
|
|
||||||
|
v6.19.0 (2022-01-08)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Remove `ARDUINOJSON_EMBEDDED_MODE` and assume we run on an embedded platform.
|
||||||
|
Dependent settings (like `ARDUINOJSON_DEFAULT_NESTING_LIMIT`) must be set individually.
|
||||||
|
* Change the default of `ARDUINOJSON_USE_DOUBLE` to `1`
|
||||||
|
* Change the default of `ARDUINOJSON_USE_LONG_LONG` to `1` on 32-bit platforms
|
||||||
|
* Add `as<JsonString>()` and `is<JsonString>()`
|
||||||
|
* Add safe bool idiom in `JsonString`
|
||||||
|
* Add support for NUL in string values (issue #1646)
|
||||||
|
* Add support for arbitrary array rank in `copyArray()`
|
||||||
|
* Add support for `char[][]` in `copyArray()`
|
||||||
|
* Remove `DeserializationError == bool` and `DeserializationError != bool`
|
||||||
|
* Renamed undocumented function `isUndefined()` to `isUnbound()`
|
||||||
|
* Fix `JsonVariant::memoryUsage()` for raw strings
|
||||||
|
* Fix `call of overloaded 'swap(BasicJsonDocument&, BasicJsonDocument&)' is ambiguous` (issue #1678)
|
||||||
|
* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move constructors
|
||||||
|
* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move assignments
|
||||||
|
* Fix return type of `StaticJsonDocument::operator=`
|
||||||
|
* Avoid pool reallocation in `BasicJsonDocument`'s copy assignment if capacity is the same
|
||||||
|
* Avoid including `Arduino.h` when all its features are disabled (issue #1692, PR #1693 by @paulocsanz)
|
||||||
|
* Assume `PROGMEM` is available as soon as `ARDUINO` is defined (consequence of #1693)
|
||||||
|
|
||||||
|
v6.18.5 (2021-09-28)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Set `ARDUINOJSON_EMBEDDED_MODE` to `1` on Nios II (issue #1657)
|
||||||
|
|
||||||
|
v6.18.4 (2021-09-06)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed error `'dummy' may be used uninitialized` on GCC 11
|
||||||
|
* Fixed error `expected unqualified-id before 'const'` on GCC 11 (issue #1622)
|
||||||
|
* Filter: exact match takes precedence over wildcard (issue #1628)
|
||||||
|
* Fixed deserialization of `\u0000` (issue #1646)
|
||||||
|
|
||||||
|
v6.18.3 (2021-07-27)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Changed return type of `convertToJson()` and `Converter<T>::toJson()` to `void`
|
||||||
|
* Added `as<std::string_view>()` and `is<std::string_view>()`
|
||||||
|
|
||||||
|
v6.18.2 (2021-07-19)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Removed a symlink because the Arduino Library Specification forbids it
|
||||||
|
|
||||||
|
v6.18.1 (2021-07-03)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed support for `volatile float` and `volatile double` (issue #1557)
|
||||||
|
* Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560)
|
||||||
|
* Fixed `serializeJson(doc, String)` when allocation fails (issue #1572)
|
||||||
|
* Fixed clang-tidy warnings (issue #1574, PR #1577 by @armandas)
|
||||||
|
* Added fake class `InvalidConversion<T1,T2>` to easily identify invalid conversions (issue #1585)
|
||||||
|
* Added support for `std::string_view` (issue #1578, PR #1554 by @0xFEEDC0DE64)
|
||||||
|
* Fixed warning `definition of implicit copy constructor for 'MsgPackDeserializer' is deprecated because it has a user-declared copy assignment operator`
|
||||||
|
* Added `JsonArray::clear()` (issue #1597)
|
||||||
|
* Fixed `JsonVariant::as<unsigned>()` (issue #1601)
|
||||||
|
* Added support for ESP-IDF component build (PR #1562 by @qt1, PR #1599 by @andreaskuster)
|
||||||
|
|
||||||
|
v6.18.0 (2021-05-05)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Added support for custom converters (issue #687)
|
||||||
|
* Added support for `Printable` (issue #1444)
|
||||||
|
* Removed support for `char` values, see below (issue #1498)
|
||||||
|
* `deserializeJson()` leaves `\uXXXX` unchanged instead of returning `NotSupported`
|
||||||
|
* `deserializeMsgPack()` inserts `null` instead of returning `NotSupported`
|
||||||
|
* Removed `DeserializationError::NotSupported`
|
||||||
|
* Added `JsonVariant::is<JsonArrayConst/JsonObjectConst>()` (issue #1412)
|
||||||
|
* Added `JsonVariant::is<JsonVariant/JsonVariantConst>()` (issue #1412)
|
||||||
|
* Changed `JsonVariantConst::is<JsonArray/JsonObject>()` to return `false` (issue #1412)
|
||||||
|
* Simplified `JsonVariant::as<T>()` to always return `T` (see below)
|
||||||
|
* Updated folders list in `.mbedignore` (PR #1515 by @AGlass0fMilk)
|
||||||
|
* Fixed member-call-on-null-pointer in `getMember()` when array is empty
|
||||||
|
* `serializeMsgPack(doc, buffer, size)` doesn't add null-terminator anymore (issue #1545)
|
||||||
|
* `serializeJson(doc, buffer, size)` adds null-terminator only if there is enough room
|
||||||
|
* PlatformIO: set `build.libArchive` to `false` (PR #1550 by @askreet)
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> #### Support for `char` removed
|
||||||
|
>
|
||||||
|
> We cannot cast a `JsonVariant` to a `char` anymore, so the following will break:
|
||||||
|
> ```c++
|
||||||
|
> char age = doc["age"]; // error: no matching function for call to 'variantAs(VariantData*&)'
|
||||||
|
> ```
|
||||||
|
> Instead, you must use another integral type, such as `int8_t`:
|
||||||
|
> ```c++
|
||||||
|
> int8_t age = doc["age"]; // OK
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> Similarly, we cannot assign from a `char` anymore, so the following will break:
|
||||||
|
> ```c++
|
||||||
|
> char age;
|
||||||
|
> doc["age"] = age; // error: no matching function for call to 'VariantRef::set(const char&)'
|
||||||
|
> ```
|
||||||
|
> Instead, you must use another integral type, such as `int8_t`:
|
||||||
|
> ```c++
|
||||||
|
> int8_t age;
|
||||||
|
> doc["age"] = age; // OK
|
||||||
|
> ```
|
||||||
|
> A deprecation warning with the message "Support for `char` is deprecated, use `int8_t` or `uint8_t` instead" was added to allow a smooth transition.
|
||||||
|
>
|
||||||
|
> #### `as<T>()` always returns `T`
|
||||||
|
>
|
||||||
|
> Previously, `JsonVariant::as<T>()` could return a type different from `T`.
|
||||||
|
> The most common example is `as<char*>()` that returned a `const char*`.
|
||||||
|
> While this feature simplified a few use cases, it was confusing and complicated the
|
||||||
|
> implementation of custom converters.
|
||||||
|
>
|
||||||
|
> Starting from this version, `as<T>` doesn't try to auto-correct the return type and always return `T`,
|
||||||
|
> which means that you cannot write this anymore:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> Serial.println(doc["sensor"].as<char*>()); // error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> Instead, you must write:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> Serial.println(doc["sensor"].as<const char*>()); // OK
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> A deprecation warning with the message "Replace `as<char*>()` with `as<const char*>()`" was added to allow a smooth transition.
|
||||||
|
>
|
||||||
|
> #### `DeserializationError::NotSupported` removed
|
||||||
|
>
|
||||||
|
> On a different topic, `DeserializationError::NotSupported` has been removed.
|
||||||
|
> Instead of returning this error:
|
||||||
|
>
|
||||||
|
> * `deserializeJson()` leaves `\uXXXX` unchanged (only when `ARDUINOJSON_DECODE_UNICODE` is `0`)
|
||||||
|
> * `deserializeMsgPack()` replaces unsupported values with `null`s
|
||||||
|
>
|
||||||
|
> #### Const-aware `is<T>()`
|
||||||
|
>
|
||||||
|
> Lastly, a very minor change concerns `JsonVariantConst::is<T>()`.
|
||||||
|
> It used to return `true` for `JsonArray` and `JsonOject`, but now it returns `false`.
|
||||||
|
> Instead, you must use `JsonArrayConst` and `JsonObjectConst`.
|
||||||
|
|
||||||
|
v6.17.3 (2021-02-15)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Made `JsonDocument`'s destructor protected (issue #1480)
|
||||||
|
* Added missing calls to `client.stop()` in `JsonHttpClient.ino` (issue #1485)
|
||||||
|
* Fixed error `expected ')' before 'char'` when `isdigit()` is a macro (issue #1487)
|
||||||
|
* Fixed error `definition of implicit copy constructor is deprecated` on Clang 10
|
||||||
|
* PlatformIO: set framework compatibility to `*` (PR #1490 by @maxgerhardt)
|
||||||
|
|
||||||
|
v6.17.2 (2020-11-14)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed invalid conversion error in `operator|(JsonVariant, char*)` (issue #1432)
|
||||||
|
* Changed the default value of `ARDUINOJSON_ENABLE_PROGMEM` (issue #1433).
|
||||||
|
It now checks that the `pgm_read_XXX` macros are defined before enabling `PROGMEM`.
|
||||||
|
|
||||||
|
v6.17.1 (2020-11-07)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed error `ambiguous overload for 'operator|'` (issue #1411)
|
||||||
|
* Fixed `operator|(MemberProxy, JsonObject)` (issue #1415)
|
||||||
|
* Allowed more than 32767 values in non-embedded mode (issue #1414)
|
||||||
|
|
||||||
|
v6.17.0 (2020-10-19)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Added a build failure when nullptr is defined as a macro (issue #1355)
|
||||||
|
* Added `JsonDocument::overflowed()` which tells if the memory pool was too small (issue #1358)
|
||||||
|
* Added `DeserializationError::EmptyInput` which tells if the input was empty
|
||||||
|
* Added `DeserializationError::f_str()` which returns a `const __FlashStringHelper*` (issue #846)
|
||||||
|
* Added `operator|(JsonVariantConst, JsonVariantConst)`
|
||||||
|
* Added filtering for MessagePack (issue #1298, PR #1394 by Luca Passarella)
|
||||||
|
* Moved float convertion tables to PROGMEM
|
||||||
|
* Fixed `JsonVariant::set((char*)0)` which returned false instead of true (issue #1368)
|
||||||
|
* Fixed error `No such file or directory #include <WString.h>` (issue #1381)
|
||||||
|
|
||||||
|
v6.16.1 (2020-08-04)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed `deserializeJson()` that stopped reading after `{}` (issue #1335)
|
||||||
|
|
||||||
|
v6.16.0 (2020-08-01)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Added comparisons (`>`, `>=`, `==`, `!=`, `<`, and `<=`) between `JsonVariant`s
|
||||||
|
* Added string deduplication (issue #1303)
|
||||||
|
* Added `JsonString::operator!=`
|
||||||
|
* Added wildcard key (`*`) for filters (issue #1309)
|
||||||
|
* Set `ARDUINOJSON_DECODE_UNICODE` to `1` by default
|
||||||
|
* Fixed `copyArray()` not working with `String`, `ElementProxy`, and `MemberProxy`
|
||||||
|
* Fixed error `getOrAddElement is not a member of ElementProxy` (issue #1311)
|
||||||
|
* Fixed excessive stack usage when compiled with `-Og` (issues #1210 and #1314)
|
||||||
|
* Fixed `Warning[Pa093]: implicit conversion from floating point to integer` on IAR compiler (PR #1328 by @stawiski)
|
||||||
|
|
||||||
|
v6.15.2 (2020-05-15)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* CMake: don't build tests when imported in another project
|
||||||
|
* CMake: made project arch-independent
|
||||||
|
* Visual Studio: fixed error C2766 with flag `/Zc:__cplusplus` (issue #1250)
|
||||||
|
* Added support for `JsonDocument` to `copyArray()` (issue #1255)
|
||||||
|
* Added support for `enum`s in `as<T>()` and `is<T>()` (issue #1256)
|
||||||
|
* Added `JsonVariant` as an input type for `deserializeXxx()`
|
||||||
|
For example, you can do: `deserializeJson(doc2, doc1["payload"])`
|
||||||
|
* Break the build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0
|
||||||
|
|
||||||
|
v6.15.1 (2020-04-08)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed "maybe-uninitialized" warning (issue #1217)
|
||||||
|
* Fixed "statement is unreachable" warning on IAR (issue #1233)
|
||||||
|
* Fixed "pointless integer comparison" warning on IAR (issue #1233)
|
||||||
|
* Added CMake "install" target (issue #1209)
|
||||||
|
* Disabled alignment on AVR (issue #1231)
|
||||||
|
|
||||||
|
v6.15.0 (2020-03-22)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Added `DeserializationOption::Filter` (issue #959)
|
||||||
|
* Added example `JsonFilterExample.ino`
|
||||||
|
* Changed the array subscript operator to automatically add missing elements
|
||||||
|
* Fixed "deprecated-copy" warning on GCC 9 (fixes #1184)
|
||||||
|
* Fixed `MemberProxy::set(char[])` not duplicating the string (issue #1191)
|
||||||
|
* Fixed enums serialized as booleans (issue #1197)
|
||||||
|
* Fixed incorrect string comparison on some platforms (issue #1198)
|
||||||
|
* Added move-constructor and move-assignment to `BasicJsonDocument`
|
||||||
|
* Added `BasicJsonDocument::garbageCollect()` (issue #1195)
|
||||||
|
* Added `StaticJsonDocument::garbageCollect()`
|
||||||
|
* Changed copy-constructor of `BasicJsonDocument` to preserve the capacity of the source.
|
||||||
|
* Removed copy-constructor of `JsonDocument` (issue #1189)
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> #### Copy-constructor of `BasicJsonDocument`
|
||||||
|
>
|
||||||
|
> In previous versions, the copy constructor of `BasicJsonDocument` looked at the source's `memoryUsage()` to choose its capacity.
|
||||||
|
> Now, the copy constructor of `BasicJsonDocument` uses the same capacity as the source.
|
||||||
|
>
|
||||||
|
> Example:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> DynamicJsonDocument doc1(64);
|
||||||
|
> doc1.set(String("example"));
|
||||||
|
>
|
||||||
|
> DynamicJsonDocument doc2 = doc1;
|
||||||
|
> Serial.print(doc2.capacity()); // 8 with ArduinoJson 6.14
|
||||||
|
> // 64 with ArduinoJson 6.15
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> I made this change to get consistent results between copy-constructor and move-constructor, and whether RVO applies or not.
|
||||||
|
>
|
||||||
|
> If you use the copy-constructor to optimize your documents, you can use `garbageCollect()` or `shrinkToFit()` instead.
|
||||||
|
>
|
||||||
|
> #### Copy-constructor of `JsonDocument`
|
||||||
|
>
|
||||||
|
> In previous versions, it was possible to create a function that take a `JsonDocument` by value.
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> void myFunction(JsonDocument doc) {}
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> This function gives the wrong clues because it doesn't receive a copy of the `JsonDocument`, only a sliced version.
|
||||||
|
> It worked because the copy constructor copied the internal pointers, but it was an accident.
|
||||||
|
>
|
||||||
|
> From now, if you need to pass a `JsonDocument` to a function, you must use a reference:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> void myFunction(JsonDocument& doc) {}
|
||||||
|
> ```
|
||||||
|
|
||||||
|
v6.14.1 (2020-01-27)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed regression in UTF16 decoding (issue #1173)
|
||||||
|
* Fixed `containsKey()` on `JsonVariantConst`
|
||||||
|
* Added `getElement()` and `getMember()` to `JsonVariantConst`
|
||||||
|
|
||||||
|
v6.14.0 (2020-01-16)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Added `BasicJsonDocument::shrinkToFit()`
|
||||||
|
* Added support of `uint8_t` for `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` (issue #1142)
|
||||||
|
* Added `ARDUINOJSON_ENABLE_COMMENTS` to enable support for comments (defaults to 0)
|
||||||
|
* Auto enable support for `std::string` and `std::stream` on modern compilers (issue #1156)
|
||||||
|
(No need to define `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_STD_STREAM` anymore)
|
||||||
|
* Improved decoding of UTF-16 surrogate pairs (PR #1157 by @kaysievers)
|
||||||
|
(ArduinoJson now produces standard UTF-8 instead of CESU-8)
|
||||||
|
* Added `measureJson`, `measureJsonPretty`, and `measureMsgPack` to `keywords.txt`
|
||||||
|
(This file is used for syntax highlighting in the Arduino IDE)
|
||||||
|
* Fixed `variant.is<nullptr_t>()`
|
||||||
|
* Fixed value returned by `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String`
|
||||||
|
* Improved speed of `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String`
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> #### Comments
|
||||||
|
>
|
||||||
|
> Support for comments in input is now optional and disabled by default.
|
||||||
|
>
|
||||||
|
> If you need support for comments, you must defined `ARDUINOJSON_ENABLE_COMMENTS` to `1`; otherwise, you'll receive `InvalidInput` errors.
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> #define ARDUINOJSON_ENABLE_COMMENTS 1
|
||||||
|
> #include <ArduinoJson.h>
|
||||||
|
> ```
|
||||||
|
|
||||||
|
v6.13.0 (2019-11-01)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Added support for custom writer/reader classes (issue #1088)
|
||||||
|
* Added conversion from `JsonArray` and `JsonObject` to `bool`, to be consistent with `JsonVariant`
|
||||||
|
* Fixed `deserializeJson()` when input contains duplicate keys (issue #1095)
|
||||||
|
* Improved `deserializeMsgPack()` speed by reading several bytes at once
|
||||||
|
* Added detection of Atmel AVR8/GNU C Compiler (issue #1112)
|
||||||
|
* Fixed deserializer that stopped reading at the first `0xFF` (PR #1118 by @mikee47)
|
||||||
|
* Fixed dangling reference in copies of `MemberProxy` and `ElementProxy` (issue #1120)
|
||||||
|
|
||||||
|
v6.12.0 (2019-09-05)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Use absolute instead of relative includes (issue #1072)
|
||||||
|
* Changed `JsonVariant::as<bool>()` to return `true` for any non-null value (issue #1005)
|
||||||
|
* Moved ancillary files to `extras/` (issue #1011)
|
||||||
|
|
||||||
|
v6.11.5 (2019-08-23)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Added fallback implementations of `strlen_P()`, `strncmp_P()`, `strcmp_P()`, and `memcpy_P()` (issue #1073)
|
||||||
|
|
||||||
|
v6.11.4 (2019-08-12)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Added `measureJson()` to the `ArduinoJson` namespace (PR #1069 by @nomis)
|
||||||
|
* Added support for `basic_string<char, traits, allocator>` (issue #1045)
|
||||||
|
* Fixed example `JsonConfigFile.ino` for ESP8266
|
||||||
|
* Include `Arduino.h` if `ARDUINO` is defined (PR #1071 by @nomis)
|
||||||
|
|
||||||
|
v6.11.3 (2019-07-22)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Added operators `==` and `!=` for `JsonDocument`, `ElementProxy`, and `MemberProxy`
|
||||||
|
* Fixed comparison of `JsonVariant` when one contains a linked string and the other contains an owned string (issue #1051)
|
||||||
|
|
||||||
|
v6.11.2 (2019-07-08)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed assignment of `JsonDocument` to `JsonVariant` (issue #1023)
|
||||||
|
* Fix invalid conversion error on Particle Argon (issue #1035)
|
||||||
|
|
||||||
|
v6.11.1 (2019-06-21)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed `serialized()` not working with Flash strings (issue #1030)
|
||||||
|
|
||||||
|
v6.11.0 (2019-05-26)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed `deserializeJson()` silently accepting a `Stream*` (issue #978)
|
||||||
|
* Fixed invalid result from `operator|` (issue #981)
|
||||||
|
* Made `deserializeJson()` more picky about trailing characters (issue #980)
|
||||||
|
* Added `ARDUINOJSON_ENABLE_NAN` (default=0) to enable NaN in JSON (issue #973)
|
||||||
|
* Added `ARDUINOJSON_ENABLE_INFINITY` (default=0) to enable Infinity in JSON
|
||||||
|
* Removed implicit conversion in comparison operators (issue #998)
|
||||||
|
* Added lexicographical comparison for `JsonVariant`
|
||||||
|
* Added support for `nullptr` (issue #998)
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> #### NaN and Infinity
|
||||||
|
>
|
||||||
|
> The JSON specification allows neither NaN not Infinity, but previous
|
||||||
|
> versions of ArduinoJson supported it. Now, ArduinoJson behaves like most
|
||||||
|
> other libraries: a NaN or and Infinity in the `JsonDocument`, becomes
|
||||||
|
> a `null` in the output JSON. Also, `deserializeJson()` returns
|
||||||
|
> `InvalidInput` if the JSON document contains NaN or Infinity.
|
||||||
|
>
|
||||||
|
> This version still supports NaN and Infinity in JSON documents, but
|
||||||
|
> it's disabled by default to be compatible with other JSON parsers.
|
||||||
|
> If you need the old behavior back, define `ARDUINOJSON_ENABLE_NAN` and
|
||||||
|
> `ARDUINOJSON_ENABLE_INFINITY` to `1`;:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> #define ARDUINOJSON_ENABLE_NAN 1
|
||||||
|
> #define ARDUINOJSON_ENABLE_INFINITY 1
|
||||||
|
> #include <ArduinoJson.h>
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> #### The "or" operator
|
||||||
|
>
|
||||||
|
> This version slightly changes the behavior of the | operator when the
|
||||||
|
> variant contains a float and the user requests an integer.
|
||||||
|
>
|
||||||
|
> Older versions returned the floating point value truncated.
|
||||||
|
> Now, it returns the default value.
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> // suppose variant contains 1.2
|
||||||
|
> int value = variant | 3;
|
||||||
|
>
|
||||||
|
> // old behavior:
|
||||||
|
> value == 1
|
||||||
|
>
|
||||||
|
> // new behavior
|
||||||
|
> value == 3
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> If you need the old behavior, you must add `if (variant.is<float>())`.
|
||||||
|
|
||||||
|
v6.10.1 (2019-04-23)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed error "attributes are not allowed on a function-definition"
|
||||||
|
* Fixed `deserializeJson()` not being picky enough (issue #969)
|
||||||
|
* Fixed error "no matching function for call to write(uint8_t)" (issue #972)
|
||||||
|
|
||||||
|
v6.10.0 (2019-03-22)
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Fixed an integer overflow in the JSON deserializer
|
||||||
|
* Added overflow handling in `JsonVariant::as<T>()` and `JsonVariant::is<T>()`.
|
||||||
|
- `as<T>()` returns `0` if the integer `T` overflows
|
||||||
|
- `is<T>()` returns `false` if the integer `T` overflows
|
||||||
|
* Added `BasicJsonDocument` to support custom allocator (issue #876)
|
||||||
|
* Added `JsonDocument::containsKey()` (issue #938)
|
||||||
|
* Added `JsonVariant::containsKey()`
|
||||||
|
|
||||||
|
v6.9.1 (2019-03-01)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Fixed warning "unused variable" with GCC 4.4 (issue #912)
|
||||||
|
* Fixed warning "cast increases required alignment" (issue #914)
|
||||||
|
* Fixed warning "conversion may alter value" (issue #914)
|
||||||
|
* Fixed naming conflict with "CAPACITY" (issue #839)
|
||||||
|
* Muted warning "will change in GCC 7.1" (issue #914)
|
||||||
|
* Added a clear error message for `StaticJsonBuffer` and `DynamicJsonBuffer`
|
||||||
|
* Marked ArduinoJson.h as a "system header"
|
||||||
|
|
||||||
|
v6.9.0 (2019-02-26)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Decode escaped Unicode characters like \u00DE (issue #304, PR #791)
|
||||||
|
Many thanks to Daniel Schulte (aka @trilader) who implemented this feature.
|
||||||
|
* Added option ARDUINOJSON_DECODE_UNICODE to enable it
|
||||||
|
* Converted `JsonArray::copyFrom()/copyTo()` to free functions `copyArray()`
|
||||||
|
* Renamed `JsonArray::copyFrom()` and `JsonObject::copyFrom()` to `set()`
|
||||||
|
* Renamed `JsonArray::get()` to `getElement()`
|
||||||
|
* Renamed `JsonArray::add()` (without arg) to `addElement()`
|
||||||
|
* Renamed `JsonObject::get()` to `getMember()`
|
||||||
|
* Renamed `JsonObject::getOrCreate()` to `getOrAddMember()`
|
||||||
|
* Fixed `JsonVariant::isNull()` not returning `true` after `set((char*)0)`
|
||||||
|
* Fixed segfault after `variant.set(serialized((char*)0))`
|
||||||
|
* Detect `IncompleteInput` in `false`, `true`, and `null`
|
||||||
|
* Added `JsonDocument::size()`
|
||||||
|
* Added `JsonDocument::remove()`
|
||||||
|
* Added `JsonVariant::clear()`
|
||||||
|
* Added `JsonVariant::remove()`
|
||||||
|
|
||||||
|
v6.8.0-beta (2019-01-30)
|
||||||
|
-----------
|
||||||
|
|
||||||
|
* Import functions in the ArduinoJson namespace to get clearer errors
|
||||||
|
* Improved syntax highlighting in Arduino IDE
|
||||||
|
* Removed default capacity of `DynamicJsonDocument`
|
||||||
|
* `JsonArray::copyFrom()` accepts `JsonArrayConst`
|
||||||
|
* `JsonVariant::set()` accepts `JsonArrayConst` and `JsonObjectConst`
|
||||||
|
* `JsonDocument` was missing in the ArduinoJson namespace
|
||||||
|
* Added `memoryUsage()` to `JsonArray`, `JsonObject`, and `JsonVariant`
|
||||||
|
* Added `nesting()` to `JsonArray`, `JsonDocument`, `JsonObject`, and `JsonVariant`
|
||||||
|
* Replaced `JsonDocument::nestingLimit` with an additional parameter
|
||||||
|
to `deserializeJson()` and `deserializeMsgPack()`
|
||||||
|
* Fixed uninitialized variant in `JsonDocument`
|
||||||
|
* Fixed `StaticJsonDocument` copy constructor and copy assignment
|
||||||
|
* The copy constructor of `DynamicJsonDocument` chooses the capacity according to the memory usage of the source, not from the capacity of the source.
|
||||||
|
* Added the ability to create/assign a `StaticJsonDocument`/`DynamicJsonDocument` from a `JsonArray`/`JsonObject`/`JsonVariant`
|
||||||
|
* Added `JsonDocument::isNull()`
|
||||||
|
* Added `JsonDocument::operator[]`
|
||||||
|
* Added `ARDUINOJSON_TAB` to configure the indentation character
|
||||||
|
* Reduced the size of the pretty JSON serializer
|
||||||
|
* Added `add()`, `createNestedArray()` and `createNestedObject()` to `JsonVariant`
|
||||||
|
* `JsonVariant` automatically promotes to `JsonObject` or `JsonArray` on write.
|
||||||
|
Calling `JsonVariant::to<T>()` is not required anymore.
|
||||||
|
* `JsonDocument` now support the same operations as `JsonVariant`.
|
||||||
|
Calling `JsonDocument::as<T>()` is not required anymore.
|
||||||
|
* Fixed example `JsonHttpClient.ino`
|
||||||
|
* User can now use a `JsonString` as a key or a value
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> #### `DynamicJsonDocument`'s constructor
|
||||||
|
>
|
||||||
|
> The parameter to the constructor of `DynamicJsonDocument` is now mandatory
|
||||||
|
>
|
||||||
|
> Old code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> DynamicJsonDocument doc;
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> New code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> DynamicJsonDocument doc(1024);
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> #### Nesting limit
|
||||||
|
>
|
||||||
|
> `JsonDocument::nestingLimit` was replaced with a new parameter to `deserializeJson()` and `deserializeMsgPack()`.
|
||||||
|
>
|
||||||
|
> Old code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> doc.nestingLimit = 15;
|
||||||
|
> deserializeJson(doc, input);
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> New code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> deserializeJson(doc, input, DeserializationOption::NestingLimit(15));
|
||||||
|
> ```
|
||||||
|
|
||||||
|
v6.7.0-beta (2018-12-07)
|
||||||
|
-----------
|
||||||
|
|
||||||
|
* Removed the automatic expansion of `DynamicJsonDocument`, it now has a fixed capacity.
|
||||||
|
* Restored the monotonic allocator because the code was getting too big
|
||||||
|
* Reduced the memory usage
|
||||||
|
* Reduced the code size
|
||||||
|
* Renamed `JsonKey` to `JsonString`
|
||||||
|
* Removed spurious files in the Particle library
|
||||||
|
|
||||||
|
v6.6.0-beta (2018-11-13)
|
||||||
|
-----------
|
||||||
|
|
||||||
|
* Removed `JsonArray::is<T>(i)` and `JsonArray::set(i,v)`
|
||||||
|
* Removed `JsonObject::is<T>(k)` and `JsonObject::set(k,v)`
|
||||||
|
* Replaced `T JsonArray::get<T>(i)` with `JsonVariant JsonArray::get(i)`
|
||||||
|
* Replaced `T JsonObject::get<T>(k)` with `JsonVariant JsonObject::get(k)`
|
||||||
|
* Added `JSON_STRING_SIZE()`
|
||||||
|
* ~~Replacing or removing a value now releases the memory~~
|
||||||
|
* Added `DeserializationError::code()` to be used in switch statements (issue #846)
|
||||||
|
|
||||||
|
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<String>()` (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<JsonArray>()` and `JsonVariant::to<JsonObject>()`
|
||||||
|
|
||||||
|
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<JsonVariant>();
|
||||||
|
> myValue.set(42);
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> #### JsonPair
|
||||||
|
>
|
||||||
|
> Old code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> for(JsonPair p : myObject) {
|
||||||
|
> Serial.println(p.key);
|
||||||
|
> Serial.println(p.value.as<int>());
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> New code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> for(JsonPair p : myObject) {
|
||||||
|
> Serial.println(p.key());
|
||||||
|
> Serial.println(p.value().as<int>());
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> 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<int>()` 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()`
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> #### Non quoted strings
|
||||||
|
>
|
||||||
|
> Non quoted strings are now forbidden in values, but they are still allowed in keys.
|
||||||
|
> For example, `{key:"value"}` is accepted, but `{key:value}` is not.
|
||||||
|
>
|
||||||
|
> #### Preformatted values
|
||||||
|
>
|
||||||
|
> Old code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> object["values"] = RawJson("[1,2,3,4]");
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> New code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> object["values"] = serialized("[1,2,3,4]");
|
||||||
|
> ```
|
||||||
|
|
||||||
|
v6.1.0-beta (2018-07-02)
|
||||||
|
-----------
|
||||||
|
|
||||||
|
* Return `JsonArray` and `JsonObject` by value instead of reference (issue #309)
|
||||||
|
* Replaced `success()` with `isNull()`
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> Old code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> JsonObject& obj = doc.to<JsonObject>();
|
||||||
|
> JsonArray& arr = obj.createNestedArray("key");
|
||||||
|
> if (!arr.success()) {
|
||||||
|
> Serial.println("Not enough memory");
|
||||||
|
> return;
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> New code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> JsonObject obj = doc.to<JsonObject>();
|
||||||
|
> JsonArray arr = obj.createNestedArray("key");
|
||||||
|
> if (arr.isNull()) {
|
||||||
|
> Serial.println("Not enough memory");
|
||||||
|
> return;
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
|
||||||
|
v6.0.1-beta (2018-06-11)
|
||||||
|
-----------
|
||||||
|
|
||||||
|
* Fixed conflicts with `isnan()` and `isinf()` macros (issue #752)
|
||||||
|
|
||||||
|
v6.0.0-beta (2018-06-07)
|
||||||
|
-----------
|
||||||
|
|
||||||
|
* Added `DynamicJsonDocument` and `StaticJsonDocument`
|
||||||
|
* Added `deserializeJson()`
|
||||||
|
* Added `serializeJson()` and `serializeJsonPretty()`
|
||||||
|
* Added `measureJson()` and `measureJsonPretty()`
|
||||||
|
* Added `serializeMsgPack()`, `deserializeMsgPack()` and `measureMsgPack()` (issue #358)
|
||||||
|
* Added example `MsgPackParser.ino` (issue #358)
|
||||||
|
* Added support for non zero-terminated strings (issue #704)
|
||||||
|
* Removed `JsonBuffer::parseArray()`, `parseObject()` and `parse()`
|
||||||
|
* Removed `JsonBuffer::createArray()` and `createObject()`
|
||||||
|
* Removed `printTo()` and `prettyPrintTo()`
|
||||||
|
* Removed `measureLength()` and `measurePrettyLength()`
|
||||||
|
* Removed all deprecated features
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> #### Deserialization
|
||||||
|
>
|
||||||
|
> Old code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> DynamicJsonBuffer jb;
|
||||||
|
> JsonObject& obj = jb.parseObject(json);
|
||||||
|
> if (obj.success()) {
|
||||||
|
>
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> New code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> DynamicJsonDocument doc;
|
||||||
|
> DeserializationError error = deserializeJson(doc, json);
|
||||||
|
> if (error) {
|
||||||
|
>
|
||||||
|
> }
|
||||||
|
> JsonObject& obj = doc.as<JsonObject>();
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> #### Serialization
|
||||||
|
>
|
||||||
|
> Old code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> DynamicJsonBuffer jb;
|
||||||
|
> JsonObject& obj = jb.createObject();
|
||||||
|
> obj["key"] = "value";
|
||||||
|
> obj.printTo(Serial);
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> New code:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> DynamicJsonDocument obj;
|
||||||
|
> JsonObject& obj = doc.to<JsonObject>();
|
||||||
|
> obj["key"] = "value";
|
||||||
|
> serializeJson(doc, Serial);
|
||||||
|
> ```
|
||||||
25
ESP_Medicine_Indicator/libraries/ArduinoJson/CMakeLists.txt
Normal file
25
ESP_Medicine_Indicator/libraries/ArduinoJson/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# ArduinoJson - https://arduinojson.org
|
||||||
|
# Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
# MIT License
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
|
||||||
|
if(ESP_PLATFORM)
|
||||||
|
# Build ArduinoJson as an ESP-IDF component
|
||||||
|
idf_component_register(INCLUDE_DIRS src)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
project(ArduinoJson VERSION 6.21.3)
|
||||||
|
|
||||||
|
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||||
|
include(CTest)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
|
||||||
|
include(extras/CompileOptions.cmake)
|
||||||
|
add_subdirectory(extras/tests)
|
||||||
|
add_subdirectory(extras/fuzzing)
|
||||||
|
endif()
|
||||||
10
ESP_Medicine_Indicator/libraries/ArduinoJson/CONTRIBUTING.md
Normal file
10
ESP_Medicine_Indicator/libraries/ArduinoJson/CONTRIBUTING.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Contribution to ArduinoJson
|
||||||
|
|
||||||
|
First, thank you for taking the time to contribute to this project.
|
||||||
|
|
||||||
|
You can submit changes via GitHub Pull Requests.
|
||||||
|
|
||||||
|
Please:
|
||||||
|
|
||||||
|
1. Update the test suite for any change of behavior
|
||||||
|
2. Use clang-format in "file" mode to format the code
|
||||||
10
ESP_Medicine_Indicator/libraries/ArduinoJson/LICENSE.txt
Normal file
10
ESP_Medicine_Indicator/libraries/ArduinoJson/LICENSE.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
161
ESP_Medicine_Indicator/libraries/ArduinoJson/README.md
Normal file
161
ESP_Medicine_Indicator/libraries/ArduinoJson/README.md
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
<p align="center">
|
||||||
|
<a href="https://arduinojson.org/"><img alt="ArduinoJson" src="https://arduinojson.org/images/logo.svg" width="200" /></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
[](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
|
||||||
|
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||||
|
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||||
|
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||||
|
[](https://www.ardu-badge.com/ArduinoJson/6.21.3)
|
||||||
|
[](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.3)
|
||||||
|
[](https://components.espressif.com/components/bblanchon/arduinojson)
|
||||||
|
[](https://github.com/bblanchon/ArduinoJson/stargazers)
|
||||||
|
[](https://github.com/sponsors/bblanchon)
|
||||||
|
|
||||||
|
ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/)
|
||||||
|
* [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/)
|
||||||
|
* [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/)
|
||||||
|
* [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/)
|
||||||
|
* [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/#filtering)
|
||||||
|
* Supports single quotes as a string delimiter
|
||||||
|
* Compatible with [NDJSON](http://ndjson.org/) and [JSON Lines](https://jsonlines.org/)
|
||||||
|
* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/)
|
||||||
|
* [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/)
|
||||||
|
* [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/)
|
||||||
|
* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/)
|
||||||
|
* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/)
|
||||||
|
* Efficient
|
||||||
|
* [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||||
|
* [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||||
|
* [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||||
|
* [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/)
|
||||||
|
* [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/)
|
||||||
|
* [Deduplicates strings](https://arduinojson.org/news/2020/08/01/version-6-16-0/)
|
||||||
|
* Versatile
|
||||||
|
* Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/)
|
||||||
|
* Supports [`String`](https://arduinojson.org/v6/api/config/enable_arduino_string/), [`std::string`](https://arduinojson.org/v6/api/config/enable_std_string/), and [`std::string_view`](https://arduinojson.org/v6/api/config/enable_string_view/)
|
||||||
|
* Supports [`Stream`](https://arduinojson.org/v6/api/config/enable_arduino_stream/) and [`std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/)
|
||||||
|
* Supports [Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/)
|
||||||
|
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/#custom-writer)
|
||||||
|
* Supports [custom converters](https://arduinojson.org/news/2021/05/04/version-6-18-0/)
|
||||||
|
* Portable
|
||||||
|
* Usable on any C++ project (not limited to Arduino)
|
||||||
|
* Compatible with C++11, C++14 and C++17
|
||||||
|
* Support for C++98/C++03 available on [ArduinoJson 6.20.x](https://github.com/bblanchon/ArduinoJson/tree/6.20.x)
|
||||||
|
* Zero warnings with `-Wall -Wextra -pedantic` and `/W4`
|
||||||
|
* [Header-only library](https://en.wikipedia.org/wiki/Header-only)
|
||||||
|
* Works with virtually any board
|
||||||
|
* Arduino boards: [Uno](https://amzn.to/38aL2ik), [Due](https://amzn.to/36YkWi2), [Micro](https://amzn.to/35WkdwG), [Nano](https://amzn.to/2QTvwRX), [Mega](https://amzn.to/36XWhuf), [Yun](https://amzn.to/30odURc), [Leonardo](https://amzn.to/36XWjlR)...
|
||||||
|
* Espressif chips: [ESP8266](https://amzn.to/36YluV8), [ESP32](https://amzn.to/2G4pRCB)
|
||||||
|
* Lolin (WeMos) boards: [D1 mini](https://amzn.to/2QUpz7q), [D1 Mini Pro](https://amzn.to/36UsGSs)...
|
||||||
|
* Teensy boards: [4.0](https://amzn.to/30ljXGq), [3.2](https://amzn.to/2FT0EuC), [2.0](https://amzn.to/2QXUMXj)
|
||||||
|
* Particle boards: [Argon](https://amzn.to/2FQHa9X), [Boron](https://amzn.to/36WgLUd), [Electron](https://amzn.to/30vEc4k), [Photon](https://amzn.to/387F9Cd)...
|
||||||
|
* Texas Instruments boards: [MSP430](https://amzn.to/30nJWgg)...
|
||||||
|
* Soft cores: [Nios II](https://en.wikipedia.org/wiki/Nios_II)...
|
||||||
|
* Tested on all major development environments
|
||||||
|
* [Arduino IDE](https://www.arduino.cc/en/Main/Software)
|
||||||
|
* [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/)
|
||||||
|
* [Atollic TrueSTUDIO](https://atollic.com/truestudio/)
|
||||||
|
* [Energia](http://energia.nu/)
|
||||||
|
* [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/)
|
||||||
|
* [Keil uVision](http://www.keil.com/)
|
||||||
|
* [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide)
|
||||||
|
* [Particle](https://www.particle.io/)
|
||||||
|
* [PlatformIO](http://platformio.org/)
|
||||||
|
* [Sloeber plugin for Eclipse](https://eclipse.baeyens.it/)
|
||||||
|
* [Visual Micro](http://www.visualmicro.com/)
|
||||||
|
* [Visual Studio](https://www.visualstudio.com/)
|
||||||
|
* [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/RlZSKy17DjJ6HcdN)
|
||||||
|
* [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/)
|
||||||
|
* Well designed
|
||||||
|
* [Elegant API](http://arduinojson.org/v6/example/)
|
||||||
|
* [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety)
|
||||||
|
* Self-contained (no external dependency)
|
||||||
|
* `const` friendly
|
||||||
|
* [`for` friendly](https://arduinojson.org/v6/api/jsonobject/begin_end/)
|
||||||
|
* [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming)
|
||||||
|
* Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/#integer-overflows)
|
||||||
|
* Well tested
|
||||||
|
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||||
|
* Continuously tested on
|
||||||
|
* [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||||
|
* [GCC 5, 6, 7, 8, 9, 10, 11](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||||
|
* [Clang 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||||
|
* [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||||
|
* Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/)
|
||||||
|
* Well documented
|
||||||
|
* [Tutorials](https://arduinojson.org/v6/doc/deserialization/)
|
||||||
|
* [Examples](https://arduinojson.org/v6/example/)
|
||||||
|
* [How-tos](https://arduinojson.org/v6/example/)
|
||||||
|
* [FAQ](https://arduinojson.org/v6/faq/)
|
||||||
|
* [Troubleshooter](https://arduinojson.org/v6/troubleshooter/)
|
||||||
|
* [Book](https://arduinojson.org/book/)
|
||||||
|
* [Changelog](CHANGELOG.md)
|
||||||
|
* Vibrant user community
|
||||||
|
* Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories)
|
||||||
|
* [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson)
|
||||||
|
* [Responsive support](https://github.com/bblanchon/ArduinoJson/issues?q=is%3Aissue+is%3Aclosed)
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
|
||||||
|
### Deserialization
|
||||||
|
|
||||||
|
Here is a program that parses a JSON document with ArduinoJson.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
||||||
|
|
||||||
|
DynamicJsonDocument doc(1024);
|
||||||
|
deserializeJson(doc, json);
|
||||||
|
|
||||||
|
const char* sensor = doc["sensor"];
|
||||||
|
long time = doc["time"];
|
||||||
|
double latitude = doc["data"][0];
|
||||||
|
double longitude = doc["data"][1];
|
||||||
|
```
|
||||||
|
|
||||||
|
See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/deserialization/)
|
||||||
|
|
||||||
|
### Serialization
|
||||||
|
|
||||||
|
Here is a program that generates a JSON document with ArduinoJson:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
DynamicJsonDocument doc(1024);
|
||||||
|
|
||||||
|
doc["sensor"] = "gps";
|
||||||
|
doc["time"] = 1351824120;
|
||||||
|
doc["data"][0] = 48.756080;
|
||||||
|
doc["data"][1] = 2.302038;
|
||||||
|
|
||||||
|
serializeJson(doc, Serial);
|
||||||
|
// This prints:
|
||||||
|
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/serialization/)
|
||||||
|
|
||||||
|
## Sponsors
|
||||||
|
|
||||||
|
ArduinoJson is thankful to its sponsors. Please give them a visit; they deserve it!
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a href="https://www.programmingelectronics.com/" rel="sponsored">
|
||||||
|
<img src="https://arduinojson.org/images/2021/10/programmingeleactronicsacademy.png" alt="Programming Electronics Academy" width="200">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="https://github.com/1technophile" rel="sponsored">
|
||||||
|
<img alt="1technophile" src="https://avatars.githubusercontent.com/u/12672732?s=40&v=4">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
If you run a commercial project that embeds ArduinoJson, think about [sponsoring the library's development](https://github.com/sponsors/bblanchon): it ensures the code that your products rely on stays actively maintained. It can also give your project some exposure to the makers' community.
|
||||||
|
|
||||||
|
If you are an individual user and want to support the development (or give a sign of appreciation), consider purchasing the book [Mastering ArduinoJson](https://arduinojson.org/book/) ❤, or simply [cast a star](https://github.com/bblanchon/ArduinoJson/stargazers) ⭐.
|
||||||
27
ESP_Medicine_Indicator/libraries/ArduinoJson/SUPPORT.md
Normal file
27
ESP_Medicine_Indicator/libraries/ArduinoJson/SUPPORT.md
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# ArduinoJson Support
|
||||||
|
|
||||||
|
First off, thank you very much for using ArduinoJson.
|
||||||
|
|
||||||
|
We'll be very happy to help you, but first please read the following.
|
||||||
|
|
||||||
|
## Before asking for help
|
||||||
|
|
||||||
|
1. Read the [FAQ](https://arduinojson.org/faq/?utm_source=github&utm_medium=support)
|
||||||
|
2. Search in the [API Reference](https://arduinojson.org/api/?utm_source=github&utm_medium=support)
|
||||||
|
|
||||||
|
If you did not find the answer, please create a [new issue on GitHub](https://github.com/bblanchon/ArduinoJson/issues/new).
|
||||||
|
|
||||||
|
It is OK to add a comment to a currently opened issue, but please avoid adding comments to a closed issue.
|
||||||
|
|
||||||
|
## Before hitting the Submit button
|
||||||
|
|
||||||
|
Please provide all the relevant information:
|
||||||
|
|
||||||
|
* Good title
|
||||||
|
* Short description of the problem
|
||||||
|
* Target platform
|
||||||
|
* Compiler model and version
|
||||||
|
* [MVCE](https://stackoverflow.com/help/mcve)
|
||||||
|
* Compiler output
|
||||||
|
|
||||||
|
Good questions get fast answers!
|
||||||
28
ESP_Medicine_Indicator/libraries/ArduinoJson/appveyor.yml
Normal file
28
ESP_Medicine_Indicator/libraries/ArduinoJson/appveyor.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
version: 6.21.3.{build}
|
||||||
|
environment:
|
||||||
|
matrix:
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
|
||||||
|
CMAKE_GENERATOR: Visual Studio 17 2022
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||||
|
CMAKE_GENERATOR: Visual Studio 16 2019
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||||
|
CMAKE_GENERATOR: Visual Studio 15 2017
|
||||||
|
- CMAKE_GENERATOR: Ninja
|
||||||
|
MINGW32: i686-6.3.0-posix-dwarf-rt_v5-rev1 # MinGW-w64 6.3.0 i686
|
||||||
|
- CMAKE_GENERATOR: Ninja
|
||||||
|
MINGW64: x86_64-6.3.0-posix-seh-rt_v5-rev1 # MinGW-w64 6.3.0 x86_64
|
||||||
|
- CMAKE_GENERATOR: Ninja
|
||||||
|
MINGW64: x86_64-7.3.0-posix-seh-rt_v5-rev0 # MinGW-w64 7.3.0 x86_64
|
||||||
|
- CMAKE_GENERATOR: Ninja
|
||||||
|
MINGW64: x86_64-8.1.0-posix-seh-rt_v6-rev0 # MinGW-w64 8.1.0 x86_64
|
||||||
|
configuration: Debug
|
||||||
|
before_build:
|
||||||
|
- set PATH=%PATH:C:\Program Files\Git\usr\bin;=% # Workaround for CMake not wanting sh.exe on PATH for MinGW
|
||||||
|
- if defined MINGW set PATH=C:\%MINGW%\bin;%PATH%
|
||||||
|
- if defined MINGW32 set PATH=C:\mingw-w64\%MINGW32%\mingw32\bin;%PATH%
|
||||||
|
- if defined MINGW64 set PATH=C:\mingw-w64\%MINGW64%\mingw64\bin;%PATH%
|
||||||
|
- cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% -G "%CMAKE_GENERATOR%" .
|
||||||
|
build_script:
|
||||||
|
- cmake --build . --config %CONFIGURATION%
|
||||||
|
test_script:
|
||||||
|
- ctest -C %CONFIGURATION% --output-on-failure .
|
||||||
@ -0,0 +1 @@
|
|||||||
|
COMPONENT_ADD_INCLUDEDIRS := src
|
||||||
@ -0,0 +1,160 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to store your project configuration in a file.
|
||||||
|
// It uses the SD library but can be easily modified for any other file-system.
|
||||||
|
//
|
||||||
|
// The file contains a JSON document with the following content:
|
||||||
|
// {
|
||||||
|
// "hostname": "examples.com",
|
||||||
|
// "port": 2731
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// To run this program, you need an SD card connected to the SPI bus as follows:
|
||||||
|
// * MOSI <-> pin 11
|
||||||
|
// * MISO <-> pin 12
|
||||||
|
// * CLK <-> pin 13
|
||||||
|
// * CS <-> pin 4
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/config/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <SD.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
// Our configuration structure.
|
||||||
|
//
|
||||||
|
// Never use a JsonDocument to store the configuration!
|
||||||
|
// A JsonDocument is *not* a permanent storage; it's only a temporary storage
|
||||||
|
// used during the serialization phase. See:
|
||||||
|
// https://arduinojson.org/v6/faq/why-must-i-create-a-separate-config-object/
|
||||||
|
struct Config {
|
||||||
|
char hostname[64];
|
||||||
|
int port;
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *filename = "/config.txt"; // <- SD library uses 8.3 filenames
|
||||||
|
Config config; // <- global configuration object
|
||||||
|
|
||||||
|
// Loads the configuration from a file
|
||||||
|
void loadConfiguration(const char *filename, Config &config) {
|
||||||
|
// Open file for reading
|
||||||
|
File file = SD.open(filename);
|
||||||
|
|
||||||
|
// Allocate a temporary JsonDocument
|
||||||
|
// Don't forget to change the capacity to match your requirements.
|
||||||
|
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||||
|
StaticJsonDocument<512> doc;
|
||||||
|
|
||||||
|
// Deserialize the JSON document
|
||||||
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
|
if (error)
|
||||||
|
Serial.println(F("Failed to read file, using default configuration"));
|
||||||
|
|
||||||
|
// Copy values from the JsonDocument to the Config
|
||||||
|
config.port = doc["port"] | 2731;
|
||||||
|
strlcpy(config.hostname, // <- destination
|
||||||
|
doc["hostname"] | "example.com", // <- source
|
||||||
|
sizeof(config.hostname)); // <- destination's capacity
|
||||||
|
|
||||||
|
// Close the file (Curiously, File's destructor doesn't close the file)
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Saves the configuration to a file
|
||||||
|
void saveConfiguration(const char *filename, const Config &config) {
|
||||||
|
// Delete existing file, otherwise the configuration is appended to the file
|
||||||
|
SD.remove(filename);
|
||||||
|
|
||||||
|
// Open file for writing
|
||||||
|
File file = SD.open(filename, FILE_WRITE);
|
||||||
|
if (!file) {
|
||||||
|
Serial.println(F("Failed to create file"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate a temporary JsonDocument
|
||||||
|
// Don't forget to change the capacity to match your requirements.
|
||||||
|
// Use https://arduinojson.org/assistant to compute the capacity.
|
||||||
|
StaticJsonDocument<256> doc;
|
||||||
|
|
||||||
|
// Set the values in the document
|
||||||
|
doc["hostname"] = config.hostname;
|
||||||
|
doc["port"] = config.port;
|
||||||
|
|
||||||
|
// Serialize JSON to file
|
||||||
|
if (serializeJson(doc, file) == 0) {
|
||||||
|
Serial.println(F("Failed to write to file"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the file
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prints the content of a file to the Serial
|
||||||
|
void printFile(const char *filename) {
|
||||||
|
// Open file for reading
|
||||||
|
File file = SD.open(filename);
|
||||||
|
if (!file) {
|
||||||
|
Serial.println(F("Failed to read file"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract each characters by one by one
|
||||||
|
while (file.available()) {
|
||||||
|
Serial.print((char)file.read());
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
// Close the file
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) continue;
|
||||||
|
|
||||||
|
// Initialize SD library
|
||||||
|
const int chipSelect = 4;
|
||||||
|
while (!SD.begin(chipSelect)) {
|
||||||
|
Serial.println(F("Failed to initialize SD library"));
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should load default config if run for the first time
|
||||||
|
Serial.println(F("Loading configuration..."));
|
||||||
|
loadConfiguration(filename, config);
|
||||||
|
|
||||||
|
// Create configuration file
|
||||||
|
Serial.println(F("Saving configuration..."));
|
||||||
|
saveConfiguration(filename, config);
|
||||||
|
|
||||||
|
// Dump config file
|
||||||
|
Serial.println(F("Print config file..."));
|
||||||
|
printFile(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// not used in this example
|
||||||
|
}
|
||||||
|
|
||||||
|
// Performance issue?
|
||||||
|
// ------------------
|
||||||
|
//
|
||||||
|
// File is an unbuffered stream, which is not optimal for ArduinoJson.
|
||||||
|
// See: https://arduinojson.org/v6/how-to/improve-speed/
|
||||||
|
|
||||||
|
// See also
|
||||||
|
// --------
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/ contains the documentation for all the functions
|
||||||
|
// used above. It also includes an FAQ that will help you solve any
|
||||||
|
// serialization or deserialization problem.
|
||||||
|
//
|
||||||
|
// The book "Mastering ArduinoJson" contains a case study of a project that has
|
||||||
|
// a complex configuration with nested members.
|
||||||
|
// Contrary to this example, the project in the book uses the SPIFFS filesystem.
|
||||||
|
// Learn more at https://arduinojson.org/book/
|
||||||
|
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to use DeserializationOption::Filter
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/filter/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) continue;
|
||||||
|
|
||||||
|
// The huge input: an extract from OpenWeatherMap response
|
||||||
|
auto input_json = F(
|
||||||
|
"{\"cod\":\"200\",\"message\":0,\"list\":[{\"dt\":1581498000,\"main\":{"
|
||||||
|
"\"temp\":3.23,\"feels_like\":-3.63,\"temp_min\":3.23,\"temp_max\":4.62,"
|
||||||
|
"\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1010,\"humidity\":"
|
||||||
|
"58,\"temp_kf\":-1.39},\"weather\":[{\"id\":800,\"main\":\"Clear\","
|
||||||
|
"\"description\":\"clear "
|
||||||
|
"sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":0},\"wind\":{\"speed\":6."
|
||||||
|
"19,\"deg\":266},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 "
|
||||||
|
"09:00:00\"},{\"dt\":1581508800,\"main\":{\"temp\":6.09,\"feels_like\":-"
|
||||||
|
"1.07,\"temp_min\":6.09,\"temp_max\":7.13,\"pressure\":1015,\"sea_"
|
||||||
|
"level\":1015,\"grnd_level\":1011,\"humidity\":48,\"temp_kf\":-1.04},"
|
||||||
|
"\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear "
|
||||||
|
"sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":9},\"wind\":{\"speed\":6."
|
||||||
|
"64,\"deg\":268},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 "
|
||||||
|
"12:00:00\"}],\"city\":{\"id\":2643743,\"name\":\"London\",\"coord\":{"
|
||||||
|
"\"lat\":51.5085,\"lon\":-0.1257},\"country\":\"GB\",\"population\":"
|
||||||
|
"1000000,\"timezone\":0,\"sunrise\":1581492085,\"sunset\":1581527294}}");
|
||||||
|
|
||||||
|
// The filter: it contains "true" for each value we want to keep
|
||||||
|
StaticJsonDocument<200> filter;
|
||||||
|
filter["list"][0]["dt"] = true;
|
||||||
|
filter["list"][0]["main"]["temp"] = true;
|
||||||
|
|
||||||
|
// Deserialize the document
|
||||||
|
StaticJsonDocument<400> doc;
|
||||||
|
deserializeJson(doc, input_json, DeserializationOption::Filter(filter));
|
||||||
|
|
||||||
|
// Print the result
|
||||||
|
serializeJsonPretty(doc, Serial);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// not used in this example
|
||||||
|
}
|
||||||
|
|
||||||
|
// See also
|
||||||
|
// --------
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/ contains the documentation for all the functions
|
||||||
|
// used above. It also includes an FAQ that will help you solve any
|
||||||
|
// deserialization problem.
|
||||||
|
//
|
||||||
|
// The book "Mastering ArduinoJson" contains a tutorial on deserialization.
|
||||||
|
// It begins with a simple example, like the one above, and then adds more
|
||||||
|
// features like deserializing directly from a file or an HTTP request.
|
||||||
|
// Learn more at https://arduinojson.org/book/
|
||||||
|
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to generate a JSON document with ArduinoJson.
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/generator/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize Serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) continue;
|
||||||
|
|
||||||
|
// Allocate the JSON document
|
||||||
|
//
|
||||||
|
// Inside the brackets, 200 is the RAM allocated to this document.
|
||||||
|
// Don't forget to change this value to match your requirement.
|
||||||
|
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||||
|
StaticJsonDocument<200> doc;
|
||||||
|
|
||||||
|
// StaticJsonObject allocates memory on the stack, it can be
|
||||||
|
// replaced by DynamicJsonDocument which allocates in the heap.
|
||||||
|
//
|
||||||
|
// DynamicJsonDocument doc(200);
|
||||||
|
|
||||||
|
// Add values in the document
|
||||||
|
//
|
||||||
|
doc["sensor"] = "gps";
|
||||||
|
doc["time"] = 1351824120;
|
||||||
|
|
||||||
|
// Add an array.
|
||||||
|
//
|
||||||
|
JsonArray data = doc.createNestedArray("data");
|
||||||
|
data.add(48.756080);
|
||||||
|
data.add(2.302038);
|
||||||
|
|
||||||
|
// Generate the minified JSON and send it to the Serial port.
|
||||||
|
//
|
||||||
|
serializeJson(doc, Serial);
|
||||||
|
// The above line prints:
|
||||||
|
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
|
||||||
|
|
||||||
|
// Start a new line
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
// Generate the prettified JSON and send it to the Serial port.
|
||||||
|
//
|
||||||
|
serializeJsonPretty(doc, Serial);
|
||||||
|
// The above line prints:
|
||||||
|
// {
|
||||||
|
// "sensor": "gps",
|
||||||
|
// "time": 1351824120,
|
||||||
|
// "data": [
|
||||||
|
// 48.756080,
|
||||||
|
// 2.302038
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// not used in this example
|
||||||
|
}
|
||||||
|
|
||||||
|
// See also
|
||||||
|
// --------
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/ contains the documentation for all the functions
|
||||||
|
// used above. It also includes an FAQ that will help you solve any
|
||||||
|
// serialization problem.
|
||||||
|
//
|
||||||
|
// The book "Mastering ArduinoJson" contains a tutorial on serialization.
|
||||||
|
// It begins with a simple example, like the one above, and then adds more
|
||||||
|
// features like serializing directly to a file or an HTTP request.
|
||||||
|
// Learn more at https://arduinojson.org/book/
|
||||||
|
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤
|
||||||
@ -0,0 +1,126 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to parse a JSON document in an HTTP response.
|
||||||
|
// It uses the Ethernet library, but can be easily adapted for Wifi.
|
||||||
|
//
|
||||||
|
// It performs a GET resquest on https://arduinojson.org/example.json
|
||||||
|
// Here is the expected response:
|
||||||
|
// {
|
||||||
|
// "sensor": "gps",
|
||||||
|
// "time": 1351824120,
|
||||||
|
// "data": [
|
||||||
|
// 48.756080,
|
||||||
|
// 2.302038
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/http-client/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <Ethernet.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize Serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) continue;
|
||||||
|
|
||||||
|
// Initialize Ethernet library
|
||||||
|
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||||
|
if (!Ethernet.begin(mac)) {
|
||||||
|
Serial.println(F("Failed to configure Ethernet"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
Serial.println(F("Connecting..."));
|
||||||
|
|
||||||
|
// Connect to HTTP server
|
||||||
|
EthernetClient client;
|
||||||
|
client.setTimeout(10000);
|
||||||
|
if (!client.connect("arduinojson.org", 80)) {
|
||||||
|
Serial.println(F("Connection failed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(F("Connected!"));
|
||||||
|
|
||||||
|
// Send HTTP request
|
||||||
|
client.println(F("GET /example.json HTTP/1.0"));
|
||||||
|
client.println(F("Host: arduinojson.org"));
|
||||||
|
client.println(F("Connection: close"));
|
||||||
|
if (client.println() == 0) {
|
||||||
|
Serial.println(F("Failed to send request"));
|
||||||
|
client.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check HTTP status
|
||||||
|
char status[32] = {0};
|
||||||
|
client.readBytesUntil('\r', status, sizeof(status));
|
||||||
|
// It should be "HTTP/1.0 200 OK" or "HTTP/1.1 200 OK"
|
||||||
|
if (strcmp(status + 9, "200 OK") != 0) {
|
||||||
|
Serial.print(F("Unexpected response: "));
|
||||||
|
Serial.println(status);
|
||||||
|
client.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip HTTP headers
|
||||||
|
char endOfHeaders[] = "\r\n\r\n";
|
||||||
|
if (!client.find(endOfHeaders)) {
|
||||||
|
Serial.println(F("Invalid response"));
|
||||||
|
client.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate the JSON document
|
||||||
|
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||||
|
const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60;
|
||||||
|
DynamicJsonDocument doc(capacity);
|
||||||
|
|
||||||
|
// Parse JSON object
|
||||||
|
DeserializationError error = deserializeJson(doc, client);
|
||||||
|
if (error) {
|
||||||
|
Serial.print(F("deserializeJson() failed: "));
|
||||||
|
Serial.println(error.f_str());
|
||||||
|
client.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract values
|
||||||
|
Serial.println(F("Response:"));
|
||||||
|
Serial.println(doc["sensor"].as<const char*>());
|
||||||
|
Serial.println(doc["time"].as<long>());
|
||||||
|
Serial.println(doc["data"][0].as<float>(), 6);
|
||||||
|
Serial.println(doc["data"][1].as<float>(), 6);
|
||||||
|
|
||||||
|
// Disconnect
|
||||||
|
client.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// not used in this example
|
||||||
|
}
|
||||||
|
|
||||||
|
// Performance issue?
|
||||||
|
// ------------------
|
||||||
|
//
|
||||||
|
// EthernetClient is an unbuffered stream, which is not optimal for ArduinoJson.
|
||||||
|
// See: https://arduinojson.org/v6/how-to/improve-speed/
|
||||||
|
|
||||||
|
// See also
|
||||||
|
// --------
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/ contains the documentation for all the functions
|
||||||
|
// used above. It also includes an FAQ that will help you solve any
|
||||||
|
// serialization problem.
|
||||||
|
//
|
||||||
|
// The book "Mastering ArduinoJson" contains a tutorial on deserialization
|
||||||
|
// showing how to parse the response from GitHub's API. In the last chapter,
|
||||||
|
// it shows how to parse the huge documents from OpenWeatherMap
|
||||||
|
// and Reddit.
|
||||||
|
// Learn more at https://arduinojson.org/book/
|
||||||
|
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to deserialize a JSON document with ArduinoJson.
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/parser/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) continue;
|
||||||
|
|
||||||
|
// Allocate the JSON document
|
||||||
|
//
|
||||||
|
// Inside the brackets, 200 is the capacity of the memory pool in bytes.
|
||||||
|
// Don't forget to change this value to match your JSON document.
|
||||||
|
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||||
|
StaticJsonDocument<200> doc;
|
||||||
|
|
||||||
|
// StaticJsonDocument<N> allocates memory on the stack, it can be
|
||||||
|
// replaced by DynamicJsonDocument which allocates in the heap.
|
||||||
|
//
|
||||||
|
// DynamicJsonDocument doc(200);
|
||||||
|
|
||||||
|
// JSON input string.
|
||||||
|
//
|
||||||
|
// Using a char[], as shown here, enables the "zero-copy" mode. This mode uses
|
||||||
|
// the minimal amount of memory because the JsonDocument stores pointers to
|
||||||
|
// the input buffer.
|
||||||
|
// If you use another type of input, ArduinoJson must copy the strings from
|
||||||
|
// the input to the JsonDocument, so you need to increase the capacity of the
|
||||||
|
// JsonDocument.
|
||||||
|
char json[] =
|
||||||
|
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
||||||
|
|
||||||
|
// Deserialize the JSON document
|
||||||
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
|
|
||||||
|
// Test if parsing succeeds.
|
||||||
|
if (error) {
|
||||||
|
Serial.print(F("deserializeJson() failed: "));
|
||||||
|
Serial.println(error.f_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch values.
|
||||||
|
//
|
||||||
|
// Most of the time, you can rely on the implicit casts.
|
||||||
|
// In other case, you can do doc["time"].as<long>();
|
||||||
|
const char* sensor = doc["sensor"];
|
||||||
|
long time = doc["time"];
|
||||||
|
double latitude = doc["data"][0];
|
||||||
|
double longitude = doc["data"][1];
|
||||||
|
|
||||||
|
// Print values.
|
||||||
|
Serial.println(sensor);
|
||||||
|
Serial.println(time);
|
||||||
|
Serial.println(latitude, 6);
|
||||||
|
Serial.println(longitude, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// not used in this example
|
||||||
|
}
|
||||||
|
|
||||||
|
// See also
|
||||||
|
// --------
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/ contains the documentation for all the functions
|
||||||
|
// used above. It also includes an FAQ that will help you solve any
|
||||||
|
// deserialization problem.
|
||||||
|
//
|
||||||
|
// The book "Mastering ArduinoJson" contains a tutorial on deserialization.
|
||||||
|
// It begins with a simple example, like the one above, and then adds more
|
||||||
|
// features like deserializing directly from a file or an HTTP request.
|
||||||
|
// Learn more at https://arduinojson.org/book/
|
||||||
|
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤
|
||||||
@ -0,0 +1,117 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to implement an HTTP server that sends a JSON document
|
||||||
|
// in the response.
|
||||||
|
// It uses the Ethernet library but can be easily adapted for Wifi.
|
||||||
|
//
|
||||||
|
// The JSON document contains the values of the analog and digital pins.
|
||||||
|
// It looks like that:
|
||||||
|
// {
|
||||||
|
// "analog": [0, 76, 123, 158, 192, 205],
|
||||||
|
// "digital": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0]
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/http-server/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <Ethernet.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||||
|
EthernetServer server(80);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) continue;
|
||||||
|
|
||||||
|
// Initialize Ethernet libary
|
||||||
|
if (!Ethernet.begin(mac)) {
|
||||||
|
Serial.println(F("Failed to initialize Ethernet library"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start to listen
|
||||||
|
server.begin();
|
||||||
|
|
||||||
|
Serial.println(F("Server is ready."));
|
||||||
|
Serial.print(F("Please connect to http://"));
|
||||||
|
Serial.println(Ethernet.localIP());
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Wait for an incomming connection
|
||||||
|
EthernetClient client = server.available();
|
||||||
|
|
||||||
|
// Do we have a client?
|
||||||
|
if (!client)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Serial.println(F("New client"));
|
||||||
|
|
||||||
|
// Read the request (we ignore the content in this example)
|
||||||
|
while (client.available()) client.read();
|
||||||
|
|
||||||
|
// Allocate a temporary JsonDocument
|
||||||
|
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||||
|
StaticJsonDocument<500> doc;
|
||||||
|
|
||||||
|
// Create the "analog" array
|
||||||
|
JsonArray analogValues = doc.createNestedArray("analog");
|
||||||
|
for (int pin = 0; pin < 6; pin++) {
|
||||||
|
// Read the analog input
|
||||||
|
int value = analogRead(pin);
|
||||||
|
|
||||||
|
// Add the value at the end of the array
|
||||||
|
analogValues.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the "digital" array
|
||||||
|
JsonArray digitalValues = doc.createNestedArray("digital");
|
||||||
|
for (int pin = 0; pin < 14; pin++) {
|
||||||
|
// Read the digital input
|
||||||
|
int value = digitalRead(pin);
|
||||||
|
|
||||||
|
// Add the value at the end of the array
|
||||||
|
digitalValues.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print(F("Sending: "));
|
||||||
|
serializeJson(doc, Serial);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
// Write response headers
|
||||||
|
client.println(F("HTTP/1.0 200 OK"));
|
||||||
|
client.println(F("Content-Type: application/json"));
|
||||||
|
client.println(F("Connection: close"));
|
||||||
|
client.print(F("Content-Length: "));
|
||||||
|
client.println(measureJsonPretty(doc));
|
||||||
|
client.println();
|
||||||
|
|
||||||
|
// Write JSON document
|
||||||
|
serializeJsonPretty(doc, client);
|
||||||
|
|
||||||
|
// Disconnect
|
||||||
|
client.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Performance issue?
|
||||||
|
// ------------------
|
||||||
|
//
|
||||||
|
// EthernetClient is an unbuffered stream, which is not optimal for ArduinoJson.
|
||||||
|
// See: https://arduinojson.org/v6/how-to/improve-speed/
|
||||||
|
|
||||||
|
// See also
|
||||||
|
// --------
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/ contains the documentation for all the functions
|
||||||
|
// used above. It also includes an FAQ that will help you solve any
|
||||||
|
// serialization problem.
|
||||||
|
//
|
||||||
|
// The book "Mastering ArduinoJson" contains a tutorial on serialization.
|
||||||
|
// It begins with a simple example, then adds more features like serializing
|
||||||
|
// directly to a file or an HTTP client.
|
||||||
|
// Learn more at https://arduinojson.org/book/
|
||||||
|
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to send a JSON document to a UDP socket.
|
||||||
|
// At regular interval, it sends a UDP packet that contains the status of
|
||||||
|
// analog and digital pins.
|
||||||
|
// It looks like that:
|
||||||
|
// {
|
||||||
|
// "analog": [0, 76, 123, 158, 192, 205],
|
||||||
|
// "digital": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0]
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// If you want to test this program, you need to be able to receive the UDP
|
||||||
|
// packets.
|
||||||
|
// For example, you can run netcat on your computer
|
||||||
|
// $ ncat -ulp 8888
|
||||||
|
// See https://nmap.org/ncat/
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/udp-beacon/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <Ethernet.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||||
|
IPAddress remoteIp(192, 168, 0, 108); // <- EDIT!!!!
|
||||||
|
unsigned short remotePort = 8888;
|
||||||
|
unsigned short localPort = 8888;
|
||||||
|
EthernetUDP udp;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) continue;
|
||||||
|
|
||||||
|
// Initialize Ethernet libary
|
||||||
|
if (!Ethernet.begin(mac)) {
|
||||||
|
Serial.println(F("Failed to initialize Ethernet library"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable UDP
|
||||||
|
udp.begin(localPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Allocate a temporary JsonDocument
|
||||||
|
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||||
|
StaticJsonDocument<500> doc;
|
||||||
|
|
||||||
|
// Create the "analog" array
|
||||||
|
JsonArray analogValues = doc.createNestedArray("analog");
|
||||||
|
for (int pin = 0; pin < 6; pin++) {
|
||||||
|
// Read the analog input
|
||||||
|
int value = analogRead(pin);
|
||||||
|
|
||||||
|
// Add the value at the end of the array
|
||||||
|
analogValues.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the "digital" array
|
||||||
|
JsonArray digitalValues = doc.createNestedArray("digital");
|
||||||
|
for (int pin = 0; pin < 14; pin++) {
|
||||||
|
// Read the digital input
|
||||||
|
int value = digitalRead(pin);
|
||||||
|
|
||||||
|
// Add the value at the end of the array
|
||||||
|
digitalValues.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log
|
||||||
|
Serial.print(F("Sending to "));
|
||||||
|
Serial.print(remoteIp);
|
||||||
|
Serial.print(F(" on port "));
|
||||||
|
Serial.println(remotePort);
|
||||||
|
serializeJson(doc, Serial);
|
||||||
|
|
||||||
|
// Send UDP packet
|
||||||
|
udp.beginPacket(remoteIp, remotePort);
|
||||||
|
serializeJson(doc, udp);
|
||||||
|
udp.println();
|
||||||
|
udp.endPacket();
|
||||||
|
|
||||||
|
// Wait
|
||||||
|
delay(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Performance issue?
|
||||||
|
// ------------------
|
||||||
|
//
|
||||||
|
// EthernetUDP is an unbuffered stream, which is not optimal for ArduinoJson.
|
||||||
|
// See: https://arduinojson.org/v6/how-to/improve-speed/
|
||||||
|
|
||||||
|
// See also
|
||||||
|
// --------
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/ contains the documentation for all the functions
|
||||||
|
// used above. It also includes an FAQ that will help you solve any
|
||||||
|
// serialization problem.
|
||||||
|
//
|
||||||
|
// The book "Mastering ArduinoJson" contains a tutorial on serialization.
|
||||||
|
// It begins with a simple example, then adds more features like serializing
|
||||||
|
// directly to a file or any stream.
|
||||||
|
// Learn more at https://arduinojson.org/book/
|
||||||
|
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to deserialize a MessagePack document with
|
||||||
|
// ArduinoJson.
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/msgpack-parser/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) continue;
|
||||||
|
|
||||||
|
// Allocate the JSON document
|
||||||
|
//
|
||||||
|
// Inside the brackets, 200 is the capacity of the memory pool in bytes.
|
||||||
|
// Don't forget to change this value to match your JSON document.
|
||||||
|
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||||
|
StaticJsonDocument<200> doc;
|
||||||
|
|
||||||
|
// StaticJsonObject allocates memory on the stack, it can be
|
||||||
|
// replaced by DynamicJsonObject which allocates in the heap.
|
||||||
|
//
|
||||||
|
// DynamicJsonObject doc(200);
|
||||||
|
|
||||||
|
// MessagePack input string.
|
||||||
|
//
|
||||||
|
// Using a char[], as shown here, enables the "zero-copy" mode. This mode uses
|
||||||
|
// the minimal amount of memory because the JsonDocument stores pointers to
|
||||||
|
// the input buffer.
|
||||||
|
// If you use another type of input, ArduinoJson must copy the strings from
|
||||||
|
// the input to the JsonDocument, so you need to increase the capacity of the
|
||||||
|
// JsonDocument.
|
||||||
|
uint8_t input[] = {131, 166, 115, 101, 110, 115, 111, 114, 163, 103, 112, 115,
|
||||||
|
164, 116, 105, 109, 101, 206, 80, 147, 50, 248, 164, 100,
|
||||||
|
97, 116, 97, 146, 203, 64, 72, 96, 199, 58, 188, 148,
|
||||||
|
112, 203, 64, 2, 106, 146, 230, 33, 49, 169};
|
||||||
|
// This MessagePack document contains:
|
||||||
|
// {
|
||||||
|
// "sensor": "gps",
|
||||||
|
// "time": 1351824120,
|
||||||
|
// "data": [48.75608, 2.302038]
|
||||||
|
// }
|
||||||
|
|
||||||
|
DeserializationError error = deserializeMsgPack(doc, input);
|
||||||
|
|
||||||
|
// Test if parsing succeeded.
|
||||||
|
if (error) {
|
||||||
|
Serial.print("deserializeMsgPack() failed: ");
|
||||||
|
Serial.println(error.f_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch values.
|
||||||
|
//
|
||||||
|
// Most of the time, you can rely on the implicit casts.
|
||||||
|
// In other case, you can do doc["time"].as<long>();
|
||||||
|
const char* sensor = doc["sensor"];
|
||||||
|
long time = doc["time"];
|
||||||
|
double latitude = doc["data"][0];
|
||||||
|
double longitude = doc["data"][1];
|
||||||
|
|
||||||
|
// Print values.
|
||||||
|
Serial.println(sensor);
|
||||||
|
Serial.println(time);
|
||||||
|
Serial.println(latitude, 6);
|
||||||
|
Serial.println(longitude, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// not used in this example
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows the different ways you can use Flash strings with
|
||||||
|
// ArduinoJson.
|
||||||
|
//
|
||||||
|
// Use Flash strings sparingly, because ArduinoJson duplicates them in the
|
||||||
|
// JsonDocument. Prefer plain old char*, as they are more efficient in term of
|
||||||
|
// code size, speed, and memory usage.
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/progmem/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
DynamicJsonDocument doc(1024);
|
||||||
|
|
||||||
|
// You can use a Flash String as your JSON input.
|
||||||
|
// WARNING: the strings in the input will be duplicated in the JsonDocument.
|
||||||
|
deserializeJson(doc, F("{\"sensor\":\"gps\",\"time\":1351824120,"
|
||||||
|
"\"data\":[48.756080,2.302038]}"));
|
||||||
|
|
||||||
|
// You can use a Flash String as a key to get a member from JsonDocument
|
||||||
|
// No duplication is done.
|
||||||
|
long time = doc[F("time")];
|
||||||
|
|
||||||
|
// You can use a Flash String as a key to set a member of a JsonDocument
|
||||||
|
// WARNING: the content of the Flash String will be duplicated in the
|
||||||
|
// JsonDocument.
|
||||||
|
doc[F("time")] = time;
|
||||||
|
|
||||||
|
// You can set a Flash String as the content of a JsonVariant
|
||||||
|
// WARNING: the content of the Flash String will be duplicated in the
|
||||||
|
// JsonDocument.
|
||||||
|
doc["sensor"] = F("gps");
|
||||||
|
|
||||||
|
// It works with serialized() too:
|
||||||
|
doc["sensor"] = serialized(F("\"gps\""));
|
||||||
|
doc["sensor"] = serialized(F("\xA3gps"), 3);
|
||||||
|
|
||||||
|
// You can compare the content of a JsonVariant to a Flash String
|
||||||
|
if (doc["sensor"] == F("gps")) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// not used in this example
|
||||||
|
}
|
||||||
|
|
||||||
|
// See also
|
||||||
|
// --------
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/ contains the documentation for all the functions
|
||||||
|
// used above. It also includes an FAQ that will help you solve any memory
|
||||||
|
// problem.
|
||||||
|
//
|
||||||
|
// The book "Mastering ArduinoJson" contains a quick C++ course that explains
|
||||||
|
// how your microcontroller stores strings in memory. It also tells why you
|
||||||
|
// should not abuse Flash strings with ArduinoJson.
|
||||||
|
// Learn more at https://arduinojson.org/book/
|
||||||
|
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows the different ways you can use String with ArduinoJson.
|
||||||
|
//
|
||||||
|
// Use String objects sparingly, because ArduinoJson duplicates them in the
|
||||||
|
// JsonDocument. Prefer plain old char[], as they are more efficient in term of
|
||||||
|
// code size, speed, and memory usage.
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v6/example/string/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
DynamicJsonDocument doc(1024);
|
||||||
|
|
||||||
|
// You can use a String as your JSON input.
|
||||||
|
// WARNING: the string in the input will be duplicated in the JsonDocument.
|
||||||
|
String input =
|
||||||
|
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
||||||
|
deserializeJson(doc, input);
|
||||||
|
|
||||||
|
// You can use a String as a key to get a member from JsonDocument
|
||||||
|
// No duplication is done.
|
||||||
|
long time = doc[String("time")];
|
||||||
|
|
||||||
|
// You can use a String as a key to set a member of a JsonDocument
|
||||||
|
// WARNING: the content of the String will be duplicated in the JsonDocument.
|
||||||
|
doc[String("time")] = time;
|
||||||
|
|
||||||
|
// You can get the content of a JsonVariant as a String
|
||||||
|
// No duplication is done, at least not in the JsonDocument.
|
||||||
|
String sensor = doc["sensor"];
|
||||||
|
|
||||||
|
// Unfortunately, the following doesn't work (issue #118):
|
||||||
|
// sensor = doc["sensor"]; // <- error "ambiguous overload for 'operator='"
|
||||||
|
// As a workaround, you need to replace by:
|
||||||
|
sensor = doc["sensor"].as<String>();
|
||||||
|
|
||||||
|
// You can set a String as the content of a JsonVariant
|
||||||
|
// WARNING: the content of the String will be duplicated in the JsonDocument.
|
||||||
|
doc["sensor"] = sensor;
|
||||||
|
|
||||||
|
// It works with serialized() too:
|
||||||
|
doc["sensor"] = serialized(sensor);
|
||||||
|
|
||||||
|
// You can also concatenate strings
|
||||||
|
// WARNING: the content of the String will be duplicated in the JsonDocument.
|
||||||
|
doc[String("sen") + "sor"] = String("gp") + "s";
|
||||||
|
|
||||||
|
// You can compare the content of a JsonObject with a String
|
||||||
|
if (doc["sensor"] == sensor) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lastly, you can print the resulting JSON to a String
|
||||||
|
// WARNING: it doesn't replace the content but appends to it
|
||||||
|
String output;
|
||||||
|
serializeJson(doc, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// not used in this example
|
||||||
|
}
|
||||||
|
|
||||||
|
// See also
|
||||||
|
// --------
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/ contains the documentation for all the functions
|
||||||
|
// used above. It also includes an FAQ that will help you solve any problem.
|
||||||
|
//
|
||||||
|
// The book "Mastering ArduinoJson" contains a quick C++ course that explains
|
||||||
|
// how your microcontroller stores strings in memory. On several occasions, it
|
||||||
|
// shows how you can avoid String in your program.
|
||||||
|
// Learn more at https://arduinojson.org/book/
|
||||||
|
// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||||
|
check_required_components("@PROJECT_NAME@")
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||||
|
add_compile_options(
|
||||||
|
-pedantic
|
||||||
|
-Wall
|
||||||
|
-Wcast-align
|
||||||
|
-Wcast-qual
|
||||||
|
-Wconversion
|
||||||
|
-Wctor-dtor-privacy
|
||||||
|
-Wdisabled-optimization
|
||||||
|
-Werror
|
||||||
|
-Wextra
|
||||||
|
-Wformat=2
|
||||||
|
-Winit-self
|
||||||
|
-Wmissing-include-dirs
|
||||||
|
-Wnon-virtual-dtor
|
||||||
|
-Wold-style-cast
|
||||||
|
-Woverloaded-virtual
|
||||||
|
-Wparentheses
|
||||||
|
-Wredundant-decls
|
||||||
|
-Wshadow
|
||||||
|
-Wsign-conversion
|
||||||
|
-Wsign-promo
|
||||||
|
-Wstrict-aliasing
|
||||||
|
-Wundef
|
||||||
|
)
|
||||||
|
|
||||||
|
if(${COVERAGE})
|
||||||
|
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
|
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND(NOT ${COVERAGE}))
|
||||||
|
add_compile_options(-g -Og)
|
||||||
|
else()
|
||||||
|
add_compile_options(-g -O0)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_compile_options(
|
||||||
|
-Wstrict-null-sentinel
|
||||||
|
-Wno-vla # Allow VLA in tests
|
||||||
|
)
|
||||||
|
add_definitions(-DHAS_VARIABLE_LENGTH_ARRAY)
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5)
|
||||||
|
add_compile_options(-Wlogical-op) # the flag exists in 4.4 but is buggy
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
|
||||||
|
add_compile_options(-Wnoexcept)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
add_compile_options(
|
||||||
|
-Wc++11-compat
|
||||||
|
-Wdeprecated-register
|
||||||
|
-Wno-vla-extension # Allow VLA in tests
|
||||||
|
)
|
||||||
|
add_definitions(
|
||||||
|
-DHAS_VARIABLE_LENGTH_ARRAY
|
||||||
|
-DSUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
|
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND(NOT ${COVERAGE}))
|
||||||
|
add_compile_options(-g -Og)
|
||||||
|
else()
|
||||||
|
add_compile_options(-g -O0)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
||||||
|
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND(NOT ${COVERAGE}))
|
||||||
|
add_compile_options(-g -Og)
|
||||||
|
else()
|
||||||
|
add_compile_options(-g -O0)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||||
|
add_compile_options(
|
||||||
|
/W4 # Set warning level
|
||||||
|
/WX # Treats all compiler warnings as errors.
|
||||||
|
/Zc:__cplusplus # Enable updated __cplusplus macro
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MINGW)
|
||||||
|
# Static link on MinGW to avoid linking with the wrong DLLs when multiple
|
||||||
|
# versions are installed.
|
||||||
|
add_link_options(-static)
|
||||||
|
endif()
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
# ArduinoJson - https://arduinojson.org
|
||||||
|
# Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
# MIT License
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(example)
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
# ArduinoJson - https://arduinojson.org
|
||||||
|
# Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
# MIT License
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS "main.cpp"
|
||||||
|
INCLUDE_DIRS ""
|
||||||
|
)
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
#
|
||||||
|
# "main" pseudo-component makefile.
|
||||||
|
#
|
||||||
|
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
extern "C" void app_main() {
|
||||||
|
char buffer[256];
|
||||||
|
StaticJsonDocument<200> doc;
|
||||||
|
|
||||||
|
doc["hello"] = "world";
|
||||||
|
serializeJson(doc, buffer);
|
||||||
|
deserializeJson(doc, buffer);
|
||||||
|
serializeMsgPack(doc, buffer);
|
||||||
|
deserializeMsgPack(doc, buffer);
|
||||||
|
}
|
||||||
10
ESP_Medicine_Indicator/libraries/ArduinoJson/extras/ci/particle.sh
Executable file
10
ESP_Medicine_Indicator/libraries/ArduinoJson/extras/ci/particle.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh -ex
|
||||||
|
|
||||||
|
BOARD=$1
|
||||||
|
|
||||||
|
cd "$(dirname "$0")/../../"
|
||||||
|
|
||||||
|
cp extras/particle/src/smocktest.ino src/
|
||||||
|
cp extras/particle/project.properties ./
|
||||||
|
|
||||||
|
particle compile "$BOARD"
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_ENABLE_PROGMEM == 1, "ARDUINOJSON_ENABLE_PROGMEM");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_LONG_LONG == 0, "ARDUINOJSON_USE_LONG_LONG");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 1,
|
||||||
|
"ARDUINOJSON_SLOT_OFFSET_SIZE");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
|
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 8,
|
||||||
|
"sizeof(VariantSlot)");
|
||||||
|
|
||||||
|
void setup() {}
|
||||||
|
void loop() {}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 2,
|
||||||
|
"ARDUINOJSON_SLOT_OFFSET_SIZE");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
|
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
||||||
|
"sizeof(VariantSlot)");
|
||||||
|
|
||||||
|
void setup() {}
|
||||||
|
void loop() {}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 4,
|
||||||
|
"ARDUINOJSON_SLOT_OFFSET_SIZE");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
|
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 32,
|
||||||
|
"sizeof(VariantSlot)");
|
||||||
|
|
||||||
|
int main() {}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 2,
|
||||||
|
"ARDUINOJSON_SLOT_OFFSET_SIZE");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
|
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
||||||
|
"sizeof(VariantSlot)");
|
||||||
|
|
||||||
|
int main() {}
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
# ArduinoJson - https://arduinojson.org
|
||||||
|
# Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
# MIT License
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(msgpack_reproducer
|
||||||
|
msgpack_fuzzer.cpp
|
||||||
|
reproducer.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(msgpack_reproducer
|
||||||
|
ArduinoJson
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(json_reproducer
|
||||||
|
json_fuzzer.cpp
|
||||||
|
reproducer.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(json_reproducer
|
||||||
|
ArduinoJson
|
||||||
|
)
|
||||||
|
|
||||||
|
macro(add_fuzzer name)
|
||||||
|
set(FUZZER "${name}_fuzzer")
|
||||||
|
set(CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus")
|
||||||
|
set(SEED_CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_seed_corpus")
|
||||||
|
add_executable("${FUZZER}"
|
||||||
|
"${name}_fuzzer.cpp"
|
||||||
|
)
|
||||||
|
target_link_libraries("${FUZZER}"
|
||||||
|
ArduinoJson
|
||||||
|
)
|
||||||
|
set_target_properties("${FUZZER}"
|
||||||
|
PROPERTIES
|
||||||
|
COMPILE_FLAGS "-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
|
||||||
|
LINK_FLAGS "-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(
|
||||||
|
NAME "${FUZZER}"
|
||||||
|
COMMAND "${FUZZER}" "${CORPUS_DIR}" "${SEED_CORPUS_DIR}" -max_total_time=5 -timeout=1
|
||||||
|
)
|
||||||
|
|
||||||
|
set_tests_properties("${FUZZER}"
|
||||||
|
PROPERTIES
|
||||||
|
LABELS "Fuzzing"
|
||||||
|
)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6)
|
||||||
|
add_fuzzer(json)
|
||||||
|
add_fuzzer(msgpack)
|
||||||
|
endif()
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
# CAUTION: this file is invoked by https://github.com/google/oss-fuzz
|
||||||
|
|
||||||
|
CXXFLAGS += -I../../src -DARDUINOJSON_DEBUG=1 -std=c++11
|
||||||
|
|
||||||
|
all: \
|
||||||
|
$(OUT)/json_fuzzer \
|
||||||
|
$(OUT)/json_fuzzer_seed_corpus.zip \
|
||||||
|
$(OUT)/json_fuzzer.options \
|
||||||
|
$(OUT)/msgpack_fuzzer \
|
||||||
|
$(OUT)/msgpack_fuzzer_seed_corpus.zip \
|
||||||
|
$(OUT)/msgpack_fuzzer.options
|
||||||
|
|
||||||
|
$(OUT)/%_fuzzer: %_fuzzer.cpp $(shell find ../../src -type f)
|
||||||
|
$(CXX) $(CXXFLAGS) $< -o$@ $(LIB_FUZZING_ENGINE)
|
||||||
|
|
||||||
|
$(OUT)/%_fuzzer_seed_corpus.zip: %_seed_corpus/*
|
||||||
|
zip -j $@ $?
|
||||||
|
|
||||||
|
$(OUT)/%_fuzzer.options:
|
||||||
|
@echo "[libfuzzer]" > $@
|
||||||
|
@echo "max_len = 256" >> $@
|
||||||
|
@echo "timeout = 10" >> $@
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
DeserializationError error = deserializeJson(doc, data, size);
|
||||||
|
if (!error) {
|
||||||
|
std::string json;
|
||||||
|
serializeJson(doc, json);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
//comment
|
||||||
|
/*comment*/
|
||||||
|
[ //comment
|
||||||
|
/*comment*/"comment"/*comment*/,//comment
|
||||||
|
/*comment*/{//comment
|
||||||
|
/* comment*/"key"//comment
|
||||||
|
: //comment
|
||||||
|
"value"//comment
|
||||||
|
}/*comment*/
|
||||||
|
]//comment
|
||||||
@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
[1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20,[21,[22,[23,[24,[25,[26,[27,[28,[29,[30,[31,[32,[33,[34,[35,[36,[37,[38,[39,[40,[41,[42,[43,[44,[45,[46,[47,[48,[49,[50,[51,[52,[53,[54,[55,[56,[57,[58,[59,[60,[61,[62,[63,[64,[65,[66,[67,[68,[69,[70,[71,[72,[73,[74,[75,[76,[77,[78,[79,[80,[81,[82,[83,[84,[85,[86,[87,[88,[89,[90,[91,[92,[93,[94,[95,[96,[97,[98,[99,[100,[101,[102,[103,[104,[105,[106,[107,[108,[109,[110,[111,[112,[113,[114,[115,[116,[117,[118,[119,[120]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
|
||||||
@ -0,0 +1 @@
|
|||||||
|
9720730739393920739
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
[
|
||||||
|
123,
|
||||||
|
-123,
|
||||||
|
123.456,
|
||||||
|
-123.456,
|
||||||
|
12e34,
|
||||||
|
12e-34,
|
||||||
|
12e+34,
|
||||||
|
12E34,
|
||||||
|
12E-34,
|
||||||
|
12E+34,
|
||||||
|
12.34e56,
|
||||||
|
12.34e-56,
|
||||||
|
12.34e+56,
|
||||||
|
12.34E56,
|
||||||
|
12.34E-56,
|
||||||
|
12.34E+56,
|
||||||
|
NaN,
|
||||||
|
-NaN,
|
||||||
|
+NaN,
|
||||||
|
Infinity,
|
||||||
|
+Infinity,
|
||||||
|
-Infinity
|
||||||
|
]
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
"coord": {
|
||||||
|
"lon": -0.13,
|
||||||
|
"lat": 51.51
|
||||||
|
},
|
||||||
|
"weather": [
|
||||||
|
{
|
||||||
|
"id": 301,
|
||||||
|
"main": "Drizzle",
|
||||||
|
"description": "drizzle",
|
||||||
|
"icon": "09n"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 701,
|
||||||
|
"main": "Mist",
|
||||||
|
"description": "mist",
|
||||||
|
"icon": "50n"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 741,
|
||||||
|
"main": "Fog",
|
||||||
|
"description": "fog",
|
||||||
|
"icon": "50n"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"base": "stations",
|
||||||
|
"main": {
|
||||||
|
"temp": 281.87,
|
||||||
|
"pressure": 1032,
|
||||||
|
"humidity": 100,
|
||||||
|
"temp_min": 281.15,
|
||||||
|
"temp_max": 283.15
|
||||||
|
},
|
||||||
|
"visibility": 2900,
|
||||||
|
"wind": {
|
||||||
|
"speed": 1.5
|
||||||
|
},
|
||||||
|
"clouds": {
|
||||||
|
"all": 90
|
||||||
|
},
|
||||||
|
"dt": 1483820400,
|
||||||
|
"sys": {
|
||||||
|
"type": 1,
|
||||||
|
"id": 5091,
|
||||||
|
"message": 0.0226,
|
||||||
|
"country": "GB",
|
||||||
|
"sunrise": 1483776245,
|
||||||
|
"sunset": 1483805443
|
||||||
|
},
|
||||||
|
"id": 2643743,
|
||||||
|
"name": "London",
|
||||||
|
"cod": 200
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
[
|
||||||
|
"hello",
|
||||||
|
'hello',
|
||||||
|
hello,
|
||||||
|
{"hello":"world"},
|
||||||
|
{'hello':'world'},
|
||||||
|
{hello:world}
|
||||||
|
]
|
||||||
@ -0,0 +1,90 @@
|
|||||||
|
{
|
||||||
|
"response": {
|
||||||
|
"version": "0.1",
|
||||||
|
"termsofService": "http://www.wunderground.com/weather/api/d/terms.html",
|
||||||
|
"features": {
|
||||||
|
"conditions": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"current_observation": {
|
||||||
|
"image": {
|
||||||
|
"url": "http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png",
|
||||||
|
"title": "Weather Underground",
|
||||||
|
"link": "http://www.wunderground.com"
|
||||||
|
},
|
||||||
|
"display_location": {
|
||||||
|
"full": "San Francisco, CA",
|
||||||
|
"city": "San Francisco",
|
||||||
|
"state": "CA",
|
||||||
|
"state_name": "California",
|
||||||
|
"country": "US",
|
||||||
|
"country_iso3166": "US",
|
||||||
|
"zip": "94101",
|
||||||
|
"latitude": "37.77500916",
|
||||||
|
"longitude": "-122.41825867",
|
||||||
|
"elevation": "47.00000000"
|
||||||
|
},
|
||||||
|
"observation_location": {
|
||||||
|
"full": "SOMA - Near Van Ness, San Francisco, California",
|
||||||
|
"city": "SOMA - Near Van Ness, San Francisco",
|
||||||
|
"state": "California",
|
||||||
|
"country": "US",
|
||||||
|
"country_iso3166": "US",
|
||||||
|
"latitude": "37.773285",
|
||||||
|
"longitude": "-122.417725",
|
||||||
|
"elevation": "49 ft"
|
||||||
|
},
|
||||||
|
"estimated": {},
|
||||||
|
"station_id": "KCASANFR58",
|
||||||
|
"observation_time": "Last Updated on June 27, 5:27 PM PDT",
|
||||||
|
"observation_time_rfc822": "Wed, 27 Jun 2012 17:27:13 -0700",
|
||||||
|
"observation_epoch": "1340843233",
|
||||||
|
"local_time_rfc822": "Wed, 27 Jun 2012 17:27:14 -0700",
|
||||||
|
"local_epoch": "1340843234",
|
||||||
|
"local_tz_short": "PDT",
|
||||||
|
"local_tz_long": "America/Los_Angeles",
|
||||||
|
"local_tz_offset": "-0700",
|
||||||
|
"weather": "Partly Cloudy",
|
||||||
|
"temperature_string": "66.3 F (19.1 C)",
|
||||||
|
"temp_f": 66.3,
|
||||||
|
"temp_c": 19.1,
|
||||||
|
"relative_humidity": "65%",
|
||||||
|
"wind_string": "From the NNW at 22.0 MPH Gusting to 28.0 MPH",
|
||||||
|
"wind_dir": "NNW",
|
||||||
|
"wind_degrees": 346,
|
||||||
|
"wind_mph": 22,
|
||||||
|
"wind_gust_mph": "28.0",
|
||||||
|
"wind_kph": 35.4,
|
||||||
|
"wind_gust_kph": "45.1",
|
||||||
|
"pressure_mb": "1013",
|
||||||
|
"pressure_in": "29.93",
|
||||||
|
"pressure_trend": "+",
|
||||||
|
"dewpoint_string": "54 F (12 C)",
|
||||||
|
"dewpoint_f": 54,
|
||||||
|
"dewpoint_c": 12,
|
||||||
|
"heat_index_string": "NA",
|
||||||
|
"heat_index_f": "NA",
|
||||||
|
"heat_index_c": "NA",
|
||||||
|
"windchill_string": "NA",
|
||||||
|
"windchill_f": "NA",
|
||||||
|
"windchill_c": "NA",
|
||||||
|
"feelslike_string": "66.3 F (19.1 C)",
|
||||||
|
"feelslike_f": "66.3",
|
||||||
|
"feelslike_c": "19.1",
|
||||||
|
"visibility_mi": "10.0",
|
||||||
|
"visibility_km": "16.1",
|
||||||
|
"solarradiation": "",
|
||||||
|
"UV": "5",
|
||||||
|
"precip_1hr_string": "0.00 in ( 0 mm)",
|
||||||
|
"precip_1hr_in": "0.00",
|
||||||
|
"precip_1hr_metric": " 0",
|
||||||
|
"precip_today_string": "0.00 in (0 mm)",
|
||||||
|
"precip_today_in": "0.00",
|
||||||
|
"precip_today_metric": "0",
|
||||||
|
"icon": "partlycloudy",
|
||||||
|
"icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
|
||||||
|
"forecast_url": "http://www.wunderground.com/US/CA/San_Francisco.html",
|
||||||
|
"history_url": "http://www.wunderground.com/history/airport/KCASANFR58/2012/6/27/DailyHistory.html",
|
||||||
|
"ob_url": "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=37.773285,-122.417725"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
DeserializationError error = deserializeMsgPack(doc, data, size);
|
||||||
|
if (!error) {
|
||||||
|
std::string json;
|
||||||
|
serializeMsgPack(doc, json);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><EFBFBD>hello<EFBFBD>world
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><EFBFBD>one<01>two
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>hello world
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>@H<><48>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>@ !<21><><EFBFBD>o
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><EFBFBD><EFBFBD>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
Ҷi<EFBFBD>.
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>4Vx<56><78><EFBFBD><EFBFBD>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD><EFBFBD>
|
||||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>
|
||||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>hello
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>09
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>4Vx
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user