Browse Source

more feedback in and out

I_sense
mwaiblinger 6 years ago
parent
commit
81cebe6472
  1. 39
      src/CANNode.cpp
  2. 2
      src/CANNode.h
  3. 15
      src/Node_3_def.h

39
src/CANNode.cpp

@ -64,6 +64,7 @@ FlexCAN CANbus(CAN_speed);
// FLEXCAN0_MCR &= ~FLEXCAN_MCR_SRX_DIS;
// OneWire
uint8_t addr[8];
uint8_t data[8];
uint8_t buffer[DS2406_BUF_LEN];
uint8_t readout,trig_event,event_idx,tmp;
OneWire OW_1(OW_pin);
@ -136,7 +137,6 @@ int CAN_send(uint8_t prio, uint8_t dst, uint8_t cmd, uint8_t* data, uint8_t data
txmsg.id = forgeid(prio, dst, cmd, type);
txmsg.len = data_size;
for (uint8_t i = 0; i < txmsg.len; i++) { txmsg.buf[i] = data[i]; }
CANbus.write(txmsg);
}
int CAN_send(uint8_t prio, uint8_t dst, uint8_t cmd, uint8_t data, uint8_t type=0){
@ -144,7 +144,6 @@ int CAN_send(uint8_t prio, uint8_t dst, uint8_t cmd, uint8_t data, uint8_t type=
//txmsg.len = sizeof(data);
txmsg.len = 1;
txmsg.buf[0] = data;
CANbus.write(txmsg);
}
@ -206,20 +205,14 @@ for (uint8_t i = 0; action_map[i].tag != 0 ; i++) {
}
bool new_state = digitalRead(outputs[action_map[i].outputs_idx].address);
if ( old_state == new_state) {
switch ( new_state ) {
case 0:
CAN_send(NOTIFY, 0xFF, OFF, action_map[i].outputs_idx);
case 1:
CAN_send(NOTIFY, 0xFF, ON, action_map[i].outputs_idx);
}
data[0]=outputs[action_map[i].outputs_idx].address;
data[1]=new_state ^ outputs[action_map[i].outputs_idx].invert;
CAN_send(NOTIFY, 0x0, STATE_OUT, data, 2);
}
else {
switch ( new_state ) {
case 0:
CAN_send(NOTIFY, 0xFF, T_OFF, action_map[i].outputs_idx);
case 1:
CAN_send(NOTIFY, 0xFF, T_ON, action_map[i].outputs_idx);
}
data[0]=outputs[action_map[i].outputs_idx].address;
data[1]=new_state ^ outputs[action_map[i].outputs_idx].invert;
CAN_send(NOTIFY, 0x0, NEWSTATE_OUT, data, 2);
}
}
}
@ -298,7 +291,7 @@ void loop(void)
Serial.print("Found a device: ");
print_OW_Device(addr);
Serial.println();
CAN_send(NOTIFY, 0xFF, NEW_TWID, addr, sizeof(addr));
CAN_send(NOTIFY, 0x0, NEW_TWID, addr, sizeof(addr));
}
}
@ -334,9 +327,17 @@ void loop(void)
Serial.print(switches[s_idx].nick);
if (readout & 0x08) {
Serial.println(F(" is now OFF"));
data[0]=switches[s_idx].nick;
data[1]=0;
CAN_send(NOTIFY, 0x0, STATE_IN, data, 2);
CANbus.write(txmsg);
send_event(switches[s_idx].event_tag[0]);
} else {
Serial.println(F(" is now ON"));
data[0]=switches[s_idx].nick;
data[1]=1;
CAN_send(NOTIFY, 0x0, STATE_IN, data, 2);
CANbus.write(txmsg);
send_event(switches[s_idx].event_tag[1]);
}
action[0] = 0;
@ -346,9 +347,17 @@ void loop(void)
Serial.print(switches[s_idx].nick);
if (readout & 0x04) {
Serial.println(F(" is now OFF"));
data[0]=switches[s_idx].nick;
data[1]=2;
CAN_send(NOTIFY, 0x0, STATE_IN, data, 2);
CANbus.write(txmsg);
send_event(switches[s_idx].event_tag[2]);
} else {
Serial.println(F(" is now ON"));
data[0]=switches[s_idx].nick;
data[1]=3;
CAN_send(NOTIFY, 0x0, STATE_IN, data, 2);
CANbus.write(txmsg);
send_event(switches[s_idx].event_tag[3]);
}
action[1] = 0;

2
src/CANNode.h

@ -4,7 +4,7 @@
enum out_type { GPIO, PWM, OW, I2C, SPI, WS2811, DMX, NOP };
enum event_type { LOCAL, SEND};
enum cmd_type { OFF, ON, VALUE, TOGGLE, T_OFF, T_ON, BIN_DUMP, NEW_TWID };
enum cmd_type { OFF, ON, VALUE, TOGGLE, STATE_OUT, STATE_IN, NEWSTATE_OUT, NEWSTATE_IN, BIN_DUMP, NEW_TWID };
enum telegram_prio { ALERT, EVENT, NOTIFY, INFO };
typedef struct CAN_telegram_t {

15
src/Node_3_def.h

@ -35,6 +35,8 @@ static OW_switch_t switches[N_SWITCHES] PROGMEM={
//{ 21, { 0x12, 0x86, 0xB4, 0x54, 0x0, 0x0, 0x0, 0x5F }, { 3, 3, 4, 4 } },
{ 22, { 0x12, 0x84, 0xAD, 0x4F, 0x0, 0x0, 0x0, 0x12 }, { 1, 1, 2, 2 } }, // EZ -> Küche
// { 31, { 0x12, 0x88, 0xDD, 0x53, 0x0, 0x0, 0x0, 0x28 }, { 210, 211, 220, 221 } }, // Roldenschalter (A - UP, B - DOWN)
{ 31, { 0x12, 0x8F, 0xE2, 0x86 ,0x0, 0x0, 0x0, 0xC6}, { 220, 221, 210, 211 } } // Roldenschalter (A - UP, B - DOWN)
};
static uint8_t switches_state[N_SWITCHES];
static outputs_t outputs[N_OUTPUTS] PROGMEM={
@ -45,13 +47,8 @@ static outputs_t outputs[N_OUTPUTS] PROGMEM={
{ GPIO, 22, 0, true }, // 3
{ GPIO, 17, 0, true }, // 4
{ GPIO, 16, 0, true }, // 5
<<<<<<< HEAD
{ GPIO, 9, 255, true }, // 6
{ GPIO, 10, 0, true }, // 7
=======
{ GPIO, 19, 0, true }, // 6
{ GPIO, 18, 0, true }, // 7
>>>>>>> led
{ NOP, 0xFF, 0, 0 }
};
static uint8_t outputs_state[N_OUTPUTS];
@ -72,10 +69,10 @@ static event_t tx_events[N_EVENTS] PROGMEM={
{ 8, 0x03, 0x03, TOGGLE, 0x08},
{ 11, 0x03, 0x01, ON, 0x01},
{ 12, 0x03, 0x01, ON, 0x02},
{ 210, 0x03, 0xff, OFF, 0x06},
{ 211, 0x03, 0xff, ON, 0x06},
{ 220, 0x03, 0xff, OFF, 0x07},
{ 221, 0x03, 0xff, ON, 0x07},
{ 210, 0x03, 0xff, OFF, 0x04},
{ 211, 0x03, 0xff, ON, 0x04},
{ 220, 0x03, 0xff, OFF, 0x05},
{ 221, 0x03, 0xff, ON, 0x05},
{ 255, 0x03, 0xff, OFF, 0x09},
{ 254, 0x03, 0xff, ON, 0x09},
{ 10, 0x03, 0xff, TOGGLE, 0x01},

Loading…
Cancel
Save