2021-01-29 06:31:58 -05:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: printHelpers.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2018-01-21
|
2022-04-15 14:50:26 -04:00
|
|
|
// VERSION: 0.2.4
|
2021-12-24 07:26:40 -05:00
|
|
|
// PUPROSE: Arduino library to help formatting for printing.
|
2021-01-29 06:31:58 -05:00
|
|
|
// URL: https://github.com/RobTillaart/printHelpers
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
|
|
|
|
2022-04-15 14:50:26 -04:00
|
|
|
#define PRINTHELPERS_VERSION (F("0.2.4"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
// global buffer used by all functions so no static buffer in every function
|
|
|
|
// is needed ==> results need to be printed/copied asap
|
|
|
|
// not usable in multi-threading environments (use with care)
|
2022-04-15 14:50:26 -04:00
|
|
|
//
|
|
|
|
// 24 is a pretty safe minimum
|
|
|
|
#ifndef PRINTBUFFERSIZE
|
|
|
|
#define PRINTBUFFERSIZE 66
|
|
|
|
#endif
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
//
|
2021-12-24 07:26:40 -05:00
|
|
|
// PRINT 64 BIT
|
2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
// print64 note
|
|
|
|
// buffer size 66 will work for base 2 -36
|
|
|
|
// buffer size 34 will work for base 4 -36
|
|
|
|
// buffer size 24 will work for base 8 -36
|
|
|
|
// buffer size 22 will work for base 10 - 36
|
|
|
|
|
2022-04-15 14:50:26 -04:00
|
|
|
char * print64(int64_t value, uint8_t base = 10);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-04-15 14:50:26 -04:00
|
|
|
char * print64(uint64_t value, uint8_t base = 10);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SCIENTIFIC NOTATIION
|
|
|
|
//
|
|
|
|
|
2021-12-24 07:26:40 -05:00
|
|
|
// typical buffer size for 8 byte double is 22 bytes
|
2021-01-29 06:31:58 -05:00
|
|
|
// 15 bytes mantissa, sign dot E-xxx
|
2021-11-13 12:15:22 -05:00
|
|
|
// em = exponentMultiple.
|
2022-04-15 14:50:26 -04:00
|
|
|
char * scieng(double value, uint8_t decimals, uint8_t em);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-04-15 14:50:26 -04:00
|
|
|
char * eng(double value, uint8_t decimals);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-04-15 14:50:26 -04:00
|
|
|
char * sci(double value, uint8_t decimals);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-04-15 14:50:26 -04:00
|
|
|
void sci(Stream &str, double value, uint8_t decimals);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-12-24 07:26:40 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
//
|
2021-12-24 07:26:40 -05:00
|
|
|
// toBytes
|
2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
// official support to UDA == 1024^12
|
|
|
|
// kilo mega giga tera peta exa (1024^6)
|
|
|
|
// zetta yotta xona weka vunda uda (1024^12)
|
|
|
|
//
|
2021-12-24 07:26:40 -05:00
|
|
|
// (treda Byte == TDB is the next one and it is 2 char
|
2021-11-13 12:15:22 -05:00
|
|
|
// so code wise difficult and as it is seldom used, support stops there.
|
2021-12-24 07:26:40 -05:00
|
|
|
//
|
2021-01-29 06:31:58 -05:00
|
|
|
// To have some support the code uses lowercase for the next 8 levels
|
|
|
|
// treda sorta rinta quexa pepta ocha nena minga luma (1024 ^21 ~~ 10^63)
|
2022-04-15 14:50:26 -04:00
|
|
|
char * toBytes(double value, uint8_t decimals = 2);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
// -- END OF FILE --
|
2021-12-24 07:26:40 -05:00
|
|
|
|