GY-63_MS5611/libraries/printHelpers/printHelpers.h

112 lines
2.9 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: printHelpers.h
// AUTHOR: Rob Tillaart
// DATE: 2018-01-21
2023-01-29 05:51:20 -05:00
// VERSION: 0.4.0
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"
2023-01-29 05:51:20 -05:00
#define PRINTHELPERS_VERSION (F("0.4.0"))
2021-01-29 06:31:58 -05:00
2022-11-22 09:52:32 -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
//
2022-11-22 09:52:32 -05:00
// 24 is a pretty safe minimum
2023-01-28 07:52:36 -05:00
//
2022-04-15 14:50:26 -04:00
#ifndef PRINTBUFFERSIZE
#define PRINTBUFFERSIZE 66
#endif
2021-01-29 06:31:58 -05:00
////////////////////////////////////////////////////////////
//
2023-01-28 07:52:36 -05:00
// print64()
2021-01-29 06:31:58 -05:00
//
2022-11-22 09:52:32 -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
2021-01-29 06:31:58 -05:00
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
////////////////////////////////////////////////////////////
//
2023-01-28 07:52:36 -05:00
// Scientific + Engineering notation
2021-01-29 06:31:58 -05:00
//
2022-11-22 09:52:32 -05:00
// typical buffer size for 8 byte double is 22 bytes
// 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
2023-01-28 07:52:36 -05:00
char * eng(double value, uint8_t decimals); // em == 3
2021-01-29 06:31:58 -05:00
2023-01-28 07:52:36 -05:00
char * sci(double value, uint8_t decimals); // em == 1
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
////////////////////////////////////////////////////////////
//
2023-01-28 07:52:36 -05:00
// toBytes()
2021-01-29 06:31:58 -05:00
//
2022-11-22 09:52:32 -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-01-29 06:31:58 -05:00
//
2022-11-22 09:52:32 -05:00
// (treda Byte == TDB is the next one and it is 2 char
// so code wise difficult and as it is seldom used, support stops there.
2021-12-24 07:26:40 -05:00
//
2022-11-22 09:52:32 -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
2022-11-29 11:12:53 -05:00
////////////////////////////////////////////////////////////
//
2023-01-28 07:52:36 -05:00
// hex()
2022-11-29 11:12:53 -05:00
//
2023-01-28 07:52:36 -05:00
// always leading zero's - no prefix - no separators
2022-11-29 11:12:53 -05:00
// cast if needed.
char * hex(uint64_t value, uint8_t digits = 16);
2023-01-28 07:52:36 -05:00
char * hex(uint32_t value, uint8_t digits = 8);
char * hex(uint16_t value, uint8_t digits = 4);
char * hex(uint8_t value, uint8_t digits = 2);
2022-11-29 11:12:53 -05:00
////////////////////////////////////////////////////////////
//
2023-01-28 07:52:36 -05:00
// BIN
2022-11-29 11:12:53 -05:00
//
2023-01-28 07:52:36 -05:00
// always leading zero's - no prefix - no separators
2022-11-29 11:12:53 -05:00
// cast if needed.
char * bin(uint64_t value, uint8_t digits = 64);
char * bin(uint32_t value, uint8_t digits = 32);
char * bin(uint16_t value, uint8_t digits = 16);
char * bin(uint8_t value, uint8_t digits = 8);
2023-01-29 05:51:20 -05:00
////////////////////////////////////////////////////////////
//
// toRoman()
//
// value should be in range 1..9999
// values 10K-100M are experimental (see readme.md)
char * toRoman(uint32_t value);
2022-11-22 09:52:32 -05:00
// -- END OF FILE --
2021-12-24 07:26:40 -05:00