API  2.2
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
dio_read.c

This is an example showing how to read a value from a Digital Input/Output (DIO). If the selected DIO is at high level, we switch on a LED connected to another DIO.

/*
* @file dio_read.c
* @author TST
* @version V0.0
* @date 19/06/2012
* @brief DIO example. This is an example showing how to read a value from a Digital Input/Output (DIO).
* User must set a high level voltage (3.3 Volts) to the selected reading DIO, then the LED connected
* to its associated DIO will switch on.
*
*/
#include "tsmart.h"
/*
* Task function. Main process to read a selected DIO through its associated PIN and switch on a LED if we
* read a high level value.
*
*/
void vDIO_READ_EXAMPLE(void *pvParameters){
/* Variables */
uint8_t value = 0;
for(;;){
/* Read DIO. We read DIO1 */
/* If the value read is high ('1'), we switch on the LED connected to the DIO0a */
if(value == 1){
/* Set DIO. This function switches on/off the LED connected to DIO0a */
}else{
}
}
}
/*
* @brief init() function
*
* This is the first thing that the user must do for using TSmarT.
* It initializes the specific hardware resources (GPRS, GPS, AI, DIO, MODBUS, MSA...)
* and software resources (queues, mutex, tasks...) for the user application.
*
* The way to fill in this function properly is to initialize first
* hardware resources and after that software resources.
*
* This function must return: TSMART_PASS when every thing is OK or
* TSMART_FAIL when a failure happened.
*
* @return
* @arg TSMART_PASS
* @arg TSMART_FAIL
*/
int32_t init() {
/* Variables */
tsmart_dio_config_t tsmart_dio_config;
tsmart_dio_config_t tsmart_dio_config_read;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* DIO configuration. User needs to configure the DIO to connect a LED */
tsmart_dio_config.mode = TSMART_DIO_OD;
tsmart_dio_config.irq_mode = TSMART_DIO_IRQ_NULL;
/* DIO configuration for reading. User needs to define the DIO as an input */
tsmart_dio_config_read.mode = TSMART_DIO_IPU;
tsmart_dio_config_read.irq_mode = TSMART_DIO_IRQ_NULL;
/* Initialize DIOs
* User must initialize the DIOs to use. In this example one for reading a value and another one for
* connecting a LED */
TSMART_DIO_Init(&tsmart_dio0a, &tsmart_dio_config);
TSMART_DIO_Init(&tsmart_dio1a, &tsmart_dio_config_read);
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* Create the DIO_READ_EXAMPLE task */
if(xTaskCreate(vDIO_READ_EXAMPLE, "DIO_EXAMPLE", 512, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}