GY-63_MS5611/libraries/Multiplex/README.md

107 lines
4.3 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/Multiplex/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-09-14 11:02:45 -04:00
[![JSON check](https://github.com/RobTillaart/Multiplex/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Multiplex/actions/workflows/jsoncheck.yml)
[![Arduino-lint](https://github.com/RobTillaart/Multiplex/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Multiplex/actions/workflows/arduino-lint.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Multiplex/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Multiplex.svg?maxAge=3600)](https://github.com/RobTillaart/Multiplex/releases)
2021-12-22 06:37:31 -05:00
2021-01-29 06:31:58 -05:00
# Multiplex
2021-09-14 11:02:45 -04:00
Arduino Library implementing a (Print) stream multiplexer.
2021-01-29 06:31:58 -05:00
## Description
2021-09-14 11:02:45 -04:00
Multiplex is a library in which one can add multiple Print streams.
If one prints to the multiplexer the data is sent to all the streams that were added.
2021-08-10 16:25:19 -04:00
2021-09-19 07:30:34 -04:00
The maximum number of streams to add is 4.
This value is defined in the **multiplex.h file** with `#define MAX_MULTIPLEX`.
2021-09-14 11:02:45 -04:00
This value can be set to 254 MAX as the number 255 / 0xFF is used as a NOT_FOUND flag.
2021-08-10 16:25:19 -04:00
2021-09-14 11:02:45 -04:00
Streams can be enabled or disabled by calling `enable()/disable()` passing either an index (based on the order
in which `add` was called; 0 is first) or a pointer to the `Print`
object that was passed to `add(Print *)` by calling `enableStream()/disableStream()`
2021-08-10 16:25:19 -04:00
2021-09-14 11:02:45 -04:00
It is not possible to remove a stream from the multiplexer (yet), as this would affect the indices used.
Solution is to reset and repopulate for now.
2021-01-29 06:31:58 -05:00
2021-09-19 07:30:34 -04:00
**Note**: 0.2.2 has **experimental** remove support.
2021-01-29 06:31:58 -05:00
## Interface
2021-09-14 11:02:45 -04:00
2021-01-29 06:31:58 -05:00
### Constructor
2021-09-14 11:02:45 -04:00
- **Multiplex(uint8_t max_multiplex = 4)** constructor,
sets the maximum number of streams to 4 by default.
MAX number is 254 as 255 (0xFF) is used as a flag for **NOT FOUND**.
- **~Multiplex()** destructor
- **void reset()** resets the count in the multiplexer to zero streams.
2021-01-29 06:31:58 -05:00
### Core
2021-09-19 07:30:34 -04:00
- **size_t write(uint8_t c)** workhorse of the Print interface.
2021-09-14 11:02:45 -04:00
Writes a character to all enabled streams.
2021-12-22 06:37:31 -05:00
- **size_t write(const uint8_t \* buffer, size_t size)**
2021-09-14 11:02:45 -04:00
Writes a buffer of size characters to all enabled streams.
2021-09-19 07:30:34 -04:00
- **bool add(Print \* stream)** add another Print stream.
Returns false if no space left.
2021-09-20 13:23:26 -04:00
Use the **index(Stream)** to get the actual index of the stream.
2021-09-19 07:30:34 -04:00
#### Experimental 0.2.2
Removing a stream is experimental.
2021-09-20 13:23:26 -04:00
It changes the internal indices used, so if you want to use **remove()** in your sketch, you
should only use the functions with a stream as parameter as these will always work correctly.
Alternative is to request the **index(Stream)** after you called **remove()** and update your indices.
2021-09-19 07:30:34 -04:00
- **bool remove(Print \* stream)** remove a Print stream.
Returns false if not in the multiplexer.
- **bool remove(uint8_t index)** remove a stream by its internal index.
Returns false if index is out of range.
2021-01-29 06:31:58 -05:00
### Control
2021-09-14 11:02:45 -04:00
- **uint8_t count()** returns number of streams added, MAX 4 in initial release
2021-01-29 06:31:58 -05:00
- **uint8_t size()** returns size which is 4 in the current release.
2021-09-14 11:02:45 -04:00
- **uint8_t free()** returns number of free slots.
2021-09-19 07:30:34 -04:00
Note: the index based functions are (slightly) faster than the stream based functions.
How much faster depends on **MAX_MULTIPLEX** as the stream based functions do a lookup in every call.
2021-09-14 11:02:45 -04:00
- **bool enable(uint8_t index)** enable the stream at index.
Returns true on success, false otherwise.
- **bool enableStream(Stream \* stream)** enable the stream.
Returns true on success, false otherwise.
- **bool disable(uint8_t index)** disable the stream at index.
Returns true on success, false otherwise.
- **bool disableStream(Stream \* stream)** disable the stream.
Returns true on success, false otherwise.
- **bool isEnabled(uint8_t index)** returns true if the stream at index is enabled,
false otherwise.
- **bool isEnabledStream(Stream \* stream)** returns true if the stream is enabled,
false otherwise.
- **uint8_t index(Print \*stream)** returns the index of the stream if it was added,
otherwise it returns 0xFF == 255.
2021-09-20 13:23:26 -04:00
Can be used to check if a stream is added to the multiplexer.
2021-09-14 11:02:45 -04:00
- **Print \* stream(uint8_t index)** returns the stream at index or NULL otherwise.
Convenience function.
2021-01-29 06:31:58 -05:00
## Future
2021-09-14 11:02:45 -04:00
- set size in constructor - dynamic memory
- pack enabled flag in one or more bytes
2021-01-29 06:31:58 -05:00
- add names?
## Operation
See examples