GY-63_MS5611/libraries/Multiplex
2021-09-20 19:23:26 +02:00
..
.github/workflows 0.2.1 Multiplex 2021-09-14 17:02:45 +02:00
examples 0.2.1 Multiplex 2021-09-14 17:02:45 +02:00
test 0.2.0 Multiplex 2021-08-10 22:25:19 +02:00
.arduino-ci.yml 2021-01-29 2021-01-29 12:31:58 +01:00
keywords.txt 0.2.2 Multiplex 2021-09-19 13:30:34 +02:00
library.json 0.2.2 Multiplex 2021-09-19 13:30:34 +02:00
library.properties 0.2.2 Multiplex 2021-09-19 13:30:34 +02:00
LICENSE 2021-01-29 2021-01-29 12:31:58 +01:00
Multiplex.cpp 0.2.2 Multiplex 2021-09-19 13:30:34 +02:00
Multiplex.h 0.2.2 Multiplex 2021-09-19 13:30:34 +02:00
README.md 0.2.2 Multiplex 2021-09-20 19:23:26 +02:00

Arduino CI JSON check Arduino-lint License: MIT GitHub release

Multiplex

Arduino Library implementing a (Print) stream multiplexer.

Description

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.

The maximum number of streams to add is 4. This value is defined in the multiplex.h file with #define MAX_MULTIPLEX. This value can be set to 254 MAX as the number 255 / 0xFF is used as a NOT_FOUND flag.

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()

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.

Note: 0.2.2 has experimental remove support.

Interface

Constructor

  • 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.

Core

  • size_t write(uint8_t c) workhorse of the Print interface. Writes a character to all enabled streams.
  • size_t write(const uint8_t *buffer, size_t size) Writes a buffer of size characters to all enabled streams.
  • bool add(Print * stream) add another Print stream. Returns false if no space left. Use the index(Stream) to get the actual index of the stream.

Experimental 0.2.2

Removing a stream is experimental. 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.

  • 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.

Control

  • uint8_t count() returns number of streams added, MAX 4 in initial release
  • uint8_t size() returns size which is 4 in the current release.
  • uint8_t free() returns number of free slots.

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.

  • 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.
    Can be used to check if a stream is added to the multiplexer.
  • Print * stream(uint8_t index) returns the stream at index or NULL otherwise. Convenience function.

Future

  • set size in constructor - dynamic memory
  • pack enabled flag in one or more bytes
  • add names?

Operation

See examples