BigW Consortium Gitlab

Commit 1c8cdd21 by Ashish Syal

Added mangoh yellowsensor to cloud

parent 89414340
//--------------------------------------------------------------------------------------------------
/**
* Component definition file for the file utilities component.
*/
//--------------------------------------------------------------------------------------------------
sources:
{
fileUtils.c
}
//--------------------------------------------------------------------------------------------------
/**
* @file fileUtils.c
*
* Utility functions used to read numbers from sysfs files.
*
* Copyright (C) Sierra Wireless Inc.
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "fileUtils.h"
//--------------------------------------------------------------------------------------------------
/**
* Read a signed integer from a sysfs file (convert the string contents to a number).
*
* @return
* - LE_OK if successful
* - LE_IO_ERROR if the file could not be opened.
* - LE_FORMAT_ERROR if the file contents could not be converted into a signed integer.
*/
//--------------------------------------------------------------------------------------------------
le_result_t file_ReadInt
(
const char *filePath,
int *value
)
{
le_result_t r = LE_OK;
FILE *f = fopen(filePath, "r");
if (f == NULL)
{
LE_WARN("Couldn't open '%s' - %m", filePath);
r = LE_IO_ERROR;
goto done;
}
int numScanned = fscanf(f, "%d", value);
if (numScanned != 1)
{
r = LE_FORMAT_ERROR;
}
fclose(f);
done:
return r;
}
//--------------------------------------------------------------------------------------------------
/**
* Read a floating point number from a sysfs file (convert the string contents to a number).
*
* @return
* - LE_OK if successful
* - LE_IO_ERROR if the file could not be opened.
* - LE_FORMAT_ERROR if the file contents could not be converted into a number.
*/
//--------------------------------------------------------------------------------------------------
le_result_t file_ReadDouble
(
const char *filePath,
double *value
)
{
le_result_t r = LE_OK;
FILE *f = fopen(filePath, "r");
if (f == NULL)
{
LE_WARN("Couldn't open '%s' - %m", filePath);
r = LE_IO_ERROR;
goto done;
}
int numScanned = fscanf(f, "%lf", value);
if (numScanned != 1)
{
r = LE_FORMAT_ERROR;
}
fclose(f);
done:
return r;
}
COMPONENT_INIT
{
}
//--------------------------------------------------------------------------------------------------
/**
* @file fileUtils.h
*
* Utility functions used to read numbers from sysfs files.
*
* Copyright (C) Sierra Wireless Inc.
*/
//--------------------------------------------------------------------------------------------------
#ifndef FILE_UTILS_H_INCLUDE_GUARD
#define FILE_UTILS_H_INCLUDE_GUARD
//--------------------------------------------------------------------------------------------------
/**
* Read a signed integer from a sysfs file (convert the string contents to a number).
*
* @return
* - LE_OK if successful
* - LE_IO_ERROR if the file could not be opened.
* - LE_FORMAT_ERROR if the file contents could not be converted into a signed integer.
*/
//--------------------------------------------------------------------------------------------------
LE_SHARED le_result_t file_ReadInt
(
const char *filePath,
int *value
);
//--------------------------------------------------------------------------------------------------
/**
* Read a floating point number from a sysfs file (convert the string contents to a number).
*
* @return
* - LE_OK if successful
* - LE_IO_ERROR if the file could not be opened.
* - LE_FORMAT_ERROR if the file contents could not be converted into a number.
*/
//--------------------------------------------------------------------------------------------------
LE_SHARED le_result_t file_ReadDouble
(
const char *filePath,
double *value
);
#endif // FILE_UTILS_H_INCLUDE_GUARD
//--------------------------------------------------------------------------------------------------
/**
* Component definition file for the mangOH Yellow pressure/temperature/gas sensor interface component.
*/
//--------------------------------------------------------------------------------------------------
cflags:
{
-I$LEGATO_ROOT/apps/sample/dataHub/components/periodicSensor
-std=c99
-I$CURDIR/../../fileUtils
}
provides:
{
api:
{
$CURDIR/../../../interfaces/pressure.api
$CURDIR/../../../interfaces/temperature.api
$CURDIR/../../../interfaces/gas.api
$CURDIR/../../../interfaces/humidity.api
}
}
requires:
{
api:
{
dhubIO = io.api
}
component:
{
$LEGATO_ROOT/apps/sample/dataHub/components/periodicSensor
../../fileUtils
}
file:
{
#if ${LEGATO_TARGET} = wp85
/sys/bus/i2c/devices/2-0076/iio:device0/in_temp_input /driver/
/sys/bus/i2c/devices/2-0076/iio:device0/in_pressure_input /driver/
/sys/bus/i2c/devices/2-0076/iio:device0/in_resistance_input /driver/
/sys/bus/i2c/devices/2-0076/iio:device0/in_humidityrelative_input /driver/
#elif ${LEGATO_TARGET} = wp750x
/sys/bus/i2c/devices/2-0076/iio:device0/in_temp_input /driver/
/sys/bus/i2c/devices/2-0076/iio:device0/in_pressure_input /driver/
/sys/bus/i2c/devices/2-0076/iio:device0/in_resistance_input /driver/
/sys/bus/i2c/devices/2-0076/iio:device0/in_humidityrelative_input /driver/
#elif ${LEGATO_TARGET} = wp76xx
/sys/bus/i2c/devices/6-0076/iio:device0/in_temp_input /driver/
/sys/bus/i2c/devices/6-0076/iio:device0/in_pressure_input /driver/
/sys/bus/i2c/devices/6-0076/iio:device0/in_resistance_input /driver/
/sys/bus/i2c/devices/6-0076/iio:device0/in_humidityrelative_input /driver/
#elif ${LEGATO_TARGET} = wp77xx
/sys/bus/i2c/devices/6-0076/iio:device0/in_temp_input /driver/
/sys/bus/i2c/devices/6-0076/iio:device0/in_pressure_input /driver/
/sys/bus/i2c/devices/6-0076/iio:device0/in_resistance_input /driver/
/sys/bus/i2c/devices/6-0076/iio:device0/in_humidityrelative_input /driver/
#endif
}
}
sources:
{
environmentSensor.c
}
//--------------------------------------------------------------------------------------------------
/**
* @file pressureSensor.c
*
* Implementation of the mangOH Yellow pressure/temperature/gas/humidity sensor interface component.
*
* Publishes the pressure, temperature, humidity and gas readings to the Data Hub.
*
* Copyright (C) Sierra Wireless Inc.
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "interfaces.h"
#include "periodicSensor.h"
#include "fileUtils.h"
static const char PressureFile[] = "/driver/in_pressure_input";
static const char TemperatureFile[] = "/driver/in_temp_input";
static const char GasFile[] = "/driver/in_resistance_input";
static const char HumidityFile[] = "/driver/in_humidityrelative_input";
static void SamplePressure
(
psensor_Ref_t ref
)
{
double sample;
le_result_t result = pressure_Read(&sample);
if (result == LE_OK)
{
psensor_PushNumeric(ref, 0 /* now */, sample);
}
else
{
LE_ERROR("Failed to read sensor (%s).", LE_RESULT_TXT(result));
}
}
static void SampleTemperature
(
psensor_Ref_t ref
)
{
double sample;
le_result_t result = temperature_Read(&sample);
if (result == LE_OK)
{
psensor_PushNumeric(ref, 0 /* now */, sample);
}
else
{
LE_ERROR("Failed to read sensor (%s).", LE_RESULT_TXT(result));
}
}
static void SampleGas
(
psensor_Ref_t ref
)
{
double sample;
le_result_t result = gas_Read(&sample);
if (result == LE_OK)
{
psensor_PushNumeric(ref, 0 /* now */, sample);
}
else
{
LE_ERROR("Failed to read sensor (%s)", LE_RESULT_TXT(result));
}
}
static void SampleHumidity
(
psensor_Ref_t ref
)
{
double sample;
le_result_t result = humidity_Read(&sample);
if (result == LE_OK)
{
psensor_PushNumeric(ref, 0 /* now */, sample);
}
else
{
LE_ERROR("Failed to read sensor (%s)", LE_RESULT_TXT(result));
}
}
//--------------------------------------------------------------------------------------------------
/**
* Read the air pressure measurement in kiloPascals (kPa).
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
le_result_t pressure_Read
(
double* readingPtr
///< [OUT] Where the pressure reading (kPa) will be put if LE_OK is returned.
)
{
return file_ReadDouble(PressureFile, readingPtr);
}
//--------------------------------------------------------------------------------------------------
/**
* Read the temperature measurement.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
le_result_t temperature_Read
(
double* readingPtr
///< [OUT] Where the reading (in degrees C) will be put if LE_OK is returned.
)
{
int temp;
le_result_t r = file_ReadInt(TemperatureFile, &temp);
if (r != LE_OK)
{
return r;
}
// The divider is 1000 based on the comments in the kernel driver on bmp280_compensate_temp()
// which is called by bmp280_read_temp()
*readingPtr = ((double)temp);
return LE_OK;
}
//--------------------------------------------------------------------------------------------------
/**
* Read the gas measurement.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
le_result_t gas_Read
(
double* readingPtr
///< [OUT] Where the reading (in kilo Ohms) will be put if LE_OK is returned.
)
{
int gas;
le_result_t r = file_ReadInt(GasFile, &gas);
if (r != LE_OK)
{
return r;
}
// The divider is 1000 based on the comments in the kernel driver on bmp280_compensate_gas()
// which is called by bmp280_read_gas()
*readingPtr = ((double)gas) / 1000.0;
return LE_OK;
}
//--------------------------------------------------------------------------------------------------
/**
* Read the humidity measurement.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
le_result_t humidity_Read
(
double* readingPtr
///< [OUT] Where the reading (in %rH) will be put if LE_OK is returned.
)
{
int humidity;
le_result_t r = file_ReadInt(HumidityFile, &humidity);
if (r != LE_OK)
{
return r;
}
*readingPtr = (double)humidity ;
return LE_OK;
}
COMPONENT_INIT
{
// Use the periodic sensor component from the Data Hub to implement the timers and the
// interface to the Data Hub.
psensor_Create("environment/pressure", DHUBIO_DATA_TYPE_NUMERIC, "kPa", SamplePressure);
psensor_Create("environment/temp", DHUBIO_DATA_TYPE_NUMERIC, "degC", SampleTemperature);
psensor_Create("environment/gas", DHUBIO_DATA_TYPE_NUMERIC, "kOhms", SampleGas);
psensor_Create("environment/humidity", DHUBIO_DATA_TYPE_NUMERIC, "%rH", SampleHumidity);
}
#ifndef ENVIRONMENT_SENSOR_H
#define ENVIRONMENT_SENSOR_H
LE_SHARED le_result_t mangOH_ReadPressureSensor(double *reading);
LE_SHARED le_result_t mangOH_ReadTemperatureSensor(double *reading);
LE_SHARED le_result_t mangOH_ReadGasSensor(double *reading);
LE_SHARED le_result_t mangOH_ReadHumiditySensor(double *reading);
#endif // ENVIRONMENT_SENSOR_H
//--------------------------------------------------------------------------------------------------
/**
* Component definition file for the mangOH Red Inertial Measurement Unit (IMU)
* sensor interface component.
*/
//--------------------------------------------------------------------------------------------------
cflags:
{
-I$CURDIR/../../fileUtils
-I$LEGATO_ROOT/apps/sample/dataHub/components/periodicSensor
-std=c99
}
provides:
{
api:
{
$CURDIR/../../../interfaces/imu.api
$CURDIR/../../../interfaces/temperature.api
}
}
requires:
{
api:
{
dhubIO = io.api
}
component:
{
../../fileUtils
$LEGATO_ROOT/apps/sample/dataHub/components/periodicSensor
}
file:
{
#if ${LEGATO_TARGET} = wp85
/sys/bus/i2c/devices/2-0068/iio:device1/in_accel_x_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_accel_y_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_accel_z_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_accel_scale /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_anglvel_x_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_anglvel_y_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_anglvel_z_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_anglvel_scale /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_temp_scale /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_temp_offset /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_temp_raw /driver/
#elif ${LEGATO_TARGET} = wp750x
/sys/bus/i2c/devices/2-0068/iio:device1/in_accel_x_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_accel_y_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_accel_z_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_accel_scale /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_anglvel_x_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_anglvel_y_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_anglvel_z_raw /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_anglvel_scale /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_temp_scale /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_temp_offset /driver/
/sys/bus/i2c/devices/2-0068/iio:device1/in_temp_raw /driver/
#elif ${LEGATO_TARGET} = wp76xx
/sys/bus/i2c/devices/6-0068/iio:device1/in_accel_x_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_accel_y_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_accel_z_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_accel_scale /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_anglvel_x_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_anglvel_y_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_anglvel_z_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_anglvel_scale /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_temp_scale /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_temp_offset /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_temp_raw /driver/
#elif ${LEGATO_TARGET} = wp77xx
/sys/bus/i2c/devices/6-0068/iio:device1/in_accel_x_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_accel_y_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_accel_z_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_accel_scale /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_anglvel_x_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_anglvel_y_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_anglvel_z_raw /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_anglvel_scale /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_temp_scale /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_temp_offset /driver/
/sys/bus/i2c/devices/6-0068/iio:device1/in_temp_raw /driver/
#endif
}
}
sources:
{
imu.c
}
//--------------------------------------------------------------------------------------------------
/**
* Implementation of the mangOH Red Inertial Measurement Unit (IMU) sensor interface.
*
* Provides the accelerometer and gyro IPC API services and plugs into the Legato Data Hub.
*
* Copyright (C) Sierra Wireless Inc.
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "interfaces.h"
#include "imu.h"
#include "fileUtils.h"
#include "periodicSensor.h"
//--------------------------------------------------------------------------------------------------
/**
* Read the accelerometer's linear acceleration measurement in meters per second squared.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
le_result_t imu_ReadAccel
(
double* xPtr,
///< [OUT] Where the x-axis acceleration (m/s2) will be put if LE_OK is returned.
double* yPtr,
///< [OUT] Where the y-axis acceleration (m/s2) will be put if LE_OK is returned.
double* zPtr
///< [OUT] Where the z-axis acceleration (m/s2) will be put if LE_OK is returned.
)
{
le_result_t r;
double scaling = 0.0;
r = file_ReadDouble("/driver/in_accel_scale", &scaling);
if (r != LE_OK)
{
goto done;
}
r = file_ReadDouble("/driver/in_accel_x_raw", xPtr);
if (r != LE_OK)
{
goto done;
}
*xPtr *= scaling;
r = file_ReadDouble("/driver/in_accel_y_raw", yPtr);
if (r != LE_OK)
{
goto done;
}
*yPtr *= scaling;
r = file_ReadDouble("/driver/in_accel_z_raw", zPtr);
if (r != LE_OK)
{
goto done;
}
*zPtr *= scaling;
done:
return r;
}
//--------------------------------------------------------------------------------------------------
/**
* Read the gyroscope's angular velocity measurement in radians per seconds.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
le_result_t imu_ReadGyro
(
double* xPtr,
///< [OUT] Where the x-axis rotation (rads/s) will be put if LE_OK is returned.
double* yPtr,
///< [OUT] Where the y-axis rotation (rads/s) will be put if LE_OK is returned.
double* zPtr
///< [OUT] Where the z-axis rotation (rads/s) will be put if LE_OK is returned.
)
{
le_result_t r;
double scaling = 0.0;
r = file_ReadDouble("/driver/in_anglvel_scale", &scaling);
if (r != LE_OK)
{
goto done;
}
r = file_ReadDouble("/driver/in_anglvel_x_raw", xPtr);
if (r != LE_OK)
{
goto done;
}
*xPtr *= scaling;
r = file_ReadDouble("/driver/in_anglvel_y_raw", yPtr);
if (r != LE_OK)
{
goto done;
}
*yPtr *= scaling;
r = file_ReadDouble("/driver/in_anglvel_z_raw", zPtr);
if (r != LE_OK)
{
goto done;
}
*zPtr *= scaling;
done:
return r;
}
//--------------------------------------------------------------------------------------------------
/**
* Read the temperature measurement.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
le_result_t temperature_Read
(
double* readingPtr
///< [OUT] Where the reading (in degrees C) will be put if LE_OK is returned.
)
{
le_result_t r;
double scaling = 0.0;
r = file_ReadDouble("/driver/in_temp_scale", &scaling);
if (r != LE_OK)
{
LE_ERROR("Failed to read scale");
goto done;
}
double offset = 0.0;
r = file_ReadDouble("/driver/in_temp_offset", &offset);
if (r != LE_OK)
{
LE_ERROR("Failed to read offset (%s)", LE_RESULT_TXT(r));
goto done;
}
r = file_ReadDouble("/driver/in_temp_raw", readingPtr);
if (r != LE_OK)
{
LE_ERROR("Failed to read raw value (%s)", LE_RESULT_TXT(r));
goto done;
}
*readingPtr = (*readingPtr + offset) * scaling / 1000;
done:
return r;
}
//--------------------------------------------------------------------------------------------------
/**
* Sample the gyroscope and publish the results to the Data Hub.
*/
//--------------------------------------------------------------------------------------------------
static void SampleGyro
(
psensor_Ref_t ref
)
{
double x;
double y;
double z;
le_result_t result = imu_ReadGyro(&x, &y, &z);
if (result == LE_OK)
{
char sample[256];
int len = snprintf(sample, sizeof(sample), "{\"x\":%lf, \"y\":%lf, \"z\":%lf}", x, y, z);
if (len >= sizeof(sample))
{
LE_FATAL("JSON string (len %d) is longer than buffer (size %zu).", len, sizeof(sample));
}
psensor_PushJson(ref, 0 /* now */, sample);
}
else
{
LE_ERROR("Failed to read gyro (%s).", LE_RESULT_TXT(result));
}
}
//--------------------------------------------------------------------------------------------------
/**
* Sample the accelerometer and publish the results to the Data Hub.
*/
//--------------------------------------------------------------------------------------------------
static void SampleAccel
(
psensor_Ref_t ref
)
{
double x;
double y;
double z;
le_result_t result = imu_ReadAccel(&x, &y, &z);
if (result == LE_OK)
{
char sample[256];
int len = snprintf(sample, sizeof(sample), "{\"x\":%lf, \"y\":%lf, \"z\":%lf}", x, y, z);
if (len >= sizeof(sample))
{
LE_FATAL("JSON string (len %d) is longer than buffer (size %zu).", len, sizeof(sample));
}
psensor_PushJson(ref, 0 /* now */, sample);
}
else
{
LE_ERROR("Failed to read accelerometer (%s).", LE_RESULT_TXT(result));
}
}
//--------------------------------------------------------------------------------------------------
/**
* Sample the temperature and publish the results to the Data Hub.
*/
//--------------------------------------------------------------------------------------------------
static void SampleTemp
(
psensor_Ref_t ref
)
{
double sample;
le_result_t result = temperature_Read(&sample);
if (result == LE_OK)
{
psensor_PushNumeric(ref, 0 /* now */, sample);
}
else
{
LE_ERROR("Failed to read IMU temperature (%s).", LE_RESULT_TXT(result));
}
}
//--------------------------------------------------------------------------------------------------
/**
* Initializes the IMU component.
*/
//--------------------------------------------------------------------------------------------------
COMPONENT_INIT
{
// Use the Periodic Sensor component from the Data Hub to implement the sensor interfaces.
psensor_Create("gyro", DHUBIO_DATA_TYPE_JSON, "", SampleGyro);
psensor_Create("accel", DHUBIO_DATA_TYPE_JSON, "", SampleAccel);
psensor_Create("imu/temp", DHUBIO_DATA_TYPE_NUMERIC, "degC", SampleTemp);
}
//--------------------------------------------------------------------------------------------------
/**
* @file imu.h
*
* Inertial Measurement Unit (IMU) sensor interface. Provides an interface between the Linux
* kernel driver for the IMU and the Legato Data Hub.
*
* Copyright (C) Sierra Wireless Inc.
*/
//--------------------------------------------------------------------------------------------------
#ifndef IMU_H_INCLUDE_GUARD
#define IMU_H_INCLUDE_GUARD
LE_SHARED le_result_t mangOH_ReadAccelerometer(double *xAcc, double *yAcc, double *zAcc);
LE_SHARED le_result_t mangOH_ReadGyro(double *x, double *y, double *z);
LE_SHARED le_result_t mangOH_ReadImuTemp(double *temperature);
#endif // IMU_H_INCLUDE_GUARD
//--------------------------------------------------------------------------------------------------
/**
* Component definition file for the mangOH Yellow Light
* sensor interface component.
*/
//--------------------------------------------------------------------------------------------------
cflags:
{
-I$CURDIR/../../fileUtils
-I$LEGATO_ROOT/apps/sample/dataHub/components/periodicSensor
// -I${MANGOH_ROOT}/components/libiioComponent/libiio
-std=c99
}
provides:
{
api:
{
$CURDIR/../../../interfaces/light.api
}
}
requires:
{
api:
{
dhubIO = io.api
}
component:
{
../../fileUtils
$LEGATO_ROOT/apps/sample/dataHub/components/periodicSensor
// ${MANGOH_ROOT}/components/libiioComponent
}
file:
{
#if ${LEGATO_TARGET} = wp85
/sys/bus/i2c/devices/3-0044/iio:device3/in_illuminance_input /driver/
#elif ${LEGATO_TARGET} = wp750x
/sys/bus/i2c/devices/3-0044/iio:device3/in_illuminance_input /driver/
#elif ${LEGATO_TARGET} = wp76xx
/sys/bus/i2c/devices/7-0044/iio:device3/in_illuminance_input /driver/
#elif ${LEGATO_TARGET} = wp77xx
/sys/bus/i2c/devices/7-0044/iio:device3/in_illuminance_input /driver/
#endif
}
/* lib:
{
libiio.so
libiio.so.0:Ex
libiio.so.0.15
}*/
}
sources:
{
lightSensor.c
}
//--------------------------------------------------------------------------------------------------
/**
* Implementation of the mangOH Red light sensor interface.
*
* Provides the accelerometer and gyro IPC API services and plugs into the Legato Data Hub.
*
* Copyright (C) Sierra Wireless Inc.
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "interfaces.h"
#include "periodicSensor.h"
#include "lightSensor.h"
#include "fileUtils.h"
static const char LightFile[] = "/driver/in_illuminance_input";
//--------------------------------------------------------------------------------------------------
/**
* Read the light measurement.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
le_result_t light_Read
(
double* readingPtr
///< [OUT] Where the reading (in LUX ) will be put if LE_OK is returned.
)
{
double light;
le_result_t r = file_ReadDouble( LightFile, &light);
if (r != LE_OK)
{
return r;
}
*readingPtr = ((double)light);
return LE_OK;
}
static void SampleLight
(
psensor_Ref_t ref
)
{
double sample;
le_result_t result = light_Read(&sample);
if (result == LE_OK)
{
psensor_PushNumeric(ref, 0 /* now */, sample);
}
else
{
LE_ERROR("Failed to read sensor (%s).", LE_RESULT_TXT(result));
}
}
COMPONENT_INIT
{
psensor_Create("light", DHUBIO_DATA_TYPE_NUMERIC, "lux", SampleLight);
}
#ifndef LIGHT_SENSOR_H
#define LIGHT_SENSOR_H
LE_SHARED le_result_t mangOH_ReadLightSensor(double *reading);
#endif // LIGHT_SENSOR_H
//--------------------------------------------------------------------------------------------------
/**
* Component definition file for the mangOH Red Inertial Measurement Unit (IMU)
* sensor interface component.
*/
//--------------------------------------------------------------------------------------------------
cflags:
{
-I$CURDIR/../../fileUtils
-I$LEGATO_ROOT/apps/sample/dataHub/components/periodicSensor
-std=c99
}
provides:
{
api:
{
$CURDIR/../../../interfaces/magn.api
}
}
requires:
{
api:
{
dhubIO = io.api
}
component:
{
../../fileUtils
$LEGATO_ROOT/apps/sample/dataHub/components/periodicSensor
}
file:
{
#if ${LEGATO_TARGET} = wp85
/sys/bus/i2c/devices/2-0010/iio:device2/in_magn_x_raw /driver/
/sys/bus/i2c/devices/2-0010/iio:device2/in_magn_y_raw /driver/
/sys/bus/i2c/devices/2-0010/iio:device2/in_magn_z_raw /driver/
/sys/bus/i2c/devices/2-0010/iio:device2/in_magn_scale /driver/
#elif ${LEGATO_TARGET} = wp750x
/sys/bus/i2c/devices/2-0010/iio:device2/in_magn_x_raw /driver/
/sys/bus/i2c/devices/2-0010/iio:device2/in_magn_y_raw /driver/
/sys/bus/i2c/devices/2-0010/iio:device2/in_magn_z_raw /driver/
/sys/bus/i2c/devices/2-0010/iio:device2/in_magn_scale /driver/
#elif ${LEGATO_TARGET} = wp76xx
/sys/bus/i2c/devices/6-0010/iio:device2/in_magn_x_raw /driver/
/sys/bus/i2c/devices/6-0010/iio:device2/in_magn_y_raw /driver/
/sys/bus/i2c/devices/6-0010/iio:device2/in_magn_z_raw /driver/
/sys/bus/i2c/devices/6-0010/iio:device2/in_magn_scale /driver/
#elif ${LEGATO_TARGET} = wp77xx
/sys/bus/i2c/devices/6-0010/iio:device2/in_magn_x_raw /driver/
/sys/bus/i2c/devices/6-0010/iio:device2/in_magn_y_raw /driver/
/sys/bus/i2c/devices/6-0010/iio:device2/in_magn_z_raw /driver/
/sys/bus/i2c/devices/6-0010/iio:device2/in_magn_scale /driver/
#endif
}
}
sources:
{
magn.c
}
//--------------------------------------------------------------------------------------------------
/**
* Implementation of the mangOH Yellow Magnetometer sensor interface.
*
* Provides the magnetometer IPC API services and plugs into the Legato Data Hub.
*
* Copyright (C) Sierra Wireless Inc.
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "interfaces.h"
#include "magn.h"
#include "fileUtils.h"
#include "periodicSensor.h"
//--------------------------------------------------------------------------------------------------
/**
* Read the magnetometer measurement in meters per second squared.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
le_result_t magn_ReadMagn
(
double* xPtr,
///< [OUT] Where the x-axis magnetometer (m/s2) will be put if LE_OK is returned.
double* yPtr,
///< [OUT] Where the y-axis magnetometer (m/s2) will be put if LE_OK is returned.
double* zPtr
///< [OUT] Where the z-axis magnetometer (m/s2) will be put if LE_OK is returned.
)
{
le_result_t r;
double scaling = 0.0;
r = file_ReadDouble("/driver/in_magn_scale", &scaling);
if (r != LE_OK)
{
goto done;
}
r = file_ReadDouble("/driver/in_magn_x_raw", xPtr);
if (r != LE_OK)
{
goto done;
}
*xPtr *= scaling;
r = file_ReadDouble("/driver/in_magn_y_raw", yPtr);
if (r != LE_OK)
{
goto done;
}
*yPtr *= scaling;
r = file_ReadDouble("/driver/in_magn_z_raw", zPtr);
if (r != LE_OK)
{
goto done;
}
*zPtr *= scaling;
done:
return r;
}
//--------------------------------------------------------------------------------------------------
/**
* Sample the magnetometer and publish the results to the Data Hub.
*/
//--------------------------------------------------------------------------------------------------
static void SampleMagn
(
psensor_Ref_t ref
)
{
double x;
double y;
double z;
le_result_t result = magn_ReadMagn(&x, &y, &z);
if (result == LE_OK)
{
char sample[256];
int len = snprintf(sample, sizeof(sample), "{\"x\":%lf, \"y\":%lf, \"z\":%lf}", x, y, z);
if (len >= sizeof(sample))
{
LE_FATAL("JSON string (len %d) is longer than buffer (size %zu).", len, sizeof(sample));
}
psensor_PushJson(ref, 0 /* now */, sample);
}
else
{
LE_ERROR("Failed to read magnetometer (%s).", LE_RESULT_TXT(result));
}
}
//--------------------------------------------------------------------------------------------------
/**
* Initializes the IMU component.
*/
//--------------------------------------------------------------------------------------------------
COMPONENT_INIT
{
// Use the Periodic Sensor component from the Data Hub to implement the sensor interfaces.
psensor_Create("magn", DHUBIO_DATA_TYPE_JSON, "", SampleMagn);
}
//--------------------------------------------------------------------------------------------------
/**
* @file magn.h
*
* Magnetometer (MAGN) sensor interface. Provides an interface between the Linux
* kernel driver for the MAGN and the Legato Data Hub.
*
* Copyright (C) Sierra Wireless Inc.
*/
//--------------------------------------------------------------------------------------------------
#ifndef MAGN_H_INCLUDE_GUARD
#define MAGN_H_INCLUDE_GUARD
LE_SHARED le_result_t mangOH_ReadMagn(double *xMagn, double *yMagn, double *zMagn);
#endif // MAGN_H_INCLUDE_GUARD
//--------------------------------------------------------------------------------------------------
/**
* @page c_mangoh_pressure Pressure Sensor API
*
* The following function can be used to fetch gas resistance measurement:
*
* - gas_Read()
*
* <hr>
*
* Copyright (C) Sierra Wireless Inc.
*
* @file gas_interface.h
*/
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
* Read the air pressure measurement in kiloPascals (kPa).
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
FUNCTION le_result_t Read
(
double reading OUT ///< Where the gas reading (kOhm) will be put if LE_OK is returned.
);
//--------------------------------------------------------------------------------------------------
/**
* @page c_mangoh_relativehumidity Relative Humidity Sensor API
*
* The following function can be used to fetch humidity measurement:
*
* - humidity_Read()
*
* <hr>
*
* Copyright (C) Sierra Wireless Inc.
*
* @file humidity_interface.h
*/
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
* Read the relative humidity measurement in % (%rH).
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
FUNCTION le_result_t Read
(
double reading OUT ///< Where the relative humidity (%rH) will be put if LE_OK is returned.
);
//--------------------------------------------------------------------------------------------------
/**
* @page c_mangoh_imu Inertial Measurement Unit API
*
* The following functions can be used to access the accelerometer and gyroscope data provided
* by the Inertial Measurement Unit (IMU) chip:
*
* - imu_ReadAccel()
* - imu_ReadGyro()
*
* In addition, the IMU includes a temperature sensor that can also be read using
*
* - imuTemp_Read()
*
* <hr>
*
* Copyright (C) Sierra Wireless Inc.
*
* @file imu_interface.h
*/
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
* Read the accelerometer's linear acceleration measurement in meters per second squared.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
FUNCTION le_result_t ReadAccel
(
double x OUT, ///< Where the x-axis acceleration (m/s2) will be put if LE_OK is returned.
double y OUT, ///< Where the y-axis acceleration (m/s2) will be put if LE_OK is returned.
double z OUT ///< Where the z-axis acceleration (m/s2) will be put if LE_OK is returned.
);
//--------------------------------------------------------------------------------------------------
/**
* Read the gyroscope's angular velocity measurement in radians per seconds.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
FUNCTION le_result_t ReadGyro
(
double x OUT, ///< Where the x-axis rotation (rads/s) will be put if LE_OK is returned.
double y OUT, ///< Where the y-axis rotation (rads/s) will be put if LE_OK is returned.
double z OUT ///< Where the z-axis rotation (rads/s) will be put if LE_OK is returned.
);
//--------------------------------------------------------------------------------------------------
/**
* @page c_mangoh_light Light Sensor API
*
* The following function can be used to access the light intensity measurement provided
* by the light sensor on the mangOH Red DV3:
*
* - light_Read()
*
* <hr>
*
* Copyright (C) Sierra Wireless Inc.
*
* @file light_interface.h
*/
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
* Read the light intensity measurement.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
FUNCTION le_result_t Read
(
double reading OUT ///< Where the light intensity reading will be put if LE_OK is returned.
);
//--------------------------------------------------------------------------------------------------
/**
* @page c_mangoh_imu Inertial Measurement Unit API
*
* The following functions can be used to access the accelerometer and gyroscope data provided
* by the Inertial Measurement Unit (IMU) chip:
*
* - imu_ReadAccel()
* - imu_ReadGyro()
*
* In addition, the IMU includes a temperature sensor that can also be read using
*
* - imuTemp_Read()
*
* <hr>
*
* Copyright (C) Sierra Wireless Inc.
*
* @file imu_interface.h
*/
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
* Read the accelerometer's linear acceleration measurement in meters per second squared.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
FUNCTION le_result_t ReadMagn
(
double x OUT, ///< Where the x-axis acceleration (m/s2) will be put if LE_OK is returned.
double y OUT, ///< Where the y-axis acceleration (m/s2) will be put if LE_OK is returned.
double z OUT ///< Where the z-axis acceleration (m/s2) will be put if LE_OK is returned.
);
//--------------------------------------------------------------------------------------------------
/**
* @page c_mangoh_pressure Pressure Sensor API
*
* The following function can be used to fetch an air pressure measurement:
*
* - pressure_Read()
*
* <hr>
*
* Copyright (C) Sierra Wireless Inc.
*
* @file pressure_interface.h
*/
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
* Read the air pressure measurement in kiloPascals (kPa).
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
FUNCTION le_result_t Read
(
double reading OUT ///< Where the pressure reading (kPa) will be put if LE_OK is returned.
);
//--------------------------------------------------------------------------------------------------
/**
* @page c_mangoh_temperature Temperature Sensor API
*
* The following function can be used to fetch a temperature measurement:
*
* - temperature_Read()
*
* <hr>
*
* Copyright (C) Sierra Wireless Inc.
*
* @file temperature_interface.h
*/
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
/**
* Read the temperature measurement.
*
* @return LE_OK if successful.
*/
//--------------------------------------------------------------------------------------------------
FUNCTION le_result_t Read
(
double reading OUT ///< Where the reading (in degrees C) will be put if LE_OK is returned.
);
sandboxed: true
start: auto
version: 0.0
extern:
{
imu = yellowSensor.imu.imu
imuTemp = yellowSensor.imu.temperature
light = yellowSensor.light.light
pressure = yellowSensor.environment.pressure
environmentTemp = yellowSensor.environment.temperature
gas = yellowSensor.environment.gas
humidity = yellowSensor.environment.humidity
magn = yellowSensor.magnetometer.magn
}
executables:
{
yellowSensor = (
components/sensors/environment
components/sensors/imu
components/sensors/magnetometer
components/sensors/light
)
}
processes:
{
run:
{
( yellowSensor )
}
envVars:
{
LE_LOG_LEVEL = DEBUG
LD_LIBRARY_PATH = /legato/systems/current/apps/yellowSensor/read-only/usr/lib
}
}
bindings:
{
yellowSensor.periodicSensor.dhubIO -> dataHub.io
yellowSensor.imu.dhubIO -> dataHub.io
yellowSensor.light.dhubIO -> dataHub.io
yellowSensor.environment.dhubIO -> dataHub.io
yellowSensor.magnetometer.dhubIO -> dataHub.io
}
......@@ -54,7 +54,7 @@ apps:
$MANGOH_ROOT/apps/Heartbeat/heartbeatGreen
#elif ${MANGOH_BOARD} = yellow
// $MANGOH_ROOT/apps/YellowSensorToCloud/yellowSensor
$MANGOH_ROOT/apps/YellowSensorToCloud/yellowSensor
$LEGATO_ROOT/apps/sample/dataHub/dataHub
$MANGOH_ROOT/apps/Mcp9700aTemperatureSensor/mcp9700aTemperatureSensor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment