0.2.5 Multiplex

This commit is contained in:
rob tillaart 2022-10-23 14:12:48 +02:00
parent 226874f05b
commit dac3300279
8 changed files with 65 additions and 34 deletions

View File

@ -1,11 +1,27 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile: compile:
# Choosing to run compilation tests on 2 different Arduino platforms # Choosing to run compilation tests on 2 different Arduino platforms
platforms: platforms:
- uno - uno
- due # - due
- zero # - zero
- leonardo # - leonardo
- m4 - m4
- esp32 - esp32
- esp8266 - esp8266
- mega2560 # - mega2560
- rpipico

View File

@ -1,24 +1,13 @@
// //
// FILE: Multiplex.cpp // FILE: Multiplex.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.2.4 // VERSION: 0.2.5
// PURPOSE: Arduino library to multiplex streams // PURPOSE: Arduino library to multiplex streams
// DATE: 2021-01-09 // DATE: 2021-01-09
// URL: https://github.com/RobTillaart/Multiplex // URL: https://github.com/RobTillaart/Multiplex
// //
// HISTORY: // HISTORY: see changelog.md
// 0.1.0 2021-01-09 initial version
// 0.2.0 2021-08-09 See issues #2 and #3
// 0.2.1 2021-09-12 made index(Stream) public; added stream(index)
// enable() / disable() return true on success
// added free() function
// minor refactor.
// 0.2.2 2021-09-12 add remove(Stream) + remove(index);
// 0.2.3 2021-12-22 update library.json, readme, license, minor edits
// 0.2.4 2022-06-12 add isEnabledAny() to see if writes makes sense.
// keep the streams in adding order when removing a stream.
// add getOutputCount() and resetOutputCount() to
// keep track of bytes multiplexed.
#include "Multiplex.h" #include "Multiplex.h"
@ -116,6 +105,18 @@ size_t Multiplex::write(const uint8_t *buffer, size_t size)
} }
void Multiplex::flush() // see issue 13
{
for (uint8_t i = 0; i < _count; i++)
{
if (_enabled[i])
{
_stream[i]->flush();
}
}
}
uint8_t Multiplex::index(Print *stream) uint8_t Multiplex::index(Print *stream)
{ {
for (uint8_t i = 0; i < _count; i++) for (uint8_t i = 0; i < _count; i++)

View File

@ -2,7 +2,7 @@
// //
// FILE: Multiplex.h // FILE: Multiplex.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.2.4 // VERSION: 0.2.5
// PURPOSE: Arduino library to multiplex streams // PURPOSE: Arduino library to multiplex streams
// DATE: 2021-01-09 // DATE: 2021-01-09
// URL: https://github.com/RobTillaart/Multiplex // URL: https://github.com/RobTillaart/Multiplex
@ -11,7 +11,7 @@
#include "Arduino.h" #include "Arduino.h"
#define MULTIPLEX_LIB_VERSION (F("0.2.4")) #define MULTIPLEX_LIB_VERSION (F("0.2.5"))
// MAX 254 (in theory) as 0xFF is a special value // MAX 254 (in theory) as 0xFF is a special value
@ -39,6 +39,8 @@ public:
bool remove(Print * stream); bool remove(Print * stream);
bool remove(uint8_t index); bool remove(uint8_t index);
// see issue 13
virtual void flush() override;
// CONTROL // CONTROL
uint8_t count() { return _count; }; uint8_t count() { return _count; };

View File

@ -49,11 +49,12 @@ If you want to prevent this effect, you should use **reset()** and repopulate th
### Constructor ### Constructor
- **Multiplex(uint8_t max_multiplex = 4)** constructor, - **Multiplex()** constructor,
sets the maximum number of streams to 4 by default. sets the maximum number of streams to MAX_MULTIPLEX == 4 by default.
MAX number is 254 as 255 (0xFF) is used as a flag for **NOT FOUND**. MAX number is 254 as 255 (0xFF) is used as a flag for **NOT FOUND**.
- **~Multiplex()** destructor - **~Multiplex()** destructor
- **void reset()** resets the count in the multiplexer to zero streams. - **void reset()** resets the count in the multiplexer to zero streams.
Effectively a remove all.
### Core ### Core
@ -66,13 +67,14 @@ Use the **index(Stream)** to get the actual index of the stream.
Writes a character to all enabled streams. Writes a character to all enabled streams.
- **size_t write(const uint8_t \* buffer, size_t size)** - **size_t write(const uint8_t \* buffer, size_t size)**
Writes a buffer of size characters to all enabled streams. Writes a buffer of size characters to all enabled streams.
- **virtual void flush() override** flushes all enabled streams.
With respect to the latter two functions: With respect to the two **write()** functions:
The performance will be affected by the number of streams and their performance. The performance will be affected by the number of streams and their performance.
One slow stream can hold them all. One slow stream can hold them all.
Note: the different streams will get the data in order of addition, Note: the different streams will get the data in order of addition,
and therefore they will get the data on different times. and therefore they will get the data at different times.
### Remove - experimental ### Remove - experimental
@ -139,7 +141,7 @@ It is kept in the library for now, however it might be removed in the future.
Footprint is minimal. Footprint is minimal.
- **uint32_t getOutputCount()** returns number of bytes multiplexed. - **uint32_t getOutputCount()** returns number of bytes multiplexed.
So if 6 bytes are sent to 3 streams the byte count is 3 x 6 = 18. So if 6 bytes are sent to 3 streams the output byte count is 3 x 6 = 18.
For diagnostic purpose. For diagnostic purpose.
- **void resetOutputCount()** set internal counter to 0. - **void resetOutputCount()** set internal counter to 0.
@ -151,20 +153,27 @@ See examples
## Future ## Future
#### 0.3.0
- set size in constructor - set size in constructor
- dynamic memory for all internal arrays - dynamic memory for all internal arrays
- breaking change ==> 0.3.0 - breaking change ==> 0.3.0
- should **int add()** return the index? Or -1 if fails. - should **int add()** return the index? Or -1 if fails.
- usable idea - usable idea
- breaking change ==> 0.3.0 - breaking change ==> 0.3.0
- add **removeAll()** ==> reset()
#### should
- error handling
- add an error flag if one of the streams does not **write()** - add an error flag if one of the streams does not **write()**
correctly and returns 0 or less than it should. correctly and returns 0 or less than it should.
- add more examples. - add more examples.
- add performance measurement - add performance measurement
- KB / second - KB / second
- move all code to .cpp
#### wont
### wont
- pack enabled flag in one or more bytes. - pack enabled flag in one or more bytes.
(not much faster + need to encode/decode) (not much faster + need to encode/decode)

View File

@ -89,6 +89,8 @@ void setup()
uint32_t stop = micros(); uint32_t stop = micros();
Serial.print("TIME: "); Serial.print("TIME: ");
Serial.println(stop - start); Serial.println(stop - start);
mp.flush();
} }

View File

@ -7,6 +7,7 @@ Multiplex KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
write KEYWORD2 write KEYWORD2
flush KEYWORD2
add KEYWORD2 add KEYWORD2
remove KEYWORD2 remove KEYWORD2
reset KEYWORD2 reset KEYWORD2

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/Multiplex" "url": "https://github.com/RobTillaart/Multiplex"
}, },
"version": "0.2.4", "version": "0.2.5",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=Multiplex name=Multiplex
version=0.2.4 version=0.2.5
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library implementing a stream multiplexer sentence=Arduino Library implementing a stream multiplexer