Extended Rules defined for Switch / UP Fixed

This commit is contained in:
Meydin87
2023-05-17 07:40:00 +02:00
parent 1d2d148d11
commit 3edf1a6b7b
3 changed files with 239 additions and 79 deletions

View File

@@ -3,13 +3,13 @@
struct can_frame _frame;
MCP2515 mcp2515(PIN_PA3);
const byte SoftwareVersionHigh = 2;
MCP2515 mcp2515(PIN_PD4);
const byte SoftwareVersionHigh = 3;
const byte SoftwareVersionLow = 0;
const byte HardwareVersionHigh = 3;
const byte HardwareVersionHigh = 5;
const byte HardwareVersionLow = 0;
typedef struct
typedef struct PinState
{
int pin_id;
bool pin_state;
@@ -24,57 +24,56 @@ typedef struct
this->is_input = true;
this->meyPinId = meyPinId;
}
} PinState;
} ;
int PinCount = 8;
PinState PinPD2[8];
byte DeviceId[2];
PinState MeyPins[8];
int16_t myDeviceId;
void setup() {
SPI.begin();
PinPD2[0] = PinState();
PinPD2[0].Init(PIN_PC7, (byte) 1);
MeyPins[0] = PinState();
MeyPins[0].Init(PIN_PD0, (byte) 1);
PinPD2[1] = PinState();
PinPD2[1].Init(PIN_PD0, (byte) 2);
MeyPins[1] = PinState();
MeyPins[1].Init(PIN_PD2, (byte) 2);
PinPD2[2] = PinState();
PinPD2[2].Init(PIN_PD1, (byte) 3);
MeyPins[2] = PinState();
MeyPins[2].Init(PIN_PD5, (byte) 3);
PinPD2[3] = PinState();
PinPD2[3].Init(PIN_PD2, (byte) 4);
MeyPins[3] = PinState();
MeyPins[3].Init(PIN_PD7, (byte) 4);
PinPD2[4] = PinState();
PinPD2[4].Init(PIN_PD6, (byte) 5);
MeyPins[4] = PinState();
MeyPins[4].Init(PIN_PC7, (byte) 5);
PinPD2[5] = PinState();
PinPD2[5].Init(PIN_PD5, (byte) 6);
MeyPins[5] = PinState();
MeyPins[5].Init(PIN_PD1, (byte) 6);
PinPD2[6] = PinState();
PinPD2[6].Init(PIN_PD4, (byte) 7);
MeyPins[6] = PinState();
MeyPins[6].Init(PIN_PD3, (byte) 7);
PinPD2[7] = PinState();
PinPD2[7].Init(PIN_PD3, (byte) 8);
MeyPins[7] = PinState();
MeyPins[7].Init(PIN_PD6, (byte) 8);
_PROTECTED_WRITE(CLKCTRL.MCLKCTRLA, CLKCTRL.MCLKCTRLA | 1 << 7);
delay(20);
mcp2515.reset();
mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ); //Sets CAN at speed 500KBPS and Clock 8MHz
mcp2515.setNormalMode();
for (int i = 0; i <= PinCount - 1; i++)
{
pinMode(PinPD2[i].pin_id, INPUT_PULLUP);
PinPD2[i].pin_state = ReadPin(&PinPD2[i]);
pinMode(MeyPins[i].pin_id, INPUT_PULLUP);
MeyPins[i].pin_state = ReadPin(&MeyPins[i]);
}
DeviceId[0] = GetDeviceIdLow();
DeviceId[1] = GetDeviceIdHigh();
CalculateMyDeviceId();
SendSerialPackage();
}
@@ -83,8 +82,8 @@ void loop()
{
for (int i = 0; i <= PinCount - 1; i++)
{
if (CheckPinStatus(&PinPD2[i]))
SendSwitchedTriggeredCanPackage(PinPD2[i].meyPinId, PinPD2[i].pin_state);
if (CheckPinStatus(&MeyPins[i]))
SendSwitchedTriggeredCanPackage(MeyPins[i].meyPinId, MeyPins[i].pin_state);
}
if (mcp2515.readMessage(&_frame) == MCP2515::ERROR_OK)
@@ -98,9 +97,9 @@ void loop()
PinState *adressedPin;
for (int i = 0; i <= PinCount - 1; i++)
if (PinPD2[i].meyPinId == meyPinId)
if (MeyPins[i].meyPinId == meyPinId)
{
adressedPin = &PinPD2[i];
adressedPin = &MeyPins[i];
break;
}
@@ -195,12 +194,17 @@ uint32_t GetPackageType(uint32_t canFrameId)
uint32_t CreateCanId(uint32_t commandId)
{
return ((commandId & 0xFFF) * 0x10000) | ( DeviceId[0] << 8) | (DeviceId[1]) | CAN_EFF_FLAG;
return ((commandId & 0xFFF) * 0x10000) | GetMyDeviceId() | CAN_EFF_FLAG;
}
uint32_t GetMyDeviceId()
void CalculateMyDeviceId()
{
return ( DeviceId[0] << 8) | (DeviceId[1]);
myDeviceId = (GetDeviceIdHigh() << 8) | GetDeviceIdLow();
}
uint16_t GetMyDeviceId()
{
return myDeviceId;
}
byte GetDeviceIdLow() {