Initial commit
This commit is contained in:
@@ -1,128 +1,80 @@
|
||||
#ifndef MEYCAN_H
|
||||
#define MEYCAN_H
|
||||
|
||||
#include <SPI.h>
|
||||
#include <mcp2515.h>
|
||||
|
||||
typedef struct CanInterface
|
||||
{
|
||||
MCP2515 *interface;
|
||||
CanInterface *next = NULL;
|
||||
|
||||
void ForEach(void (*handle)( MCP2515 *interface))
|
||||
{
|
||||
if (this->interface != NULL)
|
||||
handle(this->interface);
|
||||
|
||||
if (this->next != NULL)
|
||||
this->next->ForEach(handle);
|
||||
}
|
||||
|
||||
void ForEach(void (*handle)( MCP2515 *interface, can_frame *frame), can_frame *frame, MCP2515* exclude = NULL)
|
||||
{
|
||||
if (this->interface != NULL && this->interface != exclude)
|
||||
handle(this->interface, frame);
|
||||
|
||||
if (this->next != NULL)
|
||||
this->next->ForEach(handle, frame);
|
||||
}
|
||||
|
||||
void AddCanInterface(CanInterface *newCanInterface)
|
||||
{
|
||||
if (next == NULL)
|
||||
{
|
||||
this->next = newCanInterface;
|
||||
newCanInterface->next = NULL;
|
||||
} else {
|
||||
next->AddCanInterface(newCanInterface);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
typedef struct PinState
|
||||
{
|
||||
int pin_id;
|
||||
bool pin_state;
|
||||
bool is_input;
|
||||
byte meyPinId;
|
||||
PinState *next = NULL;
|
||||
|
||||
PinState() {}
|
||||
void Init(int pin_id, byte meyPinId)
|
||||
{
|
||||
this->pin_id = pin_id;
|
||||
this->pin_state = true;
|
||||
this->is_input = true;
|
||||
this->meyPinId = meyPinId;
|
||||
}
|
||||
|
||||
void AddPinState(PinState *nextPinState)
|
||||
{
|
||||
if (next == NULL)
|
||||
{
|
||||
this->next = nextPinState;
|
||||
nextPinState->next = NULL;
|
||||
} else {
|
||||
next->AddPinState(nextPinState);
|
||||
}
|
||||
}
|
||||
|
||||
PinState* Find(byte meyPinId)
|
||||
{
|
||||
if (this->meyPinId == meyPinId)
|
||||
return this;
|
||||
|
||||
if (this->next != NULL)
|
||||
return this->next->Find(meyPinId);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ForEach(void (*handle)(PinState *theState))
|
||||
{
|
||||
handle(this);
|
||||
if (this->next != NULL)
|
||||
this->next->ForEach(handle);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const byte SOFTWARE_VERSION_HIGH = 5;
|
||||
const byte SOFTWARE_VERSION_LOW = 0;
|
||||
const byte HARDWARE_VERSION_HIGH = 7;
|
||||
const byte HARDWARE_VERSION_LOW = 0;
|
||||
|
||||
const uint16_t HELP_PACKAGE_CAN_ID = 0x0FFFUL;
|
||||
const uint16_t SWITCH_TRIGGERED_CAN_ID = 0x0050;
|
||||
const uint16_t TRIGGER_SWITCH_CAN_ID = 0x0055;
|
||||
|
||||
void SetCanInterface(byte index, byte pinId);
|
||||
void SetMeyPin(byte index, byte meyPinId, byte pinId);
|
||||
|
||||
void SetupMeyCan();
|
||||
|
||||
void ForEachCanInterface(void (*handle)(MCP2515 *canInterace));
|
||||
bool ReadPin(PinState *state);
|
||||
bool CheckPinStatus(PinState * state);
|
||||
void CheckMeyPinsTriggered(); /* checks weather a meypin triggered and sends a can pkg is neccessary */
|
||||
void HandleFrame(can_frame *frame, MCP2515 *source);
|
||||
void HandleTriggerMeypinCanPackage(can_frame *frame);
|
||||
byte CircularShift(byte b);
|
||||
uint16_t GetDeviceId(uint32_t canFrameId);
|
||||
uint16_t GetPackageType(uint32_t canFrameId);
|
||||
byte GetDeviceIdLow();
|
||||
|
||||
byte GetDeviceIdHigh();
|
||||
|
||||
uint32_t CreateCanId(uint16_t commandId);
|
||||
void SendVersionPackage(MCP2515 *interface);
|
||||
|
||||
void SendSwitchedTriggeredCanPackage(byte pinId, int state);
|
||||
void BroadcastTriggerMeyPinCanPackage(uint16_t targetCanId, byte pinId, byte state);
|
||||
|
||||
void DoSendCanPkg(can_frame *frame);
|
||||
void DoSendCanPkg(MCP2515 *interface, can_frame *frame);
|
||||
|
||||
void CalculateMyDeviceId();
|
||||
|
||||
#endif
|
||||
#ifndef MEYCAN_H
|
||||
#define MEYCAN_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
#include "driver/twai.h"
|
||||
|
||||
typedef struct PinState
|
||||
{
|
||||
int pin_id;
|
||||
bool pin_state;
|
||||
bool is_input;
|
||||
byte meyPinId;
|
||||
PinState *next = NULL;
|
||||
|
||||
PinState() {}
|
||||
void Init(int pin_id, byte meyPinId)
|
||||
{
|
||||
this->pin_id = pin_id;
|
||||
this->pin_state = true;
|
||||
this->is_input = true;
|
||||
this->meyPinId = meyPinId;
|
||||
}
|
||||
|
||||
void AddPinState(PinState *nextPinState)
|
||||
{
|
||||
if (next == NULL)
|
||||
{
|
||||
this->next = nextPinState;
|
||||
nextPinState->next = NULL;
|
||||
} else {
|
||||
next->AddPinState(nextPinState);
|
||||
}
|
||||
}
|
||||
|
||||
PinState* Find(byte meyPinId)
|
||||
{
|
||||
if (this->meyPinId == meyPinId)
|
||||
return this;
|
||||
|
||||
if (this->next != NULL)
|
||||
return this->next->Find(meyPinId);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ForEach(void (*handle)(PinState *theState))
|
||||
{
|
||||
handle(this);
|
||||
if (this->next != NULL)
|
||||
this->next->ForEach(handle);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const byte SOFTWARE_VERSION_HIGH = 6;
|
||||
const byte SOFTWARE_VERSION_LOW = 0;
|
||||
const byte HARDWARE_VERSION_HIGH = 8;
|
||||
const byte HARDWARE_VERSION_LOW = 1;
|
||||
|
||||
const uint16_t HELP_PACKAGE_CAN_ID = 0x0FFFUL;
|
||||
const uint16_t SWITCH_TRIGGERED_CAN_ID = 0x0050;
|
||||
const uint16_t TRIGGER_SWITCH_CAN_ID = 0x0055;
|
||||
|
||||
|
||||
|
||||
void SetupMeyCan(byte majorHardwareVersion, byte minorHardwareVersion, byte deviceTypeId);
|
||||
uint32_t CreateCanId(uint16_t commandId);
|
||||
void SetDevicedId(byte high, byte low);
|
||||
void SetMeyPin(byte meyPinId, byte pinId);
|
||||
uint16_t GetDeviceId(uint32_t canFrameId);
|
||||
uint16_t GetPackageType(uint32_t canFrameId);
|
||||
void SendSwitchedTriggeredCanPackage(byte pinId, int state);
|
||||
|
||||
void HandleFrame(twai_message_t *frame);
|
||||
void CheckPinStatus(PinState *state);
|
||||
void CheckMeyPinsTriggered(); /* checks weather a meypin triggered and sends a can pkg is neccessary */
|
||||
|
||||
void DoSendCanPkg(twai_message_t *frame) ;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user