mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-02 23:00:38 +08:00

* Update WebSocket library * Update SSDP library * Update TFT_eSPI library * Update EspLuaEngine library * Update SDFat library * Change to pioarduino * Make ESP3DMessageFIFO and ESP3DMessage more thread safe * Fix sanity checks for BT * Add some C6 support * Refactor ethernet code * Split Ethernet Sta / WiFi sta ESP Commands and settings * Simplify wait and wdtFeed code * Set C3 with 4MB by default in platformio.ini * Apply Disable brown out only on ESP32 to avoid crash e.g:ESP32S3 * Add missing entries in platformio.ini
92 lines
2.6 KiB
C++
92 lines
2.6 KiB
C++
/**
|
|
* Copyright (c) 2011-2020 Bill Greiman
|
|
* This file is part of the SdFat library for SD memory cards.
|
|
*
|
|
* MIT License
|
|
*
|
|
* 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:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* 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.
|
|
*/
|
|
#include "PrintBasic.h"
|
|
#if ENABLE_ARDUINO_FEATURES == 0
|
|
#include <math.h>
|
|
|
|
size_t PrintBasic::print(long n, uint8_t base) {
|
|
if (n < 0 && base == 10) {
|
|
return print('-') + printNum(-n, base);
|
|
}
|
|
return printNum(n, base);
|
|
}
|
|
size_t PrintBasic::printNum(unsigned long n, uint8_t base) {
|
|
const uint8_t DIM = 8 * sizeof(long);
|
|
char buf[DIM];
|
|
char *str = &buf[DIM];
|
|
|
|
if (base < 2) return 0;
|
|
|
|
do {
|
|
char c = n % base;
|
|
n /= base;
|
|
*--str = c + (c < 10 ? '0' : 'A' - 10);
|
|
} while (n);
|
|
return write(str, &buf[DIM] - str);
|
|
}
|
|
|
|
size_t PrintBasic::printDouble(double n, uint8_t prec) {
|
|
// Max printable 32-bit floating point number. AVR uses 32-bit double.
|
|
const double maxfp = static_cast<double>(0XFFFFFF00UL);
|
|
size_t rtn = 0;
|
|
|
|
if (isnan(n)) {
|
|
return write("NaN");
|
|
}
|
|
if (n < 0) {
|
|
n = -n;
|
|
rtn += print('-');
|
|
}
|
|
if (isinf(n)) {
|
|
return rtn + write("Inf");
|
|
}
|
|
if (n > maxfp) {
|
|
return rtn + write("Ovf");
|
|
}
|
|
|
|
double round = 0.5;
|
|
for (uint8_t i = 0; i < prec; ++i) {
|
|
round *= 0.1;
|
|
}
|
|
|
|
n += round;
|
|
|
|
uint32_t whole = (uint32_t)n;
|
|
rtn += print(whole);
|
|
|
|
if (prec) {
|
|
rtn += print('.');
|
|
double fraction = n - static_cast<double>(whole);
|
|
for (uint8_t i = 0; i < prec; i++) {
|
|
fraction *= 10.0;
|
|
uint8_t digit = fraction;
|
|
rtn += print(digit);
|
|
fraction -= digit;
|
|
}
|
|
}
|
|
return rtn;
|
|
}
|
|
#endif // ENABLE_ARDUINO_FEATURES == 0
|