2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
[![Arduino CI](https://github.com/RobTillaart/PrintCharArray/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
2021-11-13 10:35:33 -05:00
|
|
|
[![Arduino-lint](https://github.com/RobTillaart/PrintCharArray/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PrintCharArray/actions/workflows/arduino-lint.yml)
|
|
|
|
[![JSON check](https://github.com/RobTillaart/PrintCharArray/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PrintCharArray/actions/workflows/jsoncheck.yml)
|
2023-11-16 04:36:39 -05:00
|
|
|
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/PrintCharArray.svg)](https://github.com/RobTillaart/PrintCharArray/issues)
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PrintCharArray/blob/master/LICENSE)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PrintCharArray.svg?maxAge=3600)](https://github.com/RobTillaart/PrintCharArray/releases)
|
2023-11-16 04:36:39 -05:00
|
|
|
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/PrintCharArray.svg)](https://registry.platformio.org/libraries/robtillaart/PrintCharArray)
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
2020-11-27 05:28:57 -05:00
|
|
|
# PrintCharArray
|
|
|
|
|
2021-11-13 10:35:33 -05:00
|
|
|
Arduino library to print to a char array.
|
2020-11-27 05:28:57 -05:00
|
|
|
|
2017-12-09 14:39:12 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
## Description
|
2017-12-09 14:39:12 -05:00
|
|
|
|
2021-11-13 10:35:33 -05:00
|
|
|
PrintCharArray is a class that implements the Print interface and an internal char array.
|
|
|
|
It will effectively buffer a number of print statements and allows it to be printed or
|
|
|
|
processed (for real) later.
|
2021-01-29 06:31:58 -05:00
|
|
|
The internal buffer can be set in the constructor and has a minimum of 20 bytes and
|
2021-11-13 10:35:33 -05:00
|
|
|
a maximum of 250 bytes. Default size is 100 bytes.
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
Applications
|
2021-12-24 07:08:51 -05:00
|
|
|
- Buffer slowly generated data, and send it with minimum time between bytes.
|
|
|
|
Use it e.g. for faster printing to SD card or Ethernet which can handle larger buffers.
|
2021-11-13 10:35:33 -05:00
|
|
|
- print to buffer to see how many chars the output will be.
|
|
|
|
- use to prevent "display line overflow" (e.g. floats).
|
|
|
|
- use to right align output (see examples).
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2024-04-11 07:29:13 -04:00
|
|
|
#### Template class
|
|
|
|
|
|
|
|
Since 0.4.0 the library has a template class too - Thanks to me21.
|
|
|
|
See also issue #7.
|
|
|
|
|
|
|
|
This template class is called PrintCharArrayT for now.
|
|
|
|
|
|
|
|
The interface and functionality is similar (except constructor).
|
|
|
|
Performance is similar, footprint is smaller on AVR (no malloc lib).
|
|
|
|
The space needed will not be dynamically allocated (stack iso heap).
|
|
|
|
|
|
|
|
```
|
|
|
|
printCharArray4.ino = 3532 bytes. global var use 422 bytes.
|
|
|
|
printCharArray4_template.ino = 2840 bytes. global var use 627 bytes.
|
|
|
|
```
|
|
|
|
|
|
|
|
This template version needs more testing, so labelled **experimental** for now.
|
|
|
|
|
2023-11-16 04:36:39 -05:00
|
|
|
|
|
|
|
#### Related
|
|
|
|
|
2024-04-11 07:29:13 -04:00
|
|
|
- https://github.com/RobTillaart/PrintCharArray captures data in a char array buffer.
|
|
|
|
- https://github.com/RobTillaart/PrintSize counts length of a number of print commands.
|
|
|
|
- https://github.com/RobTillaart/PrintString captures data in a String.
|
2021-12-24 07:08:51 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
2023-11-16 04:36:39 -05:00
|
|
|
```cpp
|
|
|
|
#include "PrintCharArray.h"
|
|
|
|
```
|
|
|
|
|
2021-11-13 10:35:33 -05:00
|
|
|
- **PrintCharArray(uint8_t size = 100)** constructor, default size of 100 bytes.
|
|
|
|
- **size_t write(uint8_t c)** workhorse I of Print interface.
|
|
|
|
- **size_t write(uint8_t \* str, uint8_t length)** workhorse II of Print interface.
|
|
|
|
- **void clear()** wipes the internal buffer.
|
2021-01-29 06:31:58 -05:00
|
|
|
- **int available()** shows how much space is left in the internal buffer.
|
|
|
|
Replaces free().
|
2021-11-13 10:35:33 -05:00
|
|
|
- **int size()** current usage of the buffer.
|
|
|
|
- **int bufSize()** size of the whole buffer.
|
|
|
|
Recall that a char array must have a '\0' delimiter.
|
2021-01-29 06:31:58 -05:00
|
|
|
- **char \* getBuffer()** to access the buffer.
|
|
|
|
|
|
|
|
|
2024-04-11 07:29:13 -04:00
|
|
|
## Interface template version
|
|
|
|
|
|
|
|
- **PrintCharArrayT<int BUFSIZE>** constructor, no default size.
|
|
|
|
|
|
|
|
Remaining interface is identical.
|
|
|
|
|
|
|
|
|
2020-11-27 05:28:57 -05:00
|
|
|
## Operation
|
2017-12-09 14:39:12 -05:00
|
|
|
|
2021-12-24 07:08:51 -05:00
|
|
|
See examples.
|
2021-11-13 10:35:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Future
|
|
|
|
|
2023-11-16 04:36:39 -05:00
|
|
|
#### Must
|
|
|
|
|
2022-11-22 09:51:21 -05:00
|
|
|
- documentation
|
|
|
|
|
2023-11-16 04:36:39 -05:00
|
|
|
#### Should
|
|
|
|
|
2021-11-13 10:35:33 -05:00
|
|
|
- testing
|
2024-04-11 07:29:13 -04:00
|
|
|
- platforms
|
|
|
|
- template version
|
2022-11-22 09:51:21 -05:00
|
|
|
|
2023-11-16 04:36:39 -05:00
|
|
|
#### Could
|
|
|
|
|
2021-12-24 07:08:51 -05:00
|
|
|
- examples
|
|
|
|
- inject spaces in "middle align" example? possible?
|
2024-04-11 07:29:13 -04:00
|
|
|
- rename size() => length()
|
|
|
|
- rename bufSize() => size() ? ambiguous renaming.
|
2021-12-24 07:08:51 -05:00
|
|
|
- add real live examples.
|
2024-04-11 07:29:13 -04:00
|
|
|
- **size_t repeat(uint8_t length, uint8_t c)** convenience function for alignment.
|
2021-11-13 10:35:33 -05:00
|
|
|
- add error flag
|
2023-11-16 04:36:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
#### Wont
|
|
|
|
|
2024-04-11 07:29:13 -04:00
|
|
|
- move code to .cpp file
|
|
|
|
|
|
|
|
|
2023-11-16 04:36:39 -05:00
|
|
|
## 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 10:35:33 -05:00
|
|
|
|