From 6865f4c9e50bb3c7589264610d238d18290f8da2 Mon Sep 17 00:00:00 2001 From: Michael Waiblinger Date: Thu, 2 Jun 2016 01:48:37 +0200 Subject: [PATCH] state change implemented --- src/CANode.cpp | 45 +++++++++++++++++++++++++++++++++++++-------- src/CANode.h | 12 ++++++------ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/CANode.cpp b/src/CANode.cpp index c4d68a7..78d8fcb 100644 --- a/src/CANode.cpp +++ b/src/CANode.cpp @@ -14,6 +14,7 @@ #include #include #include "CANode.h" + // Configurations // Misc #define DEBUG 0 @@ -41,6 +42,10 @@ #define PIO_B 0x40 #define DS2406_BUF_LEN 10 +// Definitions +static OW_switch_t switches; + + // Initialisation // Misc @@ -62,7 +67,7 @@ FlexCAN CANbus(CAN_speed); // OneWire uint8_t addr[8]; uint8_t buffer[DS2406_BUF_LEN]; -uint8_t tmp; +uint8_t readout,tmp; OneWire OW_1(OW_pin); @@ -123,6 +128,20 @@ uint8_t read_DS2406(uint8_t* addr) { void setup(void) { // Misc + switches.nick = 1; + switches.addr[0] = 0x12, + switches.addr[1] = 0x5b; + switches.addr[2] = 0x27; + switches.addr[3] = 0x50; + switches.addr[4] = 0x0; + switches.addr[5] = 0x0; + switches.addr[6] = 0x0; + switches.addr[7] = 0x26; + switches.state = 0x60; + //my_sw.event[0] = { 0x01020304, 2, { 0xde, 0xad }}; + + //{ 0x02040608, 2, { 0xbe, 0xef }}}; + Serial.begin(115200); pinMode(led, OUTPUT); digitalWrite(led, 1); @@ -163,18 +182,28 @@ void loop(void) // At this point, we know we have a DS2406. Blink it. - if(addr[0] == DS2406_FAMILY) { + //if(addr[0] == DS2406_FAMILY) { // foundDevice = true; // digitalWrite(13, HIGH); - tmp = read_DS2406(addr); - bool pioA = tmp & 0x04; - bool pioB = tmp & 0x08; - digitalWrite(led, pioA); - } +// tmp = read_DS2406(addr); +// bool pioA = tmp & 0x04; +// bool pioB = tmp & 0x08; +// digitalWrite(led, pioA)i; +// } } + } if (METRO_OW_read.check() ) { - + bool action[2]; + readout = read_DS2406(switches.addr); + if (switches.state != readout) { + tmp = readout ^ switches.state; + switches.state = readout; + action[0] = tmp & 0x04; + action[1] = tmp & 0x08; + } + if (action[0]) { Serial.print("pioA toggled"); digitalWrite(led, !digitalRead(led));} + if (action[1]) { Serial.print("pioB toggled"); digitalWrite(led, !digitalRead(led));} } diff --git a/src/CANode.h b/src/CANode.h index b6b98ff..d4ea9d9 100644 --- a/src/CANode.h +++ b/src/CANode.h @@ -1,14 +1,14 @@ #include -typedef struct CAN_telegram { +typedef struct CAN_telegram_t { uint32_t id; uint8_t len; uint8_t buf[8]; -} CAN_telegram; +} CAN_telegram_t; -typedef struct OW_switch { +typedef struct OW_switch_t { uint8_t nick; uint8_t addr[8]; - uint8_t last_state; - CAN_telegram event[2]; -} OW_switch; + uint8_t state; + CAN_telegram_t event[2]; +} OW_switch_t;