Files
info.linkwitz.ha_pcb/Software/Switch/Switch.ino
2023-07-18 06:39:39 +02:00

73 lines
2.3 KiB
C++

#include <avr/io.h>;
#include <avr/xmega.h>;
#include <SPI.h>;
#include <mcp2515.h>;
#include "MeyCan.h";
#include "MeyRule.h";
struct can_frame incomingCanFrame;
void setup() {
SPI.begin();
AddToggleInverse(0x051F, 5, 0x3D2D, 4); // Lichtschalter Wohnzimmer Licht 1
AddToggleInverse(0x051F, 5, 0x3D2D, 3); // Lichtschalter Wohnzimmer Licht 2
AddToggle(0x05df, 1, 0x3D2D, 4); // Licht 1 von Terassenschalter
AddToggle(0x05df, 1, 0x3D2D, 3); // Licht 2 von Terassenschalter
AddToggle(0x0769, 1, 0x3D2D, 6); // Eingangstür Flur Licht 2
AddToggle(0x0769, 1, 0x9829, 1); //Eingangstür Flur Licht 1
AddSimple(0x051F, 3, 0x3D2D, 1); // Licht 1 Wochzimmer Eingangstür
AddSimple(0x051F, 4, 0x3D2D, 2); // Licht 2 Wochzimmer Eingangstür
AddToggle(0x1177, 1, 0x3D2D, 7); // Licht Papa Büro
AddToggle(0x05A1, 1, 0x3D2D, 6); // Flurlicht von Papas Büro
AddToggle(0x05A1, 1, 0x9829, 1); // Flurlicht von Papas Büro
AddToggle(0x01EF, 1, 0x3D2D, 6); // Flurlicht von Papas Büro
AddToggle(0x01EF, 1, 0x9829, 1); // Flurlicht von Papas Büro
AddToggle(0x0196, 3, 0x3D2D, 6); // Flurlicht von Papas Büro
AddToggle(0x0196, 3, 0x9829, 1); // Flurlicht von Papas Büro
AddToggle(0x0632, 1, 0x9829, 5); // Flurlicht von Papas Büro
// _PROTECTED_WRITE(CLKCTRL.MCLKCTRLA, CLKCTRL.MCLKCTRLA | 1 << 7);
delay(10); // a bit delay for mcp2515 to get the clock
SetMeyPin(0, 1, PIN_PC7);
SetMeyPin(1, 2, PIN_PC6);
SetMeyPin(2, 3, PIN_PC5);
SetMeyPin(3, 4, PIN_PC4);
SetMeyPin(4, 5, PIN_PC3);
SetMeyPin(5, 6, PIN_PC2);
SetMeyPin(6, 7, PIN_PC1);
SetMeyPin(7, 8, PIN_PC0);
SetCanInterface(0, PIN_PA2);
SetCanInterface(1, PIN_PA3);
SetCanInterface(2, PIN_PB0);
SetCanInterface(3, PIN_PB1);
SetupMeyCan();
}
void loop()
{
for (int i = 0; i < sizeof(canInterfaces) / sizeof(MCP2515*); i++)
{
if (canInterfaces[i]->readMessage(&incomingCanFrame) == MCP2515::ERROR_OK)
{
// A received CAN Frame is forwarded to all other MCPs given, but not to the receiving one (no echo )
for (int j = 0; j < sizeof(canInterfaces) / sizeof(MCP2515*); j++)
{
if (j == i) continue; // thats for the echo
DoSendCanPkg(canInterfaces[j], &incomingCanFrame);
}
HandleFrame(&incomingCanFrame);
// HandleRules(&incomingCanFrame);
}
}
}