Distinguish serial index from mask (#21287)
This commit is contained in:
@@ -22,12 +22,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "../inc/MarlinConfigPre.h"
|
||||
#include "macros.h"
|
||||
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
#include "../feature/e_parser.h"
|
||||
#endif
|
||||
|
||||
// Used in multiple places
|
||||
// You can build it but not manipulate it.
|
||||
// There are only few places where it's required to access the underlying member: GCodeQueue, SerialMask and MultiSerial
|
||||
struct serial_index_t {
|
||||
// A signed index, where -1 is a special case meaning no action (neither output or input)
|
||||
int8_t index;
|
||||
|
||||
// Check if the index is within the range [a ... b]
|
||||
constexpr inline bool within(const int8_t a, const int8_t b) const { return WITHIN(index, a, b); }
|
||||
constexpr inline bool valid() const { return WITHIN(index, 0, 7); } // At most, 8 bits
|
||||
|
||||
// Construction is either from an index
|
||||
constexpr serial_index_t(const int8_t index) : index(index) {}
|
||||
|
||||
// Default to "no index"
|
||||
constexpr serial_index_t() : index(-1) {}
|
||||
};
|
||||
|
||||
// flushTX is not implemented in all HAL, so use SFINAE to call the method where it is.
|
||||
CALL_IF_EXISTS_IMPL(void, flushTX);
|
||||
CALL_IF_EXISTS_IMPL(bool, connected, true);
|
||||
@@ -79,10 +96,10 @@ struct SerialBase {
|
||||
void end() { static_cast<Child*>(this)->end(); }
|
||||
/** Check for available data from the port
|
||||
@param index The port index, usually 0 */
|
||||
int available(uint8_t index = 0) { return static_cast<Child*>(this)->available(index); }
|
||||
int available(serial_index_t index = 0) { return static_cast<Child*>(this)->available(index); }
|
||||
/** Read a value from the port
|
||||
@param index The port index, usually 0 */
|
||||
int read(uint8_t index = 0) { return static_cast<Child*>(this)->read(index); }
|
||||
int read(serial_index_t index = 0) { return static_cast<Child*>(this)->read(index); }
|
||||
// Check if the serial port is connected (usually bypassed)
|
||||
bool connected() { return static_cast<Child*>(this)->connected(); }
|
||||
// Redirect flush
|
||||
|
||||
Reference in New Issue
Block a user