From 13ff13111013f23360035c5dc761887e2f26a585 Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Sat, 27 Feb 2016 11:35:59 +0100 Subject: [PATCH] add conditional search command (0xEC) --- OneWireSlave.cpp | 21 +++++++++++++++++++++ OneWireSlave.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/OneWireSlave.cpp b/OneWireSlave.cpp index f70f3b9..1a99f9a 100644 --- a/OneWireSlave.cpp +++ b/OneWireSlave.cpp @@ -47,6 +47,7 @@ byte OneWireSlave::searchRomBytePos_; byte OneWireSlave::searchRomBitPos_; bool OneWireSlave::searchRomInverse_; bool OneWireSlave::resumeCommandFlag_; +bool OneWireSlave::alarmedFlag_; const byte* OneWireSlave::sendBuffer_; byte* OneWireSlave::recvBuffer_; @@ -79,6 +80,7 @@ void OneWireSlave::begin(const byte* rom, byte pinNumber) rom_[7] = crc8(rom_, 7); resumeCommandFlag_ = false; + alarmedFlag_ = false; clientReceiveBitCallback_ = 0; @@ -149,6 +151,11 @@ void OneWireSlave::stopWrite() write(0, 0, 0); } +void OneWireSlave::alarmed(bool value) +{ + alarmedFlag_ = value; +} + byte OneWireSlave::crc8(const byte* data, short numBytes) { byte crc = 0; @@ -410,12 +417,26 @@ void OneWireSlave::onBitReceived_(bool bit, bool error) switch (receivingByte_) { case 0xF0: // SEARCH ROM + resumeCommandFlag_ = false; beginSearchRom_(); return; + case 0xEC: // CONDITIONAL SEARCH ROM + resumeCommandFlag_ = false; + if (alarmedFlag_) + { + beginSearchRom_(); + } + else + { + beginWaitReset_(); + } + return; case 0x33: // READ ROM + resumeCommandFlag_ = false; beginWriteBytes_(rom_, 8, &OneWireSlave::noOpCallback_); return; case 0x55: // MATCH ROM + resumeCommandFlag_ = false; beginReceiveBytes_(scratchpad_, 8, &OneWireSlave::matchRomBytesReceived_); return; case 0xCC: // SKIP ROM diff --git a/OneWireSlave.h b/OneWireSlave.h index 6079db2..a3b4a6f 100644 --- a/OneWireSlave.h +++ b/OneWireSlave.h @@ -35,6 +35,8 @@ public: //! Cancels any pending write operation, started by writeBit or write. If this function is called before the master asked for a bit, then nothing is sent to the master. void stopWrite(); + void alarmed(bool value); + static byte crc8(const byte* data, short numBytes); private: @@ -103,6 +105,7 @@ private: static byte searchRomBitPos_; static bool searchRomInverse_; static bool resumeCommandFlag_; + static bool alarmedFlag_; static const byte* sendBuffer_; static byte* recvBuffer_;