├── .gitignore ├── LICENSE ├── README.md ├── images ├── Thumbs.db ├── printer_monitor_wiring.jpg ├── printing_time.jpg ├── shot_01.png ├── shot_02.png ├── shot_03.png ├── shot_04.png ├── temperatures.jpg ├── time_remaining.jpg └── video_print_monitor.png ├── printermonitor.ino.d1_mini_SH1106.bin ├── printermonitor.ino.d1_mini_SSD1306.bin ├── printermonitor.ino.d1_mini_easyboard.bin ├── printermonitor.ino.d1_mini_easyboard_repetier.bin ├── printermonitor.ino.d1_mini_repetier_SH1106.bin ├── printermonitor.ino.d1_mini_repetier_SSD1306.bin └── printermonitor ├── OctoPrintClient.cpp ├── OctoPrintClient.h ├── OpenWeatherMapClient.cpp ├── OpenWeatherMapClient.h ├── RepetierClient.cpp ├── RepetierClient.h ├── Settings.h ├── TimeClient.cpp ├── TimeClient.h ├── WeatherStationFonts.h ├── libs └── ArduinoJson │ ├── ArduinoJson.h │ ├── CHANGELOG.md │ ├── CMakeLists.txt │ ├── CONTRIBUTING.md │ ├── LICENSE.md │ ├── README.md │ ├── SUPPORT.md │ ├── appveyor.yml │ ├── banner.svg │ ├── keywords.txt │ └── src │ ├── ArduinoJson.h │ ├── ArduinoJson.hpp │ └── ArduinoJson │ ├── Configuration.hpp │ ├── Data │ ├── Encoding.hpp │ ├── JsonBufferAllocated.hpp │ ├── JsonFloat.hpp │ ├── JsonInteger.hpp │ ├── JsonVariantAs.hpp │ ├── JsonVariantContent.hpp │ ├── JsonVariantDefault.hpp │ ├── JsonVariantType.hpp │ ├── List.hpp │ ├── ListConstIterator.hpp │ ├── ListIterator.hpp │ ├── ListNode.hpp │ ├── NonCopyable.hpp │ ├── ReferenceType.hpp │ └── ValueSaver.hpp │ ├── Deserialization │ ├── Comments.hpp │ ├── JsonParser.hpp │ ├── JsonParserImpl.hpp │ └── StringWriter.hpp │ ├── DynamicJsonBuffer.hpp │ ├── JsonArray.hpp │ ├── JsonArrayImpl.hpp │ ├── JsonArraySubscript.hpp │ ├── JsonBuffer.hpp │ ├── JsonBufferBase.hpp │ ├── JsonBufferImpl.hpp │ ├── JsonObject.hpp │ ├── JsonObjectImpl.hpp │ ├── JsonObjectSubscript.hpp │ ├── JsonPair.hpp │ ├── JsonVariant.hpp │ ├── JsonVariantBase.hpp │ ├── JsonVariantCasts.hpp │ ├── JsonVariantComparisons.hpp │ ├── JsonVariantImpl.hpp │ ├── JsonVariantOr.hpp │ ├── JsonVariantSubscripts.hpp │ ├── Polyfills │ ├── attributes.hpp │ ├── ctype.hpp │ ├── isFloat.hpp │ ├── isInteger.hpp │ ├── math.hpp │ ├── parseFloat.hpp │ └── parseInteger.hpp │ ├── RawJson.hpp │ ├── Serialization │ ├── DummyPrint.hpp │ ├── DynamicStringBuilder.hpp │ ├── FloatParts.hpp │ ├── IndentedPrint.hpp │ ├── JsonPrintable.hpp │ ├── JsonSerializer.hpp │ ├── JsonSerializerImpl.hpp │ ├── JsonWriter.hpp │ ├── Prettyfier.hpp │ ├── StaticStringBuilder.hpp │ └── StreamPrintAdapter.hpp │ ├── StaticJsonBuffer.hpp │ ├── StringTraits │ ├── ArduinoStream.hpp │ ├── CharPointer.hpp │ ├── FlashString.hpp │ ├── StdStream.hpp │ ├── StdString.hpp │ └── StringTraits.hpp │ └── TypeTraits │ ├── EnableIf.hpp │ ├── FloatTraits.hpp │ ├── IsArray.hpp │ ├── IsBaseOf.hpp │ ├── IsChar.hpp │ ├── IsConst.hpp │ ├── IsFloatingPoint.hpp │ ├── IsIntegral.hpp │ ├── IsSame.hpp │ ├── IsSignedIntegral.hpp │ ├── IsUnsignedIntegral.hpp │ ├── IsVariant.hpp │ ├── RemoveConst.hpp │ └── RemoveReference.hpp └── printermonitor.ino /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | printermonitor/my_Settings.h 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Printer Monitor (OctoPrint 3D Printer Monitor) 2 | 3 | ## New Easy Monitor Board Kit: 4 | Now available is the Pre Loaded Monitor Board Kit that comes ready to plug and play on your network. 5 | * Kit on Etsy: https://www.etsy.com/listing/823257424 6 | * New 3D printed case design for Monitor Board kit: https://www.thingiverse.com/thing:4538747 7 | * Configuration video: https://www.youtube.com/watch?v=kcBspqWhpIU 8 | 9 | ## Features: 10 | * Displays the print status from OctoPrint or Repetier Server 11 | * Option to display time and weather when printer is idle 12 | * Estimated time remaining 13 | * Time Printing 14 | * Percentage complete 15 | * Progress bar 16 | * Bed and Tool Temperature 17 | * Screen turns off when printer is turned off or disconnected 18 | * Screen turns on when printer is Operational or connected 19 | * Option to display a clock screen instead of sleep mode 20 | * Option to display 24 hour clock or AM/PM style 21 | * Option to display Current Weather when printer is off 22 | * Sample rate is every 60 seconds when not printing 23 | * Sample rate is every 10 seconds when printing 24 | * Fully configurable from the web interface (not required to update Settings.h) 25 | * Supports OTA (loading firmware over WiFi connection on same LAN) 26 | * Basic Authentication to protect your settings 27 | * Version 2.2 added the ability to update firmware through web interface from a compiled binary 28 | * Can query the Octoprint [PSU Control plugin](https://plugins.octoprint.org/plugins/psucontrol/) to enter clock or blank mode when PSU is off 29 | * Repetier support added in version 3.0 -- define in Settings.h 30 | * Video: https://youtu.be/niRv9SCgAPk 31 | * Detailed build video by Chris Riley: https://youtu.be/Rm-l1FSuJpI 32 | 33 | ## Required Parts: 34 | * Wemos D1 Mini: https://amzn.to/2ImqD1n 35 | * 0.96" OLED I2C 128x64 Display (12864) SSD1306: https://amzn.to/3cyJekU 36 | * (optional) 1.3" I2C OLED Display: https://amzn.to/2IP0gRU (must uncomment #define DISPLAY_SH1106 in the Settings.h to use the 1.3" SSH1106 display) 37 | * (optional) Pre loaded Monitor Board kit: https://www.etsy.com/listing/823257424 38 | 39 | Note: Using the links provided here help to support these types of projects. Thank you for the support. 40 | 41 | ## Wiring for the Wemos D1 Mini to the I2C SSD1306 OLED 42 | SDA -> D2 43 | SCL -> D5 / D1 -- for Easy Monitor Board 44 | VCC -> 5V+ 45 | GND -> GND- 46 | 47 | ![Printer Monitor Wire Diagram](/images/printer_monitor_wiring.jpg) 48 | 49 | ## 3D Printed Case by Qrome: 50 | https://www.thingiverse.com/thing:2884823 -- for the 0.96" OLED Display 51 | https://www.thingiverse.com/thing:2934049 -- for the 1.3" OLED Display 52 | https://www.thingiverse.com/thing:4538747 -- for 0.96" With Easy Monitor Board 53 | 54 | ## Upgrading from version 2.2 or Higher 55 | Version 2.2 introduced the ability to upgrade pre-compiled firmware from a binary file. In version 2.3 and on you should find binary files that can be uploaded to your printer monitor via the web interface. From the main menu in the web interface select "Firmware Update" and follow the prompts. 56 | * **printermonitor.ino.d1_mini_SSD1306.bin** - compiled for Wemos D1 Mini for the smaller 0.96" SSD1306 OLED (default) 57 | * **printermonitor.ino.d1_mini_SH1106.bin** - compiled for Wemos D1 Mini for the larger 1.3" SH1106 OLED 58 | * **printermonitor.ino.d1_mini_repetier_SSD1306.bin** - Repetier version compiled for Wemos D1 Mini for the smaller 0.96" SSD1306 OLED (default) 59 | * **printermonitor.ino.d1_mini_repetier_SH1106.bin** - Repetier version compiled for Wemos D1 Mini for the larger 1.3" SH1106 OLED 60 | * **printermonitor.ino.d1_mini_easyboard.bin** - Version compiled for Easy Monitor Board for the smaller 0.96" SSD1306 OLED (SDA -> D2 and SCL -> D1) 61 | * **printermonitor.ino.d1_mini_easyboard_repetier.bin** - Repetier version compiled for Easy Monitor Board for the smaller 0.96" SSD1306 OLED (SDA -> D2 and SCL -> D1) 62 | 63 | ## Compiling and Loading to Wemos D1 Mini 64 | It is recommended to use Arduino IDE. You will need to configure Arduino IDE to work with the Wemos board and USB port and installed the required USB drivers etc. 65 | * USB CH340G drivers: https://sparks.gogo.co.nz/ch340.html 66 | * Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas. This will add support for the Wemos D1 Mini to Arduino IDE. 67 | * Open Boards Manager from Tools > Board menu and install esp8266 Core platform version 2.5.2 68 | * Select Board: "LOLIN(WEMOS) D1 R2 & mini" 69 | * Set 1M SPIFFS -- this project uses SPIFFS for saving and reading configuration settings. 70 | 71 | ## Loading Supporting Library Files in Arduino 72 | Use the Arduino guide for details on how to installing and manage libraries https://www.arduino.cc/en/Guide/Libraries 73 | **Packages** -- the following packages and libraries are used (download and install): 74 | ESP8266WiFi.h 75 | ESP8266WebServer.h 76 | WiFiManager.h --> https://github.com/tzapu/WiFiManager 77 | ESP8266mDNS.h 78 | ArduinoOTA.h --> Arduino OTA Library 79 | "SSD1306Wire.h" --> https://github.com/ThingPulse/esp8266-oled-ssd1306/releases/tag/4.1.0 (version 4.1.0) 80 | "OLEDDisplayUi.h" 81 | 82 | Note Printer-Monitor version 2.5 and later include ArduinoJson (version 5.13.1). 83 | 84 | ## Initial Configuration 85 | All settings may be managed from the Web Interface, however, you may update the **Settings.h** file manually -- but it is not required. There is also an option to display current weather when the print is off-line. 86 | * If you are using the Easy Monitor Board you must set the const int SCL_PIN = D1 in the Settings.h file. 87 | * By default OctoPrint client is selected. If you wish to use Repetier then uncomment //#define USE_REPETIER_CLIENT in the Settings.h file. 88 | * Your OctoPrint API Key from your OctoPrint -> User Settings -> Current API Key -- similar for Repetier API Key. 89 | * Optional OpenWeatherMap API Key -- if you want current weather when not printing. Get the api key from: https://openweathermap.org/ 90 | 91 | NOTE: The settings in the Settings.h are the default settings for the first loading. After loading you will manage changes to the settings via the Web Interface. If you want to change settings again in the settings.h, you will need to erase the file system on the Wemos or use the “Reset Settings” option in the Web Interface. 92 | 93 | ## Web Interface 94 | The Printer Monitor uses the **WiFiManager** so when it can't find the last network it was connected to 95 | it will become a **AP Hotspot** -- connect to it with your phone and you can then enter your WiFi connection information. 96 | 97 | After connected to your WiFi network it will display the IP addressed assigned to it and that can be 98 | used to open a browser to the Web Interface. **Everything** can be configured there. 99 | 100 |

101 | 102 | 103 | 104 | 105 |

106 | 107 | ## Donate or Tip 108 | Please do not feel obligated, but donations and tips are warmly welcomed. I have added the donation button at the request of a few people that wanted to contribute and show appreciation. Thank you, and enjoy the application and project. 109 | 110 | [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6VPMTLASLSKWE) 111 | 112 | Or -- you can buy me something from my Amazon Wishlist: https://www.amazon.com/hz/wishlist/ls/GINC2PHRNEY3 113 | 114 | ## Contributors 115 | David Payne -- Principal developer and architect 116 | Daniel Eichhorn -- Author of the TimeClient class and OLEDDisplayUi 117 | Florian Schütte -- added flip display to web interface 118 | Owen Carter -- Added psu control setting (v2.4) 119 | 120 | Contributing to this software is warmly welcomed. You can do this basically by 121 | forking from master, committing modifications and then making a pulling requests to be reviewed (follow the links above 122 | for operating guide). Detailed comments are encouraged. Adding change log and your contact into file header is encouraged. 123 | Thanks for your contribution. 124 | 125 | [![Watch the video](/images/video_print_monitor.png)](https://youtu.be/niRv9SCgAPk) 126 | ![Printer Monitor Temps](/images/temperatures.jpg) 127 | ![Printer Monitor Time Remaining](/images/time_remaining.jpg) 128 | ![Printer Monitor Printing Time](/images/printing_time.jpg) 129 | 130 | /* The MIT License (MIT) 131 | 132 | Copyright (c) 2018 David Payne 133 | 134 | Permission is hereby granted, free of charge, to any person obtaining a copy 135 | of this software and associated documentation files (the "Software"), to deal 136 | in the Software without restriction, including without limitation the rights 137 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 138 | copies of the Software, and to permit persons to whom the Software is 139 | furnished to do so, subject to the following conditions: 140 | 141 | The above copyright notice and this permission notice shall be included in all 142 | copies or substantial portions of the Software. 143 | 144 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 145 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 146 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 147 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 148 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 149 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 150 | SOFTWARE. 151 | */ 152 | -------------------------------------------------------------------------------- /images/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/Thumbs.db -------------------------------------------------------------------------------- /images/printer_monitor_wiring.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/printer_monitor_wiring.jpg -------------------------------------------------------------------------------- /images/printing_time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/printing_time.jpg -------------------------------------------------------------------------------- /images/shot_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/shot_01.png -------------------------------------------------------------------------------- /images/shot_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/shot_02.png -------------------------------------------------------------------------------- /images/shot_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/shot_03.png -------------------------------------------------------------------------------- /images/shot_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/shot_04.png -------------------------------------------------------------------------------- /images/temperatures.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/temperatures.jpg -------------------------------------------------------------------------------- /images/time_remaining.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/time_remaining.jpg -------------------------------------------------------------------------------- /images/video_print_monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/images/video_print_monitor.png -------------------------------------------------------------------------------- /printermonitor.ino.d1_mini_SH1106.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/printermonitor.ino.d1_mini_SH1106.bin -------------------------------------------------------------------------------- /printermonitor.ino.d1_mini_SSD1306.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/printermonitor.ino.d1_mini_SSD1306.bin -------------------------------------------------------------------------------- /printermonitor.ino.d1_mini_easyboard.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/printermonitor.ino.d1_mini_easyboard.bin -------------------------------------------------------------------------------- /printermonitor.ino.d1_mini_easyboard_repetier.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/printermonitor.ino.d1_mini_easyboard_repetier.bin -------------------------------------------------------------------------------- /printermonitor.ino.d1_mini_repetier_SH1106.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/printermonitor.ino.d1_mini_repetier_SH1106.bin -------------------------------------------------------------------------------- /printermonitor.ino.d1_mini_repetier_SSD1306.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Qrome/printer-monitor/bd8422b228ebb0742a449b7928e40aa549f6db61/printermonitor.ino.d1_mini_repetier_SSD1306.bin -------------------------------------------------------------------------------- /printermonitor/OctoPrintClient.h: -------------------------------------------------------------------------------- 1 | /** The MIT License (MIT) 2 | 3 | Copyright (c) 2018 David Payne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | // Additional Contributions: 25 | /* 15 Jan 2019 : Owen Carter : Add psucontrol query via POST api call */ 26 | 27 | #pragma once 28 | #include 29 | #include "libs/ArduinoJson/ArduinoJson.h" 30 | #include 31 | 32 | class OctoPrintClient { 33 | 34 | private: 35 | char myServer[100]; 36 | int myPort = 80; 37 | String myApiKey = ""; 38 | String encodedAuth = ""; 39 | boolean pollPsu; 40 | const String printerType = "OctoPrint"; 41 | 42 | void resetPrintData(); 43 | boolean validate(); 44 | WiFiClient getSubmitRequest(String apiGetData); 45 | WiFiClient getPostRequest(String apiPostData, String apiPostBody); 46 | 47 | String result; 48 | 49 | typedef struct { 50 | String averagePrintTime; 51 | String estimatedPrintTime; 52 | String fileName; 53 | String fileSize; 54 | String lastPrintTime; 55 | String progressCompletion; 56 | String progressFilepos; 57 | String progressPrintTime; 58 | String progressPrintTimeLeft; 59 | String state; 60 | String toolTemp; 61 | String toolTargetTemp; 62 | String filamentLength; 63 | String bedTemp; 64 | String bedTargetTemp; 65 | boolean isPrinting; 66 | boolean isPSUoff; 67 | String error; 68 | String printerName; 69 | } PrinterStruct; 70 | 71 | PrinterStruct printerData; 72 | 73 | 74 | public: 75 | OctoPrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu); 76 | void getPrinterJobResults(); 77 | void getPrinterPsuState(); 78 | void updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu); 79 | 80 | String getAveragePrintTime(); 81 | String getEstimatedPrintTime(); 82 | String getFileName(); 83 | String getFileSize(); 84 | String getLastPrintTime(); 85 | String getProgressCompletion(); 86 | String getProgressFilepos(); 87 | String getProgressPrintTime(); 88 | String getProgressPrintTimeLeft(); 89 | String getState(); 90 | boolean isPrinting(); 91 | boolean isOperational(); 92 | boolean isPSUoff(); 93 | String getTempBedActual(); 94 | String getTempBedTarget(); 95 | String getTempToolActual(); 96 | String getTempToolTarget(); 97 | String getFilamentLength(); 98 | String getValueRounded(String value); 99 | String getError(); 100 | String getPrinterType(); 101 | int getPrinterPort(); 102 | String getPrinterName(); 103 | void setPrinterName(String printer); 104 | }; 105 | -------------------------------------------------------------------------------- /printermonitor/OpenWeatherMapClient.cpp: -------------------------------------------------------------------------------- 1 | /** The MIT License (MIT) 2 | 3 | Copyright (c) 2018 David Payne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | #include "OpenWeatherMapClient.h" 25 | 26 | OpenWeatherMapClient::OpenWeatherMapClient(String ApiKey, int CityIDs[], int cityCount, boolean isMetric, String language) { 27 | updateCityIdList(CityIDs, cityCount); 28 | updateLanguage(language); 29 | myApiKey = ApiKey; 30 | setMetric(isMetric); 31 | } 32 | 33 | void OpenWeatherMapClient::updateWeatherApiKey(String ApiKey) { 34 | myApiKey = ApiKey; 35 | } 36 | 37 | void OpenWeatherMapClient::updateLanguage(String language) { 38 | lang = language; 39 | if (lang == "") { 40 | lang = "en"; 41 | } 42 | } 43 | 44 | void OpenWeatherMapClient::updateWeather() { 45 | WiFiClient weatherClient; 46 | String apiGetData = "GET /data/2.5/group?id=" + myCityIDs + "&units=" + units + "&cnt=1&APPID=" + myApiKey + "&lang=" + lang + " HTTP/1.1"; 47 | 48 | Serial.println("Getting Weather Data"); 49 | Serial.println(apiGetData); 50 | result = ""; 51 | if (weatherClient.connect(servername, 80)) { //starts client connection, checks for connection 52 | weatherClient.println(apiGetData); 53 | weatherClient.println("Host: " + String(servername)); 54 | weatherClient.println("User-Agent: ArduinoWiFi/1.1"); 55 | weatherClient.println("Connection: close"); 56 | weatherClient.println(); 57 | } 58 | else { 59 | Serial.println("connection for weather data failed"); //error message if no client connect 60 | Serial.println(); 61 | return; 62 | } 63 | 64 | while(weatherClient.connected() && !weatherClient.available()) delay(1); //waits for data 65 | 66 | Serial.println("Waiting for data"); 67 | 68 | // Check HTTP status 69 | char status[32] = {0}; 70 | weatherClient.readBytesUntil('\r', status, sizeof(status)); 71 | Serial.println("Response Header: " + String(status)); 72 | if (strcmp(status, "HTTP/1.1 200 OK") != 0) { 73 | Serial.print(F("Unexpected response: ")); 74 | Serial.println(status); 75 | return; 76 | } 77 | 78 | // Skip HTTP headers 79 | char endOfHeaders[] = "\r\n\r\n"; 80 | if (!weatherClient.find(endOfHeaders)) { 81 | Serial.println(F("Invalid response")); 82 | return; 83 | } 84 | 85 | const size_t bufferSize = 710; 86 | DynamicJsonBuffer jsonBuffer(bufferSize); 87 | 88 | weathers[0].cached = false; 89 | weathers[0].error = ""; 90 | // Parse JSON object 91 | JsonObject& root = jsonBuffer.parseObject(weatherClient); 92 | if (!root.success()) { 93 | Serial.println(F("Weather Data Parsing failed!")); 94 | weathers[0].error = "Weather Data Parsing failed!"; 95 | return; 96 | } 97 | 98 | weatherClient.stop(); //stop client 99 | 100 | if (root.measureLength() <= 150) { 101 | Serial.println("Error Does not look like we got the data. Size: " + String(root.measureLength())); 102 | weathers[0].cached = true; 103 | weathers[0].error = (const char*)root["message"]; 104 | Serial.println("Error: " + weathers[0].error); 105 | return; 106 | } 107 | int count = root["cnt"]; 108 | 109 | for (int inx = 0; inx < count; inx++) { 110 | weathers[inx].lat = (const char*)root["list"][inx]["coord"]["lat"]; 111 | weathers[inx].lon = (const char*)root["list"][inx]["coord"]["lon"]; 112 | weathers[inx].dt = (const char*)root["list"][inx]["dt"]; 113 | weathers[inx].city = (const char*)root["list"][inx]["name"]; 114 | weathers[inx].country = (const char*)root["list"][inx]["sys"]["country"]; 115 | weathers[inx].temp = (const char*)root["list"][inx]["main"]["temp"]; 116 | weathers[inx].humidity = (const char*)root["list"][inx]["main"]["humidity"]; 117 | weathers[inx].condition = (const char*)root["list"][inx]["weather"][0]["main"]; 118 | weathers[inx].wind = (const char*)root["list"][inx]["wind"]["speed"]; 119 | weathers[inx].weatherId = (const char*)root["list"][inx]["weather"][0]["id"]; 120 | weathers[inx].description = (const char*)root["list"][inx]["weather"][0]["description"]; 121 | weathers[inx].icon = (const char*)root["list"][inx]["weather"][0]["icon"]; 122 | 123 | Serial.println("lat: " + weathers[inx].lat); 124 | Serial.println("lon: " + weathers[inx].lon); 125 | Serial.println("dt: " + weathers[inx].dt); 126 | Serial.println("city: " + weathers[inx].city); 127 | Serial.println("country: " + weathers[inx].country); 128 | Serial.println("temp: " + weathers[inx].temp); 129 | Serial.println("humidity: " + weathers[inx].humidity); 130 | Serial.println("condition: " + weathers[inx].condition); 131 | Serial.println("wind: " + weathers[inx].wind); 132 | Serial.println("weatherId: " + weathers[inx].weatherId); 133 | Serial.println("description: " + weathers[inx].description); 134 | Serial.println("icon: " + weathers[inx].icon); 135 | Serial.println(); 136 | 137 | } 138 | } 139 | 140 | String OpenWeatherMapClient::roundValue(String value) { 141 | float f = value.toFloat(); 142 | int rounded = (int)(f+0.5f); 143 | return String(rounded); 144 | } 145 | 146 | void OpenWeatherMapClient::updateCityIdList(int CityIDs[], int cityCount) { 147 | myCityIDs = ""; 148 | for (int inx = 0; inx < cityCount; inx++) { 149 | if (CityIDs[inx] > 0) { 150 | if (myCityIDs != "") { 151 | myCityIDs = myCityIDs + ","; 152 | } 153 | myCityIDs = myCityIDs + String(CityIDs[inx]); 154 | } 155 | } 156 | } 157 | 158 | void OpenWeatherMapClient::setMetric(boolean isMetric) { 159 | if (isMetric) { 160 | units = "metric"; 161 | } else { 162 | units = "imperial"; 163 | } 164 | } 165 | 166 | String OpenWeatherMapClient::getWeatherResults() { 167 | return result; 168 | } 169 | 170 | String OpenWeatherMapClient::getLat(int index) { 171 | return weathers[index].lat; 172 | } 173 | 174 | String OpenWeatherMapClient::getLon(int index) { 175 | return weathers[index].lon; 176 | } 177 | 178 | String OpenWeatherMapClient::getDt(int index) { 179 | return weathers[index].dt; 180 | } 181 | 182 | String OpenWeatherMapClient::getCity(int index) { 183 | return weathers[index].city; 184 | } 185 | 186 | String OpenWeatherMapClient::getCountry(int index) { 187 | return weathers[index].country; 188 | } 189 | 190 | String OpenWeatherMapClient::getTemp(int index) { 191 | return weathers[index].temp; 192 | } 193 | 194 | String OpenWeatherMapClient::getTempRounded(int index) { 195 | return roundValue(getTemp(index)); 196 | } 197 | 198 | String OpenWeatherMapClient::getHumidity(int index) { 199 | return weathers[index].humidity; 200 | } 201 | 202 | String OpenWeatherMapClient::getHumidityRounded(int index) { 203 | return roundValue(getHumidity(index)); 204 | } 205 | 206 | String OpenWeatherMapClient::getCondition(int index) { 207 | return weathers[index].condition; 208 | } 209 | 210 | String OpenWeatherMapClient::getWind(int index) { 211 | return weathers[index].wind; 212 | } 213 | 214 | String OpenWeatherMapClient::getWindRounded(int index) { 215 | return roundValue(getWind(index)); 216 | } 217 | 218 | String OpenWeatherMapClient::getWeatherId(int index) { 219 | return weathers[index].weatherId; 220 | } 221 | 222 | String OpenWeatherMapClient::getDescription(int index) { 223 | return weathers[index].description; 224 | } 225 | 226 | String OpenWeatherMapClient::getIcon(int index) { 227 | return weathers[index].icon; 228 | } 229 | 230 | boolean OpenWeatherMapClient::getCached() { 231 | return weathers[0].cached; 232 | } 233 | 234 | String OpenWeatherMapClient::getMyCityIDs() { 235 | return myCityIDs; 236 | } 237 | 238 | String OpenWeatherMapClient::getError() { 239 | return weathers[0].error; 240 | } 241 | 242 | String OpenWeatherMapClient::getWeatherIcon(int index) 243 | { 244 | int id = getWeatherId(index).toInt(); 245 | String W = ")"; 246 | switch(id) 247 | { 248 | case 800: W = "B"; break; 249 | case 801: W = "Y"; break; 250 | case 802: W = "H"; break; 251 | case 803: W = "H"; break; 252 | case 804: W = "Y"; break; 253 | 254 | case 200: W = "0"; break; 255 | case 201: W = "0"; break; 256 | case 202: W = "0"; break; 257 | case 210: W = "0"; break; 258 | case 211: W = "0"; break; 259 | case 212: W = "0"; break; 260 | case 221: W = "0"; break; 261 | case 230: W = "0"; break; 262 | case 231: W = "0"; break; 263 | case 232: W = "0"; break; 264 | 265 | case 300: W = "R"; break; 266 | case 301: W = "R"; break; 267 | case 302: W = "R"; break; 268 | case 310: W = "R"; break; 269 | case 311: W = "R"; break; 270 | case 312: W = "R"; break; 271 | case 313: W = "R"; break; 272 | case 314: W = "R"; break; 273 | case 321: W = "R"; break; 274 | 275 | case 500: W = "R"; break; 276 | case 501: W = "R"; break; 277 | case 502: W = "R"; break; 278 | case 503: W = "R"; break; 279 | case 504: W = "R"; break; 280 | case 511: W = "R"; break; 281 | case 520: W = "R"; break; 282 | case 521: W = "R"; break; 283 | case 522: W = "R"; break; 284 | case 531: W = "R"; break; 285 | 286 | case 600: W = "W"; break; 287 | case 601: W = "W"; break; 288 | case 602: W = "W"; break; 289 | case 611: W = "W"; break; 290 | case 612: W = "W"; break; 291 | case 615: W = "W"; break; 292 | case 616: W = "W"; break; 293 | case 620: W = "W"; break; 294 | case 621: W = "W"; break; 295 | case 622: W = "W"; break; 296 | 297 | case 701: W = "M"; break; 298 | case 711: W = "M"; break; 299 | case 721: W = "M"; break; 300 | case 731: W = "M"; break; 301 | case 741: W = "M"; break; 302 | case 751: W = "M"; break; 303 | case 761: W = "M"; break; 304 | case 762: W = "M"; break; 305 | case 771: W = "M"; break; 306 | case 781: W = "M"; break; 307 | 308 | default:break; 309 | } 310 | return W; 311 | } 312 | -------------------------------------------------------------------------------- /printermonitor/OpenWeatherMapClient.h: -------------------------------------------------------------------------------- 1 | /** The MIT License (MIT) 2 | 3 | Copyright (c) 2018 David Payne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | #pragma once 25 | #include 26 | #include "libs/ArduinoJson/ArduinoJson.h" 27 | 28 | class OpenWeatherMapClient { 29 | 30 | private: 31 | String myCityIDs = ""; 32 | String myApiKey = ""; 33 | String units = ""; 34 | String lang = ""; 35 | 36 | const char* servername = "api.openweathermap.org"; // remote server we will connect to 37 | String result; 38 | 39 | typedef struct { 40 | String lat; 41 | String lon; 42 | String dt; 43 | String city; 44 | String country; 45 | String temp; 46 | String humidity; 47 | String condition; 48 | String wind; 49 | String weatherId; 50 | String description; 51 | String icon; 52 | boolean cached; 53 | String error; 54 | } weather; 55 | 56 | weather weathers[5]; 57 | 58 | String roundValue(String value); 59 | 60 | public: 61 | OpenWeatherMapClient(String ApiKey, int CityIDs[], int cityCount, boolean isMetric, String language); 62 | void updateWeather(); 63 | void updateWeatherApiKey(String ApiKey); 64 | void updateCityIdList(int CityIDs[], int cityCount); 65 | void updateLanguage(String language); 66 | void setMetric(boolean isMetric); 67 | 68 | String getWeatherResults(); 69 | 70 | String getLat(int index); 71 | String getLon(int index); 72 | String getDt(int index); 73 | String getCity(int index); 74 | String getCountry(int index); 75 | String getTemp(int index); 76 | String getTempRounded(int index); 77 | String getHumidity(int index); 78 | String getHumidityRounded(int index); 79 | String getCondition(int index); 80 | String getWind(int index); 81 | String getWindRounded(int index); 82 | String getWeatherId(int index); 83 | String getDescription(int index); 84 | String getIcon(int index); 85 | boolean getCached(); 86 | String getMyCityIDs(); 87 | String getWeatherIcon(int index); 88 | String getError(); 89 | }; 90 | -------------------------------------------------------------------------------- /printermonitor/RepetierClient.h: -------------------------------------------------------------------------------- 1 | /** The MIT License (MIT) 2 | 3 | Copyright (c) 2018 David Payne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | /* 07 April 2019 : Jon Smith : added class for Repetier Server (kg4iae@github)*/ 25 | 26 | 27 | #pragma once 28 | #include 29 | #include "libs/ArduinoJson/ArduinoJson.h" 30 | #include 31 | 32 | class RepetierClient { 33 | 34 | private: 35 | char myServer[100]; 36 | int myPort = 3344; 37 | String myApiKey = ""; 38 | String encodedAuth = ""; 39 | boolean pollPsu; 40 | const String printerType = "Repetier"; 41 | 42 | void resetPrintData(); 43 | boolean validate(); 44 | WiFiClient getSubmitRequest(String apiGetData); 45 | WiFiClient getPostRequest(String apiPostData, String apiPostBody); 46 | 47 | String result; 48 | 49 | typedef struct { 50 | String averagePrintTime; 51 | String estimatedPrintTime; 52 | String fileName; 53 | String fileSize; 54 | String lastPrintTime; 55 | String progressCompletion; 56 | String progressFilepos; 57 | String progressPrintTime; 58 | String progressPrintTimeLeft; 59 | String state; 60 | String toolTemp; 61 | String toolTargetTemp; 62 | String filamentLength; 63 | String bedTemp; 64 | String bedTargetTemp; 65 | boolean isPrinting; 66 | boolean isPSUoff; 67 | String error; 68 | String printerName; 69 | } PrinterStruct; 70 | 71 | PrinterStruct printerData; 72 | 73 | 74 | public: 75 | RepetierClient(String ApiKey, String server, int port, String user, String pass, boolean psu); 76 | void getPrinterJobResults(); 77 | void getPrinterPsuState(); 78 | void updatePrintClient(String ApiKey, String server, int port, String user, String pass, boolean psu); 79 | 80 | String getAveragePrintTime(); 81 | String getEstimatedPrintTime(); 82 | String getFileName(); 83 | String getFileSize(); 84 | String getLastPrintTime(); 85 | String getProgressCompletion(); 86 | String getProgressFilepos(); 87 | String getProgressPrintTime(); 88 | String getProgressPrintTimeLeft(); 89 | String getState(); 90 | boolean isPrinting(); 91 | boolean isOperational(); 92 | boolean isPSUoff(); 93 | String getTempBedActual(); 94 | String getTempBedTarget(); 95 | String getTempToolActual(); 96 | String getTempToolTarget(); 97 | String getFilamentLength(); 98 | String getValueRounded(String value); 99 | String getError(); 100 | String getPrinterType(); 101 | int getPrinterPort(); 102 | String getPrinterName(); 103 | void setPrinterName(String printer); 104 | }; 105 | -------------------------------------------------------------------------------- /printermonitor/Settings.h: -------------------------------------------------------------------------------- 1 | /** The MIT License (MIT) 2 | 3 | Copyright (c) 2018 David Payne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | // Additional Contributions: 25 | /* 15 Jan 2019 : Owen Carter : Add psucontrol setting */ 26 | 27 | /****************************************************************************** 28 | * Printer Monitor is designed for the Wemos D1 ESP8266 29 | * Wemos D1 Mini: https://amzn.to/2qLyKJd 30 | * 0.96" OLED I2C 128x64 Display (12864) SSD1306 31 | * OLED Display: https://amzn.to/2JDEAUF 32 | ******************************************************************************/ 33 | /****************************************************************************** 34 | * NOTE: The settings here are the default settings for the first loading. 35 | * After loading you will manage changes to the settings via the Web Interface. 36 | * If you want to change settings again in the settings.h, you will need to 37 | * erase the file system on the Wemos or use the “Reset Settings” option in 38 | * the Web Interface. 39 | ******************************************************************************/ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include "TimeClient.h" 48 | #include "RepetierClient.h" 49 | #include "OctoPrintClient.h" 50 | #include "OpenWeatherMapClient.h" 51 | #include "WeatherStationFonts.h" 52 | #include "FS.h" 53 | #include "SH1106Wire.h" 54 | #include "SSD1306Wire.h" 55 | #include "OLEDDisplayUi.h" 56 | 57 | //****************************** 58 | // Start Settings 59 | //****************************** 60 | 61 | // OctoPrint / Repetier Monitoring -- Monitor your 3D OctoPrint or Repetier Server 62 | //#define USE_REPETIER_CLIENT // Uncomment this line to use the Repetier Printer Server -- OctoPrint is used by default and is most common 63 | String PrinterApiKey = ""; // ApiKey from your User Account on OctoPrint / Repetier 64 | String PrinterHostName = "octopi";// Default 'octopi' -- or hostname if different (optional if your IP changes) 65 | String PrinterServer = ""; // IP or Address of your OctoPrint / Repetier Server (DO NOT include http://) 66 | int PrinterPort = 80; // the port you are running your OctoPrint / Repetier server on (usually 80); 67 | String PrinterAuthUser = ""; // only used if you have haproxy or basic athentintication turned on (not default) 68 | String PrinterAuthPass = ""; // only used with haproxy or basic auth (only needed if you must authenticate) 69 | 70 | // Weather Configuration 71 | boolean DISPLAYWEATHER = true; // true = show weather when not printing / false = no weather 72 | String WeatherApiKey = ""; // Your API Key from http://openweathermap.org/ 73 | // Default City Location (use http://openweathermap.org/find to find city ID) 74 | int CityIDs[] = { 5304391 }; //Only USE ONE for weather marquee 75 | boolean IS_METRIC = false; // false = Imperial and true = Metric 76 | // Languages: ar, bg, ca, cz, de, el, en, fa, fi, fr, gl, hr, hu, it, ja, kr, la, lt, mk, nl, pl, pt, ro, ru, se, sk, sl, es, tr, ua, vi, zh_cn, zh_tw 77 | String WeatherLanguage = "en"; //Default (en) English 78 | 79 | // Webserver 80 | const int WEBSERVER_PORT = 80; // The port you can access this device on over HTTP 81 | const boolean WEBSERVER_ENABLED = true; // Device will provide a web interface via http://[ip]:[port]/ 82 | boolean IS_BASIC_AUTH = true; // true = require athentication to change configuration settings / false = no auth 83 | char* www_username = "admin"; // User account for the Web Interface 84 | char* www_password = "password"; // Password for the Web Interface 85 | 86 | // Date and Time 87 | float UtcOffset = -7; // Hour offset from GMT for your timezone 88 | boolean IS_24HOUR = false; // 23:00 millitary 24 hour clock 89 | int minutesBetweenDataRefresh = 15; 90 | boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false = turn off display when not printing 91 | 92 | // Display Settings 93 | const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d) 94 | const int SDA_PIN = D2; 95 | const int SCL_PIN = D5; // original code D5 -- Monitor Easy Board use D1 96 | boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom 97 | //#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common 98 | 99 | // LED Settings 100 | const int externalLight = LED_BUILTIN; // LED will always flash on bootup or Wifi Errors 101 | boolean USE_FLASH = true; // true = System LED will Flash on Service Calls; false = disabled LED flashing 102 | 103 | // PSU Control 104 | boolean HAS_PSU = false; // Set to true if https://github.com/kantlivelong/OctoPrint-PSUControl/ in use 105 | 106 | // OTA Updates 107 | boolean ENABLE_OTA = true; // this will allow you to load firmware to the device over WiFi (see OTA for ESP8266) 108 | String OTA_Password = ""; // Set an OTA password here -- leave blank if you don't want to be prompted for password 109 | 110 | //****************************** 111 | // End Settings 112 | //****************************** 113 | 114 | String themeColor = "light-green"; // this can be changed later in the web interface. 115 | -------------------------------------------------------------------------------- /printermonitor/TimeClient.cpp: -------------------------------------------------------------------------------- 1 | /**The MIT License (MIT) 2 | 3 | Copyright (c) 2015 by Daniel Eichhorn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | /* 25 | Modified by David Payne for use in the Scrolling Marquee 26 | */ 27 | 28 | #include "TimeClient.h" 29 | 30 | TimeClient::TimeClient(float utcOffset) { 31 | myUtcOffset = utcOffset; 32 | } 33 | 34 | void TimeClient::updateTime() { 35 | WiFiClient client; 36 | 37 | if (!client.connect(ntpServerName, httpPort)) { 38 | Serial.println("connection failed"); 39 | return; 40 | } 41 | 42 | // This will send the request to the server 43 | client.print(String("GET / HTTP/1.1\r\n") + 44 | String("Host: www.google.com\r\n") + 45 | String("Connection: close\r\n\r\n")); 46 | int repeatCounter = 0; 47 | while(!client.available() && repeatCounter < 10) { 48 | delay(1000); 49 | Serial.println("."); 50 | repeatCounter++; 51 | } 52 | 53 | String line; 54 | 55 | int size = 0; 56 | client.setNoDelay(false); 57 | while(client.connected()) { 58 | while((size = client.available()) > 0) { 59 | line = client.readStringUntil('\n'); 60 | line.toUpperCase(); 61 | // example: 62 | // date: Thu, 19 Nov 2015 20:25:40 GMT 63 | if (line.startsWith("DATE: ")) { 64 | Serial.println(line.substring(23, 25) + ":" + line.substring(26, 28) + ":" +line.substring(29, 31)); 65 | int parsedHours = line.substring(23, 25).toInt(); 66 | int parsedMinutes = line.substring(26, 28).toInt(); 67 | int parsedSeconds = line.substring(29, 31).toInt(); 68 | Serial.println(String(parsedHours) + ":" + String(parsedMinutes) + ":" + String(parsedSeconds)); 69 | 70 | localEpoc = (parsedHours * 60 * 60 + parsedMinutes * 60 + parsedSeconds); 71 | Serial.println(localEpoc); 72 | localMillisAtUpdate = millis(); 73 | client.stop(); 74 | } 75 | } 76 | } 77 | 78 | } 79 | 80 | void TimeClient::setUtcOffset(float utcOffset) { 81 | myUtcOffset = utcOffset; 82 | } 83 | 84 | String TimeClient::getHours() { 85 | if (localEpoc == 0) { 86 | return "--"; 87 | } 88 | int hours = ((getCurrentEpochWithUtcOffset() % 86400L) / 3600) % 24; 89 | if (hours < 10) { 90 | return "0" + String(hours); 91 | } 92 | return String(hours); // print the hour (86400 equals secs per day) 93 | 94 | } 95 | String TimeClient::getMinutes() { 96 | if (localEpoc == 0) { 97 | return "--"; 98 | } 99 | int minutes = ((getCurrentEpochWithUtcOffset() % 3600) / 60); 100 | if (minutes < 10 ) { 101 | // In the first 10 minutes of each hour, we'll want a leading '0' 102 | return "0" + String(minutes); 103 | } 104 | return String(minutes); 105 | } 106 | String TimeClient::getSeconds() { 107 | if (localEpoc == 0) { 108 | return "--"; 109 | } 110 | int seconds = getCurrentEpochWithUtcOffset() % 60; 111 | if ( seconds < 10 ) { 112 | // In the first 10 seconds of each minute, we'll want a leading '0' 113 | return "0" + String(seconds); 114 | } 115 | return String(seconds); 116 | } 117 | 118 | String TimeClient::getAmPmHours() { 119 | int hours = getHours().toInt(); 120 | if (hours >= 13) { 121 | hours = hours - 12; 122 | } 123 | if (hours == 0) { 124 | hours = 12; 125 | } 126 | return String(hours); 127 | } 128 | 129 | String TimeClient::getAmPm() { 130 | int hours = getHours().toInt(); 131 | String ampmValue = "AM"; 132 | if (hours >= 12) { 133 | ampmValue = "PM"; 134 | } 135 | return ampmValue; 136 | } 137 | 138 | String TimeClient::getFormattedTime() { 139 | return getHours() + ":" + getMinutes() + ":" + getSeconds(); 140 | } 141 | 142 | String TimeClient::getAmPmFormattedTime() { 143 | return getAmPmHours() + ":" + getMinutes() + " " + getAmPm(); 144 | } 145 | 146 | long TimeClient::getCurrentEpoch() { 147 | return localEpoc + ((millis() - localMillisAtUpdate) / 1000); 148 | } 149 | 150 | long TimeClient::getCurrentEpochWithUtcOffset() { 151 | return (long)round(getCurrentEpoch() + 3600 * myUtcOffset + 86400L) % 86400L; 152 | } 153 | -------------------------------------------------------------------------------- /printermonitor/TimeClient.h: -------------------------------------------------------------------------------- 1 | /**The MIT License (MIT) 2 | 3 | Copyright (c) 2015 by Daniel Eichhorn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | See more at http://blog.squix.ch 24 | */ 25 | 26 | /* 27 | Modified by David Payne for use in the Scrolling Marquee 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | #define NTP_PACKET_SIZE 48 35 | 36 | class TimeClient { 37 | 38 | private: 39 | float myUtcOffset = 0; 40 | long localEpoc = 0; 41 | long localMillisAtUpdate; 42 | const char* ntpServerName = "www.google.com"; 43 | const int httpPort = 80; 44 | byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 45 | 46 | public: 47 | TimeClient(float utcOffset); 48 | void updateTime(); 49 | 50 | void setUtcOffset(float utcOffset); 51 | String getHours(); 52 | String getAmPmHours(); 53 | String getAmPm(); 54 | String getMinutes(); 55 | String getSeconds(); 56 | String getFormattedTime(); 57 | String getAmPmFormattedTime(); 58 | long getCurrentEpoch(); 59 | long getCurrentEpochWithUtcOffset(); 60 | 61 | }; 62 | 63 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/ArduinoJson.h: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #include "src/ArduinoJson.h" 6 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ArduinoJson - arduinojson.org 2 | # Copyright Benoit Blanchon 2014-2018 3 | # MIT License 4 | 5 | cmake_minimum_required(VERSION 3.0) 6 | project(ArduinoJson) 7 | 8 | enable_testing() 9 | 10 | if(${COVERAGE}) 11 | set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") 12 | endif() 13 | 14 | include_directories(${CMAKE_CURRENT_LIST_DIR}/src) 15 | add_subdirectory(third-party/catch) 16 | add_subdirectory(test) 17 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution to ArduinoJson 2 | 3 | First, thank you for taking the time to contribute to this project. 4 | 5 | You can submit changes via GitHub Pull Requests. 6 | 7 | Please: 8 | 9 | 1. Unit test every change in behavior 10 | 2. Use clang-format in "file" mode to format the code 11 | 3. Consider using the Continuous Integration (Travis and AppVeyor) 12 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | --------------------- 3 | 4 | Copyright © 2014-2018 Benoit BLANCHON 5 | 6 | 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: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | 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. 11 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/README.md: -------------------------------------------------------------------------------- 1 | ![ArduinoJson](banner.svg) 2 | 3 | --- 4 | 5 | [![Build status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/master?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/master) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=master)](https://travis-ci.org/bblanchon/ArduinoJson) [![Coverage Status](https://img.shields.io/coveralls/bblanchon/ArduinoJson.svg)](https://coveralls.io/r/bblanchon/ArduinoJson?branch=master) [![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson) 6 | 7 | ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). 8 | 9 | ## Features 10 | 11 | * JSON decoding (comments are supported) 12 | * JSON encoding (with optional indentation) 13 | * Elegant API, easy to use 14 | * Fixed memory allocation (zero malloc) 15 | * No data duplication (zero copy) 16 | * Portable (written in C++98, can be used in any C++ project) 17 | * Self-contained (no external dependency) 18 | * Small footprint 19 | * Input and output streams 20 | * [100% code coverage](https://coveralls.io/github/bblanchon/ArduinoJson) 21 | * [Header-only library](https://en.wikipedia.org/wiki/Header-only) 22 | * [MIT License](https://en.wikipedia.org/wiki/MIT_License) 23 | * [Comprehensive documentation](https://arduinojson.org?utm_source=github&utm_medium=readme) 24 | 25 | ## Compatibility 26 | 27 | ArduinoJson works on the following hardware: 28 | 29 | * Arduino boards: [Uno](https://www.arduino.cc/en/Main/ArduinoBoardUno), [Due](https://www.arduino.cc/en/Main/ArduinoBoardDue), [Mini](https://www.arduino.cc/en/Main/ArduinoBoardMini), [Micro](https://www.arduino.cc/en/Main/ArduinoBoardMicro), [Yun](https://www.arduino.cc/en/Main/ArduinoBoardYun)... 30 | * Espressif chips: [ESP8266](https://en.wikipedia.org/wiki/ESP8266), [ESP32](https://en.wikipedia.org/wiki/ESP32) 31 | * WeMos boards: [D1](https://wiki.wemos.cc/products:d1:d1), [D1 mini](https://wiki.wemos.cc/products:d1:d1_mini), ... 32 | * RedBearLab boards: [BLE Nano](http://redbearlab.com/blenano/), [BLE Mini](http://redbearlab.com/blemini/), [WiFi Micro](https://redbear.cc/product/wifi/wifi-micro.html), [LOLIN32](https://wiki.wemos.cc/products:lolin32:lolin32)... 33 | * [Teensy](https://www.pjrc.com/teensy/) boards 34 | * Intel boards: Edison, Galileo... 35 | * Particle boards: [Photon](https://www.particle.io/products/hardware/photon-wifi-dev-kit), [Electron](https://www.particle.io/products/hardware/electron-cellular-dev-kit)... 36 | * Texas Instruments boards: [MSP430](http://www.ti.com/microcontrollers/msp430-ultra-low-power-mcus/overview/overview.html)... 37 | 38 | ArduinoJson compiles with zero warning on the following compilers, IDEs, and platforms: 39 | 40 | * [Arduino IDE](https://www.arduino.cc/en/Main/Software) 41 | * [PlatformIO](http://platformio.org/) 42 | * [Energia](http://energia.nu/) 43 | * [Visual Micro](http://www.visualmicro.com/) 44 | * [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/) 45 | * [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/) 46 | * [Atollic TrueSTUDIO](https://atollic.com/truestudio/) 47 | * [Keil uVision](http://www.keil.com/) 48 | * [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide) 49 | * [GCC](https://gcc.gnu.org/) 50 | * [Clang](https://clang.llvm.org/) 51 | * [Visual Studio](https://www.visualstudio.com/) 52 | 53 | ## Quickstart 54 | 55 | ### Deserialization 56 | 57 | Here is a program that parses a JSON document with ArduinoJson. 58 | 59 | ```c++ 60 | char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; 61 | 62 | StaticJsonBuffer<200> jsonBuffer; 63 | 64 | JsonObject& root = jsonBuffer.parseObject(json); 65 | 66 | const char* sensor = root["sensor"]; 67 | long time = root["time"]; 68 | double latitude = root["data"][0]; 69 | double longitude = root["data"][1]; 70 | ``` 71 | 72 | See the [tutorial on arduinojson.org](https://arduinojson.org/doc/decoding/?utm_source=github&utm_medium=readme) 73 | 74 | ### Serialization 75 | 76 | Here is a program that generates a JSON document with ArduinoJson: 77 | 78 | ```c++ 79 | StaticJsonBuffer<200> jsonBuffer; 80 | 81 | JsonObject& root = jsonBuffer.createObject(); 82 | root["sensor"] = "gps"; 83 | root["time"] = 1351824120; 84 | 85 | JsonArray& data = root.createNestedArray("data"); 86 | data.add(48.756080); 87 | data.add(2.302038); 88 | 89 | root.printTo(Serial); 90 | // This prints: 91 | // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} 92 | ``` 93 | 94 | See the [tutorial on arduinojson.org](https://arduinojson.org/doc/encoding/?utm_source=github&utm_medium=readme) 95 | 96 | ## Documentation 97 | 98 | The documentation is available on [arduinojson.org](https://arduinojson.org/?utm_source=github&utm_medium=readme), here are some shortcuts: 99 | 100 | * The [Examples](https://arduinojson.org/example/?utm_source=github&utm_medium=readme) show how to use the library in various situations. 101 | * The [API Reference](https://arduinojson.org/api/?utm_source=github&utm_medium=readme) contains the description of each class and function. 102 | * The [FAQ](https://arduinojson.org/faq/?utm_source=github&utm_medium=readme) has the answer to virtually every question. 103 | * The [ArduinoJson Assistant](https://arduinojson.org/assistant/?utm_source=github&utm_medium=readme) writes programs for you! 104 | 105 | --- 106 | 107 | Do you like this library? Please [star this project on GitHub](https://github.com/bblanchon/ArduinoJson/stargazers)! 108 | 109 | What? You don't like it but you *love* it? 110 | We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time! -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/SUPPORT.md: -------------------------------------------------------------------------------- 1 | # ArduinoJson Support 2 | 3 | First off, thank you very much for using ArduinoJson. 4 | 5 | We'll be very happy to help you, but first please read the following. 6 | 7 | ## Before asking for help 8 | 9 | 1. Read the [FAQ](https://arduinojson.org/faq/?utm_source=github&utm_medium=support) 10 | 2. Search in the [API Reference](https://arduinojson.org/api/?utm_source=github&utm_medium=support) 11 | 12 | If you did not find the answer, please create a [new issue on GitHub](https://github.com/bblanchon/ArduinoJson/issues/new). 13 | 14 | It is OK to add a comment to a currently opened issue, but please avoid adding comments to a closed issue. 15 | 16 | ## Before hitting the Submit button 17 | 18 | Please provide all the relevant information: 19 | 20 | * Good title 21 | * Short description of the problem 22 | * Target platform 23 | * Compiler model and version 24 | * [MVCE](https://stackoverflow.com/help/mcve) 25 | * Compiler output 26 | 27 | Good questions get fast answers! 28 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 5.13.1.{build} 2 | environment: 3 | matrix: 4 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 5 | CMAKE_GENERATOR: Visual Studio 15 2017 6 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 7 | CMAKE_GENERATOR: Visual Studio 14 2015 8 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 9 | CMAKE_GENERATOR: Visual Studio 12 2013 10 | - CMAKE_GENERATOR: Visual Studio 11 2012 11 | - CMAKE_GENERATOR: Visual Studio 10 2010 12 | - CMAKE_GENERATOR: MinGW Makefiles 13 | configuration: Debug 14 | before_build: 15 | - set PATH=C:\MinGW\bin;%PATH:C:\Program Files\Git\usr\bin;=% # Workaround for CMake not wanting sh.exe on PATH for MinGW 16 | - cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% -G "%CMAKE_GENERATOR%" . 17 | build_script: 18 | - cmake --build . --config %CONFIGURATION% 19 | test_script: 20 | - ctest --output-on-failure . 21 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/keywords.txt: -------------------------------------------------------------------------------- 1 | JsonArray KEYWORD1 2 | JsonObject KEYWORD1 3 | JsonVariant KEYWORD1 4 | StaticJsonBuffer KEYWORD1 5 | DynamicJsonBuffer KEYWORD1 6 | add KEYWORD2 7 | createArray KEYWORD2 8 | createNestedArray KEYWORD2 9 | createNestedObject KEYWORD2 10 | createObject KEYWORD2 11 | parseArray KEYWORD2 12 | parseObject KEYWORD2 13 | prettyPrintTo KEYWORD2 14 | printTo KEYWORD2 15 | success KEYWORD2 16 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson.h: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #ifdef __cplusplus 8 | 9 | #include "ArduinoJson.hpp" 10 | 11 | using namespace ArduinoJson; 12 | 13 | #else 14 | 15 | #error ArduinoJson requires a C++ compiler, please change file extension to .cc or .cpp 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "ArduinoJson/DynamicJsonBuffer.hpp" 8 | #include "ArduinoJson/JsonArray.hpp" 9 | #include "ArduinoJson/JsonObject.hpp" 10 | #include "ArduinoJson/StaticJsonBuffer.hpp" 11 | 12 | #include "ArduinoJson/Deserialization/JsonParserImpl.hpp" 13 | #include "ArduinoJson/JsonArrayImpl.hpp" 14 | #include "ArduinoJson/JsonBufferImpl.hpp" 15 | #include "ArduinoJson/JsonObjectImpl.hpp" 16 | #include "ArduinoJson/JsonVariantImpl.hpp" 17 | #include "ArduinoJson/Serialization/JsonSerializerImpl.hpp" 18 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Configuration.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | // Small or big machine? 8 | #ifndef ARDUINOJSON_EMBEDDED_MODE 9 | #if defined(ARDUINO) || defined(__IAR_SYSTEMS_ICC__) || defined(__XC) || \ 10 | defined(__ARMCC_VERSION) 11 | #define ARDUINOJSON_EMBEDDED_MODE 1 12 | #else 13 | #define ARDUINOJSON_EMBEDDED_MODE 0 14 | #endif 15 | #endif 16 | 17 | #if ARDUINOJSON_EMBEDDED_MODE 18 | 19 | // Store floats by default to reduce the memory usage (issue #134) 20 | #ifndef ARDUINOJSON_USE_DOUBLE 21 | #define ARDUINOJSON_USE_DOUBLE 0 22 | #endif 23 | 24 | // Store longs by default, because they usually match the size of a float. 25 | #ifndef ARDUINOJSON_USE_LONG_LONG 26 | #define ARDUINOJSON_USE_LONG_LONG 0 27 | #endif 28 | #ifndef ARDUINOJSON_USE_INT64 29 | #define ARDUINOJSON_USE_INT64 0 30 | #endif 31 | 32 | // Embedded systems usually don't have std::string 33 | #ifndef ARDUINOJSON_ENABLE_STD_STRING 34 | #define ARDUINOJSON_ENABLE_STD_STRING 0 35 | #endif 36 | 37 | // Embedded systems usually don't have std::stream 38 | #ifndef ARDUINOJSON_ENABLE_STD_STREAM 39 | #define ARDUINOJSON_ENABLE_STD_STREAM 0 40 | #endif 41 | 42 | // Limit nesting as the stack is likely to be small 43 | #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT 44 | #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 45 | #endif 46 | 47 | #else // ARDUINOJSON_EMBEDDED_MODE 48 | 49 | // On a computer we have plenty of memory so we can use doubles 50 | #ifndef ARDUINOJSON_USE_DOUBLE 51 | #define ARDUINOJSON_USE_DOUBLE 1 52 | #endif 53 | 54 | // Use long long when available 55 | #ifndef ARDUINOJSON_USE_LONG_LONG 56 | #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) 57 | #define ARDUINOJSON_USE_LONG_LONG 1 58 | #else 59 | #define ARDUINOJSON_USE_LONG_LONG 0 60 | #endif 61 | #endif 62 | 63 | // Use _int64 on old versions of Visual Studio 64 | #ifndef ARDUINOJSON_USE_INT64 65 | #if defined(_MSC_VER) && _MSC_VER <= 1700 66 | #define ARDUINOJSON_USE_INT64 1 67 | #else 68 | #define ARDUINOJSON_USE_INT64 0 69 | #endif 70 | #endif 71 | 72 | // On a computer, we can use std::string 73 | #ifndef ARDUINOJSON_ENABLE_STD_STRING 74 | #define ARDUINOJSON_ENABLE_STD_STRING 1 75 | #endif 76 | 77 | // On a computer, we can assume std::stream 78 | #ifndef ARDUINOJSON_ENABLE_STD_STREAM 79 | #define ARDUINOJSON_ENABLE_STD_STREAM 1 80 | #endif 81 | 82 | // On a computer, the stack is large so we can increase nesting limit 83 | #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT 84 | #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 85 | #endif 86 | 87 | #endif // ARDUINOJSON_EMBEDDED_MODE 88 | 89 | #ifdef ARDUINO 90 | 91 | // Enable support for Arduino String 92 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING 93 | #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 94 | #endif 95 | 96 | // Enable support for Arduino Stream 97 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM 98 | #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1 99 | #endif 100 | 101 | #else // ARDUINO 102 | 103 | // Disable support for Arduino String 104 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING 105 | #define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 106 | #endif 107 | 108 | // Disable support for Arduino Stream 109 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM 110 | #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0 111 | #endif 112 | 113 | #endif // ARDUINO 114 | 115 | #ifndef ARDUINOJSON_ENABLE_PROGMEM 116 | #ifdef PROGMEM 117 | #define ARDUINOJSON_ENABLE_PROGMEM 1 118 | #else 119 | #define ARDUINOJSON_ENABLE_PROGMEM 0 120 | #endif 121 | #endif 122 | 123 | #ifndef ARDUINOJSON_ENABLE_ALIGNMENT 124 | #ifdef ARDUINO_ARCH_AVR 125 | // alignment isn't needed for 8-bit AVR 126 | #define ARDUINOJSON_ENABLE_ALIGNMENT 0 127 | #else 128 | // but most processors need pointers to be align on word size 129 | #define ARDUINOJSON_ENABLE_ALIGNMENT 1 130 | #endif 131 | #endif 132 | 133 | // Enable deprecated functions by default 134 | #ifndef ARDUINOJSON_ENABLE_DEPRECATED 135 | #define ARDUINOJSON_ENABLE_DEPRECATED 1 136 | #endif 137 | 138 | // Control the exponentiation threshold for big numbers 139 | // CAUTION: cannot be more that 1e9 !!!! 140 | #ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 141 | #define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7 142 | #endif 143 | 144 | // Control the exponentiation threshold for small numbers 145 | #ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 146 | #define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 147 | #endif 148 | 149 | #if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64 150 | #error ARDUINOJSON_USE_LONG_LONG and ARDUINOJSON_USE_INT64 cannot be set together 151 | #endif 152 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/Encoding.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | class Encoding { 11 | public: 12 | // Optimized for code size on a 8-bit AVR 13 | static char escapeChar(char c) { 14 | const char *p = escapeTable(false); 15 | while (p[0] && p[1] != c) { 16 | p += 2; 17 | } 18 | return p[0]; 19 | } 20 | 21 | // Optimized for code size on a 8-bit AVR 22 | static char unescapeChar(char c) { 23 | const char *p = escapeTable(true); 24 | for (;;) { 25 | if (p[0] == '\0') return c; 26 | if (p[0] == c) return p[1]; 27 | p += 2; 28 | } 29 | } 30 | 31 | private: 32 | static const char *escapeTable(bool excludeIdenticals) { 33 | return &"\"\"\\\\b\bf\fn\nr\rt\t"[excludeIdenticals ? 4 : 0]; 34 | } 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/JsonBufferAllocated.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonBuffer.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | class JsonBufferAllocated { 13 | public: 14 | void *operator new(size_t n, JsonBuffer *jsonBuffer) throw() { 15 | if (!jsonBuffer) return NULL; 16 | return jsonBuffer->alloc(n); 17 | } 18 | 19 | void operator delete(void *, JsonBuffer *)throw(); 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/JsonFloat.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | #if ARDUINOJSON_USE_DOUBLE 13 | typedef double JsonFloat; 14 | #else 15 | typedef float JsonFloat; 16 | #endif 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/JsonInteger.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | #if ARDUINOJSON_USE_LONG_LONG 13 | typedef long long JsonInteger; 14 | typedef unsigned long long JsonUInt; 15 | #elif ARDUINOJSON_USE_INT64 16 | typedef __int64 JsonInteger; 17 | typedef unsigned _int64 JsonUInt; 18 | #else 19 | typedef long JsonInteger; 20 | typedef unsigned long JsonUInt; 21 | #endif 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/JsonVariantAs.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A metafunction that returns the type of the value returned by 11 | // JsonVariant::as() 12 | template 13 | struct JsonVariantAs { 14 | typedef T type; 15 | }; 16 | 17 | template <> 18 | struct JsonVariantAs { 19 | typedef const char* type; 20 | }; 21 | 22 | template <> 23 | struct JsonVariantAs { 24 | typedef JsonArray& type; 25 | }; 26 | 27 | template <> 28 | struct JsonVariantAs { 29 | typedef const JsonArray& type; 30 | }; 31 | 32 | template <> 33 | struct JsonVariantAs { 34 | typedef JsonObject& type; 35 | }; 36 | 37 | template <> 38 | struct JsonVariantAs { 39 | typedef const JsonObject& type; 40 | }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/JsonVariantContent.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonFloat.hpp" 8 | #include "JsonInteger.hpp" 9 | 10 | namespace ArduinoJson { 11 | 12 | // Forward declarations 13 | class JsonArray; 14 | class JsonObject; 15 | 16 | namespace Internals { 17 | // A union that defines the actual content of a JsonVariant. 18 | // The enum JsonVariantType determines which member is in use. 19 | union JsonVariantContent { 20 | JsonFloat asFloat; // used for double and float 21 | JsonUInt asInteger; // used for bool, char, short, int and longs 22 | const char* asString; // asString can be null 23 | JsonArray* asArray; // asArray cannot be null 24 | JsonObject* asObject; // asObject cannot be null 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/JsonVariantDefault.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | template 11 | struct JsonVariantDefault { 12 | static T get() { 13 | return T(); 14 | } 15 | }; 16 | 17 | template 18 | struct JsonVariantDefault : JsonVariantDefault {}; 19 | 20 | template 21 | struct JsonVariantDefault : JsonVariantDefault {}; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/JsonVariantType.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | class JsonArray; 9 | class JsonObject; 10 | 11 | namespace Internals { 12 | 13 | // Enumerated type to know the current type of a JsonVariant. 14 | // The value determines which member of JsonVariantContent is used. 15 | enum JsonVariantType { 16 | JSON_UNDEFINED, // JsonVariant has not been initialized 17 | JSON_UNPARSED, // JsonVariant contains an unparsed string 18 | JSON_STRING, // JsonVariant stores a const char* 19 | JSON_BOOLEAN, // JsonVariant stores a bool 20 | JSON_POSITIVE_INTEGER, // JsonVariant stores an JsonUInt 21 | JSON_NEGATIVE_INTEGER, // JsonVariant stores an JsonUInt that must be negated 22 | JSON_ARRAY, // JsonVariant stores a pointer to a JsonArray 23 | JSON_OBJECT, // JsonVariant stores a pointer to a JsonObject 24 | JSON_FLOAT // JsonVariant stores a JsonFloat 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/List.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonBuffer.hpp" 8 | #include "ListConstIterator.hpp" 9 | #include "ListIterator.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | // A singly linked list of T. 15 | // The linked list is composed of ListNode. 16 | // It is derived by JsonArray and JsonObject 17 | template 18 | class List { 19 | public: 20 | typedef T value_type; 21 | typedef ListNode node_type; 22 | typedef ListIterator iterator; 23 | typedef ListConstIterator const_iterator; 24 | 25 | // Creates an empty List attached to a JsonBuffer. 26 | // The JsonBuffer allows to allocate new nodes. 27 | // When buffer is NULL, the List is not able to grow and success() returns 28 | // false. This is used to identify bad memory allocations and parsing 29 | // failures. 30 | explicit List(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {} 31 | 32 | // Returns true if the object is valid 33 | // Would return false in the following situation: 34 | // - the memory allocation failed (StaticJsonBuffer was too small) 35 | // - the JSON parsing failed 36 | bool success() const { 37 | return _buffer != NULL; 38 | } 39 | 40 | // Returns the numbers of elements in the list. 41 | // For a JsonObject, it would return the number of key-value pairs 42 | size_t size() const { 43 | size_t nodeCount = 0; 44 | for (node_type *node = _firstNode; node; node = node->next) nodeCount++; 45 | return nodeCount; 46 | } 47 | 48 | iterator add() { 49 | node_type *newNode = new (_buffer) node_type(); 50 | 51 | if (_firstNode) { 52 | node_type *lastNode = _firstNode; 53 | while (lastNode->next) lastNode = lastNode->next; 54 | lastNode->next = newNode; 55 | } else { 56 | _firstNode = newNode; 57 | } 58 | 59 | return iterator(newNode); 60 | } 61 | 62 | iterator begin() { 63 | return iterator(_firstNode); 64 | } 65 | iterator end() { 66 | return iterator(NULL); 67 | } 68 | 69 | const_iterator begin() const { 70 | return const_iterator(_firstNode); 71 | } 72 | const_iterator end() const { 73 | return const_iterator(NULL); 74 | } 75 | 76 | void remove(iterator it) { 77 | node_type *nodeToRemove = it._node; 78 | if (!nodeToRemove) return; 79 | if (nodeToRemove == _firstNode) { 80 | _firstNode = nodeToRemove->next; 81 | } else { 82 | for (node_type *node = _firstNode; node; node = node->next) 83 | if (node->next == nodeToRemove) node->next = nodeToRemove->next; 84 | } 85 | } 86 | 87 | protected: 88 | JsonBuffer *_buffer; 89 | 90 | private: 91 | node_type *_firstNode; 92 | }; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/ListConstIterator.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "ListNode.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // A read-only forward itertor for List 13 | template 14 | class ListConstIterator { 15 | public: 16 | explicit ListConstIterator(const ListNode *node = NULL) : _node(node) {} 17 | 18 | const T &operator*() const { 19 | return _node->content; 20 | } 21 | const T *operator->() { 22 | return &_node->content; 23 | } 24 | 25 | bool operator==(const ListConstIterator &other) const { 26 | return _node == other._node; 27 | } 28 | 29 | bool operator!=(const ListConstIterator &other) const { 30 | return _node != other._node; 31 | } 32 | 33 | ListConstIterator &operator++() { 34 | if (_node) _node = _node->next; 35 | return *this; 36 | } 37 | 38 | ListConstIterator &operator+=(size_t distance) { 39 | while (_node && distance) { 40 | _node = _node->next; 41 | --distance; 42 | } 43 | return *this; 44 | } 45 | 46 | private: 47 | const ListNode *_node; 48 | }; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/ListIterator.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "ListConstIterator.hpp" 8 | #include "ListNode.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | template 14 | class List; 15 | 16 | // A read-write forward iterator for List 17 | template 18 | class ListIterator { 19 | friend class List; 20 | 21 | public: 22 | explicit ListIterator(ListNode *node = NULL) : _node(node) {} 23 | 24 | T &operator*() const { 25 | return _node->content; 26 | } 27 | T *operator->() { 28 | return &_node->content; 29 | } 30 | 31 | bool operator==(const ListIterator &other) const { 32 | return _node == other._node; 33 | } 34 | 35 | bool operator!=(const ListIterator &other) const { 36 | return _node != other._node; 37 | } 38 | 39 | ListIterator &operator++() { 40 | if (_node) _node = _node->next; 41 | return *this; 42 | } 43 | 44 | ListIterator &operator+=(size_t distance) { 45 | while (_node && distance) { 46 | _node = _node->next; 47 | --distance; 48 | } 49 | return *this; 50 | } 51 | 52 | operator ListConstIterator() const { 53 | return ListConstIterator(_node); 54 | } 55 | 56 | private: 57 | ListNode *_node; 58 | }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/ListNode.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include // for NULL 8 | 9 | #include "JsonBufferAllocated.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | // A node for a singly-linked list. 15 | // Used by List and its iterators. 16 | template 17 | struct ListNode : public Internals::JsonBufferAllocated { 18 | ListNode() throw() : next(NULL) {} 19 | 20 | ListNode *next; 21 | T content; 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/NonCopyable.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A type that cannot be copied 11 | class NonCopyable { 12 | protected: 13 | NonCopyable() {} 14 | 15 | private: 16 | // copy constructor is private 17 | NonCopyable(const NonCopyable&); 18 | 19 | // copy operator is private 20 | NonCopyable& operator=(const NonCopyable&); 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/ReferenceType.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A type that is meant to be used by reference only (JsonArray and JsonObject) 11 | class ReferenceType { 12 | public: 13 | bool operator==(const ReferenceType& other) const { 14 | // two JsonArray are equal if they are the same instance 15 | // (we don't compare the content) 16 | return this == &other; 17 | } 18 | 19 | bool operator!=(const ReferenceType& other) const { 20 | return this != &other; 21 | } 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Data/ValueSaver.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonBuffer.hpp" 8 | #include "../JsonVariant.hpp" 9 | #include "../StringTraits/StringTraits.hpp" 10 | #include "../TypeTraits/EnableIf.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | template 16 | struct ValueSaver { 17 | template 18 | static bool save(JsonBuffer*, Destination& destination, Source source) { 19 | destination = source; 20 | return true; 21 | } 22 | }; 23 | 24 | template 25 | struct ValueSaver< 26 | Source, typename EnableIf::should_duplicate>::type> { 27 | template 28 | static bool save(JsonBuffer* buffer, Destination& dest, Source source) { 29 | if (!StringTraits::is_null(source)) { 30 | typename StringTraits::duplicate_t dup = 31 | StringTraits::duplicate(source, buffer); 32 | if (!dup) return false; 33 | dest = dup; 34 | } else { 35 | dest = reinterpret_cast(0); 36 | } 37 | return true; 38 | } 39 | }; 40 | 41 | // const char*, const signed char*, const unsigned char* 42 | template 43 | struct ValueSaver< 44 | Char*, typename EnableIf::should_duplicate>::type> { 45 | template 46 | static bool save(JsonBuffer*, Destination& dest, Char* source) { 47 | dest = reinterpret_cast(source); 48 | return true; 49 | } 50 | }; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Deserialization/Comments.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | template 10 | void skipSpacesAndComments(TInput& input) { 11 | for (;;) { 12 | switch (input.current()) { 13 | // spaces 14 | case ' ': 15 | case '\t': 16 | case '\r': 17 | case '\n': 18 | input.move(); 19 | continue; 20 | 21 | // comments 22 | case '/': 23 | switch (input.next()) { 24 | // C-style block comment 25 | case '*': 26 | input.move(); // skip '/' 27 | // no need to skip '*' 28 | for (;;) { 29 | input.move(); 30 | if (input.current() == '\0') return; 31 | if (input.current() == '*' && input.next() == '/') { 32 | input.move(); // skip '*' 33 | input.move(); // skip '/' 34 | break; 35 | } 36 | } 37 | break; 38 | 39 | // C++-style line comment 40 | case '/': 41 | // not need to skip "//" 42 | for (;;) { 43 | input.move(); 44 | if (input.current() == '\0') return; 45 | if (input.current() == '\n') break; 46 | } 47 | break; 48 | 49 | // not a comment, just a '/' 50 | default: 51 | return; 52 | } 53 | break; 54 | 55 | default: 56 | return; 57 | } 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Deserialization/JsonParser.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonBuffer.hpp" 8 | #include "../JsonVariant.hpp" 9 | #include "../TypeTraits/IsConst.hpp" 10 | #include "StringWriter.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | // Parse JSON string to create JsonArrays and JsonObjects 16 | // This internal class is not indended to be used directly. 17 | // Instead, use JsonBuffer.parseArray() or .parseObject() 18 | template 19 | class JsonParser { 20 | public: 21 | JsonParser(JsonBuffer *buffer, TReader reader, TWriter writer, 22 | uint8_t nestingLimit) 23 | : _buffer(buffer), 24 | _reader(reader), 25 | _writer(writer), 26 | _nestingLimit(nestingLimit) {} 27 | 28 | JsonArray &parseArray(); 29 | JsonObject &parseObject(); 30 | 31 | JsonVariant parseVariant() { 32 | JsonVariant result; 33 | parseAnythingTo(&result); 34 | return result; 35 | } 36 | 37 | private: 38 | JsonParser &operator=(const JsonParser &); // non-copiable 39 | 40 | static bool eat(TReader &, char charToSkip); 41 | FORCE_INLINE bool eat(char charToSkip) { 42 | return eat(_reader, charToSkip); 43 | } 44 | 45 | const char *parseString(); 46 | bool parseAnythingTo(JsonVariant *destination); 47 | FORCE_INLINE bool parseAnythingToUnsafe(JsonVariant *destination); 48 | 49 | inline bool parseArrayTo(JsonVariant *destination); 50 | inline bool parseObjectTo(JsonVariant *destination); 51 | inline bool parseStringTo(JsonVariant *destination); 52 | 53 | static inline bool isBetween(char c, char min, char max) { 54 | return min <= c && c <= max; 55 | } 56 | 57 | static inline bool canBeInNonQuotedString(char c) { 58 | return isBetween(c, '0', '9') || isBetween(c, '_', 'z') || 59 | isBetween(c, 'A', 'Z') || c == '+' || c == '-' || c == '.'; 60 | } 61 | 62 | static inline bool isQuote(char c) { 63 | return c == '\'' || c == '\"'; 64 | } 65 | 66 | JsonBuffer *_buffer; 67 | TReader _reader; 68 | TWriter _writer; 69 | uint8_t _nestingLimit; 70 | }; 71 | 72 | template 73 | struct JsonParserBuilder { 74 | typedef typename StringTraits::Reader InputReader; 75 | typedef JsonParser TParser; 76 | 77 | static TParser makeParser(TJsonBuffer *buffer, TString &json, 78 | uint8_t nestingLimit) { 79 | return TParser(buffer, InputReader(json), *buffer, nestingLimit); 80 | } 81 | }; 82 | 83 | template 84 | struct JsonParserBuilder::value>::type> { 86 | typedef typename StringTraits::Reader TReader; 87 | typedef StringWriter TWriter; 88 | typedef JsonParser TParser; 89 | 90 | static TParser makeParser(TJsonBuffer *buffer, TChar *json, 91 | uint8_t nestingLimit) { 92 | return TParser(buffer, TReader(json), TWriter(json), nestingLimit); 93 | } 94 | }; 95 | 96 | template 97 | inline typename JsonParserBuilder::TParser makeParser( 98 | TJsonBuffer *buffer, TString &json, uint8_t nestingLimit) { 99 | return JsonParserBuilder::makeParser(buffer, json, 100 | nestingLimit); 101 | } 102 | } // namespace Internals 103 | } // namespace ArduinoJson 104 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Deserialization/JsonParserImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Comments.hpp" 8 | #include "JsonParser.hpp" 9 | 10 | template 11 | inline bool ArduinoJson::Internals::JsonParser::eat( 12 | TReader &reader, char charToSkip) { 13 | skipSpacesAndComments(reader); 14 | if (reader.current() != charToSkip) return false; 15 | reader.move(); 16 | return true; 17 | } 18 | 19 | template 20 | inline bool 21 | ArduinoJson::Internals::JsonParser::parseAnythingTo( 22 | JsonVariant *destination) { 23 | if (_nestingLimit == 0) return false; 24 | _nestingLimit--; 25 | bool success = parseAnythingToUnsafe(destination); 26 | _nestingLimit++; 27 | return success; 28 | } 29 | 30 | template 31 | inline bool 32 | ArduinoJson::Internals::JsonParser::parseAnythingToUnsafe( 33 | JsonVariant *destination) { 34 | skipSpacesAndComments(_reader); 35 | 36 | switch (_reader.current()) { 37 | case '[': 38 | return parseArrayTo(destination); 39 | 40 | case '{': 41 | return parseObjectTo(destination); 42 | 43 | default: 44 | return parseStringTo(destination); 45 | } 46 | } 47 | 48 | template 49 | inline ArduinoJson::JsonArray & 50 | ArduinoJson::Internals::JsonParser::parseArray() { 51 | // Create an empty array 52 | JsonArray &array = _buffer->createArray(); 53 | 54 | // Check opening braket 55 | if (!eat('[')) goto ERROR_MISSING_BRACKET; 56 | if (eat(']')) goto SUCCESS_EMPTY_ARRAY; 57 | 58 | // Read each value 59 | for (;;) { 60 | // 1 - Parse value 61 | JsonVariant value; 62 | if (!parseAnythingTo(&value)) goto ERROR_INVALID_VALUE; 63 | if (!array.add(value)) goto ERROR_NO_MEMORY; 64 | 65 | // 2 - More values? 66 | if (eat(']')) goto SUCCES_NON_EMPTY_ARRAY; 67 | if (!eat(',')) goto ERROR_MISSING_COMMA; 68 | } 69 | 70 | SUCCESS_EMPTY_ARRAY: 71 | SUCCES_NON_EMPTY_ARRAY: 72 | return array; 73 | 74 | ERROR_INVALID_VALUE: 75 | ERROR_MISSING_BRACKET: 76 | ERROR_MISSING_COMMA: 77 | ERROR_NO_MEMORY: 78 | return JsonArray::invalid(); 79 | } 80 | 81 | template 82 | inline bool ArduinoJson::Internals::JsonParser::parseArrayTo( 83 | JsonVariant *destination) { 84 | JsonArray &array = parseArray(); 85 | if (!array.success()) return false; 86 | 87 | *destination = array; 88 | return true; 89 | } 90 | 91 | template 92 | inline ArduinoJson::JsonObject & 93 | ArduinoJson::Internals::JsonParser::parseObject() { 94 | // Create an empty object 95 | JsonObject &object = _buffer->createObject(); 96 | 97 | // Check opening brace 98 | if (!eat('{')) goto ERROR_MISSING_BRACE; 99 | if (eat('}')) goto SUCCESS_EMPTY_OBJECT; 100 | 101 | // Read each key value pair 102 | for (;;) { 103 | // 1 - Parse key 104 | const char *key = parseString(); 105 | if (!key) goto ERROR_INVALID_KEY; 106 | if (!eat(':')) goto ERROR_MISSING_COLON; 107 | 108 | // 2 - Parse value 109 | JsonVariant value; 110 | if (!parseAnythingTo(&value)) goto ERROR_INVALID_VALUE; 111 | if (!object.set(key, value)) goto ERROR_NO_MEMORY; 112 | 113 | // 3 - More keys/values? 114 | if (eat('}')) goto SUCCESS_NON_EMPTY_OBJECT; 115 | if (!eat(',')) goto ERROR_MISSING_COMMA; 116 | } 117 | 118 | SUCCESS_EMPTY_OBJECT: 119 | SUCCESS_NON_EMPTY_OBJECT: 120 | return object; 121 | 122 | ERROR_INVALID_KEY: 123 | ERROR_INVALID_VALUE: 124 | ERROR_MISSING_BRACE: 125 | ERROR_MISSING_COLON: 126 | ERROR_MISSING_COMMA: 127 | ERROR_NO_MEMORY: 128 | return JsonObject::invalid(); 129 | } 130 | 131 | template 132 | inline bool ArduinoJson::Internals::JsonParser::parseObjectTo( 133 | JsonVariant *destination) { 134 | JsonObject &object = parseObject(); 135 | if (!object.success()) return false; 136 | 137 | *destination = object; 138 | return true; 139 | } 140 | 141 | template 142 | inline const char * 143 | ArduinoJson::Internals::JsonParser::parseString() { 144 | typename RemoveReference::type::String str = _writer.startString(); 145 | 146 | skipSpacesAndComments(_reader); 147 | char c = _reader.current(); 148 | 149 | if (isQuote(c)) { // quotes 150 | _reader.move(); 151 | char stopChar = c; 152 | for (;;) { 153 | c = _reader.current(); 154 | if (c == '\0') break; 155 | _reader.move(); 156 | 157 | if (c == stopChar) break; 158 | 159 | if (c == '\\') { 160 | // replace char 161 | c = Encoding::unescapeChar(_reader.current()); 162 | if (c == '\0') break; 163 | _reader.move(); 164 | } 165 | 166 | str.append(c); 167 | } 168 | } else { // no quotes 169 | for (;;) { 170 | if (!canBeInNonQuotedString(c)) break; 171 | _reader.move(); 172 | str.append(c); 173 | c = _reader.current(); 174 | } 175 | } 176 | 177 | return str.c_str(); 178 | } 179 | 180 | template 181 | inline bool ArduinoJson::Internals::JsonParser::parseStringTo( 182 | JsonVariant *destination) { 183 | bool hasQuotes = isQuote(_reader.current()); 184 | const char *value = parseString(); 185 | if (value == NULL) return false; 186 | if (hasQuotes) { 187 | *destination = value; 188 | } else { 189 | *destination = RawJson(value); 190 | } 191 | return true; 192 | } 193 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Deserialization/StringWriter.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | template 11 | class StringWriter { 12 | public: 13 | class String { 14 | public: 15 | String(TChar** ptr) : _writePtr(ptr), _startPtr(*ptr) {} 16 | 17 | void append(char c) { 18 | *(*_writePtr)++ = TChar(c); 19 | } 20 | 21 | const char* c_str() const { 22 | *(*_writePtr)++ = 0; 23 | return reinterpret_cast(_startPtr); 24 | } 25 | 26 | private: 27 | TChar** _writePtr; 28 | TChar* _startPtr; 29 | }; 30 | 31 | StringWriter(TChar* buffer) : _ptr(buffer) {} 32 | 33 | String startString() { 34 | return String(&_ptr); 35 | } 36 | 37 | private: 38 | TChar* _ptr; 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/DynamicJsonBuffer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonBufferBase.hpp" 8 | 9 | #include 10 | 11 | #if defined(__clang__) 12 | #pragma clang diagnostic push 13 | #pragma clang diagnostic ignored "-Wnon-virtual-dtor" 14 | #elif defined(__GNUC__) 15 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 16 | #pragma GCC diagnostic push 17 | #endif 18 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 19 | #endif 20 | 21 | namespace ArduinoJson { 22 | namespace Internals { 23 | class DefaultAllocator { 24 | public: 25 | void* allocate(size_t size) { 26 | return malloc(size); 27 | } 28 | void deallocate(void* pointer) { 29 | free(pointer); 30 | } 31 | }; 32 | 33 | template 34 | class DynamicJsonBufferBase 35 | : public JsonBufferBase > { 36 | struct Block; 37 | struct EmptyBlock { 38 | Block* next; 39 | size_t capacity; 40 | size_t size; 41 | }; 42 | struct Block : EmptyBlock { 43 | uint8_t data[1]; 44 | }; 45 | 46 | public: 47 | enum { EmptyBlockSize = sizeof(EmptyBlock) }; 48 | 49 | DynamicJsonBufferBase(size_t initialSize = 256) 50 | : _head(NULL), _nextBlockCapacity(initialSize) {} 51 | 52 | ~DynamicJsonBufferBase() { 53 | clear(); 54 | } 55 | 56 | // Gets the number of bytes occupied in the buffer 57 | size_t size() const { 58 | size_t total = 0; 59 | for (const Block* b = _head; b; b = b->next) total += b->size; 60 | return total; 61 | } 62 | 63 | // Allocates the specified amount of bytes in the buffer 64 | virtual void* alloc(size_t bytes) { 65 | alignNextAlloc(); 66 | return canAllocInHead(bytes) ? allocInHead(bytes) : allocInNewBlock(bytes); 67 | } 68 | 69 | // Resets the buffer. 70 | // USE WITH CAUTION: this invalidates all previously allocated data 71 | void clear() { 72 | Block* currentBlock = _head; 73 | while (currentBlock != NULL) { 74 | _nextBlockCapacity = currentBlock->capacity; 75 | Block* nextBlock = currentBlock->next; 76 | _allocator.deallocate(currentBlock); 77 | currentBlock = nextBlock; 78 | } 79 | _head = 0; 80 | } 81 | 82 | class String { 83 | public: 84 | String(DynamicJsonBufferBase* parent) 85 | : _parent(parent), _start(NULL), _length(0) {} 86 | 87 | void append(char c) { 88 | if (_parent->canAllocInHead(1)) { 89 | char* end = static_cast(_parent->allocInHead(1)); 90 | *end = c; 91 | if (_length == 0) _start = end; 92 | } else { 93 | char* newStart = 94 | static_cast(_parent->allocInNewBlock(_length + 1)); 95 | if (_start && newStart) memcpy(newStart, _start, _length); 96 | if (newStart) newStart[_length] = c; 97 | _start = newStart; 98 | } 99 | _length++; 100 | } 101 | 102 | const char* c_str() { 103 | append(0); 104 | return _start; 105 | } 106 | 107 | private: 108 | DynamicJsonBufferBase* _parent; 109 | char* _start; 110 | size_t _length; 111 | }; 112 | 113 | String startString() { 114 | return String(this); 115 | } 116 | 117 | private: 118 | void alignNextAlloc() { 119 | if (_head) _head->size = this->round_size_up(_head->size); 120 | } 121 | 122 | bool canAllocInHead(size_t bytes) const { 123 | return _head != NULL && _head->size + bytes <= _head->capacity; 124 | } 125 | 126 | void* allocInHead(size_t bytes) { 127 | void* p = _head->data + _head->size; 128 | _head->size += bytes; 129 | return p; 130 | } 131 | 132 | void* allocInNewBlock(size_t bytes) { 133 | size_t capacity = _nextBlockCapacity; 134 | if (bytes > capacity) capacity = bytes; 135 | if (!addNewBlock(capacity)) return NULL; 136 | _nextBlockCapacity *= 2; 137 | return allocInHead(bytes); 138 | } 139 | 140 | bool addNewBlock(size_t capacity) { 141 | size_t bytes = EmptyBlockSize + capacity; 142 | Block* block = static_cast(_allocator.allocate(bytes)); 143 | if (block == NULL) return false; 144 | block->capacity = capacity; 145 | block->size = 0; 146 | block->next = _head; 147 | _head = block; 148 | return true; 149 | } 150 | 151 | TAllocator _allocator; 152 | Block* _head; 153 | size_t _nextBlockCapacity; 154 | }; 155 | } 156 | 157 | #if defined(__clang__) 158 | #pragma clang diagnostic pop 159 | #elif defined(__GNUC__) 160 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 161 | #pragma GCC diagnostic pop 162 | #endif 163 | #endif 164 | 165 | // Implements a JsonBuffer with dynamic memory allocation. 166 | // You are strongly encouraged to consider using StaticJsonBuffer which is much 167 | // more suitable for embedded systems. 168 | typedef Internals::DynamicJsonBufferBase 169 | DynamicJsonBuffer; 170 | } 171 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonArray.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Data/JsonBufferAllocated.hpp" 8 | #include "Data/List.hpp" 9 | #include "Data/ReferenceType.hpp" 10 | #include "Data/ValueSaver.hpp" 11 | #include "JsonVariant.hpp" 12 | #include "Serialization/JsonPrintable.hpp" 13 | #include "StringTraits/StringTraits.hpp" 14 | #include "TypeTraits/EnableIf.hpp" 15 | #include "TypeTraits/IsArray.hpp" 16 | #include "TypeTraits/IsFloatingPoint.hpp" 17 | #include "TypeTraits/IsSame.hpp" 18 | 19 | // Returns the size (in bytes) of an array with n elements. 20 | // Can be very handy to determine the size of a StaticJsonBuffer. 21 | #define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \ 22 | (sizeof(JsonArray) + (NUMBER_OF_ELEMENTS) * sizeof(JsonArray::node_type)) 23 | 24 | namespace ArduinoJson { 25 | 26 | // Forward declarations 27 | class JsonObject; 28 | class JsonBuffer; 29 | namespace Internals { 30 | class JsonArraySubscript; 31 | } 32 | 33 | // An array of JsonVariant. 34 | // 35 | // The constructor is private, instances must be created via 36 | // JsonBuffer::createArray() or JsonBuffer::parseArray(). 37 | // A JsonArray can be serialized to a JSON string via JsonArray::printTo(). 38 | // It can also be deserialized from a JSON string via JsonBuffer::parseArray(). 39 | class JsonArray : public Internals::JsonPrintable, 40 | public Internals::ReferenceType, 41 | public Internals::NonCopyable, 42 | public Internals::List, 43 | public Internals::JsonBufferAllocated { 44 | public: 45 | // Create an empty JsonArray attached to the specified JsonBuffer. 46 | // You should not call this constructor directly. 47 | // Instead, use JsonBuffer::createArray() or JsonBuffer::parseArray(). 48 | explicit JsonArray(JsonBuffer *buffer) throw() 49 | : Internals::List(buffer) {} 50 | 51 | // Gets the value at the specified index 52 | const Internals::JsonArraySubscript operator[](size_t index) const; 53 | 54 | // Gets or sets the value at specified index 55 | Internals::JsonArraySubscript operator[](size_t index); 56 | 57 | // Adds the specified value at the end of the array. 58 | // 59 | // bool add(TValue); 60 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant, 61 | // std::string, String, JsonArray, JsonObject 62 | template 63 | bool add(const T &value) { 64 | return add_impl(value); 65 | } 66 | // 67 | // bool add(TValue); 68 | // TValue = char*, const char*, const FlashStringHelper* 69 | template 70 | bool add(T *value) { 71 | return add_impl(value); 72 | } 73 | // 74 | // bool add(TValue value, uint8_t decimals); 75 | // TValue = float, double 76 | template 77 | DEPRECATED("Second argument is not supported anymore") 78 | bool add(T value, uint8_t) { 79 | return add_impl(JsonVariant(value)); 80 | } 81 | 82 | // Sets the value at specified index. 83 | // 84 | // bool add(size_t index, const TValue&); 85 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant, 86 | // std::string, String, JsonArray, JsonObject 87 | template 88 | bool set(size_t index, const T &value) { 89 | return set_impl(index, value); 90 | } 91 | // 92 | // bool add(size_t index, TValue); 93 | // TValue = char*, const char*, const FlashStringHelper* 94 | template 95 | bool set(size_t index, T *value) { 96 | return set_impl(index, value); 97 | } 98 | // 99 | // bool set(size_t index, TValue value, uint8_t decimals); 100 | // TValue = float, double 101 | template 102 | typename Internals::EnableIf::value, bool>::type 103 | set(size_t index, T value, uint8_t decimals) { 104 | return set_impl(index, JsonVariant(value, decimals)); 105 | } 106 | 107 | // Gets the value at the specified index. 108 | template 109 | typename Internals::JsonVariantAs::type get(size_t index) const { 110 | const_iterator it = begin() += index; 111 | return it != end() ? it->as() : Internals::JsonVariantDefault::get(); 112 | } 113 | 114 | // Check the type of the value at specified index. 115 | template 116 | bool is(size_t index) const { 117 | const_iterator it = begin() += index; 118 | return it != end() ? it->is() : false; 119 | } 120 | 121 | // Creates a JsonArray and adds a reference at the end of the array. 122 | // It's a shortcut for JsonBuffer::createArray() and JsonArray::add() 123 | JsonArray &createNestedArray(); 124 | 125 | // Creates a JsonObject and adds a reference at the end of the array. 126 | // It's a shortcut for JsonBuffer::createObject() and JsonArray::add() 127 | JsonObject &createNestedObject(); 128 | 129 | // Removes element at specified index. 130 | void remove(size_t index) { 131 | remove(begin() += index); 132 | } 133 | using Internals::List::remove; 134 | 135 | // Returns a reference an invalid JsonArray. 136 | // This object is meant to replace a NULL pointer. 137 | // This is used when memory allocation or JSON parsing fail. 138 | static JsonArray &invalid() { 139 | static JsonArray instance(NULL); 140 | return instance; 141 | } 142 | 143 | // Imports a 1D array 144 | template 145 | bool copyFrom(T (&array)[N]) { 146 | return copyFrom(array, N); 147 | } 148 | 149 | // Imports a 1D array 150 | template 151 | bool copyFrom(T *array, size_t len) { 152 | bool ok = true; 153 | for (size_t i = 0; i < len; i++) { 154 | ok &= add(array[i]); 155 | } 156 | return ok; 157 | } 158 | 159 | // Imports a 2D array 160 | template 161 | bool copyFrom(T (&array)[N1][N2]) { 162 | bool ok = true; 163 | for (size_t i = 0; i < N1; i++) { 164 | JsonArray &nestedArray = createNestedArray(); 165 | for (size_t j = 0; j < N2; j++) { 166 | ok &= nestedArray.add(array[i][j]); 167 | } 168 | } 169 | return ok; 170 | } 171 | 172 | // Exports a 1D array 173 | template 174 | size_t copyTo(T (&array)[N]) const { 175 | return copyTo(array, N); 176 | } 177 | 178 | // Exports a 1D array 179 | template 180 | size_t copyTo(T *array, size_t len) const { 181 | size_t i = 0; 182 | for (const_iterator it = begin(); it != end() && i < len; ++it) 183 | array[i++] = *it; 184 | return i; 185 | } 186 | 187 | // Exports a 2D array 188 | template 189 | void copyTo(T (&array)[N1][N2]) const { 190 | size_t i = 0; 191 | for (const_iterator it = begin(); it != end() && i < N1; ++it) { 192 | it->as().copyTo(array[i++]); 193 | } 194 | } 195 | 196 | #if ARDUINOJSON_ENABLE_DEPRECATED 197 | DEPRECATED("use remove() instead") 198 | FORCE_INLINE void removeAt(size_t index) { 199 | return remove(index); 200 | } 201 | #endif 202 | 203 | private: 204 | template 205 | bool set_impl(size_t index, TValueRef value) { 206 | iterator it = begin() += index; 207 | if (it == end()) return false; 208 | return Internals::ValueSaver::save(_buffer, *it, value); 209 | } 210 | 211 | template 212 | bool add_impl(TValueRef value) { 213 | iterator it = Internals::List::add(); 214 | if (it == end()) return false; 215 | return Internals::ValueSaver::save(_buffer, *it, value); 216 | } 217 | }; 218 | 219 | namespace Internals { 220 | template <> 221 | struct JsonVariantDefault { 222 | static JsonArray &get() { 223 | return JsonArray::invalid(); 224 | } 225 | }; 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonArrayImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonArray.hpp" 8 | #include "JsonArraySubscript.hpp" 9 | #include "JsonObject.hpp" 10 | 11 | namespace ArduinoJson { 12 | 13 | inline JsonArray &JsonArray::createNestedArray() { 14 | if (!_buffer) return JsonArray::invalid(); 15 | JsonArray &array = _buffer->createArray(); 16 | add(array); 17 | return array; 18 | } 19 | 20 | inline JsonObject &JsonArray::createNestedObject() { 21 | if (!_buffer) return JsonObject::invalid(); 22 | JsonObject &object = _buffer->createObject(); 23 | add(object); 24 | return object; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonArraySubscript.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Configuration.hpp" 8 | #include "JsonVariantBase.hpp" 9 | 10 | #ifdef _MSC_VER 11 | #pragma warning(push) 12 | #pragma warning(disable : 4522) 13 | #endif 14 | 15 | namespace ArduinoJson { 16 | namespace Internals { 17 | class JsonArraySubscript : public JsonVariantBase { 18 | public: 19 | FORCE_INLINE JsonArraySubscript(JsonArray& array, size_t index) 20 | : _array(array), _index(index) {} 21 | 22 | FORCE_INLINE JsonArraySubscript& operator=(const JsonArraySubscript& src) { 23 | _array.set(_index, src); 24 | return *this; 25 | } 26 | 27 | // Replaces the value 28 | // 29 | // operator=(const TValue&) 30 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant, 31 | // std::string, String, JsonArray, JsonObject 32 | template 33 | FORCE_INLINE JsonArraySubscript& operator=(const T& src) { 34 | _array.set(_index, src); 35 | return *this; 36 | } 37 | // 38 | // operator=(TValue) 39 | // TValue = char*, const char*, const FlashStringHelper* 40 | template 41 | FORCE_INLINE JsonArraySubscript& operator=(T* src) { 42 | _array.set(_index, src); 43 | return *this; 44 | } 45 | 46 | FORCE_INLINE bool success() const { 47 | return _index < _array.size(); 48 | } 49 | 50 | template 51 | FORCE_INLINE typename JsonVariantAs::type as() const { 52 | return _array.get(_index); 53 | } 54 | 55 | template 56 | FORCE_INLINE bool is() const { 57 | return _array.is(_index); 58 | } 59 | 60 | // Replaces the value 61 | // 62 | // bool set(const TValue&) 63 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant, 64 | // std::string, String, JsonArray, JsonObject 65 | template 66 | FORCE_INLINE bool set(const TValue& value) { 67 | return _array.set(_index, value); 68 | } 69 | // 70 | // bool set(TValue) 71 | // TValue = char*, const char*, const FlashStringHelper* 72 | template 73 | FORCE_INLINE bool set(TValue* value) { 74 | return _array.set(_index, value); 75 | } 76 | // 77 | // bool set(TValue, uint8_t decimals); 78 | // TValue = float, double 79 | template 80 | DEPRECATED("Second argument is not supported anymore") 81 | FORCE_INLINE bool set(const TValue& value, uint8_t) { 82 | return _array.set(_index, value); 83 | } 84 | 85 | private: 86 | JsonArray& _array; 87 | const size_t _index; 88 | }; 89 | 90 | template 91 | inline JsonArraySubscript JsonVariantSubscripts::operator[]( 92 | size_t index) { 93 | return impl()->template as()[index]; 94 | } 95 | 96 | template 97 | inline const JsonArraySubscript JsonVariantSubscripts::operator[]( 98 | size_t index) const { 99 | return impl()->template as()[index]; 100 | } 101 | 102 | #if ARDUINOJSON_ENABLE_STD_STREAM 103 | inline std::ostream& operator<<(std::ostream& os, 104 | const JsonArraySubscript& source) { 105 | return source.printTo(os); 106 | } 107 | #endif 108 | } 109 | 110 | inline Internals::JsonArraySubscript JsonArray::operator[](size_t index) { 111 | return Internals::JsonArraySubscript(*this, index); 112 | } 113 | 114 | inline const Internals::JsonArraySubscript JsonArray::operator[]( 115 | size_t index) const { 116 | return Internals::JsonArraySubscript(*const_cast(this), index); 117 | } 118 | } 119 | 120 | #ifdef _MSC_VER 121 | #pragma warning(pop) 122 | #endif 123 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonBuffer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include // for size_t 8 | #include // for uint8_t 9 | #include 10 | 11 | #include "Data/NonCopyable.hpp" 12 | #include "JsonVariant.hpp" 13 | #include "TypeTraits/EnableIf.hpp" 14 | #include "TypeTraits/IsArray.hpp" 15 | 16 | namespace ArduinoJson { 17 | class JsonArray; 18 | class JsonObject; 19 | 20 | // Entry point for using the library. 21 | // 22 | // Handle the memory management (done in derived classes) and calls the parser. 23 | // This abstract class is implemented by StaticJsonBuffer which implements a 24 | // fixed memory allocation. 25 | class JsonBuffer : Internals::NonCopyable { 26 | public: 27 | // Allocates an empty JsonArray. 28 | // 29 | // Returns a reference to the new JsonArray or JsonArray::invalid() if the 30 | // allocation fails. 31 | JsonArray &createArray(); 32 | 33 | // Allocates an empty JsonObject. 34 | // 35 | // Returns a reference to the new JsonObject or JsonObject::invalid() if the 36 | // allocation fails. 37 | JsonObject &createObject(); 38 | 39 | // Duplicates a string 40 | // 41 | // const char* strdup(TValue); 42 | // TValue = const std::string&, const String&, 43 | template 44 | DEPRECATED("char* are duplicated, you don't need strdup() anymore") 45 | typename Internals::EnableIf::value, 46 | const char *>::type strdup(const TString &src) { 47 | return Internals::StringTraits::duplicate(src, this); 48 | } 49 | // 50 | // const char* strdup(TValue); 51 | // TValue = char*, const char*, const FlashStringHelper* 52 | template 53 | DEPRECATED("char* are duplicated, you don't need strdup() anymore") 54 | const char *strdup(TString *src) { 55 | return Internals::StringTraits::duplicate(src, this); 56 | } 57 | 58 | // Allocates n bytes in the JsonBuffer. 59 | // Return a pointer to the allocated memory or NULL if allocation fails. 60 | virtual void *alloc(size_t size) = 0; 61 | 62 | protected: 63 | // CAUTION: NO VIRTUAL DESTRUCTOR! 64 | // If we add a virtual constructor the Arduino compiler will add malloc() 65 | // and free() to the binary, adding 706 useless bytes. 66 | ~JsonBuffer() {} 67 | 68 | // Preserve aligment if necessary 69 | static FORCE_INLINE size_t round_size_up(size_t bytes) { 70 | #if ARDUINOJSON_ENABLE_ALIGNMENT 71 | const size_t x = sizeof(void *) - 1; 72 | return (bytes + x) & ~x; 73 | #else 74 | return bytes; 75 | #endif 76 | } 77 | }; 78 | } 79 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonBufferBase.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Deserialization/JsonParser.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | template 12 | class JsonBufferBase : public JsonBuffer { 13 | public: 14 | // Allocates and populate a JsonArray from a JSON string. 15 | // 16 | // The First argument is a pointer to the JSON string, the memory must be 17 | // writable 18 | // because the parser will insert null-terminators and replace escaped chars. 19 | // 20 | // The second argument set the nesting limit 21 | // 22 | // Returns a reference to the new JsonObject or JsonObject::invalid() if the 23 | // allocation fails. 24 | // With this overload, the JsonBuffer will make a copy of the string 25 | // 26 | // JsonArray& parseArray(TString); 27 | // TString = const std::string&, const String& 28 | template 29 | typename Internals::EnableIf::value, 30 | JsonArray &>::type 31 | parseArray(const TString &json, 32 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { 33 | return Internals::makeParser(that(), json, nestingLimit).parseArray(); 34 | } 35 | // 36 | // JsonArray& parseArray(TString); 37 | // TString = const char*, const char[N], const FlashStringHelper* 38 | template 39 | JsonArray &parseArray( 40 | TString *json, uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { 41 | return Internals::makeParser(that(), json, nestingLimit).parseArray(); 42 | } 43 | // 44 | // JsonArray& parseArray(TString); 45 | // TString = std::istream&, Stream& 46 | template 47 | JsonArray &parseArray( 48 | TString &json, uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { 49 | return Internals::makeParser(that(), json, nestingLimit).parseArray(); 50 | } 51 | 52 | // Allocates and populate a JsonObject from a JSON string. 53 | // 54 | // The First argument is a pointer to the JSON string, the memory must be 55 | // writable 56 | // because the parser will insert null-terminators and replace escaped chars. 57 | // 58 | // The second argument set the nesting limit 59 | // 60 | // Returns a reference to the new JsonObject or JsonObject::invalid() if the 61 | // allocation fails. 62 | // 63 | // JsonObject& parseObject(TString); 64 | // TString = const std::string&, const String& 65 | template 66 | typename Internals::EnableIf::value, 67 | JsonObject &>::type 68 | parseObject(const TString &json, 69 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { 70 | return Internals::makeParser(that(), json, nestingLimit).parseObject(); 71 | } 72 | // 73 | // JsonObject& parseObject(TString); 74 | // TString = const char*, const char[N], const FlashStringHelper* 75 | template 76 | JsonObject &parseObject( 77 | TString *json, uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { 78 | return Internals::makeParser(that(), json, nestingLimit).parseObject(); 79 | } 80 | // 81 | // JsonObject& parseObject(TString); 82 | // TString = std::istream&, Stream& 83 | template 84 | JsonObject &parseObject( 85 | TString &json, uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { 86 | return Internals::makeParser(that(), json, nestingLimit).parseObject(); 87 | } 88 | 89 | // Generalized version of parseArray() and parseObject(), also works for 90 | // integral types. 91 | // 92 | // JsonVariant parse(TString); 93 | // TString = const std::string&, const String& 94 | template 95 | typename Internals::EnableIf::value, 96 | JsonVariant>::type 97 | parse(const TString &json, 98 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { 99 | return Internals::makeParser(that(), json, nestingLimit).parseVariant(); 100 | } 101 | // 102 | // JsonVariant parse(TString); 103 | // TString = const char*, const char[N], const FlashStringHelper* 104 | template 105 | JsonVariant parse(TString *json, 106 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { 107 | return Internals::makeParser(that(), json, nestingLimit).parseVariant(); 108 | } 109 | // 110 | // JsonVariant parse(TString); 111 | // TString = std::istream&, Stream& 112 | template 113 | JsonVariant parse(TString &json, 114 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) { 115 | return Internals::makeParser(that(), json, nestingLimit).parseVariant(); 116 | } 117 | 118 | protected: 119 | ~JsonBufferBase() {} 120 | 121 | private: 122 | TDerived *that() { 123 | return static_cast(this); 124 | } 125 | }; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonBufferImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Deserialization/JsonParser.hpp" 8 | 9 | inline ArduinoJson::JsonArray &ArduinoJson::JsonBuffer::createArray() { 10 | JsonArray *ptr = new (this) JsonArray(this); 11 | return ptr ? *ptr : JsonArray::invalid(); 12 | } 13 | 14 | inline ArduinoJson::JsonObject &ArduinoJson::JsonBuffer::createObject() { 15 | JsonObject *ptr = new (this) JsonObject(this); 16 | return ptr ? *ptr : JsonObject::invalid(); 17 | } 18 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonObjectImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonArray.hpp" 8 | #include "JsonObject.hpp" 9 | #include "JsonObjectSubscript.hpp" 10 | 11 | namespace ArduinoJson { 12 | 13 | template 14 | inline JsonArray &JsonObject::createNestedArray_impl(TStringRef key) { 15 | if (!_buffer) return JsonArray::invalid(); 16 | JsonArray &array = _buffer->createArray(); 17 | set(key, array); 18 | return array; 19 | } 20 | 21 | template 22 | inline JsonObject &JsonObject::createNestedObject_impl(TStringRef key) { 23 | if (!_buffer) return JsonObject::invalid(); 24 | JsonObject &object = _buffer->createObject(); 25 | set(key, object); 26 | return object; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonObjectSubscript.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Configuration.hpp" 8 | #include "JsonVariantBase.hpp" 9 | #include "TypeTraits/EnableIf.hpp" 10 | 11 | #ifdef _MSC_VER 12 | #pragma warning(push) 13 | #pragma warning(disable : 4522) 14 | #endif 15 | 16 | namespace ArduinoJson { 17 | namespace Internals { 18 | 19 | template 20 | class JsonObjectSubscript 21 | : public JsonVariantBase > { 22 | typedef JsonObjectSubscript this_type; 23 | 24 | public: 25 | FORCE_INLINE JsonObjectSubscript(JsonObject& object, TStringRef key) 26 | : _object(object), _key(key) {} 27 | 28 | FORCE_INLINE this_type& operator=(const this_type& src) { 29 | _object.set(_key, src); 30 | return *this; 31 | } 32 | 33 | // Set the specified value 34 | // 35 | // operator=(const TValue&); 36 | // TValue = bool, char, long, int, short, float, double, 37 | // std::string, String, JsonArray, JsonObject 38 | template 39 | FORCE_INLINE typename EnableIf::value, this_type&>::type 40 | operator=(const TValue& src) { 41 | _object.set(_key, src); 42 | return *this; 43 | } 44 | // 45 | // operator=(TValue); 46 | // TValue = char*, const char*, const FlashStringHelper* 47 | template 48 | FORCE_INLINE this_type& operator=(TValue* src) { 49 | _object.set(_key, src); 50 | return *this; 51 | } 52 | 53 | FORCE_INLINE bool success() const { 54 | return _object.containsKey(_key); 55 | } 56 | 57 | template 58 | FORCE_INLINE typename JsonVariantAs::type as() const { 59 | return _object.get(_key); 60 | } 61 | 62 | template 63 | FORCE_INLINE bool is() const { 64 | return _object.is(_key); 65 | } 66 | 67 | // Sets the specified value. 68 | // 69 | // bool set(const TValue&); 70 | // TValue = bool, char, long, int, short, float, double, RawJson, JsonVariant, 71 | // std::string, String, JsonArray, JsonObject 72 | template 73 | FORCE_INLINE typename EnableIf::value, bool>::type set( 74 | const TValue& value) { 75 | return _object.set(_key, value); 76 | } 77 | // 78 | // bool set(TValue); 79 | // TValue = char*, const char, const FlashStringHelper* 80 | template 81 | FORCE_INLINE bool set(const TValue* value) { 82 | return _object.set(_key, value); 83 | } 84 | // 85 | // bool set(TValue, uint8_t decimals); 86 | // TValue = float, double 87 | template 88 | DEPRECATED("Second argument is not supported anymore") 89 | FORCE_INLINE bool set(const TValue& value, uint8_t) { 90 | return _object.set(_key, value); 91 | } 92 | 93 | private: 94 | JsonObject& _object; 95 | TStringRef _key; 96 | }; 97 | 98 | #if ARDUINOJSON_ENABLE_STD_STREAM 99 | template 100 | inline std::ostream& operator<<(std::ostream& os, 101 | const JsonObjectSubscript& source) { 102 | return source.printTo(os); 103 | } 104 | #endif 105 | } 106 | } 107 | 108 | #ifdef _MSC_VER 109 | #pragma warning(pop) 110 | #endif 111 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonPair.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonVariant.hpp" 8 | 9 | namespace ArduinoJson { 10 | 11 | // A key value pair for JsonObject. 12 | struct JsonPair { 13 | const char* key; 14 | JsonVariant value; 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonVariant.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include 8 | #include // for uint8_t 9 | 10 | #include "Data/JsonVariantContent.hpp" 11 | #include "Data/JsonVariantDefault.hpp" 12 | #include "Data/JsonVariantType.hpp" 13 | #include "JsonVariantBase.hpp" 14 | #include "RawJson.hpp" 15 | #include "Serialization/JsonPrintable.hpp" 16 | #include "TypeTraits/EnableIf.hpp" 17 | #include "TypeTraits/IsChar.hpp" 18 | #include "TypeTraits/IsFloatingPoint.hpp" 19 | #include "TypeTraits/IsIntegral.hpp" 20 | #include "TypeTraits/IsSame.hpp" 21 | #include "TypeTraits/IsSignedIntegral.hpp" 22 | #include "TypeTraits/IsUnsignedIntegral.hpp" 23 | #include "TypeTraits/RemoveConst.hpp" 24 | #include "TypeTraits/RemoveReference.hpp" 25 | 26 | namespace ArduinoJson { 27 | 28 | // Forward declarations. 29 | class JsonArray; 30 | class JsonObject; 31 | 32 | // A variant that can be a any value serializable to a JSON value. 33 | // 34 | // It can be set to: 35 | // - a boolean 36 | // - a char, short, int or a long (signed or unsigned) 37 | // - a string (const char*) 38 | // - a reference to a JsonArray or JsonObject 39 | class JsonVariant : public Internals::JsonVariantBase { 40 | template 41 | friend class Internals::JsonSerializer; 42 | 43 | public: 44 | // Creates an uninitialized JsonVariant 45 | JsonVariant() : _type(Internals::JSON_UNDEFINED) {} 46 | 47 | // Create a JsonVariant containing a boolean value. 48 | // It will be serialized as "true" or "false" in JSON. 49 | JsonVariant(bool value) { 50 | using namespace Internals; 51 | _type = JSON_BOOLEAN; 52 | _content.asInteger = static_cast(value); 53 | } 54 | 55 | // Create a JsonVariant containing a floating point value. 56 | // JsonVariant(double value); 57 | // JsonVariant(float value); 58 | template 59 | JsonVariant(T value, typename Internals::EnableIf< 60 | Internals::IsFloatingPoint::value>::type * = 0) { 61 | using namespace Internals; 62 | _type = JSON_FLOAT; 63 | _content.asFloat = static_cast(value); 64 | } 65 | template 66 | DEPRECATED("Second argument is not supported anymore") 67 | JsonVariant(T value, uint8_t, 68 | typename Internals::EnableIf< 69 | Internals::IsFloatingPoint::value>::type * = 0) { 70 | using namespace Internals; 71 | _type = JSON_FLOAT; 72 | _content.asFloat = static_cast(value); 73 | } 74 | 75 | // Create a JsonVariant containing an integer value. 76 | // JsonVariant(char) 77 | // JsonVariant(signed short) 78 | // JsonVariant(signed int) 79 | // JsonVariant(signed long) 80 | // JsonVariant(signed char) 81 | template 82 | JsonVariant( 83 | T value, 84 | typename Internals::EnableIf::value || 85 | Internals::IsSame::value>::type * = 86 | 0) { 87 | using namespace Internals; 88 | if (value >= 0) { 89 | _type = JSON_POSITIVE_INTEGER; 90 | _content.asInteger = static_cast(value); 91 | } else { 92 | _type = JSON_NEGATIVE_INTEGER; 93 | _content.asInteger = static_cast(-value); 94 | } 95 | } 96 | // JsonVariant(unsigned short) 97 | // JsonVariant(unsigned int) 98 | // JsonVariant(unsigned long) 99 | template 100 | JsonVariant(T value, 101 | typename Internals::EnableIf< 102 | Internals::IsUnsignedIntegral::value>::type * = 0) { 103 | using namespace Internals; 104 | _type = JSON_POSITIVE_INTEGER; 105 | _content.asInteger = static_cast(value); 106 | } 107 | 108 | // Create a JsonVariant containing a string. 109 | // JsonVariant(const char*); 110 | // JsonVariant(const signed char*); 111 | // JsonVariant(const unsigned char*); 112 | template 113 | JsonVariant( 114 | const TChar *value, 115 | typename Internals::EnableIf::value>::type * = 116 | 0) { 117 | _type = Internals::JSON_STRING; 118 | _content.asString = reinterpret_cast(value); 119 | } 120 | 121 | // Create a JsonVariant containing an unparsed string 122 | JsonVariant(Internals::RawJsonString value) { 123 | _type = Internals::JSON_UNPARSED; 124 | _content.asString = value; 125 | } 126 | 127 | // Create a JsonVariant containing a reference to an array. 128 | // CAUTION: we are lying about constness, because the array can be modified if 129 | // the variant is converted back to a JsonArray& 130 | JsonVariant(const JsonArray &array); 131 | 132 | // Create a JsonVariant containing a reference to an object. 133 | // CAUTION: we are lying about constness, because the object can be modified 134 | // if the variant is converted back to a JsonObject& 135 | JsonVariant(const JsonObject &object); 136 | 137 | // Get the variant as the specified type. 138 | // 139 | // char as() const; 140 | // signed char as() const; 141 | // signed short as() const; 142 | // signed int as() const; 143 | // signed long as() const; 144 | // unsigned char as() const; 145 | // unsigned short as() const; 146 | // unsigned int as() const; 147 | // unsigned long as() const; 148 | template 149 | const typename Internals::EnableIf::value, T>::type 150 | as() const { 151 | return variantAsInteger(); 152 | } 153 | // bool as() const 154 | template 155 | const typename Internals::EnableIf::value, T>::type 156 | as() const { 157 | return variantAsInteger() != 0; 158 | } 159 | // 160 | // double as() const; 161 | // float as() const; 162 | template 163 | const typename Internals::EnableIf::value, 164 | T>::type 165 | as() const { 166 | return variantAsFloat(); 167 | } 168 | // 169 | // const char* as() const; 170 | // const char* as() const; 171 | template 172 | typename Internals::EnableIf::value || 173 | Internals::IsSame::value, 174 | const char *>::type 175 | as() const { 176 | return variantAsString(); 177 | } 178 | // 179 | // std::string as() const; 180 | // String as() const; 181 | template 182 | typename Internals::EnableIf::has_append, T>::type 183 | as() const { 184 | const char *cstr = variantAsString(); 185 | if (cstr) return T(cstr); 186 | T s; 187 | printTo(s); 188 | return s; 189 | } 190 | // 191 | // JsonArray& as const; 192 | // JsonArray& as const; 193 | template 194 | typename Internals::EnableIf< 195 | Internals::IsSame::type, 196 | JsonArray>::value, 197 | JsonArray &>::type 198 | as() const { 199 | return variantAsArray(); 200 | } 201 | // 202 | // const JsonArray& as const; 203 | template 204 | typename Internals::EnableIf< 205 | Internals::IsSame::type, 206 | const JsonArray>::value, 207 | const JsonArray &>::type 208 | as() const { 209 | return variantAsArray(); 210 | } 211 | // 212 | // JsonObject& as const; 213 | // JsonObject& as const; 214 | template 215 | typename Internals::EnableIf< 216 | Internals::IsSame::type, 217 | JsonObject>::value, 218 | JsonObject &>::type 219 | as() const { 220 | return variantAsObject(); 221 | } 222 | // 223 | // JsonObject& as const; 224 | // JsonObject& as const; 225 | template 226 | typename Internals::EnableIf< 227 | Internals::IsSame::type, 228 | const JsonObject>::value, 229 | const JsonObject &>::type 230 | as() const { 231 | return variantAsObject(); 232 | } 233 | // 234 | // JsonVariant as const; 235 | template 236 | typename Internals::EnableIf::value, 237 | T>::type 238 | as() const { 239 | return *this; 240 | } 241 | 242 | // Tells weither the variant has the specified type. 243 | // Returns true if the variant has type type T, false otherwise. 244 | // 245 | // bool is() const; 246 | // bool is() const; 247 | // bool is() const; 248 | // bool is() const; 249 | // bool is() const; 250 | // bool is() const; 251 | // bool is() const; 252 | // bool is() const; 253 | // bool is() const; 254 | template 255 | typename Internals::EnableIf::value, bool>::type is() 256 | const { 257 | return variantIsInteger(); 258 | } 259 | // 260 | // bool is() const; 261 | // bool is() const; 262 | template 263 | typename Internals::EnableIf::value, bool>::type 264 | is() const { 265 | return variantIsFloat(); 266 | } 267 | // 268 | // bool is() const 269 | template 270 | typename Internals::EnableIf::value, bool>::type 271 | is() const { 272 | return variantIsBoolean(); 273 | } 274 | // 275 | // bool is() const; 276 | // bool is() const; 277 | template 278 | typename Internals::EnableIf::value || 279 | Internals::IsSame::value, 280 | bool>::type 281 | is() const { 282 | return variantIsString(); 283 | } 284 | // 285 | // bool is const; 286 | // bool is const; 287 | // bool is const; 288 | template 289 | typename Internals::EnableIf< 290 | Internals::IsSame::type>::type, 292 | JsonArray>::value, 293 | bool>::type 294 | is() const { 295 | return variantIsArray(); 296 | } 297 | // 298 | // bool is const; 299 | // bool is const; 300 | // bool is const; 301 | template 302 | typename Internals::EnableIf< 303 | Internals::IsSame::type>::type, 305 | JsonObject>::value, 306 | bool>::type 307 | is() const { 308 | return variantIsObject(); 309 | } 310 | 311 | // Returns true if the variant has a value 312 | bool success() const { 313 | return _type != Internals::JSON_UNDEFINED; 314 | } 315 | 316 | private: 317 | JsonArray &variantAsArray() const; 318 | JsonObject &variantAsObject() const; 319 | const char *variantAsString() const; 320 | template 321 | T variantAsFloat() const; 322 | template 323 | T variantAsInteger() const; 324 | bool variantIsBoolean() const; 325 | bool variantIsFloat() const; 326 | bool variantIsInteger() const; 327 | bool variantIsArray() const { 328 | return _type == Internals::JSON_ARRAY; 329 | } 330 | bool variantIsObject() const { 331 | return _type == Internals::JSON_OBJECT; 332 | } 333 | bool variantIsString() const { 334 | return _type == Internals::JSON_STRING || 335 | (_type == Internals::JSON_UNPARSED && _content.asString && 336 | !strcmp("null", _content.asString)); 337 | } 338 | 339 | // The current type of the variant 340 | Internals::JsonVariantType _type; 341 | 342 | // The various alternatives for the value of the variant. 343 | Internals::JsonVariantContent _content; 344 | }; 345 | 346 | DEPRECATED("Decimal places are ignored, use the float value instead") 347 | inline JsonVariant float_with_n_digits(float value, uint8_t) { 348 | return JsonVariant(value); 349 | } 350 | 351 | DEPRECATED("Decimal places are ignored, use the double value instead") 352 | inline JsonVariant double_with_n_digits(double value, uint8_t) { 353 | return JsonVariant(value); 354 | } 355 | } 356 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonVariantBase.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonVariantCasts.hpp" 8 | #include "JsonVariantComparisons.hpp" 9 | #include "JsonVariantOr.hpp" 10 | #include "JsonVariantSubscripts.hpp" 11 | #include "Serialization/JsonPrintable.hpp" 12 | 13 | namespace ArduinoJson { 14 | namespace Internals { 15 | 16 | template 17 | class JsonVariantBase : public JsonPrintable, 18 | public JsonVariantCasts, 19 | public JsonVariantComparisons, 20 | public JsonVariantOr, 21 | public JsonVariantSubscripts, 22 | public JsonVariantTag {}; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonVariantCasts.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Data/JsonVariantAs.hpp" 8 | #include "Polyfills/attributes.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | template 14 | class JsonVariantCasts { 15 | public: 16 | #if ARDUINOJSON_ENABLE_DEPRECATED 17 | DEPRECATED("use as() instead") 18 | FORCE_INLINE JsonArray &asArray() const { 19 | return impl()->template as(); 20 | } 21 | 22 | DEPRECATED("use as() instead") 23 | FORCE_INLINE JsonObject &asObject() const { 24 | return impl()->template as(); 25 | } 26 | 27 | DEPRECATED("use as() instead") 28 | FORCE_INLINE const char *asString() const { 29 | return impl()->template as(); 30 | } 31 | #endif 32 | 33 | // Gets the variant as an array. 34 | // Returns a reference to the JsonArray or JsonArray::invalid() if the 35 | // variant 36 | // is not an array. 37 | FORCE_INLINE operator JsonArray &() const { 38 | return impl()->template as(); 39 | } 40 | 41 | // Gets the variant as an object. 42 | // Returns a reference to the JsonObject or JsonObject::invalid() if the 43 | // variant is not an object. 44 | FORCE_INLINE operator JsonObject &() const { 45 | return impl()->template as(); 46 | } 47 | 48 | template 49 | FORCE_INLINE operator T() const { 50 | return impl()->template as(); 51 | } 52 | 53 | private: 54 | const TImpl *impl() const { 55 | return static_cast(this); 56 | } 57 | }; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonVariantComparisons.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "StringTraits/StringTraits.hpp" 8 | #include "TypeTraits/EnableIf.hpp" 9 | #include "TypeTraits/IsVariant.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | template 15 | class JsonVariantComparisons { 16 | public: 17 | template 18 | friend bool operator==(const JsonVariantComparisons &variant, 19 | TComparand comparand) { 20 | return variant.equals(comparand); 21 | } 22 | 23 | template 24 | friend typename EnableIf::value, bool>::type 25 | operator==(TComparand comparand, const JsonVariantComparisons &variant) { 26 | return variant.equals(comparand); 27 | } 28 | 29 | template 30 | friend bool operator!=(const JsonVariantComparisons &variant, 31 | TComparand comparand) { 32 | return !variant.equals(comparand); 33 | } 34 | 35 | template 36 | friend typename EnableIf::value, bool>::type 37 | operator!=(TComparand comparand, const JsonVariantComparisons &variant) { 38 | return !variant.equals(comparand); 39 | } 40 | 41 | template 42 | friend bool operator<=(const JsonVariantComparisons &left, TComparand right) { 43 | return left.as() <= right; 44 | } 45 | 46 | template 47 | friend bool operator<=(TComparand comparand, 48 | const JsonVariantComparisons &variant) { 49 | return comparand <= variant.as(); 50 | } 51 | 52 | template 53 | friend bool operator>=(const JsonVariantComparisons &variant, 54 | TComparand comparand) { 55 | return variant.as() >= comparand; 56 | } 57 | 58 | template 59 | friend bool operator>=(TComparand comparand, 60 | const JsonVariantComparisons &variant) { 61 | return comparand >= variant.as(); 62 | } 63 | 64 | template 65 | friend bool operator<(const JsonVariantComparisons &varian, 66 | TComparand comparand) { 67 | return varian.as() < comparand; 68 | } 69 | 70 | template 71 | friend bool operator<(TComparand comparand, 72 | const JsonVariantComparisons &variant) { 73 | return comparand < variant.as(); 74 | } 75 | 76 | template 77 | friend bool operator>(const JsonVariantComparisons &variant, 78 | TComparand comparand) { 79 | return variant.as() > comparand; 80 | } 81 | 82 | template 83 | friend bool operator>(TComparand comparand, 84 | const JsonVariantComparisons &variant) { 85 | return comparand > variant.as(); 86 | } 87 | 88 | private: 89 | const TImpl *impl() const { 90 | return static_cast(this); 91 | } 92 | 93 | template 94 | const typename JsonVariantAs::type as() const { 95 | return impl()->template as(); 96 | } 97 | 98 | template 99 | bool is() const { 100 | return impl()->template is(); 101 | } 102 | 103 | template 104 | typename EnableIf::has_equals, bool>::type equals( 105 | const TString &comparand) const { 106 | const char *value = as(); 107 | return StringTraits::equals(comparand, value); 108 | } 109 | 110 | template 111 | typename EnableIf::value && 112 | !StringTraits::has_equals, 113 | bool>::type 114 | equals(const TComparand &comparand) const { 115 | return as() == comparand; 116 | } 117 | 118 | template 119 | bool equals(const JsonVariantComparisons &right) const { 120 | using namespace Internals; 121 | if (is() && right.template is()) 122 | return as() == right.template as(); 123 | if (is() && right.template is()) 124 | return as() == right.template as(); 125 | if (is() && right.template is()) 126 | return as() == right.template as(); 127 | if (is() && right.template is()) 128 | return as() == right.template as(); 129 | if (is() && right.template is()) 130 | return as() == right.template as(); 131 | if (is() && right.template is()) 132 | return strcmp(as(), right.template as()) == 0; 133 | 134 | return false; 135 | } 136 | }; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonVariantImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Configuration.hpp" 8 | #include "JsonArray.hpp" 9 | #include "JsonObject.hpp" 10 | #include "JsonVariant.hpp" 11 | #include "Polyfills/isFloat.hpp" 12 | #include "Polyfills/isInteger.hpp" 13 | #include "Polyfills/parseFloat.hpp" 14 | #include "Polyfills/parseInteger.hpp" 15 | 16 | #include // for strcmp 17 | 18 | namespace ArduinoJson { 19 | 20 | inline JsonVariant::JsonVariant(const JsonArray &array) { 21 | if (array.success()) { 22 | _type = Internals::JSON_ARRAY; 23 | _content.asArray = const_cast(&array); 24 | } else { 25 | _type = Internals::JSON_UNDEFINED; 26 | } 27 | } 28 | 29 | inline JsonVariant::JsonVariant(const JsonObject &object) { 30 | if (object.success()) { 31 | _type = Internals::JSON_OBJECT; 32 | _content.asObject = const_cast(&object); 33 | } else { 34 | _type = Internals::JSON_UNDEFINED; 35 | } 36 | } 37 | 38 | inline JsonArray &JsonVariant::variantAsArray() const { 39 | if (_type == Internals::JSON_ARRAY) return *_content.asArray; 40 | return JsonArray::invalid(); 41 | } 42 | 43 | inline JsonObject &JsonVariant::variantAsObject() const { 44 | if (_type == Internals::JSON_OBJECT) return *_content.asObject; 45 | return JsonObject::invalid(); 46 | } 47 | 48 | template 49 | inline T JsonVariant::variantAsInteger() const { 50 | using namespace Internals; 51 | switch (_type) { 52 | case JSON_UNDEFINED: 53 | return 0; 54 | case JSON_POSITIVE_INTEGER: 55 | case JSON_BOOLEAN: 56 | return T(_content.asInteger); 57 | case JSON_NEGATIVE_INTEGER: 58 | return T(~_content.asInteger + 1); 59 | case JSON_STRING: 60 | case JSON_UNPARSED: 61 | return parseInteger(_content.asString); 62 | default: 63 | return T(_content.asFloat); 64 | } 65 | } 66 | 67 | inline const char *JsonVariant::variantAsString() const { 68 | using namespace Internals; 69 | if (_type == JSON_UNPARSED && _content.asString && 70 | !strcmp("null", _content.asString)) 71 | return NULL; 72 | if (_type == JSON_STRING || _type == JSON_UNPARSED) return _content.asString; 73 | return NULL; 74 | } 75 | 76 | template 77 | inline T JsonVariant::variantAsFloat() const { 78 | using namespace Internals; 79 | switch (_type) { 80 | case JSON_UNDEFINED: 81 | return 0; 82 | case JSON_POSITIVE_INTEGER: 83 | case JSON_BOOLEAN: 84 | return static_cast(_content.asInteger); 85 | case JSON_NEGATIVE_INTEGER: 86 | return -static_cast(_content.asInteger); 87 | case JSON_STRING: 88 | case JSON_UNPARSED: 89 | return parseFloat(_content.asString); 90 | default: 91 | return static_cast(_content.asFloat); 92 | } 93 | } 94 | 95 | inline bool JsonVariant::variantIsBoolean() const { 96 | using namespace Internals; 97 | if (_type == JSON_BOOLEAN) return true; 98 | 99 | if (_type != JSON_UNPARSED || _content.asString == NULL) return false; 100 | 101 | return !strcmp(_content.asString, "true") || 102 | !strcmp(_content.asString, "false"); 103 | } 104 | 105 | inline bool JsonVariant::variantIsInteger() const { 106 | using namespace Internals; 107 | 108 | return _type == JSON_POSITIVE_INTEGER || _type == JSON_NEGATIVE_INTEGER || 109 | (_type == JSON_UNPARSED && isInteger(_content.asString)); 110 | } 111 | 112 | inline bool JsonVariant::variantIsFloat() const { 113 | using namespace Internals; 114 | 115 | return _type == JSON_FLOAT || _type == JSON_POSITIVE_INTEGER || 116 | _type == JSON_NEGATIVE_INTEGER || 117 | (_type == JSON_UNPARSED && isFloat(_content.asString)); 118 | } 119 | 120 | #if ARDUINOJSON_ENABLE_STD_STREAM 121 | inline std::ostream &operator<<(std::ostream &os, const JsonVariant &source) { 122 | return source.printTo(os); 123 | } 124 | #endif 125 | 126 | } // namespace ArduinoJson 127 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonVariantOr.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Data/JsonVariantAs.hpp" 8 | #include "Polyfills/attributes.hpp" 9 | #include "TypeTraits/EnableIf.hpp" 10 | #include "TypeTraits/IsIntegral.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | template 16 | class JsonVariantOr { 17 | public: 18 | // Returns the default value if the JsonVariant is undefined of incompatible 19 | template 20 | typename EnableIf::value, T>::type operator|( 21 | const T &defaultValue) const { 22 | if (impl()->template is()) 23 | return impl()->template as(); 24 | else 25 | return defaultValue; 26 | } 27 | 28 | // Returns the default value if the JsonVariant is undefined of incompatible 29 | // Special case for string: null is treated as undefined 30 | const char *operator|(const char *defaultValue) const { 31 | const char *value = impl()->template as(); 32 | return value ? value : defaultValue; 33 | } 34 | 35 | // Returns the default value if the JsonVariant is undefined of incompatible 36 | // Special case for integers: we also accept double 37 | template 38 | typename EnableIf::value, Integer>::type operator|( 39 | const Integer &defaultValue) const { 40 | if (impl()->template is()) 41 | return impl()->template as(); 42 | else 43 | return defaultValue; 44 | } 45 | 46 | private: 47 | const TImpl *impl() const { 48 | return static_cast(this); 49 | } 50 | }; 51 | } // namespace Internals 52 | } // namespace ArduinoJson 53 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/JsonVariantSubscripts.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "Data/JsonVariantAs.hpp" 8 | #include "Polyfills/attributes.hpp" 9 | #include "StringTraits/StringTraits.hpp" 10 | #include "TypeTraits/EnableIf.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | // Forward declarations. 16 | class JsonArraySubscript; 17 | template 18 | class JsonObjectSubscript; 19 | 20 | template 21 | class JsonVariantSubscripts { 22 | public: 23 | // Mimics an array or an object. 24 | // Returns the size of the array or object if the variant has that type. 25 | // Returns 0 if the variant is neither an array nor an object 26 | size_t size() const { 27 | return impl()->template as().size() + 28 | impl()->template as().size(); 29 | } 30 | 31 | // Mimics an array. 32 | // Returns the element at specified index if the variant is an array. 33 | // Returns JsonVariant::invalid() if the variant is not an array. 34 | FORCE_INLINE const JsonArraySubscript operator[](size_t index) const; 35 | FORCE_INLINE JsonArraySubscript operator[](size_t index); 36 | 37 | // Mimics an object. 38 | // Returns the value associated with the specified key if the variant is 39 | // an object. 40 | // Return JsonVariant::invalid() if the variant is not an object. 41 | // 42 | // const JsonObjectSubscript operator[](TKey) const; 43 | // TKey = const std::string&, const String& 44 | template 45 | FORCE_INLINE 46 | typename EnableIf::has_equals, 47 | const JsonObjectSubscript >::type 48 | operator[](const TString &key) const { 49 | return impl()->template as()[key]; 50 | } 51 | // 52 | // const JsonObjectSubscript operator[](TKey) const; 53 | // TKey = const std::string&, const String& 54 | template 55 | FORCE_INLINE typename EnableIf::has_equals, 56 | JsonObjectSubscript >::type 57 | operator[](const TString &key) { 58 | return impl()->template as()[key]; 59 | } 60 | // 61 | // JsonObjectSubscript operator[](TKey); 62 | // TKey = const char*, const char[N], const FlashStringHelper* 63 | template 64 | FORCE_INLINE typename EnableIf::has_equals, 65 | JsonObjectSubscript >::type 66 | operator[](const TString *key) { 67 | return impl()->template as()[key]; 68 | } 69 | // 70 | // JsonObjectSubscript operator[](TKey); 71 | // TKey = const char*, const char[N], const FlashStringHelper* 72 | template 73 | FORCE_INLINE 74 | typename EnableIf::has_equals, 75 | const JsonObjectSubscript >::type 76 | operator[](const TString *key) const { 77 | return impl()->template as()[key]; 78 | } 79 | 80 | private: 81 | const TImpl *impl() const { 82 | return static_cast(this); 83 | } 84 | }; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Polyfills/attributes.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #ifdef _MSC_VER // Visual Studio 8 | 9 | #define FORCE_INLINE // __forceinline causes C4714 when returning std::string 10 | #define NO_INLINE __declspec(noinline) 11 | #define DEPRECATED(msg) __declspec(deprecated(msg)) 12 | 13 | #elif defined(__GNUC__) // GCC or Clang 14 | 15 | #define FORCE_INLINE __attribute__((always_inline)) 16 | #define NO_INLINE __attribute__((noinline)) 17 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) 18 | #define DEPRECATED(msg) __attribute__((deprecated(msg))) 19 | #else 20 | #define DEPRECATED(msg) __attribute__((deprecated)) 21 | #endif 22 | 23 | #else // Other compilers 24 | 25 | #define FORCE_INLINE 26 | #define NO_INLINE 27 | #define DEPRECATED(msg) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Polyfills/ctype.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | inline bool isdigit(char c) { 11 | return '0' <= c && c <= '9'; 12 | } 13 | 14 | inline bool issign(char c) { 15 | return '-' == c || c == '+'; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Polyfills/isFloat.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include // for strcmp 8 | #include "./ctype.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | inline bool isFloat(const char* s) { 14 | if (!s) return false; 15 | 16 | if (!strcmp(s, "NaN")) return true; 17 | if (issign(*s)) s++; 18 | if (!strcmp(s, "Infinity")) return true; 19 | if (*s == '\0') return false; 20 | 21 | while (isdigit(*s)) s++; 22 | 23 | if (*s == '.') { 24 | s++; 25 | while (isdigit(*s)) s++; 26 | } 27 | 28 | if (*s == 'e' || *s == 'E') { 29 | s++; 30 | if (issign(*s)) s++; 31 | if (!isdigit(*s)) return false; 32 | while (isdigit(*s)) s++; 33 | } 34 | 35 | return *s == '\0'; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Polyfills/isInteger.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "./ctype.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | inline bool isInteger(const char* s) { 13 | if (!s) return false; 14 | if (issign(*s)) s++; 15 | while (isdigit(*s)) s++; 16 | return *s == '\0'; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Polyfills/math.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | template 10 | bool isNaN(T x) { 11 | return x != x; 12 | } 13 | 14 | template 15 | bool isInfinity(T x) { 16 | return x != 0.0 && x * 2 == x; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Polyfills/parseFloat.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../TypeTraits/FloatTraits.hpp" 8 | #include "./ctype.hpp" 9 | #include "./math.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | template 15 | inline T parseFloat(const char* s) { 16 | typedef FloatTraits traits; 17 | typedef typename traits::mantissa_type mantissa_t; 18 | typedef typename traits::exponent_type exponent_t; 19 | 20 | if (!s) return 0; // NULL 21 | 22 | bool negative_result = false; 23 | switch (*s) { 24 | case '-': 25 | negative_result = true; 26 | s++; 27 | break; 28 | case '+': 29 | s++; 30 | break; 31 | } 32 | 33 | if (*s == 't') return 1; // true 34 | if (*s == 'n' || *s == 'N') return traits::nan(); 35 | if (*s == 'i' || *s == 'I') 36 | return negative_result ? -traits::inf() : traits::inf(); 37 | 38 | mantissa_t mantissa = 0; 39 | exponent_t exponent_offset = 0; 40 | 41 | while (isdigit(*s)) { 42 | if (mantissa < traits::mantissa_max / 10) 43 | mantissa = mantissa * 10 + (*s - '0'); 44 | else 45 | exponent_offset++; 46 | s++; 47 | } 48 | 49 | if (*s == '.') { 50 | s++; 51 | while (isdigit(*s)) { 52 | if (mantissa < traits::mantissa_max / 10) { 53 | mantissa = mantissa * 10 + (*s - '0'); 54 | exponent_offset--; 55 | } 56 | s++; 57 | } 58 | } 59 | 60 | int exponent = 0; 61 | if (*s == 'e' || *s == 'E') { 62 | s++; 63 | bool negative_exponent = false; 64 | if (*s == '-') { 65 | negative_exponent = true; 66 | s++; 67 | } else if (*s == '+') { 68 | s++; 69 | } 70 | 71 | while (isdigit(*s)) { 72 | exponent = exponent * 10 + (*s - '0'); 73 | if (exponent + exponent_offset > traits::exponent_max) { 74 | if (negative_exponent) 75 | return negative_result ? -0.0f : 0.0f; 76 | else 77 | return negative_result ? -traits::inf() : traits::inf(); 78 | } 79 | s++; 80 | } 81 | if (negative_exponent) exponent = -exponent; 82 | } 83 | exponent += exponent_offset; 84 | 85 | T result = traits::make_float(static_cast(mantissa), exponent); 86 | 87 | return negative_result ? -result : result; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Polyfills/parseInteger.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #include "../Configuration.hpp" 10 | #include "./ctype.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | template 15 | T parseInteger(const char *s) { 16 | if (!s) return 0; // NULL 17 | 18 | if (*s == 't') return 1; // "true" 19 | 20 | T result = 0; 21 | bool negative_result = false; 22 | 23 | switch (*s) { 24 | case '-': 25 | negative_result = true; 26 | s++; 27 | break; 28 | case '+': 29 | s++; 30 | break; 31 | } 32 | 33 | while (isdigit(*s)) { 34 | result = T(result * 10 + T(*s - '0')); 35 | s++; 36 | } 37 | 38 | return negative_result ? T(~result + 1) : result; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/RawJson.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | 9 | namespace Internals { 10 | // A special type of data that can be used to insert pregenerated JSON portions. 11 | template 12 | class RawJsonString { 13 | public: 14 | explicit RawJsonString(T str) : _str(str) {} 15 | operator T() const { 16 | return _str; 17 | } 18 | 19 | private: 20 | T _str; 21 | }; 22 | 23 | template 24 | struct StringTraits, void> { 25 | static bool is_null(RawJsonString source) { 26 | return StringTraits::is_null(static_cast(source)); 27 | } 28 | 29 | typedef RawJsonString duplicate_t; 30 | 31 | template 32 | static duplicate_t duplicate(RawJsonString source, Buffer* buffer) { 33 | return duplicate_t(StringTraits::duplicate(source, buffer)); 34 | } 35 | 36 | static const bool has_append = false; 37 | static const bool has_equals = false; 38 | static const bool should_duplicate = StringTraits::should_duplicate; 39 | }; 40 | } 41 | 42 | template 43 | inline Internals::RawJsonString RawJson(T str) { 44 | return Internals::RawJsonString(str); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/DummyPrint.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A dummy Print implementation used in JsonPrintable::measureLength() 11 | class DummyPrint { 12 | public: 13 | size_t print(char) { 14 | return 1; 15 | } 16 | 17 | size_t print(const char* s) { 18 | return strlen(s); 19 | } 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/DynamicStringBuilder.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../StringTraits/StringTraits.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // A Print implementation that allows to write in a String 13 | template 14 | class DynamicStringBuilder { 15 | public: 16 | DynamicStringBuilder(TString &str) : _str(str) {} 17 | 18 | size_t print(char c) { 19 | StringTraits::append(_str, c); 20 | return 1; 21 | } 22 | 23 | size_t print(const char *s) { 24 | size_t initialLen = _str.length(); 25 | StringTraits::append(_str, s); 26 | return _str.length() - initialLen; 27 | } 28 | 29 | private: 30 | DynamicStringBuilder &operator=(const DynamicStringBuilder &); 31 | 32 | TString &_str; 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/FloatParts.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | #include "../Polyfills/math.hpp" 9 | #include "../TypeTraits/FloatTraits.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | template 15 | struct FloatParts { 16 | uint32_t integral; 17 | uint32_t decimal; 18 | int16_t exponent; 19 | int8_t decimalPlaces; 20 | 21 | FloatParts(TFloat value) { 22 | uint32_t maxDecimalPart = sizeof(TFloat) >= 8 ? 1000000000 : 1000000; 23 | decimalPlaces = sizeof(TFloat) >= 8 ? 9 : 6; 24 | 25 | exponent = normalize(value); 26 | 27 | integral = uint32_t(value); 28 | // reduce number of decimal places by the number of integral places 29 | for (uint32_t tmp = integral; tmp >= 10; tmp /= 10) { 30 | maxDecimalPart /= 10; 31 | decimalPlaces--; 32 | } 33 | 34 | TFloat remainder = (value - TFloat(integral)) * TFloat(maxDecimalPart); 35 | 36 | decimal = uint32_t(remainder); 37 | remainder = remainder - TFloat(decimal); 38 | 39 | // rounding: 40 | // increment by 1 if remainder >= 0.5 41 | decimal += uint32_t(remainder * 2); 42 | if (decimal >= maxDecimalPart) { 43 | decimal = 0; 44 | integral++; 45 | if (exponent && integral >= 10) { 46 | exponent++; 47 | integral = 1; 48 | } 49 | } 50 | 51 | // remove trailing zeros 52 | while (decimal % 10 == 0 && decimalPlaces > 0) { 53 | decimal /= 10; 54 | decimalPlaces--; 55 | } 56 | } 57 | 58 | static int16_t normalize(TFloat& value) { 59 | typedef FloatTraits traits; 60 | int16_t powersOf10 = 0; 61 | 62 | int8_t index = sizeof(TFloat) == 8 ? 8 : 5; 63 | int bit = 1 << index; 64 | 65 | if (value >= ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD) { 66 | for (; index >= 0; index--) { 67 | if (value >= traits::positiveBinaryPowerOfTen(index)) { 68 | value *= traits::negativeBinaryPowerOfTen(index); 69 | powersOf10 = int16_t(powersOf10 + bit); 70 | } 71 | bit >>= 1; 72 | } 73 | } 74 | 75 | if (value > 0 && value <= ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD) { 76 | for (; index >= 0; index--) { 77 | if (value < traits::negativeBinaryPowerOfTenPlusOne(index)) { 78 | value *= traits::positiveBinaryPowerOfTen(index); 79 | powersOf10 = int16_t(powersOf10 - bit); 80 | } 81 | bit >>= 1; 82 | } 83 | } 84 | 85 | return powersOf10; 86 | } 87 | }; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/IndentedPrint.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // Decorator on top of Print to allow indented output. 11 | // This class is used by JsonPrintable::prettyPrintTo() but can also be used 12 | // for your own purpose, like logging. 13 | template 14 | class IndentedPrint { 15 | public: 16 | explicit IndentedPrint(Print &p) : sink(&p) { 17 | level = 0; 18 | tabSize = 2; 19 | isNewLine = true; 20 | } 21 | 22 | size_t print(char c) { 23 | size_t n = 0; 24 | if (isNewLine) n += writeTabs(); 25 | n += sink->print(c); 26 | isNewLine = c == '\n'; 27 | return n; 28 | } 29 | 30 | size_t print(const char *s) { 31 | // TODO: optimize 32 | size_t n = 0; 33 | while (*s) n += print(*s++); 34 | return n; 35 | } 36 | 37 | // Adds one level of indentation 38 | void indent() { 39 | if (level < MAX_LEVEL) level++; 40 | } 41 | 42 | // Removes one level of indentation 43 | void unindent() { 44 | if (level > 0) level--; 45 | } 46 | 47 | // Set the number of space printed for each level of indentation 48 | void setTabSize(uint8_t n) { 49 | if (n < MAX_TAB_SIZE) tabSize = n & MAX_TAB_SIZE; 50 | } 51 | 52 | private: 53 | Print *sink; 54 | uint8_t level : 4; 55 | uint8_t tabSize : 3; 56 | bool isNewLine : 1; 57 | 58 | size_t writeTabs() { 59 | size_t n = 0; 60 | for (int i = 0; i < level * tabSize; i++) n += sink->print(' '); 61 | return n; 62 | } 63 | 64 | static const int MAX_LEVEL = 15; // because it's only 4 bits 65 | static const int MAX_TAB_SIZE = 7; // because it's only 3 bits 66 | }; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/JsonPrintable.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | #include "../TypeTraits/EnableIf.hpp" 9 | #include "DummyPrint.hpp" 10 | #include "DynamicStringBuilder.hpp" 11 | #include "IndentedPrint.hpp" 12 | #include "JsonSerializer.hpp" 13 | #include "JsonWriter.hpp" 14 | #include "Prettyfier.hpp" 15 | #include "StaticStringBuilder.hpp" 16 | 17 | #if ARDUINOJSON_ENABLE_STD_STREAM 18 | #include "StreamPrintAdapter.hpp" 19 | #endif 20 | 21 | namespace ArduinoJson { 22 | namespace Internals { 23 | 24 | // Implements all the overloads of printTo() and prettyPrintTo() 25 | // Caution: this class use a template parameter to avoid virtual methods. 26 | // This is a bit curious but allows to reduce the size of JsonVariant, JsonArray 27 | // and JsonObject. 28 | template 29 | class JsonPrintable { 30 | public: 31 | template 32 | typename EnableIf::has_append, size_t>::type printTo( 33 | Print &print) const { 34 | JsonWriter writer(print); 35 | JsonSerializer >::serialize(downcast(), writer); 36 | return writer.bytesWritten(); 37 | } 38 | 39 | #if ARDUINOJSON_ENABLE_STD_STREAM 40 | std::ostream &printTo(std::ostream &os) const { 41 | StreamPrintAdapter adapter(os); 42 | printTo(adapter); 43 | return os; 44 | } 45 | #endif 46 | 47 | size_t printTo(char *buffer, size_t bufferSize) const { 48 | StaticStringBuilder sb(buffer, bufferSize); 49 | return printTo(sb); 50 | } 51 | 52 | template 53 | size_t printTo(char (&buffer)[N]) const { 54 | return printTo(buffer, N); 55 | } 56 | 57 | template 58 | typename EnableIf::has_append, size_t>::type printTo( 59 | TString &str) const { 60 | DynamicStringBuilder sb(str); 61 | return printTo(sb); 62 | } 63 | 64 | template 65 | size_t prettyPrintTo(IndentedPrint &print) const { 66 | Prettyfier p(print); 67 | return printTo(p); 68 | } 69 | 70 | size_t prettyPrintTo(char *buffer, size_t bufferSize) const { 71 | StaticStringBuilder sb(buffer, bufferSize); 72 | return prettyPrintTo(sb); 73 | } 74 | 75 | template 76 | size_t prettyPrintTo(char (&buffer)[N]) const { 77 | return prettyPrintTo(buffer, N); 78 | } 79 | 80 | template 81 | typename EnableIf::has_append, size_t>::type 82 | prettyPrintTo(Print &print) const { 83 | IndentedPrint indentedPrint(print); 84 | return prettyPrintTo(indentedPrint); 85 | } 86 | 87 | template 88 | typename EnableIf::has_append, size_t>::type 89 | prettyPrintTo(TString &str) const { 90 | DynamicStringBuilder sb(str); 91 | return prettyPrintTo(sb); 92 | } 93 | 94 | size_t measureLength() const { 95 | DummyPrint dp; 96 | return printTo(dp); 97 | } 98 | 99 | size_t measurePrettyLength() const { 100 | DummyPrint dp; 101 | return prettyPrintTo(dp); 102 | } 103 | 104 | private: 105 | const T &downcast() const { 106 | return *static_cast(this); 107 | } 108 | }; 109 | 110 | #if ARDUINOJSON_ENABLE_STD_STREAM 111 | template 112 | inline std::ostream &operator<<(std::ostream &os, const JsonPrintable &v) { 113 | return v.printTo(os); 114 | } 115 | #endif 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/JsonSerializer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonWriter.hpp" 8 | 9 | namespace ArduinoJson { 10 | 11 | class JsonArray; 12 | class JsonObject; 13 | class JsonVariant; 14 | 15 | namespace Internals { 16 | 17 | class JsonArraySubscript; 18 | template 19 | class JsonObjectSubscript; 20 | 21 | template 22 | class JsonSerializer { 23 | public: 24 | static void serialize(const JsonArray &, Writer &); 25 | static void serialize(const JsonArraySubscript &, Writer &); 26 | static void serialize(const JsonObject &, Writer &); 27 | template 28 | static void serialize(const JsonObjectSubscript &, Writer &); 29 | static void serialize(const JsonVariant &, Writer &); 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/JsonSerializerImpl.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../JsonArray.hpp" 8 | #include "../JsonArraySubscript.hpp" 9 | #include "../JsonObject.hpp" 10 | #include "../JsonObjectSubscript.hpp" 11 | #include "../JsonVariant.hpp" 12 | #include "JsonSerializer.hpp" 13 | 14 | template 15 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 16 | const JsonArray& array, Writer& writer) { 17 | writer.beginArray(); 18 | 19 | JsonArray::const_iterator it = array.begin(); 20 | while (it != array.end()) { 21 | serialize(*it, writer); 22 | 23 | ++it; 24 | if (it == array.end()) break; 25 | 26 | writer.writeComma(); 27 | } 28 | 29 | writer.endArray(); 30 | } 31 | 32 | template 33 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 34 | const JsonArraySubscript& arraySubscript, Writer& writer) { 35 | serialize(arraySubscript.as(), writer); 36 | } 37 | 38 | template 39 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 40 | const JsonObject& object, Writer& writer) { 41 | writer.beginObject(); 42 | 43 | JsonObject::const_iterator it = object.begin(); 44 | while (it != object.end()) { 45 | writer.writeString(it->key); 46 | writer.writeColon(); 47 | serialize(it->value, writer); 48 | 49 | ++it; 50 | if (it == object.end()) break; 51 | 52 | writer.writeComma(); 53 | } 54 | 55 | writer.endObject(); 56 | } 57 | 58 | template 59 | template 60 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 61 | const JsonObjectSubscript& objectSubscript, Writer& writer) { 62 | serialize(objectSubscript.template as(), writer); 63 | } 64 | 65 | template 66 | inline void ArduinoJson::Internals::JsonSerializer::serialize( 67 | const JsonVariant& variant, Writer& writer) { 68 | switch (variant._type) { 69 | case JSON_FLOAT: 70 | writer.writeFloat(variant._content.asFloat); 71 | return; 72 | 73 | case JSON_ARRAY: 74 | serialize(*variant._content.asArray, writer); 75 | return; 76 | 77 | case JSON_OBJECT: 78 | serialize(*variant._content.asObject, writer); 79 | return; 80 | 81 | case JSON_STRING: 82 | writer.writeString(variant._content.asString); 83 | return; 84 | 85 | case JSON_UNPARSED: 86 | writer.writeRaw(variant._content.asString); 87 | return; 88 | 89 | case JSON_NEGATIVE_INTEGER: 90 | writer.writeRaw('-'); // Falls through. 91 | 92 | case JSON_POSITIVE_INTEGER: 93 | writer.writeInteger(variant._content.asInteger); 94 | return; 95 | 96 | case JSON_BOOLEAN: 97 | writer.writeBoolean(variant._content.asInteger != 0); 98 | return; 99 | 100 | default: // JSON_UNDEFINED 101 | return; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/JsonWriter.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "../Data/Encoding.hpp" 9 | #include "../Data/JsonInteger.hpp" 10 | #include "../Polyfills/attributes.hpp" 11 | #include "../Serialization/FloatParts.hpp" 12 | 13 | namespace ArduinoJson { 14 | namespace Internals { 15 | 16 | // Writes the JSON tokens to a Print implementation 17 | // This class is used by: 18 | // - JsonArray::writeTo() 19 | // - JsonObject::writeTo() 20 | // - JsonVariant::writeTo() 21 | // Its derived by PrettyJsonWriter that overrides some members to add 22 | // indentation. 23 | template 24 | class JsonWriter { 25 | public: 26 | explicit JsonWriter(Print &sink) : _sink(sink), _length(0) {} 27 | 28 | // Returns the number of bytes sent to the Print implementation. 29 | // This is very handy for implementations of printTo() that must return the 30 | // number of bytes written. 31 | size_t bytesWritten() const { 32 | return _length; 33 | } 34 | 35 | void beginArray() { 36 | writeRaw('['); 37 | } 38 | void endArray() { 39 | writeRaw(']'); 40 | } 41 | 42 | void beginObject() { 43 | writeRaw('{'); 44 | } 45 | void endObject() { 46 | writeRaw('}'); 47 | } 48 | 49 | void writeColon() { 50 | writeRaw(':'); 51 | } 52 | void writeComma() { 53 | writeRaw(','); 54 | } 55 | 56 | void writeBoolean(bool value) { 57 | writeRaw(value ? "true" : "false"); 58 | } 59 | 60 | void writeString(const char *value) { 61 | if (!value) { 62 | writeRaw("null"); 63 | } else { 64 | writeRaw('\"'); 65 | while (*value) writeChar(*value++); 66 | writeRaw('\"'); 67 | } 68 | } 69 | 70 | void writeChar(char c) { 71 | char specialChar = Encoding::escapeChar(c); 72 | if (specialChar) { 73 | writeRaw('\\'); 74 | writeRaw(specialChar); 75 | } else { 76 | writeRaw(c); 77 | } 78 | } 79 | 80 | template 81 | void writeFloat(TFloat value) { 82 | if (isNaN(value)) return writeRaw("NaN"); 83 | 84 | if (value < 0.0) { 85 | writeRaw('-'); 86 | value = -value; 87 | } 88 | 89 | if (isInfinity(value)) return writeRaw("Infinity"); 90 | 91 | FloatParts parts(value); 92 | 93 | writeInteger(parts.integral); 94 | if (parts.decimalPlaces) writeDecimals(parts.decimal, parts.decimalPlaces); 95 | 96 | if (parts.exponent < 0) { 97 | writeRaw("e-"); 98 | writeInteger(-parts.exponent); 99 | } 100 | 101 | if (parts.exponent > 0) { 102 | writeRaw('e'); 103 | writeInteger(parts.exponent); 104 | } 105 | } 106 | 107 | template 108 | void writeInteger(UInt value) { 109 | char buffer[22]; 110 | char *end = buffer + sizeof(buffer) - 1; 111 | char *ptr = end; 112 | 113 | *ptr = 0; 114 | do { 115 | *--ptr = char(value % 10 + '0'); 116 | value = UInt(value / 10); 117 | } while (value); 118 | 119 | writeRaw(ptr); 120 | } 121 | 122 | void writeDecimals(uint32_t value, int8_t width) { 123 | // buffer should be big enough for all digits, the dot and the null 124 | // terminator 125 | char buffer[16]; 126 | char *ptr = buffer + sizeof(buffer) - 1; 127 | 128 | // write the string in reverse order 129 | *ptr = 0; 130 | while (width--) { 131 | *--ptr = char(value % 10 + '0'); 132 | value /= 10; 133 | } 134 | *--ptr = '.'; 135 | 136 | // and dump it in the right order 137 | writeRaw(ptr); 138 | } 139 | 140 | void writeRaw(const char *s) { 141 | _length += _sink.print(s); 142 | } 143 | void writeRaw(char c) { 144 | _length += _sink.print(c); 145 | } 146 | 147 | protected: 148 | Print &_sink; 149 | size_t _length; 150 | 151 | private: 152 | JsonWriter &operator=(const JsonWriter &); // cannot be assigned 153 | }; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/Prettyfier.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IndentedPrint.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // Converts a compact JSON string into an indented one. 13 | template 14 | class Prettyfier { 15 | public: 16 | explicit Prettyfier(IndentedPrint& p) : _sink(p) { 17 | _previousChar = 0; 18 | _inString = false; 19 | } 20 | 21 | size_t print(char c) { 22 | size_t n = _inString ? handleStringChar(c) : handleMarkupChar(c); 23 | _previousChar = c; 24 | return n; 25 | } 26 | 27 | size_t print(const char* s) { 28 | // TODO: optimize 29 | size_t n = 0; 30 | while (*s) n += print(*s++); 31 | return n; 32 | } 33 | 34 | private: 35 | Prettyfier& operator=(const Prettyfier&); // cannot be assigned 36 | 37 | bool inEmptyBlock() { 38 | return _previousChar == '{' || _previousChar == '['; 39 | } 40 | 41 | size_t handleStringChar(char c) { 42 | bool isQuote = c == '"' && _previousChar != '\\'; 43 | 44 | if (isQuote) _inString = false; 45 | 46 | return _sink.print(c); 47 | } 48 | 49 | size_t handleMarkupChar(char c) { 50 | switch (c) { 51 | case '{': 52 | case '[': 53 | return writeBlockOpen(c); 54 | 55 | case '}': 56 | case ']': 57 | return writeBlockClose(c); 58 | 59 | case ':': 60 | return writeColon(); 61 | 62 | case ',': 63 | return writeComma(); 64 | 65 | case '"': 66 | return writeQuoteOpen(); 67 | 68 | default: 69 | return writeNormalChar(c); 70 | } 71 | } 72 | 73 | size_t writeBlockClose(char c) { 74 | size_t n = 0; 75 | n += unindentIfNeeded(); 76 | n += _sink.print(c); 77 | return n; 78 | } 79 | 80 | size_t writeBlockOpen(char c) { 81 | size_t n = 0; 82 | n += indentIfNeeded(); 83 | n += _sink.print(c); 84 | return n; 85 | } 86 | 87 | size_t writeColon() { 88 | size_t n = 0; 89 | n += _sink.print(": "); 90 | return n; 91 | } 92 | 93 | size_t writeComma() { 94 | size_t n = 0; 95 | n += _sink.print(",\r\n"); 96 | return n; 97 | } 98 | 99 | size_t writeQuoteOpen() { 100 | _inString = true; 101 | size_t n = 0; 102 | n += indentIfNeeded(); 103 | n += _sink.print('"'); 104 | return n; 105 | } 106 | 107 | size_t writeNormalChar(char c) { 108 | size_t n = 0; 109 | n += indentIfNeeded(); 110 | n += _sink.print(c); 111 | return n; 112 | } 113 | 114 | size_t indentIfNeeded() { 115 | if (!inEmptyBlock()) return 0; 116 | 117 | _sink.indent(); 118 | return _sink.print("\r\n"); 119 | } 120 | 121 | size_t unindentIfNeeded() { 122 | if (inEmptyBlock()) return 0; 123 | 124 | _sink.unindent(); 125 | return _sink.print("\r\n"); 126 | } 127 | 128 | char _previousChar; 129 | IndentedPrint& _sink; 130 | bool _inString; 131 | }; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/StaticStringBuilder.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A Print implementation that allows to write in a char[] 11 | class StaticStringBuilder { 12 | public: 13 | StaticStringBuilder(char *buf, size_t size) : end(buf + size - 1), p(buf) { 14 | *p = '\0'; 15 | } 16 | 17 | size_t print(char c) { 18 | if (p >= end) return 0; 19 | *p++ = c; 20 | *p = '\0'; 21 | return 1; 22 | } 23 | 24 | size_t print(const char *s) { 25 | char *begin = p; 26 | while (p < end && *s) *p++ = *s++; 27 | *p = '\0'; 28 | return size_t(p - begin); 29 | } 30 | 31 | private: 32 | char *end; 33 | char *p; 34 | }; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/Serialization/StreamPrintAdapter.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | 9 | #if ARDUINOJSON_ENABLE_STD_STREAM 10 | 11 | #include 12 | 13 | namespace ArduinoJson { 14 | namespace Internals { 15 | 16 | class StreamPrintAdapter { 17 | public: 18 | explicit StreamPrintAdapter(std::ostream& os) : _os(os) {} 19 | 20 | size_t print(char c) { 21 | _os << c; 22 | return 1; 23 | } 24 | 25 | size_t print(const char* s) { 26 | _os << s; 27 | return strlen(s); 28 | } 29 | 30 | private: 31 | // cannot be assigned 32 | StreamPrintAdapter& operator=(const StreamPrintAdapter&); 33 | 34 | std::ostream& _os; 35 | }; 36 | } 37 | } 38 | 39 | #endif // ARDUINOJSON_ENABLE_STD_STREAM 40 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/StaticJsonBuffer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "JsonBufferBase.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | class StaticJsonBufferBase : public JsonBufferBase { 13 | public: 14 | class String { 15 | public: 16 | String(StaticJsonBufferBase* parent) : _parent(parent) { 17 | _start = parent->_buffer + parent->_size; 18 | } 19 | 20 | void append(char c) { 21 | if (_parent->canAlloc(1)) { 22 | char* last = static_cast(_parent->doAlloc(1)); 23 | *last = c; 24 | } 25 | } 26 | 27 | const char* c_str() const { 28 | if (_parent->canAlloc(1)) { 29 | char* last = static_cast(_parent->doAlloc(1)); 30 | *last = '\0'; 31 | return _start; 32 | } else { 33 | return NULL; 34 | } 35 | } 36 | 37 | private: 38 | StaticJsonBufferBase* _parent; 39 | char* _start; 40 | }; 41 | 42 | StaticJsonBufferBase(char* buffer, size_t capa) 43 | : _buffer(buffer), _capacity(capa), _size(0) {} 44 | 45 | // Gets the capacity of the buffer in bytes 46 | size_t capacity() const { 47 | return _capacity; 48 | } 49 | 50 | // Gets the current usage of the buffer in bytes 51 | size_t size() const { 52 | return _size; 53 | } 54 | 55 | // Allocates the specified amount of bytes in the buffer 56 | virtual void* alloc(size_t bytes) { 57 | alignNextAlloc(); 58 | if (!canAlloc(bytes)) return NULL; 59 | return doAlloc(bytes); 60 | } 61 | 62 | // Resets the buffer. 63 | // USE WITH CAUTION: this invalidates all previously allocated data 64 | void clear() { 65 | _size = 0; 66 | } 67 | 68 | String startString() { 69 | return String(this); 70 | } 71 | 72 | protected: 73 | ~StaticJsonBufferBase() {} 74 | 75 | private: 76 | void alignNextAlloc() { 77 | _size = round_size_up(_size); 78 | } 79 | 80 | bool canAlloc(size_t bytes) const { 81 | return _size + bytes <= _capacity; 82 | } 83 | 84 | void* doAlloc(size_t bytes) { 85 | void* p = &_buffer[_size]; 86 | _size += bytes; 87 | return p; 88 | } 89 | 90 | char* _buffer; 91 | size_t _capacity; 92 | size_t _size; 93 | }; 94 | } 95 | 96 | #if defined(__clang__) 97 | #pragma clang diagnostic push 98 | #pragma clang diagnostic ignored "-Wnon-virtual-dtor" 99 | #elif defined(__GNUC__) 100 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 101 | #pragma GCC diagnostic push 102 | #endif 103 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 104 | #endif 105 | 106 | // Implements a JsonBuffer with fixed memory allocation. 107 | // The template paramenter CAPACITY specifies the capacity of the buffer in 108 | // bytes. 109 | template 110 | class StaticJsonBuffer : public Internals::StaticJsonBufferBase { 111 | public: 112 | explicit StaticJsonBuffer() 113 | : Internals::StaticJsonBufferBase(_buffer, CAPACITY) {} 114 | 115 | private: 116 | char _buffer[CAPACITY]; 117 | }; 118 | } 119 | 120 | #if defined(__clang__) 121 | #pragma clang diagnostic pop 122 | #elif defined(__GNUC__) 123 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 124 | #pragma GCC diagnostic pop 125 | #endif 126 | #endif 127 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/StringTraits/ArduinoStream.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #if ARDUINOJSON_ENABLE_ARDUINO_STREAM 8 | 9 | #include 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | struct ArduinoStreamTraits { 15 | class Reader { 16 | Stream& _stream; 17 | char _current, _next; 18 | 19 | public: 20 | Reader(Stream& stream) : _stream(stream), _current(0), _next(0) {} 21 | 22 | void move() { 23 | _current = _next; 24 | _next = 0; 25 | } 26 | 27 | char current() { 28 | if (!_current) _current = read(); 29 | return _current; 30 | } 31 | 32 | char next() { 33 | // assumes that current() has been called 34 | if (!_next) _next = read(); 35 | return _next; 36 | } 37 | 38 | private: 39 | char read() { 40 | // don't use _stream.read() as it ignores the timeout 41 | char c = 0; 42 | _stream.readBytes(&c, 1); 43 | return c; 44 | } 45 | }; 46 | 47 | static const bool has_append = false; 48 | static const bool has_equals = false; 49 | }; 50 | 51 | template 52 | struct StringTraits< 53 | TStream, 54 | // match any type that is derived from Stream: 55 | typename EnableIf< 56 | IsBaseOf::type>::value>::type> 57 | : ArduinoStreamTraits {}; 58 | } 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/StringTraits/CharPointer.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | template 11 | struct CharPointerTraits { 12 | class Reader { 13 | const TChar* _ptr; 14 | 15 | public: 16 | Reader(const TChar* ptr) 17 | : _ptr(ptr ? ptr : reinterpret_cast("")) {} 18 | 19 | void move() { 20 | ++_ptr; 21 | } 22 | 23 | char current() const { 24 | return char(_ptr[0]); 25 | } 26 | 27 | char next() const { 28 | return char(_ptr[1]); 29 | } 30 | }; 31 | 32 | static bool equals(const TChar* str, const char* expected) { 33 | return strcmp(reinterpret_cast(str), expected) == 0; 34 | } 35 | 36 | static bool is_null(const TChar* str) { 37 | return !str; 38 | } 39 | 40 | typedef const char* duplicate_t; 41 | 42 | template 43 | static duplicate_t duplicate(const TChar* str, Buffer* buffer) { 44 | if (!str) return NULL; 45 | size_t size = strlen(reinterpret_cast(str)) + 1; 46 | void* dup = buffer->alloc(size); 47 | if (dup != NULL) memcpy(dup, str, size); 48 | return static_cast(dup); 49 | } 50 | 51 | static const bool has_append = false; 52 | static const bool has_equals = true; 53 | static const bool should_duplicate = !IsConst::value; 54 | }; 55 | 56 | // char*, unsigned char*, signed char* 57 | // const char*, const unsigned char*, const signed char* 58 | template 59 | struct StringTraits::value>::type> 60 | : CharPointerTraits {}; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/StringTraits/FlashString.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #if ARDUINOJSON_ENABLE_PROGMEM 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | template <> 12 | struct StringTraits { 13 | class Reader { 14 | const char* _ptr; 15 | 16 | public: 17 | Reader(const __FlashStringHelper* ptr) 18 | : _ptr(reinterpret_cast(ptr)) {} 19 | 20 | void move() { 21 | _ptr++; 22 | } 23 | 24 | char current() const { 25 | return pgm_read_byte_near(_ptr); 26 | } 27 | 28 | char next() const { 29 | return pgm_read_byte_near(_ptr + 1); 30 | } 31 | }; 32 | 33 | static bool equals(const __FlashStringHelper* str, const char* expected) { 34 | return strcmp_P(expected, (const char*)str) == 0; 35 | } 36 | 37 | static bool is_null(const __FlashStringHelper* str) { 38 | return !str; 39 | } 40 | 41 | typedef const char* duplicate_t; 42 | 43 | template 44 | static duplicate_t duplicate(const __FlashStringHelper* str, Buffer* buffer) { 45 | if (!str) return NULL; 46 | size_t size = strlen_P((const char*)str) + 1; 47 | void* dup = buffer->alloc(size); 48 | if (dup != NULL) memcpy_P(dup, (const char*)str, size); 49 | return static_cast(dup); 50 | } 51 | 52 | static const bool has_append = false; 53 | static const bool has_equals = true; 54 | static const bool should_duplicate = true; 55 | }; 56 | } 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/StringTraits/StdStream.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #if ARDUINOJSON_ENABLE_STD_STREAM 8 | 9 | #include 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | struct StdStreamTraits { 15 | class Reader { 16 | std::istream& _stream; 17 | char _current, _next; 18 | 19 | public: 20 | Reader(std::istream& stream) : _stream(stream), _current(0), _next(0) {} 21 | 22 | void move() { 23 | _current = _next; 24 | _next = 0; 25 | } 26 | 27 | char current() { 28 | if (!_current) _current = read(); 29 | return _current; 30 | } 31 | 32 | char next() { 33 | // assumes that current() has been called 34 | if (!_next) _next = read(); 35 | return _next; 36 | } 37 | 38 | private: 39 | Reader& operator=(const Reader&); // Visual Studio C4512 40 | 41 | char read() { 42 | return _stream.eof() ? '\0' : static_cast(_stream.get()); 43 | } 44 | }; 45 | 46 | static const bool has_append = false; 47 | static const bool has_equals = false; 48 | }; 49 | 50 | template 51 | struct StringTraits< 52 | TStream, 53 | // match any type that is derived from std::istream: 54 | typename EnableIf::type>::value>::type> 56 | : StdStreamTraits {}; 57 | } 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/StringTraits/StdString.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #if ARDUINOJSON_ENABLE_STD_STRING || ARDUINOJSON_ENABLE_ARDUINO_STRING 8 | 9 | #if ARDUINOJSON_ENABLE_ARDUINO_STRING 10 | #include 11 | #endif 12 | 13 | #if ARDUINOJSON_ENABLE_STD_STRING 14 | #include 15 | #endif 16 | 17 | namespace ArduinoJson { 18 | namespace Internals { 19 | 20 | template 21 | struct StdStringTraits { 22 | typedef const char* duplicate_t; 23 | 24 | template 25 | static duplicate_t duplicate(const TString& str, Buffer* buffer) { 26 | if (!str.c_str()) return NULL; // <- Arduino string can return NULL 27 | size_t size = str.length() + 1; 28 | void* dup = buffer->alloc(size); 29 | if (dup != NULL) memcpy(dup, str.c_str(), size); 30 | return static_cast(dup); 31 | } 32 | 33 | static bool is_null(const TString& str) { 34 | // Arduino's String::c_str() can return NULL 35 | return !str.c_str(); 36 | } 37 | 38 | struct Reader : CharPointerTraits::Reader { 39 | Reader(const TString& str) : CharPointerTraits::Reader(str.c_str()) {} 40 | }; 41 | 42 | static bool equals(const TString& str, const char* expected) { 43 | return 0 == strcmp(str.c_str(), expected); 44 | } 45 | 46 | static void append(TString& str, char c) { 47 | str += c; 48 | } 49 | 50 | static void append(TString& str, const char* s) { 51 | str += s; 52 | } 53 | 54 | static const bool has_append = true; 55 | static const bool has_equals = true; 56 | static const bool should_duplicate = true; 57 | }; 58 | 59 | #if ARDUINOJSON_ENABLE_ARDUINO_STRING 60 | template <> 61 | struct StringTraits : StdStringTraits {}; 62 | template <> 63 | struct StringTraits : StdStringTraits { 64 | }; 65 | #endif 66 | 67 | #if ARDUINOJSON_ENABLE_STD_STRING 68 | template <> 69 | struct StringTraits : StdStringTraits {}; 70 | #endif 71 | } 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/StringTraits/StringTraits.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "../Configuration.hpp" 9 | #include "../TypeTraits/EnableIf.hpp" 10 | #include "../TypeTraits/IsBaseOf.hpp" 11 | #include "../TypeTraits/IsChar.hpp" 12 | #include "../TypeTraits/IsConst.hpp" 13 | #include "../TypeTraits/RemoveReference.hpp" 14 | 15 | namespace ArduinoJson { 16 | namespace Internals { 17 | 18 | template 19 | struct StringTraits { 20 | static const bool has_append = false; 21 | static const bool has_equals = false; 22 | }; 23 | 24 | template 25 | struct StringTraits : StringTraits {}; 26 | 27 | template 28 | struct StringTraits : StringTraits {}; 29 | } 30 | } 31 | 32 | #include "ArduinoStream.hpp" 33 | #include "CharPointer.hpp" 34 | #include "FlashString.hpp" 35 | #include "StdStream.hpp" 36 | #include "StdString.hpp" 37 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/EnableIf.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T if Condition is true. 11 | template 12 | struct EnableIf {}; 13 | 14 | template 15 | struct EnableIf { 16 | typedef T type; 17 | }; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/FloatTraits.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include 8 | #include // for size_t 9 | #include "../Configuration.hpp" 10 | #include "../Polyfills/math.hpp" 11 | 12 | namespace ArduinoJson { 13 | namespace Internals { 14 | 15 | template 16 | struct FloatTraits {}; 17 | 18 | template 19 | struct FloatTraits { 20 | typedef int64_t mantissa_type; 21 | static const short mantissa_bits = 52; 22 | static const mantissa_type mantissa_max = 23 | (static_cast(1) << mantissa_bits) - 1; 24 | 25 | typedef int16_t exponent_type; 26 | static const exponent_type exponent_max = 308; 27 | 28 | template 29 | static T make_float(T m, TExponent e) { 30 | if (e > 0) { 31 | for (uint8_t index = 0; e != 0; index++) { 32 | if (e & 1) m *= positiveBinaryPowerOfTen(index); 33 | e >>= 1; 34 | } 35 | } else { 36 | e = TExponent(-e); 37 | for (uint8_t index = 0; e != 0; index++) { 38 | if (e & 1) m *= negativeBinaryPowerOfTen(index); 39 | e >>= 1; 40 | } 41 | } 42 | return m; 43 | } 44 | 45 | static T positiveBinaryPowerOfTen(int index) { 46 | static T factors[] = { 47 | 1e1, 1e2, 1e4, 1e8, 1e16, 1e32, 48 | // workaround to support platforms with single precision literals 49 | forge(0x4D384F03, 0xE93FF9F5), forge(0x5A827748, 0xF9301D32), 50 | forge(0x75154FDD, 0x7F73BF3C)}; 51 | return factors[index]; 52 | } 53 | 54 | static T negativeBinaryPowerOfTen(int index) { 55 | static T factors[] = { 56 | 1e-1, 1e-2, 1e-4, 1e-8, 1e-16, 1e-32, 57 | // workaround to support platforms with single precision literals 58 | forge(0x32A50FFD, 0x44F4A73D), forge(0x255BBA08, 0xCF8C979D), 59 | forge(0x0AC80628, 0x64AC6F43)}; 60 | return factors[index]; 61 | } 62 | 63 | static T negativeBinaryPowerOfTenPlusOne(int index) { 64 | static T factors[] = { 65 | 1e0, 1e-1, 1e-3, 1e-7, 1e-15, 1e-31, 66 | // workaround to support platforms with single precision literals 67 | forge(0x32DA53FC, 0x9631D10D), forge(0x25915445, 0x81B7DEC2), 68 | forge(0x0AFE07B2, 0x7DD78B14)}; 69 | return factors[index]; 70 | } 71 | 72 | static T nan() { 73 | return forge(0x7ff80000, 0x00000000); 74 | } 75 | 76 | static T inf() { 77 | return forge(0x7ff00000, 0x00000000); 78 | } 79 | 80 | static T forge(uint32_t msb, uint32_t lsb) { 81 | union { 82 | uint64_t integerBits; 83 | T floatBits; 84 | }; 85 | integerBits = (uint64_t(msb) << 32) | lsb; 86 | return floatBits; 87 | } 88 | }; 89 | 90 | template 91 | struct FloatTraits { 92 | typedef int32_t mantissa_type; 93 | static const short mantissa_bits = 23; 94 | static const mantissa_type mantissa_max = 95 | (static_cast(1) << mantissa_bits) - 1; 96 | 97 | typedef int8_t exponent_type; 98 | static const exponent_type exponent_max = 38; 99 | 100 | template 101 | static T make_float(T m, TExponent e) { 102 | if (e > 0) { 103 | for (uint8_t index = 0; e != 0; index++) { 104 | if (e & 1) m *= positiveBinaryPowerOfTen(index); 105 | e >>= 1; 106 | } 107 | } else { 108 | e = -e; 109 | for (uint8_t index = 0; e != 0; index++) { 110 | if (e & 1) m *= negativeBinaryPowerOfTen(index); 111 | e >>= 1; 112 | } 113 | } 114 | return m; 115 | } 116 | 117 | static T positiveBinaryPowerOfTen(int index) { 118 | static T factors[] = {1e1f, 1e2f, 1e4f, 1e8f, 1e16f, 1e32f}; 119 | return factors[index]; 120 | } 121 | 122 | static T negativeBinaryPowerOfTen(int index) { 123 | static T factors[] = {1e-1f, 1e-2f, 1e-4f, 1e-8f, 1e-16f, 1e-32f}; 124 | return factors[index]; 125 | } 126 | 127 | static T negativeBinaryPowerOfTenPlusOne(int index) { 128 | static T factors[] = {1e0f, 1e-1f, 1e-3f, 1e-7f, 1e-15f, 1e-31f}; 129 | return factors[index]; 130 | } 131 | 132 | static T forge(uint32_t bits) { 133 | union { 134 | uint32_t integerBits; 135 | T floatBits; 136 | }; 137 | integerBits = bits; 138 | return floatBits; 139 | } 140 | 141 | static T nan() { 142 | return forge(0x7fc00000); 143 | } 144 | 145 | static T inf() { 146 | return forge(0x7f800000); 147 | } 148 | }; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsArray.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T without the const modifier 11 | template 12 | struct IsArray { 13 | static const bool value = false; 14 | }; 15 | template 16 | struct IsArray { 17 | static const bool value = true; 18 | }; 19 | template 20 | struct IsArray { 21 | static const bool value = true; 22 | }; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsBaseOf.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that returns true if Derived inherits from TBase is an 11 | // integral type. 12 | template 13 | class IsBaseOf { 14 | protected: // <- to avoid GCC's "all member functions in class are private" 15 | typedef char Yes[1]; 16 | typedef char No[2]; 17 | 18 | static Yes &probe(const TBase *); 19 | static No &probe(...); 20 | 21 | public: 22 | enum { 23 | value = sizeof(probe(reinterpret_cast(0))) == sizeof(Yes) 24 | }; 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsChar.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IsSame.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // A meta-function that returns true if T is a charater 13 | template 14 | struct IsChar { 15 | static const bool value = IsSame::value || 16 | IsSame::value || 17 | IsSame::value; 18 | }; 19 | 20 | template 21 | struct IsChar : IsChar {}; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsConst.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T without the const modifier 11 | template 12 | struct IsConst { 13 | static const bool value = false; 14 | }; 15 | 16 | template 17 | struct IsConst { 18 | static const bool value = true; 19 | }; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsFloatingPoint.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IsSame.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | // A meta-function that returns true if T is a floating point type 13 | template 14 | struct IsFloatingPoint { 15 | static const bool value = IsSame::value || IsSame::value; 16 | }; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsIntegral.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IsSame.hpp" 8 | #include "IsSignedIntegral.hpp" 9 | #include "IsUnsignedIntegral.hpp" 10 | 11 | namespace ArduinoJson { 12 | namespace Internals { 13 | 14 | // A meta-function that returns true if T is an integral type. 15 | template 16 | struct IsIntegral { 17 | static const bool value = IsSignedIntegral::value || 18 | IsUnsignedIntegral::value || 19 | IsSame::value; 20 | // CAUTION: differs from std::is_integral as it doesn't include bool 21 | }; 22 | 23 | template 24 | struct IsIntegral : IsIntegral {}; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsSame.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that returns true if types T and U are the same. 11 | template 12 | struct IsSame { 13 | static const bool value = false; 14 | }; 15 | 16 | template 17 | struct IsSame { 18 | static const bool value = true; 19 | }; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsSignedIntegral.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | #include "IsSame.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | // A meta-function that returns true if T is an integral type. 14 | template 15 | struct IsSignedIntegral { 16 | static const bool value = 17 | IsSame::value || IsSame::value || 18 | IsSame::value || IsSame::value || 19 | #if ARDUINOJSON_USE_LONG_LONG 20 | IsSame::value || 21 | #endif 22 | #if ARDUINOJSON_USE_INT64 23 | IsSame::value || 24 | #endif 25 | false; 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "../Configuration.hpp" 8 | #include "IsSame.hpp" 9 | 10 | namespace ArduinoJson { 11 | namespace Internals { 12 | 13 | // A meta-function that returns true if T is an integral type. 14 | template 15 | struct IsUnsignedIntegral { 16 | static const bool value = 17 | IsSame::value || IsSame::value || 18 | IsSame::value || IsSame::value || 19 | #if ARDUINOJSON_USE_LONG_LONG 20 | IsSame::value || 21 | #endif 22 | #if ARDUINOJSON_USE_INT64 23 | IsSame::value || 24 | #endif 25 | false; 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/IsVariant.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | #include "IsBaseOf.hpp" 8 | 9 | namespace ArduinoJson { 10 | namespace Internals { 11 | 12 | class JsonVariantTag {}; 13 | 14 | template 15 | struct IsVariant : IsBaseOf {}; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/RemoveConst.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T without the const modifier 11 | template 12 | struct RemoveConst { 13 | typedef T type; 14 | }; 15 | template 16 | struct RemoveConst { 17 | typedef T type; 18 | }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /printermonitor/libs/ArduinoJson/src/ArduinoJson/TypeTraits/RemoveReference.hpp: -------------------------------------------------------------------------------- 1 | // ArduinoJson - arduinojson.org 2 | // Copyright Benoit Blanchon 2014-2018 3 | // MIT License 4 | 5 | #pragma once 6 | 7 | namespace ArduinoJson { 8 | namespace Internals { 9 | 10 | // A meta-function that return the type T without the reference modifier. 11 | template 12 | struct RemoveReference { 13 | typedef T type; 14 | }; 15 | template 16 | struct RemoveReference { 17 | typedef T type; 18 | }; 19 | } 20 | } 21 | --------------------------------------------------------------------------------