├── .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 | 
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 | [](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 | [](https://youtu.be/niRv9SCgAPk)
126 | 
127 | 
128 | 
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 | 
2 |
3 | ---
4 |
5 | [](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/master) [](https://travis-ci.org/bblanchon/ArduinoJson) [](https://coveralls.io/r/bblanchon/ArduinoJson?branch=master) [](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