Callback example
Callback example
#include <io>
#include <read>
#include <float>
#include <string>
#include <core>
#include <write>
#include <define>
#include <socket>
#define TIMER_CALLBACK_PERIOD 30000
#define CAN_BUS_BAUDRATE 500000
forward public callback (event);
forward ibutton_id_cb_do();
forward go_to_sleep_cb_do();
forward can_1_cb_do();
forward can_2_cb_do();
forward timer_cb_do();
forward sms_cb_do();
forward socket_closed_cb_do();
forward socket_data_received_cb_do();
forward socket_sent_cb_do();
forward accelerometer_cb_do();
forward mqtt_publish_pending_cb_do();
forward messages_received_cb_do();
forward remote_command_cb_do();
// Remove all callback cases that are not going to be used.
public callback (event)
{
switch(event)
{
case IBUTTON_ID:
{
ibutton_id_cb_do();
}
case GO_TO_SLEEP:
{
go_to_sleep_cb_do();
}
case CAN1:
{
can_1_cb_do();
}
case CAN2:
{
can_2_cb_do();
}
case TIMER1:
{
timer_cb_do();
}
case SMS:
{
sms_cb_do();
}
case SOCKET_CLOSED:
{
socket_closed_cb_do();
}
case SOCKET_DATA_RECEIVED:
{
socket_data_received_cb_do();
}
case SOCKET_SENT:
{
socket_sent_cb_do();
}
case ACCELEROMETER:
{
accelerometer_cb_do();
}
case MQTT_PUBLISH_PENDING:
{
mqtt_publish_pending_cb_do();
}
case MESSAGES_RECEIVED:
{
messages_received_cb_do();
}
case REMOTE_COMMAND:
{
remote_command_cb_do();
}
}
return 0;
}
// Remove any functions that are not intended to be used or called.
ibutton_id_cb_do()
{
// Ibutton callback, meaning Ibutton is present, do what you want in this callback
}
go_to_sleep_cb_do()
{
// Go to sleep callback, meaning that module is going to sleep soon, do what you want in this callback
}
can_1_cb_do()
{
// CAN1 callback, meaning CAN message is received in CAN1, do what you want in this callback
}
can_2_cb_do()
{
// CAN2 callback, meaning CAN message is received in CAN2, do what you want in this callback
}
timer_cb_do()
{
// TIMER1 callback, meaning TIMER1 time period has passed and it's time to jump back into this callback, do what you want in this callback
}
sms_cb_do()
{
// SMS callback, meaning SMS message has been received, do what you want in this callback
}
socket_closed_cb_do()
{
// Socket closed callback, meaning that socket has been closed, do what you want in this callback
}
socket_data_received_cb_do()
{
// Socket data received callback, meaning that data was received via socket, do what you want in this callback
}
socket_sent_cb_do()
{
// Socket sent callback, meaning that data was succesfully sent via socket, do what you want in this callback
}
accelerometer_cb_do()
{
// Accelerometer callback, meaning that new Accelerometer value has been received, do what you want in this callback
}
mqtt_publish_pending_cb_do()
{
// MQTT publish pending callback, meaning that there's data waiting to be sent via MQTT, do what you want in this callback
}
messages_received_cb_do()
{
// Messages received callback, meaning that new message was received from other SCRIPT, do what you want in this callback
}
remote_command_cb_do()
{
// Remote command callback, meaning that new message was received from other SCRIPT, do what you want in this callback
}
main()
{
// The code below, which will not be in use, should be removed
Init(IBUTTON_ID); // Initializes IBUTTON_ID callback
Init(CAN1, NORMAL, CAN_BUS_BAUDRATE); // Initializes CAN1 and CAN1 callback
Init(CAN2, NORMAL, CAN_BUS_BAUDRATE); // Initializes CAN2 and CAN2 callback
Init(MQTT_PUBLISH_PENDING); // Initializes MQTT_PUBLISH_PENDING callback
Init(TIMER1, TIMER_CALLBACK_PERIOD); // Initializes TIMER1 callback
Init(ACCELEROMETER, false); // Initializes ACCELEROMETER calback
Init(REMOTE_COMMAND); // Initializes REMOTE_COMMAND callback
for(;;)
{
Delay(1000);
}
}