Extended MaximInterface
Dependents: mbed_DS28EC20_GPIO
Diff: Links/SelectRom.hpp
- Revision:
- 6:a8c83a2e6fa4
- Parent:
- 0:f77ad7f72d04
- Child:
- 7:471901a04573
diff -r caf56f265a13 -r a8c83a2e6fa4 Links/SelectRom.hpp --- a/Links/SelectRom.hpp Fri Jan 19 10:25:02 2018 -0600 +++ b/Links/SelectRom.hpp Wed Jan 23 13:11:04 2019 -0600 @@ -43,6 +43,7 @@ class OneWireMaster; +/// Selects a 1-Wire device on the bus for communication. typedef Function<error_code(OneWireMaster &)> SelectRom; /// Selector for a multidrop 1-Wire bus. @@ -51,41 +52,46 @@ typedef SelectRom::argument_type argument_type; typedef SelectRom::result_type result_type; - explicit SelectMatchRom(const RomId & romId = RomId()) : romId_(romId) {} + explicit SelectMatchRom(RomId::const_span romId) { setRomId(romId); } - const RomId & romId() const { return romId_; } - void setRomId(const RomId & romId) { romId_ = romId; } + RomId::const_span romId() const { return romId_; } + + void setRomId(RomId::const_span romId) { copy(romId, make_span(romId_)); } MaximInterface_EXPORT error_code operator()(OneWireMaster & master) const; private: - RomId romId_; + RomId::array romId_; }; -/// Selector for a multidrop 1-Wire bus where slaves support the Resume ROM command. +/// Selector for a multidrop 1-Wire bus where slaves support the Resume ROM +/// command. class SelectMatchRomWithResume { public: typedef SelectRom::argument_type argument_type; typedef SelectRom::result_type result_type; struct SharedData { - RomId lastRom; - - SharedData() : lastRom() {} + SharedData() : lastRomId() {} + RomId::array lastRomId; }; - explicit SelectMatchRomWithResume(SharedData & data, - const RomId & romId = RomId()) - : romId_(romId), data(&data) {} + SelectMatchRomWithResume(SharedData & data, RomId::const_span romId) + : data(&data) { + setRomId(romId); + } - const RomId & romId() const { return romId_; } - void setRomId(const RomId & romId) { romId_ = romId; } + void setSharedData(SharedData & data) { this->data = &data; } + + RomId::const_span romId() const { return romId_; } + + void setRomId(RomId::const_span romId) { copy(romId, make_span(romId_)); } MaximInterface_EXPORT error_code operator()(OneWireMaster & master) const; private: - RomId romId_; SharedData * data; + RomId::array romId_; }; } // namespace MaximInterface