|
|
@ -6,18 +6,15 @@ |
|
|
|
#define LEDPin 13 |
|
|
|
#define LEDPin 13 |
|
|
|
#define OWPin 2 |
|
|
|
#define OWPin 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_SERIAL_CHANNEL |
|
|
|
SerialChannel debug("debug"); |
|
|
|
SerialChannel debug("debug"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
Pin led(LEDPin); |
|
|
|
Pin led(LEDPin); |
|
|
|
|
|
|
|
|
|
|
|
byte owROM[7] = { 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; |
|
|
|
byte owROM[7] = { 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; |
|
|
|
|
|
|
|
|
|
|
|
byte buffer1[8]; |
|
|
|
byte acknowledge = 0x42; |
|
|
|
byte buffer2[8]; |
|
|
|
|
|
|
|
volatile byte* backBuffer = buffer1; |
|
|
|
|
|
|
|
volatile byte bufferPos = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte sendBuffer[8]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void owReceive(OneWireSlave::ReceiveEvent evt, byte data); |
|
|
|
void owReceive(OneWireSlave::ReceiveEvent evt, byte data); |
|
|
|
|
|
|
|
|
|
|
@ -32,41 +29,19 @@ void setup() |
|
|
|
Serial.begin(9600); |
|
|
|
Serial.begin(9600); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int count = 0; |
|
|
|
|
|
|
|
void loop() |
|
|
|
void loop() |
|
|
|
{ |
|
|
|
{ |
|
|
|
delay(1); |
|
|
|
delay(1); |
|
|
|
if (count++ == 1000) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
led.write(!led.read()); |
|
|
|
|
|
|
|
count = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cli();//disable interrupts
|
|
|
|
cli();//disable interrupts
|
|
|
|
|
|
|
|
#ifdef ENABLE_SERIAL_CHANNEL |
|
|
|
SerialChannel::swap(); |
|
|
|
SerialChannel::swap(); |
|
|
|
byte* frontBuffer = (byte*)backBuffer; |
|
|
|
#endif |
|
|
|
byte frontBufferSize = bufferPos; |
|
|
|
|
|
|
|
backBuffer = backBuffer == buffer1 ? buffer2 : buffer1; |
|
|
|
|
|
|
|
bufferPos = 0; |
|
|
|
|
|
|
|
sei();//enable interrupts
|
|
|
|
sei();//enable interrupts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_SERIAL_CHANNEL |
|
|
|
SerialChannel::flush(); |
|
|
|
SerialChannel::flush(); |
|
|
|
|
|
|
|
#endif |
|
|
|
for (int i = 0; i < frontBufferSize; ++i) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char msg[16]; |
|
|
|
|
|
|
|
sprintf(msg, "Received byte: %d", (int)frontBuffer[i]); |
|
|
|
|
|
|
|
debug.write(msg); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (frontBuffer[i] == 0x42) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sendBuffer[0] = 0xBA; |
|
|
|
|
|
|
|
sendBuffer[1] = 0xAD; |
|
|
|
|
|
|
|
sendBuffer[2] = 0xF0; |
|
|
|
|
|
|
|
sendBuffer[3] = 0x0D; |
|
|
|
|
|
|
|
OneWire.write(sendBuffer, 4, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void owReceive(OneWireSlave::ReceiveEvent evt, byte data) |
|
|
|
void owReceive(OneWireSlave::ReceiveEvent evt, byte data) |
|
|
@ -74,7 +49,11 @@ void owReceive(OneWireSlave::ReceiveEvent evt, byte data) |
|
|
|
switch (evt) |
|
|
|
switch (evt) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case OneWireSlave::RE_Byte: |
|
|
|
case OneWireSlave::RE_Byte: |
|
|
|
backBuffer[bufferPos++] = data; |
|
|
|
if (data == 0x01) |
|
|
|
|
|
|
|
led.writeHigh(); |
|
|
|
|
|
|
|
else if (data == 0x02) |
|
|
|
|
|
|
|
led.writeLow(); |
|
|
|
|
|
|
|
OneWire.write(&acknowledge, 1, 0); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
; |
|
|
|
; |
|
|
|