WIP
This commit is contained in:
@@ -32,3 +32,4 @@ Payload:
|
|||||||
2 bytes | TargetDeviceId -> The id of the board
|
2 bytes | TargetDeviceId -> The id of the board
|
||||||
1 byte | PinId -> Idof the pin of the board
|
1 byte | PinId -> Idof the pin of the board
|
||||||
1 byte | state -> 1 to swtich on, 0 to switch off
|
1 byte | state -> 1 to swtich on, 0 to switch off
|
||||||
|
|
||||||
@@ -15,32 +15,36 @@ typedef struct
|
|||||||
{
|
{
|
||||||
uint32_t sourceDevId;
|
uint32_t sourceDevId;
|
||||||
byte sourceMeyPinId;
|
byte sourceMeyPinId;
|
||||||
|
uint32_t targetDevId;
|
||||||
byte targetMeyPinId;
|
byte targetMeyPinId;
|
||||||
bool trigger;
|
bool trigger;
|
||||||
bool inverse;
|
bool inverse;
|
||||||
|
|
||||||
void InitSimple(uint32_t sourceDevId, byte sourceMeyPinId, byte targetMeyPinId)
|
void InitSimple(uint32_t sourceDevId, byte sourceMeyPinId, uint32_t targetDevId, byte targetMeyPinId)
|
||||||
{
|
{
|
||||||
this->sourceDevId = sourceDevId;
|
this->sourceDevId = sourceDevId;
|
||||||
this->sourceMeyPinId = sourceMeyPinId;
|
this->sourceMeyPinId = sourceMeyPinId;
|
||||||
|
this->targetDevId = targetDevId;
|
||||||
this->targetMeyPinId = targetMeyPinId;
|
this->targetMeyPinId = targetMeyPinId;
|
||||||
trigger = false;
|
trigger = false;
|
||||||
inverse = false;
|
inverse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitTrigger(uint32_t sourceDevId, byte sourceMeyPinId, byte targetMeyPinId)
|
void InitTrigger(uint32_t sourceDevId, byte sourceMeyPinId, uint32_t targetDevId, byte targetMeyPinId)
|
||||||
{
|
{
|
||||||
this->sourceDevId = sourceDevId;
|
this->sourceDevId = sourceDevId;
|
||||||
this->sourceMeyPinId = sourceMeyPinId;
|
this->sourceMeyPinId = sourceMeyPinId;
|
||||||
|
this->targetDevId = targetDevId;
|
||||||
this->targetMeyPinId = targetMeyPinId;
|
this->targetMeyPinId = targetMeyPinId;
|
||||||
trigger = true;
|
trigger = true;
|
||||||
inverse = false;
|
inverse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitTriggerInverse(uint32_t sourceDevId, byte sourceMeyPinId, byte targetMeyPinId)
|
void InitTriggerInverse(uint32_t sourceDevId, byte sourceMeyPinId, uint32_t targetDevId, byte targetMeyPinId)
|
||||||
{
|
{
|
||||||
this->sourceDevId = sourceDevId;
|
this->sourceDevId = sourceDevId;
|
||||||
this->sourceMeyPinId = sourceMeyPinId;
|
this->sourceMeyPinId = sourceMeyPinId;
|
||||||
|
this->targetDevId = targetDevId;
|
||||||
this->targetMeyPinId = targetMeyPinId;
|
this->targetMeyPinId = targetMeyPinId;
|
||||||
trigger = true;
|
trigger = true;
|
||||||
inverse = true;
|
inverse = true;
|
||||||
@@ -70,7 +74,7 @@ PinState MeyPins[8];
|
|||||||
bool flag = false;
|
bool flag = false;
|
||||||
int32_t myDeviceId;
|
int32_t myDeviceId;
|
||||||
|
|
||||||
Rule Rules[10];
|
Rule Rules[0];
|
||||||
|
|
||||||
MCP2515 mcp2515_0(PIN_PA2);
|
MCP2515 mcp2515_0(PIN_PA2);
|
||||||
MCP2515 mcp2515_1(PIN_PA3);
|
MCP2515 mcp2515_1(PIN_PA3);
|
||||||
@@ -80,6 +84,8 @@ MCP2515 mcp2515_3(PIN_PB1);
|
|||||||
void setup() {
|
void setup() {
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
|
|
||||||
|
Rules[0] = Rule();
|
||||||
|
Rules[0].InitTrigger(0x055F, 1, 0x3D2D, 2); // should switch MeyPin #2 of Device 3D2D to the settet state of MeyPin #1 of 0x055F is changed
|
||||||
|
|
||||||
MeyPins[0] = PinState();
|
MeyPins[0] = PinState();
|
||||||
MeyPins[0].Init(PIN_PC7, (byte) 1);
|
MeyPins[0].Init(PIN_PC7, (byte) 1);
|
||||||
@@ -185,16 +191,16 @@ void loop() {
|
|||||||
|
|
||||||
void HandleFrame(can_frame *frame)
|
void HandleFrame(can_frame *frame)
|
||||||
{
|
{
|
||||||
HandleSwitchTriggeredCanPackage(frame);
|
|
||||||
HandleTriggerMeypinCanPackage(frame);
|
HandleTriggerMeypinCanPackage(frame);
|
||||||
|
|
||||||
|
// Handle rules needs to be the last call
|
||||||
|
HandleRules(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleTriggerMeypinCanPackage(can_frame *frame)
|
void HandleTriggerMeypinCanPackage(can_frame *frame)
|
||||||
{
|
{
|
||||||
if (GetDeviceId(frame->can_id) == GetMyDeviceId())
|
if (GetDeviceId(frame->can_id) == GetMyDeviceId())
|
||||||
{
|
{
|
||||||
|
|
||||||
int meyPinId = frame->data[0];
|
int meyPinId = frame->data[0];
|
||||||
bool state = frame->data[1] > 0;
|
bool state = frame->data[1] > 0;
|
||||||
|
|
||||||
@@ -220,23 +226,16 @@ void HandleTriggerMeypinCanPackage(can_frame *frame)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleSwitchTriggeredCanPackage(can_frame *frame)
|
void HandleRules(can_frame *frame)
|
||||||
{
|
{
|
||||||
if (GetPackageType(frame->can_id) == SWITCH_TRIGGERED_CAN_ID)
|
if (GetPackageType(frame->can_id) == SWITCH_TRIGGERED_CAN_ID)
|
||||||
{
|
|
||||||
for (int i = 0; i < sizeof(Rules) / sizeof(Rule); i++)
|
for (int i = 0; i < sizeof(Rules) / sizeof(Rule); i++)
|
||||||
{
|
if ( Rules[i].sourceDevId == GetDeviceId(frame->can_id) && Rules[i].sourceMeyPinId == frame->data[0] )
|
||||||
if (Rules[i].sourceDevId == 0x0000 || ( Rules[i].sourceDevId == GetDeviceId(frame->can_id) && Rules[i].sourceMeyPinId == frame->data[0] ))
|
HandleRule(Rules[i].targetMeyPinId, _frame.data[1], Rules[i].trigger, Rules[i].inverse );
|
||||||
{
|
|
||||||
ProcessTriggerSwitchPackage( Rules[i].targetMeyPinId, _frame.data[1], Rules[i].trigger, Rules[i].inverse );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessTriggerSwitchPackage( byte meyPinId, byte state, bool asTrigger, bool inverse)
|
void HandleRule(byte meyPinId, byte state, bool asTrigger, bool inverse)
|
||||||
{
|
{
|
||||||
|
|
||||||
int pinState = state > 0;
|
int pinState = state > 0;
|
||||||
if (inverse)
|
if (inverse)
|
||||||
pinState = !pinState;
|
pinState = !pinState;
|
||||||
|
|||||||
Reference in New Issue
Block a user