Browse Source

small optimization

timer1
Youen Toupin 10 years ago
parent
commit
f53e2adae8
  1. 21
      OneWireIO.ino

21
OneWireIO.ino

@ -58,6 +58,8 @@ unsigned long lastReset = (unsigned long)-1;
unsigned long bitStart = (unsigned long)-1; unsigned long bitStart = (unsigned long)-1;
byte receivingByte = 0; byte receivingByte = 0;
byte receivingBitPos = 0; byte receivingBitPos = 0;
bool searchRomNextBit = false;
bool searchRomNextBitToSend = false;
void setup() void setup()
{ {
@ -211,6 +213,9 @@ void onewireInterruptImpl(void)
searchROMSendingInverse = false; searchROMSendingInverse = false;
searchROMCurrentByte = 0; searchROMCurrentByte = 0;
searchROMCurrentBit = 0; searchROMCurrentBit = 0;
byte currentByte = owROM[searchROMCurrentByte];
searchRomNextBit = bitRead(currentByte, searchROMCurrentBit);
searchRomNextBitToSend = searchROMSendingInverse ? !searchRomNextBit : searchRomNextBit;
attachInterrupt(InterruptNumber, onewireInterruptSearchROM, FALLING); attachInterrupt(InterruptNumber, onewireInterruptSearchROM, FALLING);
return; return;
} }
@ -232,10 +237,7 @@ void onewireInterruptSearchROM()
{ {
bool bit = readBit(); bool bit = readBit();
byte currentByte = owROM[searchROMCurrentByte]; if (bit != searchRomNextBit)
bool currentBit = bitRead(currentByte, searchROMCurrentBit);
if (bit != currentBit)
{ {
debug.SC_APPEND_STR("Master didn't send our bit, leaving ROM search"); debug.SC_APPEND_STR("Master didn't send our bit, leaving ROM search");
status = OS_WaitReset; status = OS_WaitReset;
@ -263,12 +265,7 @@ void onewireInterruptSearchROM()
} }
else else
{ {
byte currentByte = owROM[searchROMCurrentByte]; sendBit(searchRomNextBitToSend);
bool currentBit = bitRead(currentByte, searchROMCurrentBit);
//bool currentBit = 0;
bool bitToSend = searchROMSendingInverse ? !currentBit : currentBit;
sendBit(bitToSend);
/*if (bitToSend) /*if (bitToSend)
debug.SC_APPEND_STR("sent ROM search bit : 1"); debug.SC_APPEND_STR("sent ROM search bit : 1");
else else
@ -284,6 +281,10 @@ void onewireInterruptSearchROM()
searchROMSendingInverse = true; searchROMSendingInverse = true;
} }
} }
byte currentByte = owROM[searchROMCurrentByte];
searchRomNextBit = bitRead(currentByte, searchROMCurrentBit);
searchRomNextBitToSend = searchROMSendingInverse ? !searchRomNextBit : searchRomNextBit;
} }
bool readBit() bool readBit()

Loading…
Cancel
Save