20using namespace ARDUINOJSON_NAMESPACE;
29constexpr int PATTERN_BUFFER_SIZE = 4096;
30static char patterns_list[PATTERN_BUFFER_SIZE];
38 DynamicJsonDocument patterns(PATTERN_BUFFER_SIZE);
41 const JsonObject pattern = patterns.createNestedObject();
45 serializeJson(patterns, patterns_list);
57 static bool initialized =
false;
64 request->send(HTTP_OK, CONTENT_JSON, patterns_list);
83 uint8_t pattern_num = request->getParam(0)->value().toInt();
89 String idx = String(
" \"idx\": ") + p.idx;
90 String bright = String(
", \"brightness\": ") + p.
brightness;
91 String smooth = String(
", \"smoothing\": ") + p.
smoothing;
92 String minhue = String(
", \"hue_min\": ") + p.
minhue;
93 String maxhue = String(
", \"hue_max\": ") + p.maxhue;
94 String conf = String(
", \"config\": ") + p.config;
95 String postprocess = String(
", \"postprocess\": ") + p.postprocessing_mode;
98 const String response = String(
"{") + idx + bright + smooth + minhue + maxhue + conf + postprocess + String(
" }");
99 request->send(HTTP_OK, CONTENT_JSON, response);
117 const String response = String(
"{") + count + alpha + mode + String(
" }");
118 request->send(HTTP_OK, CONTENT_JSON, response);
128 if (request->method() == HTTP_PUT) {
129 const JsonObject& payload = json.as<JsonObject>();
131 int status = HTTP_OK;
133 uint8_t count = payload[
"pattern_count"];
134 uint8_t alpha = payload[
"alpha"];
135 uint8_t mode = payload[
"mode"];
136 uint8_t noise = payload[
"noise"];
164 request->send(HTTP_METHOD_NOT_ALLOWED);
176 if (request->method() == HTTP_PUT) {
177 const JsonObject& payload = json.as<JsonObject>();
179 int status = HTTP_OK;
181 uint8_t pattern_num = request->getParam(0)->value().toInt();
183 const uint8_t idx = payload[
"idx"];
184 const uint8_t bright = payload[
"brightness"];
185 const uint8_t smooth = payload[
"smoothing"];
186 const uint8_t minhue = payload[
"hue_min"];
187 const uint8_t maxhue = payload[
"hue_max"];
188 const uint8_t conf = payload[
"config"];
189 const uint8_t postprocess = payload[
"postprocess"];
212 request->send(HTTP_METHOD_NOT_ALLOWED);
223 if (request->method() == HTTP_PUT) {
224 const JsonObject& payload = json.as<JsonObject>();
226 int status = HTTP_OK;
228 const uint8_t slot = payload[
"slot"];
262 request->send(HTTP_METHOD_NOT_ALLOWED);
273 if (request->method() == HTTP_PUT) {
274 const JsonObject& payload = json.as<JsonObject>();
276 int status = HTTP_OK;
278 const uint8_t slot = payload[
"slot"];
311 request->send(HTTP_METHOD_NOT_ALLOWED);
321 if (request->method() == HTTP_PUT) {
322 const JsonObject& payload = json.as<JsonObject>();
324 int status = HTTP_OK;
326 uint8_t length = payload[
"length"];
327 uint8_t
loop = payload[
"loop"];
328 uint8_t debug = payload[
"debug"];
334 if(
config.length != length)
351 request->send(HTTP_METHOD_NOT_ALLOWED);
362 String length = String(
" \"length\": ") +
config.length;
367 const String response = String(
"{") + length +
loop + debug + String(
" }");
368 request->send(HTTP_OK, CONTENT_JSON, response);
371inline void handle_new_password_put_request(AsyncWebServerRequest* request, JsonVariant& json){
373 if (request->method() == HTTP_PUT) {
374 const JsonObject& payload = json.as<JsonObject>();
376 int status = HTTP_OK;
378 const char * new_password = payload[
"new_password"];
382 for(uint8_t i = 0; i < 7; i++){
383 if(new_password[i] == 0)
400 for(uint8_t i = 0; i < 16; i++){
401 if(new_password[i] == 0)
416 for(uint8_t i = 0; i < 16; i++){
418 if(new_password[i] ==
'\0')
432 request->send(HTTP_METHOD_NOT_ALLOWED);
444constexpr int API_GET_HOOK_COUNT = 4;
453 {
"/api/updatePassword", handle_new_password_put_request },
455constexpr int API_PUT_HOOK_COUNT = 6;
APIPutHook apiPutHooks[]
The currently active put requests.
Definition api.h:447
void handle_system_settings_put_request(AsyncWebServerRequest *request, JsonVariant &json)
Handler function for updating system settings.
Definition api.h:320
void handle_pattern_put_request(AsyncWebServerRequest *request, JsonVariant &json)
Handler function for updating pattern data.
Definition api.h:175
APIGetHook apiGetHooks[]
The currently active get requests.
Definition api.h:438
void initialize_pattern_list()
Creates a JSON file with the list of patterns.
Definition api.h:36
void handle_load_save_slot_put_request(AsyncWebServerRequest *request, JsonVariant &json)
Handler function for loading a saved pattern.
Definition api.h:222
void handle_pattern_get_request(AsyncWebServerRequest *request)
Handler function for getting pattern data.
Definition api.h:81
void handle_strip_put_request(AsyncWebServerRequest *request, JsonVariant &json)
Handler function for updating strip data.
Definition api.h:127
void handle_system_settings_get_request(AsyncWebServerRequest *request)
Handler function for getting system settings.
Definition api.h:359
void handle_save_to_slot_put_request(AsyncWebServerRequest *request, JsonVariant &json)
Handler function for saving the currently-running pattern.
Definition api.h:272
void handle_patterns_list_request(AsyncWebServerRequest *request)
Handles sending the JSON of patterns to other devices.
Definition api.h:56
void handle_strip_get_request(AsyncWebServerRequest *request)
Handler function for getting pattern data.
Definition api.h:108
int NUM_PATTERNS
The number of patterns that can be shown, externed from globals.h.
Definition globals.h:75
Pattern mainPatterns[]
The current list of patterns, externed from globals.h.
Definition globals.h:58
Config_Data config
The currently-loaded device config.
Definition main.ino:61
volatile bool manual_control_enabled
MANUAL CONTROL VARIABLES.
Definition main.ino:70
Strip_Data loaded_patterns
The current strip configuration being ran by the device.
Definition main.ino:55
volatile bool pattern_changed
Updated to "true" when the web server changes significant pattern settings.
Definition main.ino:52
void loop()
Runs the main program loop.
Definition main.ino:399
void bound_byte(uint8_t *val, int lower, int upper)
Bounds a byte between an upper and a lower value.
Definition nanolux_util.cpp:71
void save_config_to_nvs()
Saves configuration data to the NVS.
Definition storage.cpp:157
void load_slot(int slot)
Move patterns in a slot to the main buffer.
Definition storage.cpp:94
void set_slot(int slot)
Saves the currently-loaded pattern to a save slot.
Definition storage.cpp:111
void save_to_nvs()
Saves all currently-loaded patterns to NVS.
Definition storage.cpp:127
#define PATTERN_LIMIT
The number of patterns that can run at maximum.
Definition storage.h:37
#define NUM_SAVES
The number of saved strip configs the ESP32 is able to address.
Definition storage.h:34
Definition webServer.h:126
Definition webServer.h:131
char pass[16]
If the loaded config data is valid.
Definition storage.h:72
uint8_t debug_mode
The number of milliseconds one program loop takes.
Definition storage.h:70
uint8_t loop_ms
The length of the LED strip.
Definition storage.h:69
uint8_t smoothing
The pattern's brightness.
Definition storage.h:45
uint8_t minhue
How smoothed pattern light changes are.
Definition storage.h:46
uint8_t brightness
The selected pattern name to run.
Definition storage.h:44
uint8_t noise_thresh
How transparent the top pattern is in Z-layering.
Definition storage.h:58
uint8_t mode
The minimum noise floor to consider as audio.
Definition storage.h:59
Pattern_Data pattern[PATTERN_LIMIT]
The number of patterns this config has.
Definition storage.h:61
uint8_t pattern_count
The currently-running pattern mode (splitting vs layering).
Definition storage.h:60