Swtich PCB from LDO to StepDown Module

This commit is contained in:
Meydin87
2023-06-04 08:01:55 +02:00
parent d4130f5705
commit e274cdc4ce
28 changed files with 10356 additions and 4015 deletions

View File

@@ -134,9 +134,9 @@ struct RemotePinInfo remotePinInfos = RemotePinInfo();
PinState MeyPins[8];
bool flag = false;
int32_t myDeviceId;
int16_t myDeviceId;
Rule Rules[8];
Rule Rules[16];
MCP2515 mcp2515_0(PIN_PA2);
MCP2515 mcp2515_1(PIN_PA3);
@@ -146,24 +146,52 @@ MCP2515 mcp2515_3(PIN_PB1);
void setup() {
SPI.begin();
Rules[0] = Rule();
Rules[0].InitToggle(0x1EC3, 1, 0x3D2D, 2); // should switch MeyPin #2 of Device 3D2D to the settet state of MeyPin #1 of 0x055F is changed
Rules[0] = Rule();
Rules[0].InitToggleInverse(0x051F, 5, 0x3D2D, 4); // Lichtschalter Wohnzimmer Licht 1
Rules[1] = Rule();
Rules[1].InitToggle(0xD8C0, 2, 0x3D2D, 2); // should switch MeyPin #2 of Device 3D2D to the settet state of MeyPin #1 of 0x055F is changed
Rules[1].InitToggleInverse(0x051F, 5, 0x3D2D, 3); // Lichtschalter Wohnzimmer Licht 2
Rules[2] = Rule();
Rules[2].InitToggle(0x1EC2, 3, 0x3D2D, 3); // should switch MeyPin #2 of Device 3D2D to the settet state of MeyPin #1 of 0x055F is changed
Rules[2].InitToggle(0x05df, 1, 0x3D2D, 4); // Licht 1 von Terassenschalter
Rules[3] = Rule();
Rules[3].InitToggle(0x1EC2, 4, 0x3D2D, 4); // should switch MeyPin #2 of Device 3D2D to the settet state of MeyPin #1 of 0x055F is changed
Rules[3].InitToggle(0x05df, 1, 0x3D2D, 3); // Licht 2 von Terassenschalter
Rules[4] = Rule();
Rules[4].InitToggle(0x1EC2, 5, 0x3D2D, 5); // should switch MeyPin #2 of Device 3D2D to the settet state of MeyPin #1 of 0x055F is changed
Rules[4].InitToggle(0x0769, 1, 0x3D2D, 6); // Eingangstür Flur Licht 2
Rules[5] = Rule();
Rules[5].InitToggle(0x1EC2, 6, 0x3D2D, 6); // should switch MeyPin #2 of Device 3D2D to the settet state of MeyPin #1 of 0x055F is changed
Rules[5].InitToggle(0x0769, 1, 0x9829, 1); //Eingangstür Flur Licht 1
Rules[6] = Rule();
Rules[6].InitToggle(0x1EC2, 7, 0x3D2D, 7); // should switch MeyPin #2 of Device 3D2D to the settet state of MeyPin #1 of 0x055F is changed
Rules[6].InitSimple(0x051F, 3,0x3D2D, 1); // Licht 1 Wochzimmer Eingangstür
Rules[7] = Rule();
Rules[7].InitToggle(0x1EC2, 8, 0x3D2D, 8); // should switch MeyPin #2 of Device 3D2D to the settet state of MeyPin #1 of 0x055F is changed
Rules[7].InitSimple(0x051F, 4,0x3D2D, 2); // Licht 2 Wochzimmer Eingangstür
Rules[8] = Rule();
Rules[8].InitToggle(0x1177, 1, 0x3D2D, 7); // Licht Papa Büro
Rules[9] = Rule();
Rules[9].InitToggle(0x05A1, 1,0x3D2D, 6); // Flurlicht von Papas Büro
Rules[10] = Rule();
Rules[10].InitToggle(0x05A1, 1,0x9829, 1); // Flurlicht von Papas Büro
Rules[11] = Rule();
Rules[11].InitToggle(0x01EF, 1,0x3D2D, 6); // Flurlicht von Papas Büro
Rules[12] = Rule();
Rules[12].InitToggle(0x01EF, 1,0x9829, 1); // Flurlicht von Papas Büro#
Rules[13] = Rule();
Rules[13].InitToggle(0x0196, 3,0x3D2D, 6); // Flurlicht von Papas Büro
Rules[14] = Rule();
Rules[14].InitToggle(0x0196, 3,0x9829, 1); // Flurlicht von Papas Büro
Rules[15] = Rule();
Rules[15].InitToggle(0x0632, 1, 0x9829, 5); // Flurlicht von Papas Büro
delay(10);
MeyPins[0] = PinState();
MeyPins[0].Init(PIN_PC7, (byte) 1);
@@ -209,13 +237,10 @@ void setup() {
mcp2515_3.setBitrate(CAN_500KBPS, MCP_8MHZ); //Sets CAN at speed 500KBPS and Clock 8MHz
mcp2515_3.setNormalMode();
//delay(20000);
for (int i = 0; i < sizeof(MeyPins) / sizeof(PinState); i++)
{
pinMode(MeyPins[i].pin_id, OUTPUT);
// digitalWrite(MeyPins[i].pin_id, HIGH);
//delay(100);
digitalWrite(MeyPins[i].pin_id, LOW);
}
@@ -228,14 +253,14 @@ void setup() {
}
bool debugState = false;
void ToggleDebug()
{
delay(500);
byte debugState = digitalRead(PIN_PC7)^true;
debugState = debugState^true;
if (debugState)
digitalWrite(PIN_PC7, HIGH);
digitalWrite(PIN_PC1, HIGH);
else
digitalWrite(PIN_PC7, LOW);
digitalWrite(PIN_PC1, LOW);
}
@@ -269,11 +294,11 @@ void loop()
mcp2515_2.sendMessage(MCP2515::TXB1, &_frame);
HandleFrame(&_frame);
}
delay(10);
}
void HandleFrame(can_frame *frame)
{
// ToggleDebug();
HandleMeyPinTriggeredCanPackage(frame);
HandleTriggerMeypinCanPackage(frame);
// Handle rules needs to be the last call
@@ -342,12 +367,15 @@ void HandleRules(can_frame *frame)
{
if (GetPackageType(frame->can_id) == SWITCH_TRIGGERED_CAN_ID)
{
uint16_t deviceId = GetDeviceId(frame->can_id);
uint8_t dt = _frame.data[1];
uint8_t state = frame->data[0];
for (int i = 0; i < sizeof(Rules) / sizeof(Rule); i++)
{
if ( Rules[i].sourceDevId == GetDeviceId(frame->can_id))
if (Rules[i].sourceMeyPinId == frame->data[0])
HandleRule(&Rules[i], _frame.data[1] );
if ( Rules[i].sourceDevId == deviceId)
if (Rules[i].sourceMeyPinId == state)
HandleRule(&Rules[i], dt );
}
}
}
@@ -388,7 +416,7 @@ byte CircularShift(byte b)
return (b << 1) | (b >> 7 & 1);
}
uint32_t GetDeviceId(uint32_t canFrameId)
uint16_t GetDeviceId(uint32_t canFrameId)
{
return canFrameId & 0xFFFF;
}
@@ -398,17 +426,22 @@ uint32_t GetPackageType(uint32_t canFrameId)
return (canFrameId / 0x10000) & 0xFFF;
}
uint32_t CreateCanId(uint32_t commandId)
uint32_t CreateCanId(uint16_t commandId)
{
return ((commandId & 0xFFF) * 0x10000) | myDeviceId | CAN_EFF_FLAG;
}
uint32_t CreateCanId(uint16_t commandId, uint16_t deviceId)
{
return ((commandId & 0xFFF) * 0x10000) | deviceId | CAN_EFF_FLAG;
}
void CalculateMyDeviceId()
{
myDeviceId = (GetDeviceIdHigh() << 8) | GetDeviceIdLow();
}
uint32_t GetMyDeviceId()
uint16_t GetMyDeviceId()
{
return myDeviceId;
}
@@ -453,10 +486,10 @@ void SendSwitchedTriggeredCanPackage(MCP2515 *interface, byte pinId, int state)
void SendDoTriggerSwitchCanPackage(MCP2515 *interface, uint16_t targetCanId, byte pinId, byte state)
{
_frame.can_id = CreateCanId(TRIGGER_SWITCH_CAN_ID);
_frame.can_id = CreateCanId(TRIGGER_SWITCH_CAN_ID, targetCanId);
_frame.can_dlc = 4;
_frame.data[1] = (targetCanId & 0xFF00) >> 8;
_frame.data[0] = targetCanId & 0xFF;
_frame.data[0] = (targetCanId & 0xFF00) >> 8;
_frame.data[1] = targetCanId & 0xFF;
_frame.data[2] = pinId;
_frame.data[3] = state;
interface->sendMessage(MCP2515::TXB1, &_frame);