diff --git a/.gitignore b/.gitignore index 1603dcba..3ba084fe 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ *.o sdcc/sdcc +ESP32_AP-Flasher/.vscode/extensions.json diff --git a/ESP32_AP-Flasher/include/contentmanager.h b/ESP32_AP-Flasher/include/contentmanager.h index e9c9b79a..2db3eaf8 100644 --- a/ESP32_AP-Flasher/include/contentmanager.h +++ b/ESP32_AP-Flasher/include/contentmanager.h @@ -35,7 +35,8 @@ bool getJsonTemplateFile(String &filename, String jsonfile, tagRecord *&taginfo, extern bool getJsonTemplateFileExtractVariables(String &filename, String jsonfile, JsonDocument &variables, tagRecord *&taginfo, imgParam &imageParams); int getJsonTemplateUrl(String &filename, String URL, time_t fetched, String MAC, tagRecord *&taginfo, imgParam &imageParams); void drawJsonStream(Stream &stream, String &filename, tagRecord *&taginfo, imgParam &imageParams); -void drawElement(const JsonObject &element, TFT_eSprite &spr); +void rotateBuffer(uint8_t rotation, uint8_t ¤tOrientation, TFT_eSprite &spr, imgParam &imageParams); +void drawElement(const JsonObject &element, TFT_eSprite &spr, imgParam &imageParams, uint8_t ¤tOrientation); uint16_t getColor(const String &color); char *formatHttpDate(const time_t t); String urlEncode(const char *msg); diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index 2fa9e311..82e79115 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -1173,12 +1173,13 @@ void drawAPinfo(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, imgPa TFT_eSprite spr = TFT_eSprite(&tft); DynamicJsonDocument loc(2048); + uint8_t screenCurrentOrientation = 0; getTemplate(loc, 21, taginfo->hwType); initSprite(spr, imageParams.width, imageParams.height, imageParams); const JsonArray jsonArray = loc.as(); for (const JsonVariant &elem : jsonArray) { - drawElement(elem, spr); + drawElement(elem, spr, imageParams, screenCurrentOrientation); } spr2buffer(spr, filename, imageParams); @@ -1371,8 +1372,11 @@ int getJsonTemplateUrl(String &filename, String URL, time_t fetched, String MAC, } void drawJsonStream(Stream &stream, String &filename, tagRecord *&taginfo, imgParam &imageParams) { - TFT_eSprite spr = TFT_eSprite(&tft); +TFT_eSprite spr = TFT_eSprite(&tft); initSprite(spr, imageParams.width, imageParams.height, imageParams); + uint8_t screenCurrentOrientation = 0; + //spr.setRotation(2); + //imageParams.rotatebuffer = imageParams.rotatebuffer + 1; DynamicJsonDocument doc(500); if (stream.find("[")) { do { @@ -1381,7 +1385,7 @@ void drawJsonStream(Stream &stream, String &filename, tagRecord *&taginfo, imgPa wsErr("json error " + String(error.c_str())); break; } else { - drawElement(doc.as(), spr); + drawElement(doc.as(), spr, imageParams, screenCurrentOrientation); doc.clear(); } } while (stream.findUntil(",", "]")); @@ -1391,7 +1395,44 @@ void drawJsonStream(Stream &stream, String &filename, tagRecord *&taginfo, imgPa spr.deleteSprite(); } -void drawElement(const JsonObject &element, TFT_eSprite &spr) { +void rotateBuffer(uint8_t rotation, uint8_t ¤tOrientation, TFT_eSprite &spr, imgParam &imageParams){ + rotation = rotation % 4; //First of all, let's be sure that the rotation have a valid value (0, 1, 2 or 3) + if(rotation != currentOrientation){ //If we have a rotation to do, let's do it + int stepToDo = currentOrientation - rotation; //rotation we have to do + //-2, 2: upside down + //-1, 3: 270° rotation + //-3, 1: 90° rotation + + if(abs(stepToDo) == 2){ //If we have to do a 180° rotation: + TFT_eSprite sprCpy = TFT_eSprite(&tft); //We create a new sprite that will act as a buffer + initSprite(sprCpy, spr.width(), spr.height(), imageParams); //initialisation of the new sprite + spr.pushRotated(&sprCpy, 180, TFT_WHITE); //We fill the new sprite with the old one rotated by 180° + spr.fillSprite(TFT_WHITE); //We fill the old one in white as anything that's white will be ignored by the pushRotated function + sprCpy.pushRotated(&spr, 0, TFT_WHITE); //We copy the buffer sprite to the main one + sprCpy.deleteSprite(); //We delete the buffer sprite to avoid memory leak + }else{ + int angle = 90; + if(stepToDo == -1 || stepToDo == 3){ + angle = 270; + } + TFT_eSprite sprCpy = TFT_eSprite(&tft); + initSprite(sprCpy, spr.height(), spr.width(), imageParams); + spr.pushRotated(&sprCpy, angle, TFT_WHITE); + spr.deleteSprite(); + initSprite(spr, sprCpy.width(), sprCpy.height(), imageParams); + sprCpy.pushRotated(&spr, 0, TFT_WHITE); + sprCpy.deleteSprite(); + if(imageParams.rotatebuffer==1){ + imageParams.rotatebuffer = 0; + }else{ + imageParams.rotatebuffer = 1; + } + } + currentOrientation = rotation; + } +} + +void drawElement(const JsonObject &element, TFT_eSprite &spr, imgParam &imageParams, uint8_t ¤tOrientation) { if (element.containsKey("text")) { const JsonArray &textArray = element["text"]; const uint16_t align = textArray[5] | 0; @@ -1414,6 +1455,9 @@ void drawElement(const JsonObject &element, TFT_eSprite &spr) { } else if (element.containsKey("circle")) { const JsonArray &circleArray = element["circle"]; spr.fillCircle(circleArray[0].as(), circleArray[1].as(), circleArray[2].as(), getColor(circleArray[3])); + } else if (element.containsKey("rotate")) { + uint8_t rotation = element["rotate"].as(); + rotateBuffer(rotation, currentOrientation, spr, imageParams); } }