- implemented simple protocol to turn an output on/off
- disabled debug code
This commit is contained in:
parent
c0a183c769
commit
4d94761fd5
@ -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:
|
||||||
;
|
;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "OneWireSlave.h"
|
#include "OneWireSlave.h"
|
||||||
|
|
||||||
#define DEBUG_LOG
|
//#define DEBUG_LOG
|
||||||
#define ERROR_MESSAGES
|
#define ERROR_MESSAGES
|
||||||
|
|
||||||
#ifdef DEBUG_LOG
|
#ifdef DEBUG_LOG
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "SerialChannel.h"
|
#include "SerialChannel.h"
|
||||||
|
|
||||||
|
#ifdef ENABLE_SERIAL_CHANNEL
|
||||||
|
|
||||||
byte SerialChannel::nextId = 1;
|
byte SerialChannel::nextId = 1;
|
||||||
SerialChannel* SerialChannel::first = 0;
|
SerialChannel* SerialChannel::first = 0;
|
||||||
|
|
||||||
@ -165,3 +167,4 @@ void SerialChannel::handleConnection()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif //ENABLE_SERIAL_CHANNEL
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#ifndef _SerialChannel_h_
|
#ifndef _SerialChannel_h_
|
||||||
#define _SerialChannel_h_
|
#define _SerialChannel_h_
|
||||||
|
|
||||||
|
//#define ENABLE_SERIAL_CHANNEL
|
||||||
|
|
||||||
|
#ifdef ENABLE_SERIAL_CHANNEL
|
||||||
#define SC_APPEND_STR(str) append((byte*)str, sizeof(str)-1)
|
#define SC_APPEND_STR(str) append((byte*)str, sizeof(str)-1)
|
||||||
#define SC_APPEND_STR_INT(str, arg0) appendInt(str, sizeof(str)-1, arg0)
|
#define SC_APPEND_STR_INT(str, arg0) appendInt(str, sizeof(str)-1, arg0)
|
||||||
|
|
||||||
@ -55,6 +58,7 @@ private:
|
|||||||
static void writeShort(short num);
|
static void writeShort(short num);
|
||||||
static void writeULong(unsigned long num);
|
static void writeULong(unsigned long num);
|
||||||
};
|
};
|
||||||
|
#endif // ENABLE_SERIAL_CHANNEL
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user