-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathESPixelStick.h
173 lines (149 loc) · 4.78 KB
/
ESPixelStick.h
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma once
/*
* ESPixelStick.h
*
* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
* Copyright (c) 2016, 2022 Shelby Merrick
* http://www.forkineye.com
*
* This program is provided free for you to use in any way that you wish,
* subject to the laws and regulations where you are using it. Due diligence
* is strongly suggested before using this code. Please give credit where due.
*
* The Author makes no warranty of any kind, express or implied, with regard
* to this program or the documentation contained in this document. The
* Author shall not be liable in any event for incidental or consequential
* damages in connection with, or arising out of, the furnishing, performance
* or use of these programs.
*
*/
#include <Arduino.h>
#if defined(ARDUINO_ARCH_ESP8266)
# include <ESP8266WiFi.h>
# include <ESPAsyncTCP.h>
# include <ESPAsyncUDP.h>
#elif defined(ARDUINO_ARCH_ESP32)
# include <AsyncTCP.h>
# include <AsyncUDP.h>
# include <WiFi.h>
#else
# error "Unsupported CPU type"
#endif
#define ARDUINOJSON_USE_LONG_LONG 1
#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 15
#include <Ticker.h>
#include <ArduinoJson.h>
#include "memdebug.h"
#include "ConstNames.hpp"
#include "GPIO_Defs.hpp"
#include "FastTimer.hpp"
#define REBOOT_DELAY 100 ///< Delay for rebooting once reboot flag is set
#define LOG_PORT Serial ///< Serial port for console logging
#define CLIENT_TIMEOUT 15 ///< In station/client mode try to connection for 15 seconds
#define AP_TIMEOUT 120 ///< In AP mode, wait 120 seconds for a connection or reboot
#define MilliSecondsInASecond 1000
#define MicroSecondsInAmilliSecond 1000
#define MicroSecondsInASecond (MicroSecondsInAmilliSecond * MilliSecondsInASecond)
#define NanoSecondsInAMicroSecond 1000
#define NanoSecondsInASecond (MicroSecondsInASecond * NanoSecondsInAMicroSecond)
#define NanoSecondsInAMilliSecond (NanoSecondsInAMicroSecond * MicroSecondsInAmilliSecond)
#define CPU_ClockTimeNS ((1.0 / float(F_CPU)) * float(NanoSecondsInASecond))
// Macro strings
#define STRINGIFY(X) #X
#define STRING(X) STRINGIFY(X)
extern void RequestReboot(uint32_t LoopDelay, bool SkipDisable = false);
extern bool RebootInProgress();
/// Core configuration structure
struct config_t
{
// Device
String id;
uint32_t BlankDelay = uint32_t(5);
};
String serializeCore (bool pretty = false);
void deserializeCoreHandler (JsonDocument& jsonDoc);
bool deserializeCore (JsonObject & json);
bool dsDevice (JsonObject & json);
bool dsNetwork (JsonObject & json);
extern bool IsBooting;
extern bool ResetWiFi;
extern const String ConfigFileName;
extern void FeedWDT ();
extern uint32_t DiscardedRxData;
extern void PrettyPrint (JsonObject& jsonStuff, String Name);
extern void PrettyPrint (JsonArray& jsonStuff, String Name);
extern void PrettyPrint(JsonDocument &jsonStuff, String Name);
template <typename T, typename N>
bool setFromJSON (T& OutValue, JsonObject & Json, N Name)
{
bool HasBeenModified = false;
if (Json[(char*)Name].template is<T>())
{
T temp = Json[(char*)Name];
if (temp != OutValue)
{
OutValue = temp;
HasBeenModified = true;
}
}
else
{
DEBUG_V(String("Could not find field '") + Name + "' in the json record");
PrettyPrint (Json, Name);
}
return HasBeenModified;
};
template <typename T, typename N>
bool setFromJSON (T& OutValue, JsonVariant & Json, N Name)
{
bool HasBeenModified = false;
if (Json[(char*)Name].template is<T>())
{
T temp = Json[(char*)Name];
if (temp != OutValue)
{
OutValue = temp;
HasBeenModified = true;
}
}
else
{
DEBUG_V(String("Could not find field '") + Name + "' in the json record");
PrettyPrint (Json, Name);
}
return HasBeenModified;
};
#if defined(ARDUINO_ARCH_ESP8266)
# define JsonWrite(j, n, v) (j)[String(n)] = (v)
void inline ResetGpio(const gpio_num_t pinId)
{
if(gpio_num_t(33) > pinId)
{
pinMode(pinId, INPUT);
}
}
#else // defined(ARDUINO_ARCH_ESP32)
# define JsonWrite(j, n, v) (j)[(char*)(n)] = (v)
void inline ResetGpio(const gpio_num_t pinId)
{
if(GPIO_IS_VALID_OUTPUT_GPIO(pinId))
{
gpio_reset_pin(pinId);
pinMode(pinId, INPUT);
}
}
#endif
extern bool ConsoleUartIsActive;
#define logcon(msg) \
{ \
String DN; \
GetDriverName (DN); \
extern void _logcon (String & DriverName, String Message); \
_logcon (DN, msg); \
}
extern config_t config;
extern bool ConfigSaveNeeded;
extern const uint8_t CurrentConfigVersion;
#define LOAD_CONFIG_DELAY 4
// #define DEBUG_GPIO gpio_num_t::GPIO_NUM_25
// #define DEBUG_GPIO1 gpio_num_t::GPIO_NUM_14