63 lines
2.0 KiB
Markdown
Raw Normal View History

2021-01-29 12:31:58 +01:00
[![Arduino CI](https://github.com/RobTillaart/Multiplex/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![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)
# Multiplex
Arduino Library implementing a stream multiplexer.
## Description
Multiplex is a library in which one can add multiple Print streams.
2021-08-10 22:25:19 +02:00
2021-01-29 12:31:58 +01:00
If one prints to the multiplexer it is sent to all the streams that were added.
2021-08-10 22:25:19 +02:00
The maximum nr of streams to add is 4.
2021-01-29 12:31:58 +01:00
It is possible to disable individual streams.
2021-08-10 22:25:19 +02:00
Streams can be enabled or disabled by calling `enable()/disable()` passing either an index (based on the order
in whicbh `add` was called; 0 is first) or a pointer to the `Print`
object that was passed to `add(Print *)`;
2021-01-29 12:31:58 +01:00
## Interface
### Constructor
- **Multiplex()** constructor
- **void reset()** resets to zero streams in the multiplexer.
### Core
- **size_t write(uint8_t c)** workhorse of the print interface.
- **bool add(Print \* stream)** add another print stream.
Returns false if no space left.
### Control
- **uint8_t count()** returns # streams, MAX 4 in initial release
- **uint8_t size()** returns size which is 4 in the current release.
- **void enable(uint8_t index)** enable the stream at index.
2021-08-10 22:25:19 +02:00
- **void enableStream(Stream * stream)** enable the stream.
2021-04-07 13:31:22 +02:00
- **void disable(uint8_t index)** disable the stream at index.
2021-08-10 22:25:19 +02:00
- **void disableStream(Stream * stream)** disable the stream.
2021-01-29 12:31:58 +01:00
- **bool isEnabled(uint8_t index)** checks if the stream at index is enabled.
2021-08-10 22:25:19 +02:00
- **bool isEnabledStream(Stream * stream)** checks if the stream is enabled.
2021-01-29 12:31:58 +01:00
## Future
- set size in constructor
- add names?
- bool inMp(stream)
- add returns int index? or 0xFF for fail
- remove a stream from the multiplex ??? => complexer admin.
- increase up to 8 streams. (pack enabled flag in one byte)
## Operation
See examples