DolphinV4 API  1.6.1.0
Remote control



Application file - main.c

/************************************************************************-
EVA Board:
EVA300-2
Input PIN:
ADIO_3 send an RPS telegram with information light on
ADIO_4 send an RPS telegram with information light off
Output PIN:
none
Description:
Application demonstrating RPS telegram transmission - simulating a PTM200 switch.
Using the ADIO_3 and ADIO_4 an RPS switch with ON or OFF telegram can be transmitted in
the air. The application implements also a module to handle buttons states.
Notes:
In order to be able to use ISD51 target for debugging you will have to enable
the UART interface in DolphinStudio and actualise you EO3100I_CFG file.
-************************************************************************/
#include "EO3100I_API.h"
#include "EO3100I_CFG.h"
#include "mod_button.h"
code uint8 VERSION_APP[] = {0xE0,'V','E','R','S','I','O','N',1,0,1,1,'A','R', 'E', 'M', 'O', 'T', 'E','C','O','N','T','R','O','L',0x00,0xE0};
// Define buttons
BTN_STRUCT buttonA = { ADIO_3, // Pin
0, // Active state low
10, // Time the button has to be in 'Active state' to be recognized as pressed
100 };
BTN_STRUCT buttonB = { ADIO_4, // Pin
0, // Active state low
10, // Time the button has to be in 'Active state' to be recognized as pressed
100 };
void main()
{
mainInit();
// Header: Only 32 bit Originator-ID, no extended Header, RPS telegram
// SourceID: set to 0x0000000, will be replaced in radio_sendTelegram() by the Module ID
rTel2.raw.bytes[1] = 0; // Id
rTel2.raw.bytes[2] = 0; // Id
rTel2.raw.bytes[3] = 0; // Id
rTel2.raw.bytes[4] = 0; // Id
// Data
rTel2.raw.bytes[5] = 0x00;
// Length
rTel2.raw.u8Length = 7;
// Telegram paraters: subtelegram count
pTel2.p_tx.u8SubTelNum = 3; // Send 3 subtelegrams
while (1)
{
// Check buttons
if (btn_getState(&buttonA)==BTN_PRESSED)
{
rTel2.raw.bytes[5] = 0x50; // Data
while (radio_sendTelegram2(&rTel2, &pTel2)==BUFF_FULL);
}
if (btn_getState(&buttonB)==BTN_PRESSED)
{
rTel2.raw.bytes[5] = 0x70; // Data
while (radio_sendTelegram2(&rTel2, &pTel2)==BUFF_FULL);
}
}
}



Module for handling buttons - mod_button.c

#include <EO3100I_API.h>
#include "mod_button.h"
BTN_STATE btn_getState(BTN_STRUCT *pBtn)
{
code uint8 transition_table[8][4]={ 0, 1, 0, 1,
5, 2, 5, 1,
5, 2, 5, 3,
5, 4, 5, 4,
5, 4, 5, 4,
6, 1, 0, 1,
6, 1, 7, 1,
0, 1, 0, 1 };
register uint8 u8Input;
// Get button state
io_getDigital(pBtn->u8Pin, &u8Input);
u8Input = (u8Input == pBtn->u8ActiveState)?1:0;
// Get timeout state
u8Input |= ((time_getTimeOut(&(pBtn->tTimer))==TIME_OUT)?2:0);
// Get new state
pBtn->u8State = transition_table[pBtn->u8State][u8Input]; // we want only the state, not action
// Perform action
switch (pBtn->u8State)
{
case 1:
time_setTimerCount(&(pBtn->tTimer), pBtn->u16TimeOutON);
break;
case 5:
time_setTimerCount(&(pBtn->tTimer), pBtn->u16TimeOutOFF);
break;
}
return pBtn->u8State;
}



Module for handling buttons - mod_button.h

#ifndef _MOD_BUTTON_H_INCLUDED
#define _MOD_BUTTON_H_INCLUDED
#include <EO3100I_API.h>
/*
Timeout ON
_______|_____
P | | Timeout OFF
R ___________| |________|____
^ ^ ^ ^ ^ ^ ^ ^
S 0 1 2 3 4 5 6 7
P - pressed, R - released, S - BTN_STATE
*/
typedef struct
{
// Public
uint8 u8Pin; // e.g. ADIO0
uint8 u8ActiveState; // button is pressed if (io_getDigital(u8Button)==bActiveState)
uint16 u16TimeOutON; // time the button has to be pressed to be recognized as pressed
uint16 u16TimeOutOFF; // time the button has to be pressed to be recognized as released
// Private
TIMER_TYPE tTimer;
uint8 u8State;
} BTN_STRUCT;
typedef enum
{
BTN_IDLE = 0,
BTN_EDGE1,
BTN_TRIGGERED,
BTN_PRESSED, //< most important
BTN_PRESS_HOLD,
BTN_EDGE2,
BTN_RELEASE_HOLD,
BTN_RELEASED
} BTN_STATE;
BTN_STATE btn_getState(BTN_STRUCT *pBtn);
#endif //_MOD_BUTTON_H_INCLUDED



Config file - EO3100I_CFG.h

// Generated on 2013-06-07 13:33:17 by DolphinAPIConfigurator 1.1.0.20
#ifndef _EO3100I_CFG_H_INCLUDED
#define _EO3100I_CFG_H_INCLUDED
void startupInit();
void mainInit();
//*********************RADIO PARAM***************************
#define RADIO_BUFF_NUM 10
#define RADIO_MATURITY_TIME 100
extern volatile RADIO_BUFFER_TYPE xdata gRadioBuff[RADIO_BUFF_NUM];
//*********************FILTER PARAM***************************
#define FILTER_NUM 1
extern volatile uint32 xdata u32gFilterValue[FILTER_NUM];
extern volatile uint8 xdata u8gFilterCfg[FILTER_NUM];
//*********************IO PARAM******************************
extern uint8 code io_param[];
#endif //_EO3100I_CFG_H_INCLUDED



Config file - EO3100I_CFG.c

// Generated on 2013-06-07 13:33:09 by DolphinAPIConfigurator 1.1.0.20
#include "EO3100I_API.h"
#include "EO3100I_CFG.h"
//*********************API INIT***************************
//Note: Function is called from startup.a51. Global variables are not yet initialized!
void startupInit()
{
io_init(io_param);
}
void mainInit()
{
radio_init(RADIO_BUFF_NUM, RADIO_MATURITY_TIME);
}
//*********************RADIO PARAM***************************
volatile RADIO_BUFFER_TYPE xdata gRadioBuff[RADIO_BUFF_NUM];
//*********************FILTER PARAM***************************
volatile uint32 xdata u32gFilterValue[FILTER_NUM];
volatile uint8 xdata u8gFilterCfg[FILTER_NUM];
//*********************IO PARAM******************************
uint8 code io_param[] = {
0x07, //IDX_GPIO_CONF
0x00, //IDX_GPIO0_CONF
0x0F, //IDX_GPIO0_PULL_CONF
0x00, //IDX_GPIO0_DIR
0x00, //IDX_GPIO1_AN
0x00, //IDX_GPIO1_CONF0
0x00, //IDX_GPIO1_CONF1
0x03, //IDX_GPIO1_DIG_CONF
0x00, //IDX_GPIO1_DIR
0xFF, //IDX_GPIO1_PULL
0x0C, //IDX_GPIO2_CONF
0x00, //IDX_GPIO2_DIR
0x00, //IDX_GPIO0
0x00, //IDX_GPIO1
0x00, //IDX_GPIO2
};
// I/O Configuration overview
//
// Pin : Interface Direction Pull InitValue Interrupt
// SCSEDIO0 : Digital I/O In Up 0 No
// SCLKDIO1 : Digital I/O In Up 0 No
// WSDADIO2 : Digital I/O In Up 0 No
// RSDADIO3 : Digital I/O In Up 0 No
// ADIO0 : Digital I/O In Up 0 No
// ADIO1 : Digital I/O In Up 0 No
// ADIO2 : Digital I/O In Up 0 No
// ADIO3 : Digital I/O In Up 0 No
// ADIO4 : Digital I/O In Up 0 No
// ADIO5 : Digital I/O In Up 0 No
// ADIO6 : Digital I/O In Up 0 No
// ADIO7 : Digital I/O In Up 0 No
// WXIDIO : Digital I/O In Up 0 No
// WXODIO : Digital I/O In Up 0 No
// WAKE0 : Digital I/O In None 0 No
// WAKE1 : Digital I/O In None 0 No