EasyManua.ls Logo

Bosch XDK110 - Reading Light Sensor Data

Bosch XDK110
25 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Workbench First Steps Guide XDK110
!
Page !19
XDK110 BCDS
© Bosch Connected Devices and Solutions GmbH reserves all rights even in the event of industrial property rights. We reserve all rights of disposal such as
copying and passing on to third parties. BOSCH and the symbol are registered trademarks of Robert Bosch GmbH, Germany.
Note: Specifications within this document are subject to change without notice.
The first expression is used to generate a return code. Afterwards the light sensor is initialised by
LightSensor_init(), which returns the return code that can be checked if the sensor was correctly
initiated.
3.2 Reading light sensor
After the correct initialization the sensor is ready to read. The following code snippet describes how a
function reading the incoming sensor data has to be implemented.
Code 10: Implementation to read the light sensor data
!
In code 7 the sensor value of the light sensor is read. The first expression is related to the freeRTOS
operating system and so not necessarily needed. It is only there to prevent a warning of the compiler. The
following declaration of the variable milliLuxData describes the generation of a 32-bit variable where the
light sensor data is stored. It follows the declaration of the condition state returnValue if the data could be
read. The next line of code describes the actual reading of the light sensor data via
LightSensor_readLuxData(). The display of the data takes place in the if bracket, the printf() is only
executed if the return value of LightSensor_readLuxData() is RETCODE_OK. This means that the reading of
the light sensor data was successful.
The initialization of the light sensor and a function that reads its data are implemented. Now a timer or
operating task has to be implemented that periodically reads the data und prints it to the XDK Workbench
console. Additionally to the code lines above the implementation of the timer task takes place in
appInitSystem(): The following code lines shows how to implement the required timer task.
/* Include this code in XdkApplicationTemplate.c */
static void readLightSensor(xTimerHandle xTimer)
{
(void) xTimer;
/* Read and print light sensor data */
uint32_t milliLuxData = UINT32_C(0);
Retcode_T returnValue = RETCODE_FAILURE;
returnValue = LightSensor_readLuxData(
xdkLightSensor_MAX44009_Handle,&milliLuxData);
if (RETCODE_OK == returnValue)
{
printf("Light sensor data obtained in milli lux :%d \n\r",(unsigned
int) milliLuxData);
}