GY-63_MS5611/libraries/Multiplex/Multiplex.h

81 lines
1.6 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: Multiplex.h
// AUTHOR: Rob Tillaart
2022-06-13 06:51:39 -04:00
// VERSION: 0.2.4
// PURPOSE: Arduino library to multiplex streams
2021-01-29 06:31:58 -05:00
// DATE: 2021-01-09
// URL: https://github.com/RobTillaart/Multiplex
#include "Arduino.h"
2022-06-13 06:51:39 -04:00
#define MULTIPLEX_LIB_VERSION (F("0.2.4"))
2021-01-29 06:31:58 -05:00
2022-06-13 06:51:39 -04:00
// MAX 254 (in theory) as 0xFF is a special value
2021-09-14 11:02:45 -04:00
#ifndef MAX_MULTIPLEX
2021-12-22 06:37:31 -05:00
#define MAX_MULTIPLEX 4
2021-09-14 11:02:45 -04:00
#endif
2021-01-29 06:31:58 -05:00
class Multiplex: public Print
{
public:
Multiplex();
2021-09-14 11:02:45 -04:00
~Multiplex();
2022-06-13 06:51:39 -04:00
// CORE
2021-09-14 11:02:45 -04:00
virtual size_t write(uint8_t c) override;
2022-06-13 06:51:39 -04:00
virtual size_t write(const uint8_t * buffer, size_t size) override;
2021-09-19 07:30:34 -04:00
2022-06-13 06:51:39 -04:00
bool add(Print * stream); // returns true on success
void reset();
2021-01-29 06:31:58 -05:00
2022-06-13 06:51:39 -04:00
// remove
// use with care as it changes the indices.
bool remove(Print * stream);
bool remove(uint8_t index);
2021-09-19 07:30:34 -04:00
2021-09-14 11:02:45 -04:00
2022-06-13 06:51:39 -04:00
// CONTROL
uint8_t count() { return _count; };
uint8_t size() { return _size; };
uint8_t free() { return _size - _count; };
2021-09-14 11:02:45 -04:00
2022-06-13 06:51:39 -04:00
// returns true on success, false otherwise.
bool enable(uint8_t index);
bool enableStream(Print * stream);
bool disable(uint8_t index);
bool disableStream(Print * stream);
2021-09-14 11:02:45 -04:00
2022-06-13 06:51:39 -04:00
bool isEnabled(uint8_t index);
bool isEnabledStream(Print * stream);
2021-01-29 06:31:58 -05:00
2022-06-13 06:51:39 -04:00
uint8_t index(Print *stream);
Print * stream(uint8_t index);
bool isEnabledAny();
// DIAGNOSTIC
void resetOutputCount() { _outputCount = 0; };
uint32_t getOutputCount() { return _outputCount; };
2021-09-14 11:02:45 -04:00
2021-01-29 06:31:58 -05:00
private:
2022-06-13 06:51:39 -04:00
Print * _stream[MAX_MULTIPLEX];
bool _enabled[MAX_MULTIPLEX];
2021-09-19 07:30:34 -04:00
// bool _free[MAX_MULTIPLEX];
2021-09-14 11:02:45 -04:00
2022-06-13 06:51:39 -04:00
uint8_t _count;
uint8_t _size;
uint32_t _outputCount;
2021-01-29 06:31:58 -05:00
};
2021-12-22 06:37:31 -05:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2021-12-22 06:37:31 -05:00