kopia lustrzana https://github.com/Aircoookie/WLED
rodzic
92eafcfe1a
commit
44a8ae457d
|
@ -1634,7 +1634,7 @@ uint16_t WS2812FX::mode_fire_2012(void)
|
||||||
{
|
{
|
||||||
// Step 1. Cool down every cell a little
|
// Step 1. Cool down every cell a little
|
||||||
for( int i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
for( int i = SEGMENT.start; i < SEGMENT.stop; i++) {
|
||||||
_locked[i] = qsub8(_locked[i], random8(0, ((COOLING * 10) / SEGLEN) + 2));
|
_locked[i] = qsub8(_locked[i], random8(0, (((20 + SEGMENT.speed /3) * 10) / SEGLEN) + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2. Heat from each cell drifts 'up' and diffuses a little
|
// Step 2. Heat from each cell drifts 'up' and diffuses a little
|
||||||
|
@ -1653,7 +1653,7 @@ uint16_t WS2812FX::mode_fire_2012(void)
|
||||||
CRGB color = ColorFromPalette( currentPalette, min(_locked[j],240), 255, LINEARBLEND);
|
CRGB color = ColorFromPalette( currentPalette, min(_locked[j],240), 255, LINEARBLEND);
|
||||||
setPixelColor(j, color.red, color.green, color.blue);
|
setPixelColor(j, color.red, color.green, color.blue);
|
||||||
}
|
}
|
||||||
return 10 + (uint16_t)(255 - SEGMENT.speed)/6;
|
return 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,7 @@
|
||||||
#include "ArduinoJson-v6.h"
|
#include "ArduinoJson-v6.h"
|
||||||
#include <Print.h>
|
#include <Print.h>
|
||||||
|
|
||||||
#if ARDUINOJSON_VERSION_MAJOR == 5
|
|
||||||
#define ARDUINOJSON_5_COMPATIBILITY
|
|
||||||
#else
|
|
||||||
#define DYNAMYC_JSON_DOCUMENT_SIZE 4096
|
#define DYNAMYC_JSON_DOCUMENT_SIZE 4096
|
||||||
#endif
|
|
||||||
|
|
||||||
constexpr const char* JSON_MIMETYPE = "application/json";
|
constexpr const char* JSON_MIMETYPE = "application/json";
|
||||||
|
|
||||||
|
@ -57,27 +53,13 @@ class ChunkPrint : public Print {
|
||||||
class AsyncJsonResponse: public AsyncAbstractResponse {
|
class AsyncJsonResponse: public AsyncAbstractResponse {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
|
||||||
DynamicJsonBuffer _jsonBuffer;
|
|
||||||
#else
|
|
||||||
DynamicJsonDocument _jsonBuffer;
|
DynamicJsonDocument _jsonBuffer;
|
||||||
#endif
|
|
||||||
|
|
||||||
JsonVariant _root;
|
JsonVariant _root;
|
||||||
bool _isValid;
|
bool _isValid;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
|
||||||
AsyncJsonResponse(bool isArray=false): _isValid{false} {
|
|
||||||
_code = 200;
|
|
||||||
_contentType = JSON_MIMETYPE;
|
|
||||||
if(isArray)
|
|
||||||
_root = _jsonBuffer.createArray();
|
|
||||||
else
|
|
||||||
_root = _jsonBuffer.createObject();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
AsyncJsonResponse(size_t maxJsonBufferSize = DYNAMYC_JSON_DOCUMENT_SIZE, bool isArray=false) : _jsonBuffer(maxJsonBufferSize), _isValid{false} {
|
AsyncJsonResponse(size_t maxJsonBufferSize = DYNAMYC_JSON_DOCUMENT_SIZE, bool isArray=false) : _jsonBuffer(maxJsonBufferSize), _isValid{false} {
|
||||||
_code = 200;
|
_code = 200;
|
||||||
_contentType = JSON_MIMETYPE;
|
_contentType = JSON_MIMETYPE;
|
||||||
|
@ -86,18 +68,13 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
|
||||||
else
|
else
|
||||||
_root = _jsonBuffer.createNestedObject();
|
_root = _jsonBuffer.createNestedObject();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
~AsyncJsonResponse() {}
|
~AsyncJsonResponse() {}
|
||||||
JsonVariant & getRoot() { return _root; }
|
JsonVariant & getRoot() { return _root; }
|
||||||
bool _sourceValid() const { return _isValid; }
|
bool _sourceValid() const { return _isValid; }
|
||||||
size_t setLength() {
|
size_t setLength() {
|
||||||
|
|
||||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
|
||||||
_contentLength = _root.measureLength();
|
|
||||||
#else
|
|
||||||
_contentLength = measureJson(_root);
|
_contentLength = measureJson(_root);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (_contentLength) { _isValid = true; }
|
if (_contentLength) { _isValid = true; }
|
||||||
return _contentLength;
|
return _contentLength;
|
||||||
|
@ -108,16 +85,12 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
|
||||||
size_t _fillBuffer(uint8_t *data, size_t len){
|
size_t _fillBuffer(uint8_t *data, size_t len){
|
||||||
ChunkPrint dest(data, _sentLength, len);
|
ChunkPrint dest(data, _sentLength, len);
|
||||||
|
|
||||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
|
||||||
_root.printTo( dest ) ;
|
|
||||||
#else
|
|
||||||
serializeJson(_root, dest);
|
serializeJson(_root, dest);
|
||||||
#endif
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::function<void(AsyncWebServerRequest *request, JsonVariant &json)> ArJsonRequestHandlerFunction;
|
typedef std::function<void(AsyncWebServerRequest *request, JsonObject json)> ArJsonRequestHandlerFunction;
|
||||||
|
|
||||||
class AsyncCallbackJsonWebHandler: public AsyncWebHandler {
|
class AsyncCallbackJsonWebHandler: public AsyncWebHandler {
|
||||||
private:
|
private:
|
||||||
|
@ -126,18 +99,12 @@ protected:
|
||||||
WebRequestMethodComposite _method;
|
WebRequestMethodComposite _method;
|
||||||
ArJsonRequestHandlerFunction _onRequest;
|
ArJsonRequestHandlerFunction _onRequest;
|
||||||
int _contentLength;
|
int _contentLength;
|
||||||
#ifndef ARDUINOJSON_5_COMPATIBILITY
|
|
||||||
const size_t maxJsonBufferSize;
|
const size_t maxJsonBufferSize;
|
||||||
#endif
|
|
||||||
int _maxContentLength;
|
int _maxContentLength;
|
||||||
public:
|
public:
|
||||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
|
||||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest)
|
|
||||||
: _uri(uri), _method(HTTP_POST|HTTP_PUT|HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {}
|
|
||||||
#else
|
|
||||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize=DYNAMYC_JSON_DOCUMENT_SIZE)
|
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize=DYNAMYC_JSON_DOCUMENT_SIZE)
|
||||||
: _uri(uri), _method(HTTP_POST|HTTP_PUT|HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384) {}
|
: _uri(uri), _method(HTTP_POST|HTTP_PUT|HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
void setMethod(WebRequestMethodComposite method){ _method = method; }
|
void setMethod(WebRequestMethodComposite method){ _method = method; }
|
||||||
void setMaxContentLength(int maxContentLength){ _maxContentLength = maxContentLength; }
|
void setMaxContentLength(int maxContentLength){ _maxContentLength = maxContentLength; }
|
||||||
|
@ -161,16 +128,10 @@ public:
|
||||||
if(_onRequest) {
|
if(_onRequest) {
|
||||||
if (request->_tempObject != NULL) {
|
if (request->_tempObject != NULL) {
|
||||||
|
|
||||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
|
||||||
DynamicJsonBuffer jsonBuffer;
|
|
||||||
JsonVariant json = jsonBuffer.parse((uint8_t*)(request->_tempObject));
|
|
||||||
if (json.success()) {
|
|
||||||
#else
|
|
||||||
DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize);
|
DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize);
|
||||||
DeserializationError error = deserializeJson(jsonBuffer, (uint8_t*)(request->_tempObject));
|
DeserializationError error = deserializeJson(jsonBuffer, (uint8_t*)(request->_tempObject));
|
||||||
if(!error) {
|
if(!error) {
|
||||||
JsonVariant json = jsonBuffer.as<JsonVariant>();
|
JsonObject json = jsonBuffer.as<JsonObject>();
|
||||||
#endif
|
|
||||||
|
|
||||||
_onRequest(request, json);
|
_onRequest(request, json);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
|
|
||||||
|
|
||||||
//version code in format yymmddb (b = daily build)
|
//version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 1908211
|
#define VERSION 1908251
|
||||||
char versionString[] = "0.8.5-dev";
|
char versionString[] = "0.8.5-dev";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,7 @@ void initServer()
|
||||||
serveJson(request);
|
serveJson(request);
|
||||||
});
|
});
|
||||||
|
|
||||||
AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/json", [](AsyncWebServerRequest *request, JsonVariant &json) {
|
AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/json", [](AsyncWebServerRequest *request, JsonObject root) {
|
||||||
JsonObject root = json.to<JsonObject>();
|
|
||||||
if (root.isNull()){request->send(500, "application/json", "{\"error\":\"Parsing failed\"}"); return;}
|
if (root.isNull()){request->send(500, "application/json", "{\"error\":\"Parsing failed\"}"); return;}
|
||||||
if (deserializeState(root)) { serveJson(request); return; } //if JSON contains "v" (verbose response)
|
if (deserializeState(root)) { serveJson(request); return; } //if JSON contains "v" (verbose response)
|
||||||
request->send(200, "application/json", "{\"success\":true}");
|
request->send(200, "application/json", "{\"success\":true}");
|
||||||
|
|
Ładowanie…
Reference in New Issue