Description
can_routine_callback()
– call-back method stub. Overwrite this method in your own class to be called regularly e.g. to do some background processing of your class.
class MY_CLASS : public SAMC21_CAN_RECEIVER
{
public:
void can_msg_recv_callback(const CANMessage & inMessage)
{ }
void can_routine_callback()
{ }
};
Syntax
void can_routine_callback()
{ }
Parameters
none
Returns
nothing
Example Code
Definition of a derived class that overwrites the call-back methodes.
class MY_ENGINE_CLASS : public SAMC21_CAN_RECEIVER
{
public:
uint32_t u32_RPM;
uint8_t s8_Temperature;
void can_msg_recv_callback(const CANMessage & inMessage)
{
if(inMessage.id == 0x123)
u32_RPM = inMessage.data32[0];
if(inMessage.id == 0x124)
s8_Temperature= inMessage.data[0];
}
void can_routine_callback()
{
static uint32_t u32_counter = 0;
u32_counter++;
if(u32_counter > 10000)
{
if(digitalRead(LED_BUILTIN))
digitalWrite(LED_BUILTIN, LOW);
else
digitalWrite(LED_BUILTIN, HIGH);
u32_counter = 0;
}
}
};
Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE -> CAN_Bus -> ReceiverClassExample
Notes and Warnings
It is common practise to only do calculations and to set variables in call-back routines.
Do not use any functions like delay(), yields(), println() etc. that would cause the re-entrance of the call-backs.
See also
SAMC21_CAN_RECEIVER()
can_msg_recv_callback()
regReceiver
deRegister
SAMC21_CAN – Library
CAN operation background