Compare commits
4 Commits
228f99c602
...
5d19f4ef74
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d19f4ef74 | |||
| d337fca495 | |||
| afe0b75022 | |||
| 26fced451d |
BIN
CAD/Ventilhalter v1.3mf
Normal file
BIN
CAD/Ventilhalter v1.3mf
Normal file
Binary file not shown.
2914
CAD/Ventilhalter v1.step
Normal file
2914
CAD/Ventilhalter v1.step
Normal file
File diff suppressed because it is too large
Load Diff
3478
CAD/Ventilhalter v2.step
Normal file
3478
CAD/Ventilhalter v2.step
Normal file
File diff suppressed because it is too large
Load Diff
4170
CAD/Ventilhalter v4.step
Normal file
4170
CAD/Ventilhalter v4.step
Normal file
File diff suppressed because it is too large
Load Diff
10
watering/.gitignore
vendored
Normal file
10
watering/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
|
.pioenvs
|
||||||
|
.piolibdeps
|
||||||
|
.clang_complete
|
||||||
|
.gcc-flags.json
|
||||||
|
.pio
|
||||||
10
watering/.vscode/extensions.json
vendored
Normal file
10
watering/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
20
watering/.vscode/settings.json
vendored
Normal file
20
watering/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"array": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"unordered_set": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"regex": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"memory": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
164
watering/data/index.html
Normal file
164
watering/data/index.html
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Simple.css Test Page</title>
|
||||||
|
<link rel="stylesheet" href="simple.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body id="top">
|
||||||
|
<header>
|
||||||
|
<h1>Gartenbewässerung</h1>
|
||||||
|
<p>%HOSTNAME% <mark style="border-color: var(--warn);" id="connectionTxt">Connecting...</mark></p>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
<header>
|
||||||
|
<h1 style="margin-bottom: 1rem;">%NAME_VALVE1%</h1>
|
||||||
|
<mark id="state1" style="border-color: var(--fail);margin-left: 1.2rem;">Unbekannt</mark>
|
||||||
|
</header>
|
||||||
|
<p>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h3 id="hour1" style="margin-bottom: 0.1rem;">--</h3>Std.
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h3 id="min1" style="margin-bottom: 0.1rem;">--</h3>Min.
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h3 id="sec1" style="margin-bottom: 0.1rem;">--</h3>Sek.
|
||||||
|
</td>
|
||||||
|
</table>
|
||||||
|
<button onclick="document.getElementById('dialog-vorn').showModal()">Bewässern</button><button
|
||||||
|
onclick="fetch('/setValve?valve=6&set=close')">Stop</button>
|
||||||
|
</p>
|
||||||
|
<section id="valve2" style="display:none;">
|
||||||
|
<header>
|
||||||
|
<h1 style="margin-bottom: 1rem;">%NAME_VALVE2%</h1>
|
||||||
|
<mark id="state2" style="border-color: var(--fail);margin-left: 1.2rem;">Unbekannt</mark>
|
||||||
|
</header>
|
||||||
|
<p>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h3 id="hour2" style="margin-bottom: 0.1rem;">--</h3>Std.
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h3 id="min2" style="margin-bottom: 0.1rem;">--</h3>Min.
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h3 id="sec2" style="margin-bottom: 0.1rem;">--</h3>Sek.
|
||||||
|
</td>
|
||||||
|
</table>
|
||||||
|
<button onclick="document.getElementById('dialog-trog').showModal()">Bewässern</button><button
|
||||||
|
onclick="fetch('/setValve?valve=1&set=close')">Stop</button>
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
<footer>WEG Wagner 2025
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<dialog id="dialog-vorn">
|
||||||
|
<h2>Timer</h2>
|
||||||
|
<form>
|
||||||
|
<p><strong>Garten vorn:</strong></p>
|
||||||
|
<p><input type="number" id="time1" name="time" min="10" max="120" value="60" /> Minuten</p>
|
||||||
|
<button onclick="sendValve1On()">Start</button>
|
||||||
|
<button>Abbrechen</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
<dialog id="dialog-trog">
|
||||||
|
<h2>Timer</h2>
|
||||||
|
<form>
|
||||||
|
<p><strong>Tröge:</strong></p>
|
||||||
|
<p><input type="number" id="time2" name="time" min="10" max="120" value="60" /> Minuten</p>
|
||||||
|
<button onclick="sendValve2On()">Start</button>
|
||||||
|
<button>Abbrechen</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function sendValve1On() {
|
||||||
|
fetch('/setValve?valve=6&set=open&timer=' + document.getElementById("time1").value);
|
||||||
|
}
|
||||||
|
function sendValve2On() {
|
||||||
|
fetch('/setValve?valve=1&set=open&timer=' + document.getElementById("time2").value);
|
||||||
|
}
|
||||||
|
|
||||||
|
var gateway = `ws://${window.location.hostname}/ws`;
|
||||||
|
var websocket;
|
||||||
|
function initWebSocket() {
|
||||||
|
console.log('Trying to open a WebSocket connection...');
|
||||||
|
websocket = new WebSocket(gateway);
|
||||||
|
websocket.onopen = onOpen;
|
||||||
|
websocket.onclose = onClose;
|
||||||
|
websocket.onmessage = onMessage; // <-- add this line
|
||||||
|
}
|
||||||
|
function onOpen(event) {
|
||||||
|
console.log('Connection opened');
|
||||||
|
document.getElementById("connectionTxt").innerHTML = "Connected";
|
||||||
|
document.getElementById("connectionTxt").style = "border-color: var(--ok);";
|
||||||
|
}
|
||||||
|
|
||||||
|
function onClose(event) {
|
||||||
|
console.log('Connection closed');
|
||||||
|
document.getElementById("connectionTxt").innerHTML = "Not Connected";
|
||||||
|
document.getElementById("connectionTxt").style = "border-color: var(--fail);";
|
||||||
|
setTimeout(initWebSocket, 2000);
|
||||||
|
}
|
||||||
|
function onMessage(event) {
|
||||||
|
var state;
|
||||||
|
let data = JSON.parse(event.data);
|
||||||
|
if(data.hasOwnProperty("numValves")){
|
||||||
|
if(data.numValves == 2){
|
||||||
|
document.getElementById("valve2").style = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(data.timers[6] > 0){
|
||||||
|
hours = Math.floor(data.timers[6]/3600);
|
||||||
|
data.timers[6] = data.timers[6] - hours*3600;
|
||||||
|
mins = Math.floor(data.timers[6]/60);
|
||||||
|
data.timers[6] = data.timers[6] - mins*60;
|
||||||
|
secs = data.timers[6];
|
||||||
|
document.getElementById("hour1").innerHTML = (hours < 10) ?"0"+String(hours):String(hours);
|
||||||
|
document.getElementById("min1").innerHTML = (mins < 10) ?"0"+String(mins):String(mins);
|
||||||
|
document.getElementById("sec1").innerHTML = (secs < 10) ?"0"+String(secs):String(secs);
|
||||||
|
document.getElementById("state1").style = "border-color: var(--warn);margin-left: 1.2rem;";
|
||||||
|
document.getElementById("state1").innerHTML = "Wasser AN";
|
||||||
|
}else{
|
||||||
|
document.getElementById("state1").style = "border-color: var(--ok);margin-left: 1.2rem;";
|
||||||
|
document.getElementById("state1").innerHTML = "Wasser AUS";
|
||||||
|
document.getElementById("hour1").innerHTML = "--";
|
||||||
|
document.getElementById("min1").innerHTML = "--";
|
||||||
|
document.getElementById("sec1").innerHTML = "--";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.timers[1] > 0){
|
||||||
|
hours = Math.floor(data.timers[1]/3600);
|
||||||
|
data.timers[1] = data.timers[1] - hours*3600;
|
||||||
|
mins = Math.floor(data.timers[1]/60);
|
||||||
|
data.timers[1] = data.timers[1] - mins*60;
|
||||||
|
secs = data.timers[1];
|
||||||
|
document.getElementById("hour2").innerHTML = (hours < 10) ?"0"+String(hours):String(hours);
|
||||||
|
document.getElementById("min2").innerHTML = (mins < 10) ?"0"+String(mins):String(mins);
|
||||||
|
document.getElementById("sec2").innerHTML = (secs < 10) ?"0"+String(secs):String(secs);
|
||||||
|
document.getElementById("state2").style = "border-color: var(--warn);margin-left: 1.2rem;";
|
||||||
|
document.getElementById("state2").innerHTML = "Wasser AN";
|
||||||
|
}else{
|
||||||
|
document.getElementById("state2").style = "border-color: var(--ok);margin-left: 1.2rem;";
|
||||||
|
document.getElementById("state2").innerHTML = "Wasser AUS";
|
||||||
|
document.getElementById("hour2").innerHTML = "--";
|
||||||
|
document.getElementById("min2").innerHTML = "--";
|
||||||
|
document.getElementById("sec2").innerHTML = "--";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.addEventListener('load', onLoad);
|
||||||
|
function onLoad(event) {
|
||||||
|
initWebSocket();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
762
watering/data/simple.css
Normal file
762
watering/data/simple.css
Normal file
@ -0,0 +1,762 @@
|
|||||||
|
/* Global variables. */
|
||||||
|
:root {
|
||||||
|
/* Set sans-serif & mono fonts */
|
||||||
|
--sans-font: -apple-system, BlinkMacSystemFont, "Avenir Next", Avenir,
|
||||||
|
"Nimbus Sans L", Roboto, "Noto Sans", "Segoe UI", Arial, Helvetica,
|
||||||
|
"Helvetica Neue", sans-serif;
|
||||||
|
--mono-font: Consolas, Menlo, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
|
||||||
|
--standard-border-radius: 8px;
|
||||||
|
|
||||||
|
/* Default (light) theme */
|
||||||
|
--bg: #fff;
|
||||||
|
--accent-bg: #f5f7ff;
|
||||||
|
--text: #212121;
|
||||||
|
--text-light: #585858;
|
||||||
|
--border: #898EA4;
|
||||||
|
--accent: #0d47a1;
|
||||||
|
--ok: #279c1c;
|
||||||
|
--warn: #f1d323;
|
||||||
|
--fail: #d12e2e;
|
||||||
|
--accent-hover: #1266e2;
|
||||||
|
--accent-text: var(--bg);
|
||||||
|
--code: #d81b60;
|
||||||
|
--preformatted: #444;
|
||||||
|
--marked: #e9c92b;
|
||||||
|
--disabled: #efefef;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dark theme */
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
color-scheme: dark;
|
||||||
|
--bg: #212121;
|
||||||
|
--accent-bg: #2b2b2b;
|
||||||
|
--text: #dcdcdc;
|
||||||
|
--text-light: #ababab;
|
||||||
|
--accent: #113b1e;
|
||||||
|
--ok: #279c1c;
|
||||||
|
--warn: #ddd125;
|
||||||
|
--fail: #ce3030;
|
||||||
|
--accent-hover: #1b5a2f;
|
||||||
|
--accent-text: var(--bg);
|
||||||
|
--code: #f06292;
|
||||||
|
--preformatted: #ccc;
|
||||||
|
--disabled: #111;
|
||||||
|
}
|
||||||
|
/* Add a bit of transparency so light media isn't so glaring in dark mode */
|
||||||
|
img,
|
||||||
|
video {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset box-sizing */
|
||||||
|
*, *::before, *::after {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset default appearance */
|
||||||
|
textarea,
|
||||||
|
select,
|
||||||
|
input,
|
||||||
|
progress {
|
||||||
|
appearance: none;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
-moz-appearance: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
/* Set the font globally */
|
||||||
|
font-family: var(--sans-font);
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make the body a nice central block */
|
||||||
|
body {
|
||||||
|
color: var(--text);
|
||||||
|
background-color: var(--bg);
|
||||||
|
font-size: 1.15rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr min(45rem, 90%) 1fr;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
body > * {
|
||||||
|
grid-column: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make the header bg full width, but the content inline with body */
|
||||||
|
body > header {
|
||||||
|
background-color: var(--accent-bg);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
text-align: center;
|
||||||
|
padding: 0 0.5rem 0.5rem 0.5rem;
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
body > header > *:only-child {
|
||||||
|
margin-block-start: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
body > header h1 {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 1rem auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
body > header p {
|
||||||
|
max-width: 40rem;
|
||||||
|
margin: 1rem auto;
|
||||||
|
}
|
||||||
|
/* Add a little padding to ensure spacing is correct between content and header nav */
|
||||||
|
main {
|
||||||
|
padding-top: 1.5rem;
|
||||||
|
}
|
||||||
|
body > footer {
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding: 0rem 1rem 1.5rem 1rem;
|
||||||
|
color: var(--text-light);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
text-align: center;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Format headers */
|
||||||
|
h1 {
|
||||||
|
font-size: 3rem;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 2.6rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 2rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
font-size: 1.44rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h5 {
|
||||||
|
font-size: 1.15rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h6 {
|
||||||
|
font-size: 0.96rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 1.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prevent long strings from overflowing container */
|
||||||
|
p, h1, h2, h3, h4, h5, h6 {
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fix line height when title wraps */
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3 {
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reduce header size on mobile */
|
||||||
|
@media only screen and (max-width: 720px) {
|
||||||
|
h1 {
|
||||||
|
font-size: 2.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 2.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 1.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Format links & buttons */
|
||||||
|
a,
|
||||||
|
a:visited {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
button,
|
||||||
|
.button,
|
||||||
|
a.button, /* extra specificity to override a */
|
||||||
|
input[type="submit"],
|
||||||
|
input[type="reset"],
|
||||||
|
input[type="button"] {
|
||||||
|
border: 1px solid var(--accent);
|
||||||
|
background-color: var(--accent);
|
||||||
|
color: var(--text);
|
||||||
|
padding: 0.5rem 0.9rem;
|
||||||
|
text-decoration: none;
|
||||||
|
line-height: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button[aria-disabled="true"],
|
||||||
|
input:disabled,
|
||||||
|
textarea:disabled,
|
||||||
|
select:disabled,
|
||||||
|
button[disabled] {
|
||||||
|
cursor: not-allowed;
|
||||||
|
background-color: var(--disabled);
|
||||||
|
border-color: var(--disabled);
|
||||||
|
color: var(--text-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="range"] {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the cursor to '?' on an abbreviation and style the abbreviation to show that there is more information underneath */
|
||||||
|
abbr[title] {
|
||||||
|
cursor: help;
|
||||||
|
text-decoration-line: underline;
|
||||||
|
text-decoration-style: dotted;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:enabled:hover,
|
||||||
|
.button:not([aria-disabled="true"]):hover,
|
||||||
|
input[type="submit"]:enabled:hover,
|
||||||
|
input[type="reset"]:enabled:hover,
|
||||||
|
input[type="button"]:enabled:hover {
|
||||||
|
background-color: var(--accent-hover);
|
||||||
|
border-color: var(--accent-hover);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:focus-visible,
|
||||||
|
button:focus-visible:where(:enabled),
|
||||||
|
input:enabled:focus-visible:where(
|
||||||
|
[type="submit"],
|
||||||
|
[type="reset"],
|
||||||
|
[type="button"]
|
||||||
|
) {
|
||||||
|
outline: 2px solid var(--accent);
|
||||||
|
outline-offset: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Format navigation */
|
||||||
|
header nav {
|
||||||
|
font-size: 1rem;
|
||||||
|
line-height: 2;
|
||||||
|
padding: 1rem 0 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use flexbox to allow items to wrap, as needed */
|
||||||
|
header nav ul,
|
||||||
|
header nav ol {
|
||||||
|
align-content: space-around;
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
list-style-type: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* List items are inline elements, make them behave more like blocks */
|
||||||
|
header nav ul li,
|
||||||
|
header nav ol li {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
header nav a,
|
||||||
|
header nav a:visited {
|
||||||
|
margin: 0 0.5rem 1rem 0.5rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
color: var(--text);
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.1rem 1rem;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
header nav a:hover,
|
||||||
|
header nav a.current,
|
||||||
|
header nav a[aria-current="page"],
|
||||||
|
header nav a[aria-current="true"] {
|
||||||
|
border-color: var(--accent);
|
||||||
|
color: var(--accent);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reduce nav side on mobile */
|
||||||
|
@media only screen and (max-width: 720px) {
|
||||||
|
header nav a {
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
text-decoration: underline;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Consolidate box styling */
|
||||||
|
aside, details, pre, progress {
|
||||||
|
background-color: var(--accent-bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
aside {
|
||||||
|
font-size: 1rem;
|
||||||
|
width: 30%;
|
||||||
|
padding: 0 15px;
|
||||||
|
margin-inline-start: 15px;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
*[dir="rtl"] aside {
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make aside full-width on mobile */
|
||||||
|
@media only screen and (max-width: 720px) {
|
||||||
|
aside {
|
||||||
|
width: 100%;
|
||||||
|
float: none;
|
||||||
|
margin-inline-start: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
article, fieldset, dialog {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
article h2:first-child,
|
||||||
|
section h2:first-child,
|
||||||
|
article h3:first-child,
|
||||||
|
section h3:first-child {
|
||||||
|
margin-top: 0.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
section {
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
padding: 0rem 1rem;
|
||||||
|
margin: 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Don't double separators when chaining sections */
|
||||||
|
section + section,
|
||||||
|
section:first-child {
|
||||||
|
border-top: 0;
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
section + section {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
section:last-child {
|
||||||
|
border-bottom: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
details {
|
||||||
|
padding: 0.7rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary {
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 0.7rem 1rem;
|
||||||
|
margin: -0.7rem -1rem;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
details[open] > summary + * {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
details[open] > summary {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
details[open] > :last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Format tables */
|
||||||
|
table {
|
||||||
|
margin: 1.5rem 0;
|
||||||
|
border-spacing: 20px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
figure > table {
|
||||||
|
width: max-content;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
td,
|
||||||
|
th {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
text-align: center;
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color: var(--accent-bg);
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even) {
|
||||||
|
/* Set every other cell slightly darker. Improves readability. */
|
||||||
|
background-color: var(--accent-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
table caption {
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Format forms */
|
||||||
|
textarea,
|
||||||
|
select,
|
||||||
|
input,
|
||||||
|
button,
|
||||||
|
.button {
|
||||||
|
font-size: inherit;
|
||||||
|
font-family: inherit;
|
||||||
|
padding: 0.5rem;
|
||||||
|
margin: 0 0.5rem 0 0.5rem;
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
box-shadow: none;
|
||||||
|
max-width: 100%;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
textarea,
|
||||||
|
select,
|
||||||
|
input {
|
||||||
|
color: var(--text);
|
||||||
|
background-color: var(--bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
textarea:not([cols]) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add arrow to drop-down */
|
||||||
|
select:not([multiple]) {
|
||||||
|
background-image: linear-gradient(45deg, transparent 49%, var(--text) 51%),
|
||||||
|
linear-gradient(135deg, var(--text) 51%, transparent 49%);
|
||||||
|
background-position: calc(100% - 15px), calc(100% - 10px);
|
||||||
|
background-size: 5px 5px, 5px 5px;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
padding-inline-end: 25px;
|
||||||
|
}
|
||||||
|
*[dir="rtl"] select:not([multiple]) {
|
||||||
|
background-position: 10px, 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* checkbox and radio button style */
|
||||||
|
input[type="checkbox"],
|
||||||
|
input[type="radio"] {
|
||||||
|
vertical-align: middle;
|
||||||
|
position: relative;
|
||||||
|
width: min-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="checkbox"] + label,
|
||||||
|
input[type="radio"] + label {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="radio"] {
|
||||||
|
border-radius: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="checkbox"]:checked,
|
||||||
|
input[type="radio"]:checked {
|
||||||
|
background-color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="checkbox"]:checked::after {
|
||||||
|
/* Creates a rectangle with colored right and bottom borders which is rotated to look like a check mark */
|
||||||
|
content: " ";
|
||||||
|
width: 0.18em;
|
||||||
|
height: 0.32em;
|
||||||
|
border-radius: 0;
|
||||||
|
position: absolute;
|
||||||
|
top: 0.05em;
|
||||||
|
left: 0.17em;
|
||||||
|
background-color: transparent;
|
||||||
|
border-right: solid var(--bg) 0.08em;
|
||||||
|
border-bottom: solid var(--bg) 0.08em;
|
||||||
|
font-size: 1.8em;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
input[type="radio"]:checked::after {
|
||||||
|
/* creates a colored circle for the checked radio button */
|
||||||
|
content: " ";
|
||||||
|
width: 0.25em;
|
||||||
|
height: 0.25em;
|
||||||
|
border-radius: 100%;
|
||||||
|
position: absolute;
|
||||||
|
top: 0.125em;
|
||||||
|
background-color: var(--bg);
|
||||||
|
left: 0.125em;
|
||||||
|
font-size: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Makes input fields wider on smaller screens */
|
||||||
|
@media only screen and (max-width: 720px) {
|
||||||
|
textarea,
|
||||||
|
select,
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a height for color input */
|
||||||
|
input[type="color"] {
|
||||||
|
height: 2.5rem;
|
||||||
|
padding: 0.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* do not show border around file selector button */
|
||||||
|
input[type="file"] {
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Misc body elements */
|
||||||
|
hr {
|
||||||
|
border: none;
|
||||||
|
height: 1px;
|
||||||
|
background: var(--border);
|
||||||
|
margin: 1rem auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
mark {
|
||||||
|
padding: 2px 5px;
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
border: 2px solid var(--marked);
|
||||||
|
background-color: var(--bg);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
mark a {
|
||||||
|
color: #0d47a1;
|
||||||
|
}
|
||||||
|
|
||||||
|
img,
|
||||||
|
video {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
figure {
|
||||||
|
margin: 0;
|
||||||
|
display: block;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
figure > img,
|
||||||
|
figure > picture > img {
|
||||||
|
display: block;
|
||||||
|
margin-inline: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
figcaption {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: var(--text-light);
|
||||||
|
margin-block: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
margin-inline-start: 2rem;
|
||||||
|
margin-inline-end: 0;
|
||||||
|
margin-block: 2rem;
|
||||||
|
padding: 0.4rem 0.8rem;
|
||||||
|
border-inline-start: 0.35rem solid var(--accent);
|
||||||
|
color: var(--text-light);
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
cite {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: var(--text-light);
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
dt {
|
||||||
|
color: var(--text-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use mono font for code elements */
|
||||||
|
code,
|
||||||
|
pre,
|
||||||
|
pre span,
|
||||||
|
kbd,
|
||||||
|
samp {
|
||||||
|
font-family: var(--mono-font);
|
||||||
|
color: var(--code);
|
||||||
|
}
|
||||||
|
|
||||||
|
kbd {
|
||||||
|
color: var(--preformatted);
|
||||||
|
border: 1px solid var(--preformatted);
|
||||||
|
border-bottom: 3px solid var(--preformatted);
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
padding: 0.1rem 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
padding: 1rem 1.4rem;
|
||||||
|
max-width: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
color: var(--preformatted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fix embedded code within pre */
|
||||||
|
pre code {
|
||||||
|
color: var(--preformatted);
|
||||||
|
background: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Progress bars */
|
||||||
|
/* Declarations are repeated because you */
|
||||||
|
/* cannot combine vendor-specific selectors */
|
||||||
|
progress {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
progress:indeterminate {
|
||||||
|
background-color: var(--accent-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
progress::-webkit-progress-bar {
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
background-color: var(--accent-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
progress::-webkit-progress-value {
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
background-color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
progress::-moz-progress-bar {
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
background-color: var(--accent);
|
||||||
|
transition-property: width;
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
progress:indeterminate::-moz-progress-bar {
|
||||||
|
background-color: var(--accent-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog {
|
||||||
|
background-color: var(--bg);
|
||||||
|
max-width: 40rem;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog::backdrop {
|
||||||
|
background-color: var(--bg);
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 720px) {
|
||||||
|
dialog {
|
||||||
|
max-width: calc(100vw - 2rem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Superscript & Subscript */
|
||||||
|
/* Prevent scripts from affecting line-height. */
|
||||||
|
sup, sub {
|
||||||
|
vertical-align: baseline;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
sup {
|
||||||
|
top: -0.4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub {
|
||||||
|
top: 0.3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Classes for notices */
|
||||||
|
.notice {
|
||||||
|
background: var(--accent-bg);
|
||||||
|
border: 2px solid var(--border);
|
||||||
|
border-radius: var(--standard-border-radius);
|
||||||
|
padding: 1.5rem;
|
||||||
|
margin: 2rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print */
|
||||||
|
@media print {
|
||||||
|
@page {
|
||||||
|
margin: 1cm;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
body > header {
|
||||||
|
background-color: unset;
|
||||||
|
}
|
||||||
|
body > header nav,
|
||||||
|
body > footer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
article {
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
a[href^="http"]::after {
|
||||||
|
content: " <" attr(href) ">";
|
||||||
|
}
|
||||||
|
abbr[title]:after {
|
||||||
|
content: " (" attr(title) ")";
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
widows: 3;
|
||||||
|
orphans: 3;
|
||||||
|
}
|
||||||
|
hr {
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
mark {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
pre, table, figure, img, svg {
|
||||||
|
break-inside: avoid;
|
||||||
|
}
|
||||||
|
pre code {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
watering/include/README
Normal file
37
watering/include/README
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
BIN
watering/lib/2024-08-21_1456_V-Markt Immenstadt.pdf
Normal file
BIN
watering/lib/2024-08-21_1456_V-Markt Immenstadt.pdf
Normal file
Binary file not shown.
46
watering/lib/Adafruit_NeoPixel/.github/ISSUE_TEMPLATE.md
vendored
Normal file
46
watering/lib/Adafruit_NeoPixel/.github/ISSUE_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
Thank you for opening an issue on an Adafruit Arduino library repository. To
|
||||||
|
improve the speed of resolution please review the following guidelines and
|
||||||
|
common troubleshooting steps below before creating the issue:
|
||||||
|
|
||||||
|
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
|
||||||
|
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
|
||||||
|
something isn't working as expected. In many cases the problem is a common issue
|
||||||
|
that you will more quickly receive help from the forum community. GitHub issues
|
||||||
|
are meant for known defects in the code. If you don't know if there is a defect
|
||||||
|
in the code then start with troubleshooting on the forum first.
|
||||||
|
|
||||||
|
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
|
||||||
|
check all of the steps and commands to run have been followed. Consult the
|
||||||
|
forum if you're unsure or have questions about steps in a guide/tutorial.
|
||||||
|
|
||||||
|
- **For Arduino projects check these very common issues to ensure they don't apply**:
|
||||||
|
|
||||||
|
- For uploading sketches or communicating with the board make sure you're using
|
||||||
|
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
|
||||||
|
very hard to tell the difference between a data and charge cable! Try using the
|
||||||
|
cable with other devices or swapping to another cable to confirm it is not
|
||||||
|
the problem.
|
||||||
|
|
||||||
|
- **Be sure you are supplying adequate power to the board.** Check the specs of
|
||||||
|
your board and plug in an external power supply. In many cases just
|
||||||
|
plugging a board into your computer is not enough to power it and other
|
||||||
|
peripherals.
|
||||||
|
|
||||||
|
- **Double check all soldering joints and connections.** Flakey connections
|
||||||
|
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
|
||||||
|
|
||||||
|
- **Ensure you are using an official Arduino or Adafruit board.** We can't
|
||||||
|
guarantee a clone board will have the same functionality and work as expected
|
||||||
|
with this code and don't support them.
|
||||||
|
|
||||||
|
If you're sure this issue is a defect in the code and checked the steps above
|
||||||
|
please fill in the following fields to provide enough troubleshooting information.
|
||||||
|
You may delete the guideline and text above to just leave the following details:
|
||||||
|
|
||||||
|
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
|
||||||
|
|
||||||
|
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
|
||||||
|
VERSION HERE**
|
||||||
|
|
||||||
|
- List the steps to reproduce the problem below (if possible attach a sketch or
|
||||||
|
copy the sketch code in too): **LIST REPRO STEPS BELOW**
|
||||||
26
watering/lib/Adafruit_NeoPixel/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
26
watering/lib/Adafruit_NeoPixel/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
|
||||||
|
Before you open the request please review the following guidelines and tips to
|
||||||
|
help it be more easily integrated:
|
||||||
|
|
||||||
|
- **Describe the scope of your change--i.e. what the change does and what parts
|
||||||
|
of the code were modified.** This will help us understand any risks of integrating
|
||||||
|
the code.
|
||||||
|
|
||||||
|
- **Describe any known limitations with your change.** For example if the change
|
||||||
|
doesn't apply to a supported platform of the library please mention it.
|
||||||
|
|
||||||
|
- **Please run any tests or examples that can exercise your modified code.** We
|
||||||
|
strive to not break users of the code and running tests/examples helps with this
|
||||||
|
process.
|
||||||
|
|
||||||
|
Thank you again for contributing! We will try to test and integrate the change
|
||||||
|
as soon as we can, but be aware we have many GitHub repositories to manage and
|
||||||
|
can't immediately respond to every request. There is no need to bump or check in
|
||||||
|
on a pull request (it will clutter the discussion of the request).
|
||||||
|
|
||||||
|
Also don't be worried if the request is closed or not integrated--sometimes the
|
||||||
|
priorities of Adafruit's GitHub code (education, ease of use) might not match the
|
||||||
|
priorities of the pull request. Don't fret, the open source community thrives on
|
||||||
|
forks and GitHub makes it easy to keep your changes in a forked repo.
|
||||||
|
|
||||||
|
After reviewing the guidelines above you can delete this text from the pull request.
|
||||||
29
watering/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml
vendored
Normal file
29
watering/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
name: Arduino Library CI
|
||||||
|
|
||||||
|
on: [pull_request, push, repository_dispatch]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
repository: adafruit/ci-arduino
|
||||||
|
path: ci
|
||||||
|
|
||||||
|
- name: pre-install
|
||||||
|
run: bash ci/actions_install.sh
|
||||||
|
|
||||||
|
- name: test platforms
|
||||||
|
run: python3 ci/build_platform.py main_platforms
|
||||||
|
|
||||||
|
- name: doxygen
|
||||||
|
env:
|
||||||
|
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
|
||||||
|
PRETTYNAME : "Adafruit NeoPixel Library"
|
||||||
|
run: bash ci/doxy_gen_and_deploy.sh
|
||||||
4
watering/lib/Adafruit_NeoPixel/.gitignore
vendored
Normal file
4
watering/lib/Adafruit_NeoPixel/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Our handy .gitignore for automation ease
|
||||||
|
Doxyfile*
|
||||||
|
doxygen_sqlite3.db
|
||||||
|
html
|
||||||
3735
watering/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp
Normal file
3735
watering/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp
Normal file
File diff suppressed because it is too large
Load Diff
421
watering/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h
Normal file
421
watering/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.h
Normal file
@ -0,0 +1,421 @@
|
|||||||
|
/*!
|
||||||
|
* @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};
|
||||||
|
|
||||||
|
/* Declare external methods required by the Adafruit_NeoPixel implementation
|
||||||
|
for specific hardware/library versions
|
||||||
|
*/
|
||||||
|
#if defined(ESP32)
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||||
|
extern "C" void espInit();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@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) || defined(ARDUINO_ARCH_CH32)
|
||||||
|
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
|
||||||
13
watering/lib/Adafruit_NeoPixel/CONTRIBUTING.md
Normal file
13
watering/lib/Adafruit_NeoPixel/CONTRIBUTING.md
Normal file
@ -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
watering/lib/Adafruit_NeoPixel/COPYING
Normal file
165
watering/lib/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
watering/lib/Adafruit_NeoPixel/README.md
Normal file
158
watering/lib/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/)
|
||||||
277
watering/lib/Adafruit_NeoPixel/esp.c
Normal file
277
watering/lib/Adafruit_NeoPixel/esp.c
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
// 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>
|
||||||
|
|
||||||
|
#if defined(ESP_IDF_VERSION)
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
|
||||||
|
#define HAS_ESP_IDF_4
|
||||||
|
#endif
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||||
|
#define HAS_ESP_IDF_5
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAS_ESP_IDF_5
|
||||||
|
|
||||||
|
static SemaphoreHandle_t show_mutex = NULL;
|
||||||
|
|
||||||
|
void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
|
||||||
|
// Note: Because rmtPin is shared between all instances, we will
|
||||||
|
// end up releasing/initializing the RMT channels each time we
|
||||||
|
// invoke on different pins. This is probably ok, just not
|
||||||
|
// efficient. led_data is shared between all instances but will
|
||||||
|
// be allocated with enough space for the largest instance; data
|
||||||
|
// is not used beyond the mutex lock so this should be fine.
|
||||||
|
|
||||||
|
#define SEMAPHORE_TIMEOUT_MS 50
|
||||||
|
|
||||||
|
static rmt_data_t *led_data = NULL;
|
||||||
|
static uint32_t led_data_size = 0;
|
||||||
|
static int rmtPin = -1;
|
||||||
|
|
||||||
|
if (show_mutex && xSemaphoreTake(show_mutex, SEMAPHORE_TIMEOUT_MS / portTICK_PERIOD_MS) == pdTRUE) {
|
||||||
|
uint32_t requiredSize = numBytes * 8;
|
||||||
|
if (requiredSize > led_data_size) {
|
||||||
|
free(led_data);
|
||||||
|
if (led_data = (rmt_data_t *)malloc(requiredSize * sizeof(rmt_data_t))) {
|
||||||
|
led_data_size = requiredSize;
|
||||||
|
} else {
|
||||||
|
led_data_size = 0;
|
||||||
|
}
|
||||||
|
} else if (requiredSize == 0) {
|
||||||
|
// To release RMT resources (RMT channels and led_data), call
|
||||||
|
// .updateLength(0) to set number of pixels/bytes to zero,
|
||||||
|
// then call .show() to invoke this code and free resources.
|
||||||
|
free(led_data);
|
||||||
|
led_data = NULL;
|
||||||
|
if (rmtPin >= 0) {
|
||||||
|
rmtDeinit(rmtPin);
|
||||||
|
rmtPin = -1;
|
||||||
|
}
|
||||||
|
led_data_size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (led_data_size > 0 && requiredSize <= led_data_size) {
|
||||||
|
if (pin != rmtPin) {
|
||||||
|
if (rmtPin >= 0) {
|
||||||
|
rmtDeinit(rmtPin);
|
||||||
|
rmtPin = -1;
|
||||||
|
}
|
||||||
|
if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) {
|
||||||
|
log_e("Failed to init RMT TX mode on pin %d", pin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rmtPin = pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rmtPin >= 0) {
|
||||||
|
int i=0;
|
||||||
|
for (int b=0; b < numBytes; b++) {
|
||||||
|
for (int bit=0; bit<8; bit++){
|
||||||
|
if ( pixels[b] & (1<<(7-bit)) ) {
|
||||||
|
led_data[i].level0 = 1;
|
||||||
|
led_data[i].duration0 = 8;
|
||||||
|
led_data[i].level1 = 0;
|
||||||
|
led_data[i].duration1 = 4;
|
||||||
|
} else {
|
||||||
|
led_data[i].level0 = 1;
|
||||||
|
led_data[i].duration0 = 4;
|
||||||
|
led_data[i].level1 = 0;
|
||||||
|
led_data[i].duration1 = 8;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rmtWrite(pin, led_data, numBytes * 8, RMT_WAIT_FOR_EVER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xSemaphoreGive(show_mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// To avoid race condition initializing the mutex, all instances of
|
||||||
|
// Adafruit_NeoPixel must be constructed before launching and child threads
|
||||||
|
void espInit() {
|
||||||
|
if (!show_mutex) {
|
||||||
|
show_mutex = xSemaphoreCreateMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include "driver/rmt.h"
|
||||||
|
|
||||||
|
|
||||||
|
// 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 // ifndef IDF5
|
||||||
|
|
||||||
|
|
||||||
|
#endif // ifdef(ESP32)
|
||||||
86
watering/lib/Adafruit_NeoPixel/esp8266.c
Normal file
86
watering/lib/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 @@
|
|||||||
|
|
||||||
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
50
watering/lib/Adafruit_NeoPixel/examples/simple/simple.ino
Normal file
50
watering/lib/Adafruit_NeoPixel/examples/simple/simple.ino
Normal file
@ -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 @@
|
|||||||
|
|
||||||
@ -0,0 +1,200 @@
|
|||||||
|
// 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)
|
||||||
|
bool patternComplete = false;
|
||||||
|
|
||||||
|
int pixelInterval = 50; // Pixel Interval (ms)
|
||||||
|
int pixelQueue = 0; // Pattern Pixel Queue
|
||||||
|
int pixelCycle = 0; // Pattern Pixel Cycle
|
||||||
|
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( patternComplete || (currentMillis - patternPrevious) >= patternInterval) { // Check for expired time
|
||||||
|
patternComplete = false;
|
||||||
|
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) {
|
||||||
|
static uint16_t current_pixel = 0;
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
strip.setPixelColor(current_pixel++, color); // Set pixel's color (in RAM)
|
||||||
|
strip.show(); // Update strip to match
|
||||||
|
if(current_pixel >= pixelNumber) { // Loop the pattern from the first LED
|
||||||
|
current_pixel = 0;
|
||||||
|
patternComplete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
static uint32_t loop_count = 0;
|
||||||
|
static uint16_t current_pixel = 0;
|
||||||
|
|
||||||
|
pixelInterval = wait; // Update delay time
|
||||||
|
|
||||||
|
strip.clear();
|
||||||
|
|
||||||
|
for(int c=current_pixel; c < pixelNumber; c += 3) {
|
||||||
|
strip.setPixelColor(c, color);
|
||||||
|
}
|
||||||
|
strip.show();
|
||||||
|
|
||||||
|
current_pixel++;
|
||||||
|
if (current_pixel >= 3) {
|
||||||
|
current_pixel = 0;
|
||||||
|
loop_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loop_count >= 10) {
|
||||||
|
current_pixel = 0;
|
||||||
|
loop_count = 0;
|
||||||
|
patternComplete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
74
watering/lib/Adafruit_NeoPixel/kendyte_k210.c
Normal file
74
watering/lib/Adafruit_NeoPixel/kendyte_k210.c
Normal file
@ -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
|
||||||
72
watering/lib/Adafruit_NeoPixel/keywords.txt
Normal file
72
watering/lib/Adafruit_NeoPixel/keywords.txt
Normal file
@ -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
|
||||||
|
|
||||||
10
watering/lib/Adafruit_NeoPixel/library.properties
Normal file
10
watering/lib/Adafruit_NeoPixel/library.properties
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
name=Adafruit NeoPixel
|
||||||
|
version=1.12.5
|
||||||
|
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
|
||||||
63
watering/lib/Adafruit_NeoPixel/rp2040_pio.h
Normal file
63
watering/lib/Adafruit_NeoPixel/rp2040_pio.h
Normal file
@ -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
|
||||||
12
watering/lib/ArduinoJson/.clang-format
Normal file
12
watering/lib/ArduinoJson/.clang-format
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||||
|
|
||||||
|
BasedOnStyle: Google
|
||||||
|
Standard: c++11
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IndentPPDirectives: AfterHash
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
|
||||||
|
# Always break after if to get accurate coverage
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
2
watering/lib/ArduinoJson/.gitattributes
vendored
Normal file
2
watering/lib/ArduinoJson/.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
* text=auto
|
||||||
|
*.sh text eol=lf
|
||||||
20
watering/lib/ArduinoJson/.gitignore
vendored
Normal file
20
watering/lib/ArduinoJson/.gitignore
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
.DS_Store
|
||||||
|
/.idea
|
||||||
|
/build
|
||||||
|
/bin
|
||||||
|
/lib
|
||||||
|
/sftp-config.json
|
||||||
|
.tags
|
||||||
|
.tags_sorted_by_file
|
||||||
|
/extras/fuzzing/*_fuzzer
|
||||||
|
/extras/fuzzing/*_fuzzer.options
|
||||||
|
/extras/fuzzing/*_fuzzer_seed_corpus.zip
|
||||||
|
.vs/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# Used by CI for Particle
|
||||||
|
/src/*.ino
|
||||||
|
/project.properties
|
||||||
|
|
||||||
|
# Used by IDF
|
||||||
|
/dist/
|
||||||
4
watering/lib/ArduinoJson/.mbedignore
Normal file
4
watering/lib/ArduinoJson/.mbedignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.devcontainer/
|
||||||
|
.github/
|
||||||
|
examples/
|
||||||
|
extras/
|
||||||
1
watering/lib/ArduinoJson/.prettierignore
Normal file
1
watering/lib/ArduinoJson/.prettierignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.md
|
||||||
17
watering/lib/ArduinoJson/.vscode/settings.json
vendored
Normal file
17
watering/lib/ArduinoJson/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||||
|
"git.inputValidationLength": 80,
|
||||||
|
"git.inputValidationSubjectLength": 72,
|
||||||
|
"files.insertFinalNewline": true,
|
||||||
|
"files.trimFinalNewlines": true,
|
||||||
|
"search.exclude": {
|
||||||
|
"/extras/tests/catch/*": true
|
||||||
|
},
|
||||||
|
"C_Cpp.default.includePath": [
|
||||||
|
"/src"
|
||||||
|
],
|
||||||
|
"[cmake]": {
|
||||||
|
"editor.detectIndentation": false,
|
||||||
|
"editor.insertSpaces": false,
|
||||||
|
}
|
||||||
|
}
|
||||||
5
watering/lib/ArduinoJson/ArduinoJson.h
Normal file
5
watering/lib/ArduinoJson/ArduinoJson.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#include "src/ArduinoJson.h"
|
||||||
245
watering/lib/ArduinoJson/CHANGELOG.md
Normal file
245
watering/lib/ArduinoJson/CHANGELOG.md
Normal file
@ -0,0 +1,245 @@
|
|||||||
|
ArduinoJson: change log
|
||||||
|
=======================
|
||||||
|
|
||||||
|
v7.4.0 (2025-04-09)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Optimize storage of tiny strings (up to 3 characters)
|
||||||
|
* Fix support for `const char[]` (issue #2166)
|
||||||
|
|
||||||
|
v7.3.1 (2025-02-27)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Fix conversion from static string to number
|
||||||
|
* Slightly reduce code size
|
||||||
|
|
||||||
|
v7.3.0 (2024-12-29)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Fix support for NUL characters in `deserializeJson()`
|
||||||
|
* Make `ElementProxy` and `MemberProxy` non-copyable
|
||||||
|
* Change string copy policy: only string literal are stored by pointer
|
||||||
|
* `JsonString` is now stored by copy, unless specified otherwise
|
||||||
|
* Replace undocumented `JsonString::Ownership` with `bool`
|
||||||
|
* Rename undocumented `JsonString::isLinked()` to `isStatic()`
|
||||||
|
* Move public facing SFINAEs to template declarations
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> In previous versions, `MemberProxy` (the class returned by `operator[]`) could lead to dangling pointers when used with a temporary string.
|
||||||
|
> To prevent this issue, `MemberProxy` and `ElementProxy` are now non-copyable.
|
||||||
|
>
|
||||||
|
> Your code is likely to be affected if you use `auto` to store the result of `operator[]`. For example, the following line won't compile anymore:
|
||||||
|
>
|
||||||
|
> ```cpp
|
||||||
|
> auto value = doc["key"];
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> To fix the issue, you must append either `.as<T>()` or `.to<T>()`, depending on the situation.
|
||||||
|
>
|
||||||
|
> For example, if you are extracting values from a JSON document, you should update like this:
|
||||||
|
>
|
||||||
|
> ```diff
|
||||||
|
> - auto config = doc["config"];
|
||||||
|
> + auto config = doc["config"].as<JsonObject>();
|
||||||
|
> const char* name = config["name"];
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> However, if you are building a JSON document, you should update like this:
|
||||||
|
>
|
||||||
|
> ```diff
|
||||||
|
> - auto config = doc["config"];
|
||||||
|
> + auto config = doc["config"].to<JsonObject>();
|
||||||
|
> config["name"] = "ArduinoJson";
|
||||||
|
> ```
|
||||||
|
|
||||||
|
v7.2.1 (2024-11-15)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Forbid `deserializeJson(JsonArray|JsonObject, ...)` (issue #2135)
|
||||||
|
* Fix VLA support in `JsonDocument::set()`
|
||||||
|
* Fix `operator[](variant)` ignoring NUL characters
|
||||||
|
|
||||||
|
v7.2.0 (2024-09-18)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Store object members with two slots: one for the key and one for the value
|
||||||
|
* Store 64-bit numbers (`double` and `long long`) in an additional slot
|
||||||
|
* Reduce the slot size (see table below)
|
||||||
|
* Improve message when user forgets third arg of `serializeJson()` et al.
|
||||||
|
* Set `ARDUINOJSON_USE_DOUBLE` to `0` by default on 8-bit architectures
|
||||||
|
* Deprecate `containsKey()` in favor of `doc["key"].is<T>()`
|
||||||
|
* Add support for escape sequence `\'` (issue #2124)
|
||||||
|
|
||||||
|
| Architecture | before | after |
|
||||||
|
|--------------|----------|----------|
|
||||||
|
| 8-bit | 8 bytes | 6 bytes |
|
||||||
|
| 32-bit | 16 bytes | 8 bytes |
|
||||||
|
| 64-bit | 24 bytes | 16 bytes |
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> After being on the death row for years, the `containsKey()` method has finally been deprecated.
|
||||||
|
> You should replace `doc.containsKey("key")` with `doc["key"].is<T>()`, which not only checks that the key exists but also that the value is of the expected type.
|
||||||
|
>
|
||||||
|
> ```cpp
|
||||||
|
> // Before
|
||||||
|
> if (doc.containsKey("value")) {
|
||||||
|
> int value = doc["value"];
|
||||||
|
> // ...
|
||||||
|
> }
|
||||||
|
>
|
||||||
|
> // After
|
||||||
|
> if (doc["value"].is<int>()) {
|
||||||
|
> int value = doc["value"];
|
||||||
|
> // ...
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
|
||||||
|
v7.1.0 (2024-06-27)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Add `ARDUINOJSON_STRING_LENGTH_SIZE` to the namespace name
|
||||||
|
* Add support for MsgPack binary (PR #2078 by @Sanae6)
|
||||||
|
* Add support for MsgPack extension
|
||||||
|
* Make string support even more generic (PR #2084 by @d-a-v)
|
||||||
|
* Optimize `deserializeMsgPack()`
|
||||||
|
* Allow using a `JsonVariant` as a key or index (issue #2080)
|
||||||
|
Note: works only for reading, not for writing
|
||||||
|
* Support `ElementProxy` and `MemberProxy` in `JsonDocument`'s constructor
|
||||||
|
* Don't add partial objects when allocation fails (issue #2081)
|
||||||
|
* Read MsgPack's 64-bit integers even if `ARDUINOJSON_USE_LONG_LONG` is `0`
|
||||||
|
(they are set to `null` if they don't fit in a `long`)
|
||||||
|
|
||||||
|
v7.0.4 (2024-03-12)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Make `JSON_STRING_SIZE(N)` return `N+1` to fix third-party code (issue #2054)
|
||||||
|
|
||||||
|
v7.0.3 (2024-02-05)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Improve error messages when using `char` or `char*` (issue #2043)
|
||||||
|
* Reduce stack consumption (issue #2046)
|
||||||
|
* Fix compatibility with GCC 4.8 (issue #2045)
|
||||||
|
|
||||||
|
v7.0.2 (2024-01-19)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Fix assertion `poolIndex < count_` after `JsonDocument::clear()` (issue #2034)
|
||||||
|
|
||||||
|
v7.0.1 (2024-01-10)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Fix "no matching function" with `JsonObjectConst::operator[]` (issue #2019)
|
||||||
|
* Remove unused files in the PlatformIO package
|
||||||
|
* Fix `volatile bool` serialized as `1` or `0` instead of `true` or `false` (issue #2029)
|
||||||
|
|
||||||
|
v7.0.0 (2024-01-03)
|
||||||
|
------
|
||||||
|
|
||||||
|
* Remove `BasicJsonDocument`
|
||||||
|
* Remove `StaticJsonDocument`
|
||||||
|
* Add abstract `Allocator` class
|
||||||
|
* Merge `DynamicJsonDocument` with `JsonDocument`
|
||||||
|
* Remove `JSON_ARRAY_SIZE()`, `JSON_OBJECT_SIZE()`, and `JSON_STRING_SIZE()`
|
||||||
|
* Remove `ARDUINOJSON_ENABLE_STRING_DEDUPLICATION` (string deduplication cannot be disabled anymore)
|
||||||
|
* Remove `JsonDocument::capacity()`
|
||||||
|
* Store the strings in the heap
|
||||||
|
* Reference-count shared strings
|
||||||
|
* Always store `serialized("string")` by copy (#1915)
|
||||||
|
* Remove the zero-copy mode of `deserializeJson()` and `deserializeMsgPack()`
|
||||||
|
* Fix double lookup in `to<JsonVariant>()`
|
||||||
|
* Fix double call to `size()` in `serializeMsgPack()`
|
||||||
|
* Include `ARDUINOJSON_SLOT_OFFSET_SIZE` in the namespace name
|
||||||
|
* Remove `JsonVariant::shallowCopy()`
|
||||||
|
* `JsonDocument`'s capacity grows as needed, no need to pass it to the constructor anymore
|
||||||
|
* `JsonDocument`'s allocator is not monotonic anymore, removed values get recycled
|
||||||
|
* Show a link to the documentation when user passes an unsupported input type
|
||||||
|
* Remove `JsonDocument::memoryUsage()`
|
||||||
|
* Remove `JsonDocument::garbageCollect()`
|
||||||
|
* Add `deserializeJson(JsonVariant, ...)` and `deserializeMsgPack(JsonVariant, ...)` (#1226)
|
||||||
|
* Call `shrinkToFit()` in `deserializeJson()` and `deserializeMsgPack()`
|
||||||
|
* `serializeJson()` and `serializeMsgPack()` replace the content of `std::string` and `String` instead of appending to it
|
||||||
|
* Replace `add()` with `add<T>()` (`add(T)` is still supported)
|
||||||
|
* Remove `createNestedArray()` and `createNestedObject()` (use `to<JsonArray>()` and `to<JsonObject>()` instead)
|
||||||
|
|
||||||
|
> ### BREAKING CHANGES
|
||||||
|
>
|
||||||
|
> As every major release, ArduinoJson 7 introduces several breaking changes.
|
||||||
|
> I added some stubs so that most existing programs should compile, but I highty recommend you upgrade your code.
|
||||||
|
>
|
||||||
|
> #### `JsonDocument`
|
||||||
|
>
|
||||||
|
> In ArduinoJson 6, you could allocate the memory pool on the stack (with `StaticJsonDocument`) or in the heap (with `DynamicJsonDocument`).
|
||||||
|
> In ArduinoJson 7, the memory pool is always allocated in the heap, so `StaticJsonDocument` and `DynamicJsonDocument` have been merged into `JsonDocument`.
|
||||||
|
>
|
||||||
|
> In ArduinoJson 6, `JsonDocument` had a fixed capacity; in ArduinoJson 7, it has an elastic capacity that grows as needed.
|
||||||
|
> Therefore, you don't need to specify the capacity anymore, so the macros `JSON_ARRAY_SIZE()`, `JSON_OBJECT_SIZE()`, and `JSON_STRING_SIZE()` have been removed.
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> // ArduinoJson 6
|
||||||
|
> StaticJsonDocument<256> doc;
|
||||||
|
> // or
|
||||||
|
> DynamicJsonDocument doc(256);
|
||||||
|
>
|
||||||
|
> // ArduinoJson 7
|
||||||
|
> JsonDocument doc;
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> In ArduinoJson 7, `JsonDocument` reuses released memory, so `garbageCollect()` has been removed.
|
||||||
|
> `shrinkToFit()` is still available and releases the over-allocated memory.
|
||||||
|
>
|
||||||
|
> Due to a change in the implementation, it's not possible to store a pointer to a variant from another `JsonDocument`, so `shallowCopy()` has been removed.
|
||||||
|
>
|
||||||
|
> In ArduinoJson 6, the meaning of `memoryUsage()` was clear: it returned the number of bytes used in the memory pool.
|
||||||
|
> In ArduinoJson 7, the meaning of `memoryUsage()` would be ambiguous, so it has been removed.
|
||||||
|
>
|
||||||
|
> #### Custom allocators
|
||||||
|
>
|
||||||
|
> In ArduinoJson 6, you could specify a custom allocator class as a template parameter of `BasicJsonDocument`.
|
||||||
|
> In ArduinoJson 7, you must inherit from `ArduinoJson::Allocator` and pass a pointer to an instance of your class to the constructor of `JsonDocument`.
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> // ArduinoJson 6
|
||||||
|
> class MyAllocator {
|
||||||
|
> // ...
|
||||||
|
> };
|
||||||
|
> BasicJsonDocument<MyAllocator> doc(256);
|
||||||
|
>
|
||||||
|
> // ArduinoJson 7
|
||||||
|
> class MyAllocator : public ArduinoJson::Allocator {
|
||||||
|
> // ...
|
||||||
|
> };
|
||||||
|
> MyAllocator myAllocator;
|
||||||
|
> JsonDocument doc(&myAllocator);
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> #### `createNestedArray()` and `createNestedObject()`
|
||||||
|
>
|
||||||
|
> In ArduinoJson 6, you could create a nested array or object with `createNestedArray()` and `createNestedObject()`.
|
||||||
|
> In ArduinoJson 7, you must use `add<T>()` or `to<T>()` instead.
|
||||||
|
>
|
||||||
|
> For example, to create `[[],{}]`, you would write:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> // ArduinoJson 6
|
||||||
|
> arr.createNestedArray();
|
||||||
|
> arr.createNestedObject();
|
||||||
|
>
|
||||||
|
> // ArduinoJson 7
|
||||||
|
> arr.add<JsonArray>();
|
||||||
|
> arr.add<JsonObject>();
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> And to create `{"array":[],"object":{}}`, you would write:
|
||||||
|
>
|
||||||
|
> ```c++
|
||||||
|
> // ArduinoJson 6
|
||||||
|
> obj.createNestedArray("array");
|
||||||
|
> obj.createNestedObject("object");
|
||||||
|
>
|
||||||
|
> // ArduinoJson 7
|
||||||
|
> obj["array"].to<JsonArray>();
|
||||||
|
> obj["object"].to<JsonObject>();
|
||||||
|
> ```
|
||||||
25
watering/lib/ArduinoJson/CMakeLists.txt
Normal file
25
watering/lib/ArduinoJson/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# ArduinoJson - https://arduinojson.org
|
||||||
|
# Copyright © 2014-2025, 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 7.4.0)
|
||||||
|
|
||||||
|
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
watering/lib/ArduinoJson/CONTRIBUTING.md
Normal file
10
watering/lib/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
watering/lib/ArduinoJson/LICENSE.txt
Normal file
10
watering/lib/ArduinoJson/LICENSE.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
Copyright © 2014-2025, 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.
|
||||||
158
watering/lib/ArduinoJson/README.md
Normal file
158
watering/lib/ArduinoJson/README.md
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
<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%3A7.x)
|
||||||
|
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.x)
|
||||||
|
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||||
|
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x)
|
||||||
|
[](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/v7/api/json/deserializejson/)
|
||||||
|
* [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v7/api/config/decode_unicode/)
|
||||||
|
* [Optionally supports comments in the input](https://arduinojson.org/v7/api/config/enable_comments/)
|
||||||
|
* [Optionally filters the input to keep only desired values](https://arduinojson.org/v7/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/v7/api/json/serializejson/)
|
||||||
|
* [Can write to a buffer or a stream](https://arduinojson.org/v7/api/json/serializejson/)
|
||||||
|
* [Optionally indents the document (prettified JSON)](https://arduinojson.org/v7/api/json/serializejsonpretty/)
|
||||||
|
* [MessagePack serialization](https://arduinojson.org/v7/api/msgpack/serializemsgpack/)
|
||||||
|
* [MessagePack deserialization](https://arduinojson.org/v7/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/)
|
||||||
|
* [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/v7/how-to/use-external-ram-on-esp32/)
|
||||||
|
* Supports [`String`](https://arduinojson.org/v7/api/config/enable_arduino_string/), [`std::string`](https://arduinojson.org/v7/api/config/enable_std_string/), and [`std::string_view`](https://arduinojson.org/v7/api/config/enable_string_view/)
|
||||||
|
* Supports [`Stream`](https://arduinojson.org/v7/api/config/enable_arduino_stream/) and [`std::istream`/`std::ostream`](https://arduinojson.org/v7/api/config/enable_std_stream/)
|
||||||
|
* Supports [Flash strings](https://arduinojson.org/v7/api/config/enable_progmem/)
|
||||||
|
* Supports [custom readers](https://arduinojson.org/v7/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v7/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/v7/how-to/use-arduinojson-with-cmake/)
|
||||||
|
* Well designed
|
||||||
|
* [Elegant API](http://arduinojson.org/v7/example/)
|
||||||
|
* [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety)
|
||||||
|
* Self-contained (no external dependency)
|
||||||
|
* `const` friendly
|
||||||
|
* [`for` friendly](https://arduinojson.org/v7/api/jsonobject/begin_end/)
|
||||||
|
* [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming)
|
||||||
|
* Handles [integer overflows](https://arduinojson.org/v7/api/jsonvariant/as/#integer-overflows)
|
||||||
|
* Well tested
|
||||||
|
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x)
|
||||||
|
* Continuously tested on
|
||||||
|
* [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.x)
|
||||||
|
* [GCC 4.8, 5, 6, 7, 8, 9, 10, 11, 12](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||||
|
* [Clang 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10, 11, 12, 13, 14, 15](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/v7/doc/deserialization/)
|
||||||
|
* [Examples](https://arduinojson.org/v7/example/)
|
||||||
|
* [How-tos](https://arduinojson.org/v7/example/)
|
||||||
|
* [FAQ](https://arduinojson.org/v7/faq/)
|
||||||
|
* [Troubleshooter](https://arduinojson.org/v7/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++
|
||||||
|
const char* json = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
||||||
|
|
||||||
|
JsonDocument doc;
|
||||||
|
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/v7/doc/deserialization/)
|
||||||
|
|
||||||
|
### Serialization
|
||||||
|
|
||||||
|
Here is a program that generates a JSON document with ArduinoJson:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
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/v7/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>
|
||||||
|
<a href="https://github.com/LArkema" rel="sponsored">
|
||||||
|
<img alt="LArkema" src="https://avatars.githubusercontent.com/u/38381313?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
watering/lib/ArduinoJson/SUPPORT.md
Normal file
27
watering/lib/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
watering/lib/ArduinoJson/appveyor.yml
Normal file
28
watering/lib/ArduinoJson/appveyor.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
version: 7.4.0.{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 .
|
||||||
1
watering/lib/ArduinoJson/component.mk
Normal file
1
watering/lib/ArduinoJson/component.mk
Normal file
@ -0,0 +1 @@
|
|||||||
|
COMPONENT_ADD_INCLUDEDIRS := src
|
||||||
@ -0,0 +1,152 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, 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/v7/example/config/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <SD.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
// Our configuration structure.
|
||||||
|
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
|
||||||
|
JsonDocument 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
|
||||||
|
JsonDocument 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/v7/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,64 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to use DeserializationOption::Filter
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v7/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
|
||||||
|
JsonDocument filter;
|
||||||
|
filter["list"][0]["dt"] = true;
|
||||||
|
filter["list"][0]["main"]["temp"] = true;
|
||||||
|
|
||||||
|
// Deserialize the document
|
||||||
|
JsonDocument 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,65 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to generate a JSON document with ArduinoJson.
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v7/example/generator/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize Serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Allocate the JSON document
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
// Add values in the document
|
||||||
|
doc["sensor"] = "gps";
|
||||||
|
doc["time"] = 1351824120;
|
||||||
|
|
||||||
|
// Add an array
|
||||||
|
JsonArray data = doc["data"].to<JsonArray>();
|
||||||
|
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,125 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, 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/v7/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
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
// 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/v7/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,65 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to deserialize a JSON document with ArduinoJson.
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v7/example/parser/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Allocate the JSON document
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
// JSON input string.
|
||||||
|
const 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 the 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 the 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 ❤❤❤❤❤
|
||||||
118
watering/lib/ArduinoJson/examples/JsonServer/JsonServer.ino
Normal file
118
watering/lib/ArduinoJson/examples/JsonServer/JsonServer.ino
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, 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/v7/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
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
// Create the "analog" array
|
||||||
|
JsonArray analogValues = doc["analog"].to<JsonArray>();
|
||||||
|
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["digital"].to<JsonArray>();
|
||||||
|
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/v7/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-2025, 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/v7/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
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
// Create the "analog" array
|
||||||
|
JsonArray analogValues = doc["analog"].to<JsonArray>();
|
||||||
|
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["digital"].to<JsonArray>();
|
||||||
|
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/v7/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,61 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// This example shows how to deserialize a MessagePack document with
|
||||||
|
// ArduinoJson.
|
||||||
|
//
|
||||||
|
// https://arduinojson.org/v7/example/msgpack-parser/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize serial port
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Allocate the JSON document
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
// The MessagePack input string
|
||||||
|
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]
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Parse the input
|
||||||
|
DeserializationError error = deserializeMsgPack(doc, input);
|
||||||
|
|
||||||
|
// Test if parsing succeeded
|
||||||
|
if (error) {
|
||||||
|
Serial.print("deserializeMsgPack() failed: ");
|
||||||
|
Serial.println(error.f_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the 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 the 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-2025, 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/v7/example/progmem/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
// 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,76 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, 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/v7/example/string/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
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@")
|
||||||
112
watering/lib/ArduinoJson/extras/CompileOptions.cmake
Normal file
112
watering/lib/ArduinoJson/extras/CompileOptions.cmake
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
if(NOT DEFINED COVERAGE)
|
||||||
|
set(COVERAGE OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
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.9) AND(NOT ${COVERAGE}))
|
||||||
|
add_compile_options(-g -Og)
|
||||||
|
else() # GCC 4.8
|
||||||
|
add_compile_options(
|
||||||
|
-g
|
||||||
|
-O0 # GCC 4.8 doesn't support -Og
|
||||||
|
-Wno-shadow # allow the same name for a function parameter and a member functions
|
||||||
|
-Wp,-w # Disable preprocessing warnings (see below)
|
||||||
|
)
|
||||||
|
# GCC 4.8 doesn't support __has_include, so we need to help him
|
||||||
|
add_definitions(
|
||||||
|
-DARDUINOJSON_ENABLE_STD_STRING=1
|
||||||
|
-DARDUINOJSON_ENABLE_STD_STREAM=1
|
||||||
|
)
|
||||||
|
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")
|
||||||
|
add_compile_options(-stdlib=libc++)
|
||||||
|
link_libraries(c++ m)
|
||||||
|
|
||||||
|
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()
|
||||||
8
watering/lib/ArduinoJson/extras/ci/espidf/CMakeLists.txt
Normal file
8
watering/lib/ArduinoJson/extras/ci/espidf/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# ArduinoJson - https://arduinojson.org
|
||||||
|
# Copyright © 2014-2025, 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-2025, 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.)
|
||||||
16
watering/lib/ArduinoJson/extras/ci/espidf/main/main.cpp
Normal file
16
watering/lib/ArduinoJson/extras/ci/espidf/main/main.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2025, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
extern "C" void app_main() {
|
||||||
|
char buffer[256];
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
doc["hello"] = "world";
|
||||||
|
serializeJson(doc, buffer);
|
||||||
|
deserializeJson(doc, buffer);
|
||||||
|
serializeMsgPack(doc, buffer);
|
||||||
|
deserializeMsgPack(doc, buffer);
|
||||||
|
}
|
||||||
10
watering/lib/ArduinoJson/extras/ci/particle.sh
Normal file
10
watering/lib/ArduinoJson/extras/ci/particle.sh
Normal 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"
|
||||||
18
watering/lib/ArduinoJson/extras/conf_test/avr.cpp
Normal file
18
watering/lib/ArduinoJson/extras/conf_test/avr.cpp
Normal file
@ -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_ID_SIZE == 1, "ARDUINOJSON_SLOT_ID_SIZE");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_POOL_CAPACITY == 16, "ARDUINOJSON_POOL_CAPACITY");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_DOUBLE == 0, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
|
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 6, "slot size");
|
||||||
|
|
||||||
|
void setup() {}
|
||||||
|
void loop() {}
|
||||||
16
watering/lib/ArduinoJson/extras/conf_test/esp8266.cpp
Normal file
16
watering/lib/ArduinoJson/extras/conf_test/esp8266.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_SLOT_ID_SIZE == 2, "ARDUINOJSON_SLOT_ID_SIZE");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_POOL_CAPACITY == 128, "ARDUINOJSON_POOL_CAPACITY");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
|
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 8, "slot size");
|
||||||
|
|
||||||
|
void setup() {}
|
||||||
|
void loop() {}
|
||||||
16
watering/lib/ArduinoJson/extras/conf_test/x64.cpp
Normal file
16
watering/lib/ArduinoJson/extras/conf_test/x64.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_SLOT_ID_SIZE == 4, "ARDUINOJSON_SLOT_ID_SIZE");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_POOL_CAPACITY == 256, "ARDUINOJSON_POOL_CAPACITY");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
|
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 16,
|
||||||
|
"slot size");
|
||||||
|
|
||||||
|
int main() {}
|
||||||
15
watering/lib/ArduinoJson/extras/conf_test/x86.cpp
Normal file
15
watering/lib/ArduinoJson/extras/conf_test/x86.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_SLOT_ID_SIZE == 2, "ARDUINOJSON_SLOT_ID_SIZE");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_POOL_CAPACITY == 128, "ARDUINOJSON_POOL_CAPACITY");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
|
||||||
|
|
||||||
|
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||||
|
|
||||||
|
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 8, "slot size");
|
||||||
|
|
||||||
|
int main() {}
|
||||||
67
watering/lib/ArduinoJson/extras/fuzzing/CMakeLists.txt
Normal file
67
watering/lib/ArduinoJson/extras/fuzzing/CMakeLists.txt
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# ArduinoJson - https://arduinojson.org
|
||||||
|
# Copyright © 2014-2025, 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()
|
||||||
|
|
||||||
|
# Needs Clang 6+ to compile
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6)
|
||||||
|
if(DEFINED ENV{GITHUB_ACTIONS} AND CMAKE_CXX_COMPILER_VERSION MATCHES "^11\\.")
|
||||||
|
# Clang 11 fails on GitHub Actions with the following error:
|
||||||
|
# > ERROR: UndefinedBehaviorSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
|
||||||
|
# > Sanitizer CHECK failed: /build/llvm-toolchain-11-mnvtwk/llvm-toolchain-11-11.1.0/compiler-rt/lib/sanitizer_common/sanitizer_common.cpp:54 ((0 && "unable to mmap")) != (0) (0, 0)
|
||||||
|
message(WARNING "Fuzzing is disabled on GitHub Actions to workaround a bug in Clang 11")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_fuzzer(json)
|
||||||
|
add_fuzzer(msgpack)
|
||||||
|
endif()
|
||||||
22
watering/lib/ArduinoJson/extras/fuzzing/Makefile
Normal file
22
watering/lib/ArduinoJson/extras/fuzzing/Makefile
Normal file
@ -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" >> $@
|
||||||
2
watering/lib/ArduinoJson/extras/fuzzing/json_corpus/.gitignore
vendored
Normal file
2
watering/lib/ArduinoJson/extras/fuzzing/json_corpus/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
11
watering/lib/ArduinoJson/extras/fuzzing/json_fuzzer.cpp
Normal file
11
watering/lib/ArduinoJson/extras/fuzzing/json_fuzzer.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||||
|
JsonDocument doc;
|
||||||
|
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
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user