2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
[![Arduino CI](https://github.com/RobTillaart/PrintSize/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
2021-11-13 22:52:33 +01:00
|
|
|
[![Arduino-lint](https://github.com/RobTillaart/PrintSize/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PrintSize/actions/workflows/arduino-lint.yml)
|
|
|
|
[![JSON check](https://github.com/RobTillaart/PrintSize/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PrintSize/actions/workflows/jsoncheck.yml)
|
2023-11-16 10:38:25 +01:00
|
|
|
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/PrintSize.svg)](https://github.com/RobTillaart/PrintSize/issues)
|
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PrintSize/blob/master/LICENSE)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PrintSize.svg?maxAge=3600)](https://github.com/RobTillaart/PrintSize/releases)
|
2023-11-16 10:38:25 +01:00
|
|
|
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/PrintSize.svg)](https://registry.platformio.org/libraries/robtillaart/PrintSize)
|
2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
|
2020-02-19 10:38:09 +01:00
|
|
|
# PrintSize
|
|
|
|
|
2021-11-13 22:52:33 +01:00
|
|
|
Arduino library to determine the length of print statements.
|
|
|
|
|
2020-11-27 11:28:57 +01:00
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
## Description
|
2020-11-27 11:28:57 +01:00
|
|
|
|
2020-02-19 10:38:09 +01:00
|
|
|
PrintSize is a minimal library to determine the length of a variable when printed.
|
2020-11-27 11:28:57 +01:00
|
|
|
This includes printing of floats, integers in decimal or hex notation.
|
|
|
|
|
2021-11-13 22:52:33 +01:00
|
|
|
Works for **print()**, **println()** and if supported **printf()** e.g. ESP32.
|
2020-02-19 10:38:09 +01:00
|
|
|
|
2020-11-27 11:28:57 +01:00
|
|
|
Finally since **0.2.0** it has a total counter to add up the characters "printed" since
|
|
|
|
the last **reset()** call. (see example)
|
2020-02-19 10:38:09 +01:00
|
|
|
|
2023-11-16 10:38:25 +01:00
|
|
|
|
|
|
|
#### Related
|
|
|
|
|
|
|
|
- https://github.com/RobTillaart/PrintCharArray (captures data in a char buffer)
|
|
|
|
- https://github.com/RobTillaart/PrintSize (counts length of a number of print commands)
|
|
|
|
- https://github.com/RobTillaart/PrintString (captures data in a String)
|
|
|
|
|
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
#include "PrintSize.h"
|
|
|
|
```
|
|
|
|
|
|
|
|
- **PrintSize()** Constructor
|
|
|
|
- **size_t write(uint8_t c)** core.
|
|
|
|
Note: gives a warning unused parameter.
|
|
|
|
- **size_t write(uint8_t \* str, uint8_t length)**
|
|
|
|
Note: gives a warning unused parameter.
|
|
|
|
- **void reset()** reset the total counter.
|
|
|
|
- **uint32_t total()** total bytes "printed".
|
2021-11-13 22:52:33 +01:00
|
|
|
|
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
## Operational
|
2020-11-27 11:28:57 +01:00
|
|
|
|
2021-11-13 22:52:33 +01:00
|
|
|
Example shows the right alignment of 10 random numbers.
|
|
|
|
|
|
|
|
Example shows (elementary) line fitting.
|
|
|
|
|
2020-11-27 11:28:57 +01:00
|
|
|
|
2021-11-13 22:52:33 +01:00
|
|
|
## Applications
|
2020-02-19 10:38:09 +01:00
|
|
|
|
|
|
|
Can be used to calculate the needed space.
|
2021-11-13 22:52:33 +01:00
|
|
|
- to properly do a right alignment e.g. for numbers or variable text.
|
|
|
|
- do left alignment and overwrite previous output with just enough spaces.
|
|
|
|
- centring of numbers.
|
2021-12-24 13:42:31 +01:00
|
|
|
- see if output will fit into a line / display.
|
2021-11-13 22:52:33 +01:00
|
|
|
- see if a string fits in EEPROM or any other storage medium.
|
|
|
|
- see if a string fits in a communication buffer.
|
|
|
|
|
|
|
|
|
|
|
|
## Future
|
|
|
|
|
2023-11-16 10:38:25 +01:00
|
|
|
#### Must
|
|
|
|
|
|
|
|
#### Should
|
|
|
|
|
2021-11-13 22:52:33 +01:00
|
|
|
- add examples
|
|
|
|
- add a function to handle **tab** char correctly e.g.
|
2021-12-24 13:42:31 +01:00
|
|
|
could add more than one char. Interferes with the **write(str, length)**.
|
2023-11-16 10:38:25 +01:00
|
|
|
- setTabSize(2, 4, 6, 8...);
|
2022-11-22 17:00:39 +01:00
|
|
|
- getTabSize();
|
|
|
|
- uint8_t \_tabSize = 4;
|
2023-11-16 10:38:25 +01:00
|
|
|
|
|
|
|
#### Could
|
|
|
|
|
|
|
|
- PRINTSIZE_LIB_VERSION ?
|
|
|
|
|
|
|
|
#### Wont
|
|
|
|
|
|
|
|
|
|
|
|
## Support
|
|
|
|
|
|
|
|
If you appreciate my libraries, you can support the development and maintenance.
|
|
|
|
Improve the quality of the libraries by providing issues and Pull Requests, or
|
|
|
|
donate through PayPal or GitHub sponsors.
|
|
|
|
|
|
|
|
Thank you,
|
|
|
|
|
2021-11-13 22:52:33 +01:00
|
|
|
|