Last active
September 30, 2015 19:00
-
-
Save sash13/249c6464fad8fc6a1ac0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Arduino.h" | |
| #include "LowLevel.h" | |
| #include "OneWireSlave.h" | |
| #include "OneWire.h" | |
| // DS18S20 Temperature chip i/o | |
| OneWire ds(10); // on pin 10 | |
| // This is the pin that will be used for one-wire data (depending on your arduino model, you are limited to a few choices, because some pins don't have complete interrupt support) | |
| // On Arduino Uno, you can use pin 2 or pin 3 | |
| Pin oneWireData(2); | |
| // This is the ROM the arduino will respond to, make sure it doesn't conflict with another device | |
| // Addr of dallas emulation. Get from http://www.instructables.com/file/FXG4TRKGQKM4TW5 first byte must be 0x10 or 0x28 | |
| // info http://playground.arduino.cc/Learning/OneWire | |
| const byte owROM[7] = { 0x10, 0x79, 0xB0, 0x3F, 0x02, 0x08, 0x00}; | |
| //array with temperature, dunno what is it give | |
| byte answer[12]; | |
| // | |
| const byte CMD_StartConve = 0x44; | |
| const byte CMD_ReadScratch = 0xBE; | |
| // This function will be called each time the OneWire library has an event to notify (reset, error, byte received) | |
| void owReceive(OneWireSlave::ReceiveEvent evt, byte data); | |
| void setup() | |
| { | |
| Serial.begin(9600); | |
| // Setup the OneWire library | |
| OneWire1.setReceiveCallback(&owReceive); | |
| OneWire1.begin(owROM, oneWireData.getPinNumber()); | |
| } | |
| void loop() | |
| { | |
| delay(1); | |
| // You can do anything you want here, the OneWire library works entirely in background, using interrupts. | |
| byte i; | |
| byte present = 0; | |
| byte addr[8]; | |
| ds.reset_search(); | |
| if ( !ds.search(addr)) { | |
| Serial.print("No more addresses.\n"); | |
| ds.reset_search(); | |
| return; | |
| } | |
| Serial.print("R="); | |
| for( i = 0; i < 8; i++) { | |
| Serial.print(addr[i], HEX); | |
| Serial.print(" "); | |
| } | |
| if ( OneWire::crc8( addr, 7) != addr[7]) { | |
| Serial.print("CRC is not valid!\n"); | |
| return; | |
| } | |
| if ( addr[0] == 0x10) { | |
| Serial.print("Device is a DS18S20 family device.\n"); | |
| } | |
| else if ( addr[0] == 0x28) { | |
| Serial.print("Device is a DS18B20 family device.\n"); | |
| } | |
| else { | |
| Serial.print("Device family is not recognized: 0x"); | |
| Serial.println(addr[0],HEX); | |
| return; | |
| } | |
| ds.reset(); | |
| ds.select(addr); | |
| ds.write(0x44,1); // start conversion, with parasite power on at the end | |
| delay(1000); // maybe 750ms is enough, maybe not | |
| // we might do a ds.depower() here, but the reset will take care of it. | |
| present = ds.reset(); | |
| ds.select(addr); | |
| ds.write(0xBE); // Read Scratchpad | |
| Serial.print("P="); | |
| Serial.print(present,HEX); | |
| Serial.print(" "); | |
| for ( i = 0; i < 9; i++) { // we need 9 bytes | |
| answer[i] = ds.read(); | |
| Serial.print(answer[i], HEX); | |
| Serial.print(" "); | |
| } | |
| Serial.print(" CRC="); | |
| Serial.print( OneWire::crc8( answer, 8), HEX); | |
| Serial.println(); | |
| cli();//disable interrupts | |
| // Be sure to not block interrupts for too long, OneWire timing is very tight for some operations. 1 or 2 microseconds (yes, microseconds, not milliseconds) can be too much depending on your master controller, but then it's equally unlikely that you block exactly at the moment where it matters. | |
| // This can be mitigated by using error checking and retry in your high-level communication protocol. A good thing to do anyway. | |
| sei();//enable interrupts | |
| } | |
| void owReceive(OneWireSlave::ReceiveEvent evt, byte data) | |
| { | |
| switch (evt) | |
| { | |
| case OneWireSlave::RE_Byte: | |
| if (data == CMD_StartConve) | |
| { | |
| } | |
| else if (data == CMD_ReadScratch) | |
| { | |
| OneWire1.write(answer, 9, NULL); | |
| } | |
| else | |
| { | |
| break; | |
| } | |
| // in this simple example we just reply with one byte to say we've processed the command | |
| // a real application should have a CRC system to ensure messages are not corrupt, for both directions | |
| // you can use the static OneWireSlave::crc8 method to add CRC checks in your communication protocol (it conforms to standard one-wire CRC checks, that is used to compute the ROM last byte for example) | |
| //OneWire.write(&acknowledge, 1, NULL); | |
| break; | |
| default: | |
| ; // we could also react to reset and error notifications, but not in this sample | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "OneWireSlave.h" | |
| // uncomment this line to enable sending messages along with errors (but takes more program memory) | |
| //#define ERROR_MESSAGES | |
| #ifdef ERROR_MESSAGES | |
| #define ERROR(msg) error_(msg) | |
| #else | |
| #define ERROR(msg) error_(0) | |
| #endif | |
| namespace | |
| { | |
| const unsigned long ResetMinDuration = 480; | |
| const unsigned long ResetMaxDuration = 900; | |
| const unsigned long PresenceWaitDuration = 30; | |
| const unsigned long PresenceDuration = 300; | |
| const unsigned long ReadBitSamplingTime = 25; | |
| const unsigned long SendBitDuration = 35; | |
| const byte ReceiveCommand = (byte)-1; | |
| void(*timerEvent)() = 0; | |
| } | |
| OneWireSlave OneWire1; | |
| byte OneWireSlave::rom_[8]; | |
| byte OneWireSlave::scratchpad_[8]; | |
| Pin OneWireSlave::pin_; | |
| byte OneWireSlave::tccr1bEnable_; | |
| unsigned long OneWireSlave::resetStart_; | |
| unsigned long OneWireSlave::lastReset_; | |
| void(*OneWireSlave::receiveBitCallback_)(bool bit, bool error); | |
| void(*OneWireSlave::bitSentCallback_)(bool error); | |
| void(*OneWireSlave::clientReceiveCallback_)(ReceiveEvent evt, byte data); | |
| byte OneWireSlave::receivingByte_; | |
| byte OneWireSlave::searchRomBytePos_; | |
| byte OneWireSlave::searchRomBitPos_; | |
| bool OneWireSlave::searchRomInverse_; | |
| const byte* OneWireSlave::sendBuffer_; | |
| byte* OneWireSlave::recvBuffer_; | |
| short OneWireSlave::bufferLength_; | |
| byte OneWireSlave::bufferBitPos_; | |
| short OneWireSlave::bufferPos_; | |
| void(*OneWireSlave::receiveBytesCallback_)(bool error); | |
| void(*OneWireSlave::sendBytesCallback_)(bool error); | |
| ISR(TIMER1_COMPA_vect) // timer1 interrupt | |
| { | |
| TCCR1B = 0; // disable clock | |
| void(*event)() = timerEvent; | |
| timerEvent = 0; | |
| event(); | |
| } | |
| void OneWireSlave::begin(const byte* rom, byte pinNumber) | |
| { | |
| pin_ = Pin(pinNumber); | |
| resetStart_ = (unsigned long)-1; | |
| lastReset_ = 0; | |
| memcpy(rom_, rom, 7); | |
| rom_[7] = crc8(rom_, 7); | |
| // log("Enabling 1-wire library") | |
| cli(); // disable interrupts | |
| pin_.inputMode(); | |
| pin_.writeLow(); // make sure the internal pull-up resistor is disabled | |
| // prepare hardware timer | |
| TCCR1A = 0; | |
| TCCR1B = 0; | |
| TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt | |
| tccr1bEnable_ = (1 << WGM12) | (1 << CS11) | (1 << CS10); // turn on CTC mode with 64 prescaler | |
| // start 1-wire activity | |
| beginWaitReset_(); | |
| sei(); // enable interrupts | |
| } | |
| void OneWireSlave::end() | |
| { | |
| // log("Disabling 1-wire library"); | |
| cli(); | |
| disableTimer_(); | |
| pin_.detachInterrupt(); | |
| releaseBus_(); | |
| sei(); | |
| } | |
| void OneWireSlave::write(const byte* bytes, short numBytes, void(*complete)(bool error)) | |
| { | |
| cli(); | |
| beginWriteBytes_(bytes, numBytes, complete == 0 ? noOpCallback_ : complete); | |
| sei(); | |
| } | |
| byte OneWireSlave::crc8(const byte* data, short numBytes) | |
| { | |
| byte crc = 0; | |
| while (numBytes--) { | |
| byte inbyte = *data++; | |
| for (byte i = 8; i; i--) { | |
| byte mix = (crc ^ inbyte) & 0x01; | |
| crc >>= 1; | |
| if (mix) crc ^= 0x8C; | |
| inbyte >>= 1; | |
| } | |
| } | |
| return crc; | |
| } | |
| void OneWireSlave::setTimerEvent_(short delayMicroSeconds, void(*handler)()) | |
| { | |
| delayMicroSeconds -= 10; // remove overhead (tuned on Arduino Uno) | |
| short skipTicks = (delayMicroSeconds - 3) / 4; // round the micro seconds delay to a number of ticks to skip (4us per tick, so 4us must skip 0 tick, 8us must skip 1 tick, etc.) | |
| if (skipTicks < 1) skipTicks = 1; | |
| TCNT1 = 0; | |
| OCR1A = skipTicks; | |
| timerEvent = handler; | |
| TCCR1B = tccr1bEnable_; | |
| } | |
| void OneWireSlave::disableTimer_() | |
| { | |
| TCCR1B = 0; | |
| } | |
| void OneWireSlave::onEnterInterrupt_() | |
| { | |
| } | |
| void OneWireSlave::onLeaveInterrupt_() | |
| { | |
| } | |
| void OneWireSlave::error_(const char* message) | |
| { | |
| beginWaitReset_(); | |
| } | |
| void OneWireSlave::pullLow_() | |
| { | |
| pin_.outputMode(); | |
| pin_.writeLow(); | |
| } | |
| void OneWireSlave::releaseBus_() | |
| { | |
| pin_.inputMode(); | |
| } | |
| void OneWireSlave::beginResetDetection_() | |
| { | |
| setTimerEvent_(ResetMinDuration - 50, &OneWireSlave::resetCheck_); | |
| resetStart_ = micros() - 50; | |
| } | |
| void OneWireSlave::cancelResetDetection_() | |
| { | |
| disableTimer_(); | |
| resetStart_ = (unsigned long)-1; | |
| } | |
| void OneWireSlave::resetCheck_() | |
| { | |
| onEnterInterrupt_(); | |
| if (!pin_.read()) | |
| { | |
| pin_.attachInterrupt(&OneWireSlave::waitReset_, CHANGE); | |
| // log("Reset detected during another operation"); | |
| } | |
| onLeaveInterrupt_(); | |
| } | |
| void OneWireSlave::beginReceiveBit_(void(*completeCallback)(bool bit, bool error)) | |
| { | |
| receiveBitCallback_ = completeCallback; | |
| pin_.attachInterrupt(&OneWireSlave::receive_, FALLING); | |
| } | |
| void OneWireSlave::receive_() | |
| { | |
| onEnterInterrupt_(); | |
| pin_.detachInterrupt(); | |
| setTimerEvent_(ReadBitSamplingTime, &OneWireSlave::readBit_); | |
| onLeaveInterrupt_(); | |
| } | |
| void OneWireSlave::readBit_() | |
| { | |
| onEnterInterrupt_(); | |
| bool bit = pin_.read(); | |
| if (bit) | |
| cancelResetDetection_(); | |
| else | |
| beginResetDetection_(); | |
| receiveBitCallback_(bit, false); | |
| //dbgOutput.writeLow(); | |
| //dbgOutput.writeHigh(); | |
| onLeaveInterrupt_(); | |
| } | |
| void OneWireSlave::beginSendBit_(bool bit, void(*completeCallback)(bool error)) | |
| { | |
| bitSentCallback_ = completeCallback; | |
| if (bit) | |
| { | |
| pin_.attachInterrupt(&OneWireSlave::sendBitOne_, FALLING); | |
| } | |
| else | |
| { | |
| pin_.attachInterrupt(&OneWireSlave::sendBitZero_, FALLING); | |
| } | |
| } | |
| void OneWireSlave::sendBitOne_() | |
| { | |
| onEnterInterrupt_(); | |
| beginResetDetection_(); | |
| bitSentCallback_(false); | |
| onLeaveInterrupt_(); | |
| } | |
| void OneWireSlave::sendBitZero_() | |
| { | |
| pullLow_(); // this must be executed first because the timing is very tight with some master devices | |
| onEnterInterrupt_(); | |
| pin_.detachInterrupt(); | |
| setTimerEvent_(SendBitDuration, &OneWireSlave::endSendBitZero_); | |
| onLeaveInterrupt_(); | |
| } | |
| void OneWireSlave::endSendBitZero_() | |
| { | |
| onEnterInterrupt_(); | |
| releaseBus_(); | |
| bitSentCallback_(false); | |
| onLeaveInterrupt_(); | |
| } | |
| void OneWireSlave::beginWaitReset_() | |
| { | |
| disableTimer_(); | |
| pin_.attachInterrupt(&OneWireSlave::waitReset_, CHANGE); | |
| resetStart_ = (unsigned int)-1; | |
| } | |
| void OneWireSlave::waitReset_() | |
| { | |
| onEnterInterrupt_(); | |
| bool state = pin_.read(); | |
| unsigned long now = micros(); | |
| if (state) | |
| { | |
| if (resetStart_ == (unsigned int)-1) | |
| { | |
| onLeaveInterrupt_(); | |
| return; | |
| } | |
| unsigned long resetDuration = now - resetStart_; | |
| resetStart_ = (unsigned int)-1; | |
| if (resetDuration >= ResetMinDuration) | |
| { | |
| if (resetDuration > ResetMaxDuration) | |
| { | |
| ERROR("Reset too long"); | |
| onLeaveInterrupt_(); | |
| return; | |
| } | |
| lastReset_ = now; | |
| pin_.detachInterrupt(); | |
| setTimerEvent_(PresenceWaitDuration - (micros() - now), &OneWireSlave::beginPresence_); | |
| if (clientReceiveCallback_ != 0) | |
| clientReceiveCallback_(RE_Reset, 0); | |
| } | |
| } | |
| else | |
| { | |
| resetStart_ = now; | |
| } | |
| onLeaveInterrupt_(); | |
| } | |
| void OneWireSlave::beginPresence_() | |
| { | |
| pullLow_(); | |
| setTimerEvent_(PresenceDuration, &OneWireSlave::endPresence_); | |
| } | |
| void OneWireSlave::endPresence_() | |
| { | |
| releaseBus_(); | |
| beginWaitCommand_(); | |
| } | |
| void OneWireSlave::beginWaitCommand_() | |
| { | |
| bufferPos_ = ReceiveCommand; | |
| beginReceive_(); | |
| } | |
| void OneWireSlave::beginReceive_() | |
| { | |
| receivingByte_ = 0; | |
| bufferBitPos_ = 0; | |
| beginReceiveBit_(&OneWireSlave::onBitReceived_); | |
| } | |
| void OneWireSlave::onBitReceived_(bool bit, bool error) | |
| { | |
| if (error) | |
| { | |
| ERROR("Invalid bit"); | |
| if (bufferPos_ >= 0) | |
| receiveBytesCallback_(true); | |
| return; | |
| } | |
| receivingByte_ |= ((bit ? 1 : 0) << bufferBitPos_); | |
| ++bufferBitPos_; | |
| if (bufferBitPos_ == 8) | |
| { | |
| // log("received byte", (long)receivingByte_); | |
| if (bufferPos_ == ReceiveCommand) | |
| { | |
| bufferPos_ = 0; | |
| switch (receivingByte_) | |
| { | |
| case 0xF0: // SEARCH ROM | |
| beginSearchRom_(); | |
| return; | |
| case 0x33: // READ ROM | |
| beginWriteBytes_(rom_, 8, &OneWireSlave::noOpCallback_); | |
| return; | |
| case 0x55: // MATCH ROM | |
| beginReceiveBytes_(scratchpad_, 8, &OneWireSlave::matchRomBytesReceived_); | |
| return; | |
| case 0xCC: // SKIP ROM | |
| // emulate a match rom operation | |
| memcpy(scratchpad_, rom_, 8); | |
| matchRomBytesReceived_(false); | |
| return; | |
| default: | |
| ERROR("Unknown command"); | |
| return; | |
| } | |
| } | |
| else | |
| { | |
| recvBuffer_[bufferPos_++] = receivingByte_; | |
| receivingByte_ = 0; | |
| bufferBitPos_ = 0; | |
| if (bufferPos_ == bufferLength_) | |
| { | |
| beginWaitReset_(); | |
| receiveBytesCallback_(false); | |
| return; | |
| } | |
| } | |
| } | |
| beginReceiveBit_(&OneWireSlave::onBitReceived_); | |
| } | |
| void OneWireSlave::beginSearchRom_() | |
| { | |
| searchRomBytePos_ = 0; | |
| searchRomBitPos_ = 0; | |
| searchRomInverse_ = false; | |
| beginSearchRomSendBit_(); | |
| } | |
| void OneWireSlave::beginSearchRomSendBit_() | |
| { | |
| byte currentByte = rom_[searchRomBytePos_]; | |
| bool currentBit = bitRead(currentByte, searchRomBitPos_); | |
| bool bitToSend = searchRomInverse_ ? !currentBit : currentBit; | |
| beginSendBit_(bitToSend, &OneWireSlave::continueSearchRom_); | |
| } | |
| void OneWireSlave::continueSearchRom_(bool error) | |
| { | |
| if (error) | |
| { | |
| ERROR("Failed to send bit"); | |
| return; | |
| } | |
| searchRomInverse_ = !searchRomInverse_; | |
| if (searchRomInverse_) | |
| { | |
| beginSearchRomSendBit_(); | |
| } | |
| else | |
| { | |
| beginReceiveBit_(&OneWireSlave::searchRomOnBitReceived_); | |
| } | |
| } | |
| void OneWireSlave::searchRomOnBitReceived_(bool bit, bool error) | |
| { | |
| if (error) | |
| { | |
| ERROR("Bit read error during ROM search"); | |
| return; | |
| } | |
| byte currentByte = rom_[searchRomBytePos_]; | |
| bool currentBit = bitRead(currentByte, searchRomBitPos_); | |
| if (bit == currentBit) | |
| { | |
| ++searchRomBitPos_; | |
| if (searchRomBitPos_ == 8) | |
| { | |
| searchRomBitPos_ = 0; | |
| ++searchRomBytePos_; | |
| } | |
| if (searchRomBytePos_ == 8) | |
| { | |
| // log("ROM sent entirely"); | |
| beginWaitReset_(); | |
| } | |
| else | |
| { | |
| beginSearchRomSendBit_(); | |
| } | |
| } | |
| else | |
| { | |
| // log("Leaving ROM search"); | |
| beginWaitReset_(); | |
| } | |
| } | |
| void OneWireSlave::beginWriteBytes_(const byte* data, short numBytes, void(*complete)(bool error)) | |
| { | |
| sendBuffer_ = data; | |
| bufferLength_ = numBytes; | |
| bufferPos_ = 0; | |
| bufferBitPos_ = 0; | |
| sendBytesCallback_ = complete; | |
| bool bit = bitRead(sendBuffer_[0], 0); | |
| beginSendBit_(bit, &OneWireSlave::bitSent_); | |
| } | |
| void OneWireSlave::bitSent_(bool error) | |
| { | |
| if (error) | |
| { | |
| ERROR("error sending a bit"); | |
| sendBytesCallback_(true); | |
| return; | |
| } | |
| ++bufferBitPos_; | |
| if (bufferBitPos_ == 8) | |
| { | |
| bufferBitPos_ = 0; | |
| ++bufferPos_; | |
| } | |
| if (bufferPos_ == bufferLength_) | |
| { | |
| beginWaitReset_(); | |
| sendBytesCallback_(false); | |
| return; | |
| } | |
| bool bit = bitRead(sendBuffer_[bufferPos_], bufferBitPos_); | |
| beginSendBit_(bit, &OneWireSlave::bitSent_); | |
| } | |
| void OneWireSlave::beginReceiveBytes_(byte* buffer, short numBytes, void(*complete)(bool error)) | |
| { | |
| recvBuffer_ = buffer; | |
| bufferLength_ = numBytes; | |
| bufferPos_ = 0; | |
| receiveBytesCallback_ = complete; | |
| beginReceive_(); | |
| } | |
| void OneWireSlave::noOpCallback_(bool error) | |
| { | |
| if (error) | |
| ERROR("error during an internal 1-wire operation"); | |
| } | |
| void OneWireSlave::matchRomBytesReceived_(bool error) | |
| { | |
| if (error) | |
| { | |
| ERROR("error receiving match rom bytes"); | |
| return; | |
| } | |
| if (memcmp(rom_, scratchpad_, 8) == 0) | |
| { | |
| // log("ROM matched"); | |
| beginReceiveBytes_(scratchpad_, 1, &OneWireSlave::notifyClientByteReceived_); | |
| } | |
| else | |
| { | |
| // log("ROM not matched"); | |
| beginWaitReset_(); | |
| } | |
| } | |
| void OneWireSlave::notifyClientByteReceived_(bool error) | |
| { | |
| if (error) | |
| { | |
| if (clientReceiveCallback_ != 0) | |
| clientReceiveCallback_(RE_Error, 0); | |
| ERROR("error receiving custom bytes"); | |
| return; | |
| } | |
| beginReceiveBytes_(scratchpad_, 1, &OneWireSlave::notifyClientByteReceived_); | |
| if (clientReceiveCallback_ != 0) | |
| clientReceiveCallback_(RE_Byte, scratchpad_[0]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef _OneWireSlave_h_ | |
| #define _OneWireSlave_h_ | |
| #include "Arduino.h" | |
| #include "LowLevel.h" | |
| class OneWireSlave | |
| { | |
| public: | |
| enum ReceiveEvent | |
| { | |
| RE_Reset, //!< The master has sent a general reset | |
| RE_Byte, //!< The master just sent a byte of data | |
| RE_Error //!< A communication error happened (such as a timeout) ; the library will stop all 1-wire activities until the next reset | |
| }; | |
| //! Starts listening for the 1-wire master, on the specified pin, as a virtual slave device identified by the specified ROM (7 bytes, starting from the family code, CRC will be computed internally). Reset, Presence, SearchRom and MatchRom are handled automatically. The library will use the external interrupt on the specified pin (note that this is usually not possible with all pins, depending on the board), as well as one hardware timer. Blocking interrupts (either by disabling them explicitely with sei/cli, or by spending time in another interrupt) can lead to malfunction of the library, due to tight timing for some 1-wire operations. | |
| void begin(const byte* rom, byte pinNumber); | |
| //! Stops all 1-wire activities, which frees hardware resources for other purposes. | |
| void end(); | |
| //! Sets (or replaces) a function to be called when something is received. The callback is executed from interrupts and should be as short as possible. Failure to return quickly can prevent the library from correctly reading the next byte. | |
| void setReceiveCallback(void(*callback)(ReceiveEvent evt, byte data)) { clientReceiveCallback_ = callback; } | |
| //! Enqueues the specified bytes in the send buffer. They will be sent in the background. The optional callback is used to notify when the bytes are sent, or if an error occured. Callbacks are executed from interrupts and should be as short as possible. | |
| void write(const byte* bytes, short numBytes, void(*complete)(bool error)); | |
| static byte crc8(const byte* data, short numBytes); | |
| private: | |
| static void setTimerEvent_(short delayMicroSeconds, void(*handler)()); | |
| static void disableTimer_(); | |
| static void onEnterInterrupt_(); | |
| static void onLeaveInterrupt_(); | |
| static void error_(const char* message); | |
| static void pullLow_(); | |
| static void releaseBus_(); | |
| static void beginReceiveBit_(void(*completeCallback)(bool bit, bool error)); | |
| static void beginSendBit_(bool bit, void(*completeCallback)(bool error)); | |
| static void beginResetDetection_(); | |
| static void cancelResetDetection_(); | |
| static void beginWaitReset_(); | |
| static void beginWaitCommand_(); | |
| static void beginReceive_(); | |
| static void onBitReceived_(bool bit, bool error); | |
| static void beginSearchRom_(); | |
| static void beginSearchRomSendBit_(); | |
| static void continueSearchRom_(bool error); | |
| static void searchRomOnBitReceived_(bool bit, bool error); | |
| static void beginWriteBytes_(const byte* data, short numBytes, void(*complete)(bool error)); | |
| static void beginReceiveBytes_(byte* buffer, short numBytes, void(*complete)(bool error)); | |
| static void noOpCallback_(bool error); | |
| static void matchRomBytesReceived_(bool error); | |
| static void notifyClientByteReceived_(bool error); | |
| static void bitSent_(bool error); | |
| // interrupt handlers | |
| static void waitReset_(); | |
| static void beginPresence_(); | |
| static void endPresence_(); | |
| static void receive_(); | |
| static void readBit_(); | |
| static void sendBitOne_(); | |
| static void sendBitZero_(); | |
| static void endSendBitZero_(); | |
| static void resetCheck_(); | |
| private: | |
| static byte rom_[8]; | |
| static byte scratchpad_[8]; | |
| static Pin pin_; | |
| static byte tccr1bEnable_; | |
| static unsigned long resetStart_; | |
| static unsigned long lastReset_; | |
| static void(*receiveBitCallback_)(bool bit, bool error); | |
| static void(*bitSentCallback_)(bool error); | |
| static byte receivingByte_; | |
| static byte searchRomBytePos_; | |
| static byte searchRomBitPos_; | |
| static bool searchRomInverse_; | |
| static const byte* sendBuffer_; | |
| static byte* recvBuffer_; | |
| static short bufferLength_; | |
| static short bufferPos_; | |
| static byte bufferBitPos_; | |
| static void(*receiveBytesCallback_)(bool error); | |
| static void(*sendBytesCallback_)(bool error); | |
| static void(*clientReceiveCallback_)(ReceiveEvent evt, byte data); | |
| }; | |
| extern OneWireSlave OneWire1; | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment