mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 04:52:59 +01:00
saul: use const for device parameter
This commit is contained in:
parent
b0aaf8d1e2
commit
946256d26f
@ -24,9 +24,9 @@
|
||||
#include "saul.h"
|
||||
#include "adcxx1c.h"
|
||||
|
||||
static int read_adc(void *dev, phydat_t *res)
|
||||
static int read_adc(const void *dev, phydat_t *res)
|
||||
{
|
||||
adcxx1c_read_raw((adcxx1c_t *)dev, res->val);
|
||||
adcxx1c_read_raw((const adcxx1c_t *)dev, res->val);
|
||||
|
||||
res->unit = UNIT_NONE;
|
||||
res->scale = 0;
|
||||
|
@ -21,10 +21,9 @@
|
||||
#include "saul.h"
|
||||
#include "adxl345.h"
|
||||
|
||||
static int read_acc(void *dev, phydat_t *res)
|
||||
static int read_acc(const void *dev, phydat_t *res)
|
||||
{
|
||||
adxl345_t *d = (adxl345_t *)dev;
|
||||
adxl345_read(d, (adxl345_data_t *)res->val);
|
||||
adxl345_read((const adxl345_t *)dev, (adxl345_data_t *)res->val);
|
||||
|
||||
res->unit = UNIT_G;
|
||||
res->scale = -3;
|
||||
|
@ -25,21 +25,17 @@
|
||||
#include "bmp180.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
static int read_temperature(void *dev, phydat_t *res)
|
||||
static int read_temperature(const void *dev, phydat_t *res)
|
||||
{
|
||||
bmp180_t *d = (bmp180_t *)dev;
|
||||
|
||||
res->val[0] = bmp180_read_temperature(d);
|
||||
res->val[0] = bmp180_read_temperature((const bmp180_t *)dev);
|
||||
res->unit = UNIT_TEMP_C;
|
||||
res->scale = -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_pressure(void *dev, phydat_t *res)
|
||||
static int read_pressure(const void *dev, phydat_t *res)
|
||||
{
|
||||
bmp180_t *d = (bmp180_t *)dev;
|
||||
|
||||
res->val[0] = bmp180_read_pressure(d) / 100;
|
||||
res->val[0] = bmp180_read_pressure((const bmp180_t *)dev) / 100;
|
||||
res->unit = UNIT_PA;
|
||||
res->scale = 2;
|
||||
return 1;
|
||||
|
@ -24,22 +24,18 @@
|
||||
|
||||
#include "bmx280.h"
|
||||
|
||||
static int read_temperature(void *dev, phydat_t *res)
|
||||
static int read_temperature(const void *dev, phydat_t *res)
|
||||
{
|
||||
bmx280_t *d = (bmx280_t *)dev;
|
||||
|
||||
res->val[0] = bmx280_read_temperature(d);
|
||||
res->val[0] = bmx280_read_temperature((const bmx280_t *)dev);
|
||||
res->unit = UNIT_TEMP_C;
|
||||
res->scale = -2;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_pressure(void *dev, phydat_t *res)
|
||||
static int read_pressure(const void *dev, phydat_t *res)
|
||||
{
|
||||
bmx280_t *d = (bmx280_t *)dev;
|
||||
|
||||
res->val[0] = bmx280_read_pressure(d) / 100;
|
||||
res->val[0] = bmx280_read_pressure((const bmx280_t *)dev) / 100;
|
||||
res->unit = UNIT_PA;
|
||||
res->scale = 2;
|
||||
|
||||
@ -47,11 +43,9 @@ static int read_pressure(void *dev, phydat_t *res)
|
||||
}
|
||||
|
||||
#ifdef MODULE_BME280
|
||||
static int read_relative_humidity(void *dev, phydat_t *res)
|
||||
static int read_relative_humidity(const void *dev, phydat_t *res)
|
||||
{
|
||||
bmx280_t *d = (bmx280_t *)dev;
|
||||
|
||||
res->val[0] = bme280_read_humidity(d);
|
||||
res->val[0] = bme280_read_humidity((const bmx280_t *)dev);
|
||||
res->unit = UNIT_PERCENT;
|
||||
res->scale = -2;
|
||||
|
||||
|
@ -37,18 +37,14 @@
|
||||
static int16_t temp, hum;
|
||||
static uint32_t last = 0;
|
||||
|
||||
static int check_and_read(void *dev, phydat_t *res, int16_t *val, uint8_t unit)
|
||||
static int check_and_read(const void *dev, phydat_t *res, int16_t *val, uint8_t unit)
|
||||
{
|
||||
dht_t *d = (dht_t *)dev;
|
||||
uint32_t now = xtimer_now_usec();
|
||||
|
||||
if ((now - last) > DHT_SAUL_HOLD_TIME) {
|
||||
dht_read(d, &temp, &hum);
|
||||
dht_read((const dht_t *)dev, &temp, &hum);
|
||||
last = now;
|
||||
}
|
||||
else {
|
||||
(void)d;
|
||||
}
|
||||
|
||||
res->val[0] = *val;
|
||||
memset(&res->val[1], 0, 2 * sizeof(int16_t));
|
||||
@ -57,12 +53,12 @@ static int check_and_read(void *dev, phydat_t *res, int16_t *val, uint8_t unit)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_temp(void *dev, phydat_t *res)
|
||||
static int read_temp(const void *dev, phydat_t *res)
|
||||
{
|
||||
return check_and_read(dev, res, &temp, UNIT_TEMP_C);
|
||||
}
|
||||
|
||||
static int read_hum(void *dev, phydat_t *res)
|
||||
static int read_hum(const void *dev, phydat_t *res)
|
||||
{
|
||||
return check_and_read(dev, res, &hum, UNIT_PERCENT);
|
||||
}
|
||||
|
@ -23,11 +23,9 @@
|
||||
#include "saul.h"
|
||||
#include "hdc1000.h"
|
||||
|
||||
static int read_temp(void *dev, phydat_t *res)
|
||||
static int read_temp(const void *dev, phydat_t *res)
|
||||
{
|
||||
hdc1000_t *d = (hdc1000_t *)dev;
|
||||
|
||||
if (hdc1000_read(d, &(res->val[0]), NULL) != HDC1000_OK) {
|
||||
if (hdc1000_read((const hdc1000_t *)dev, &(res->val[0]), NULL) != HDC1000_OK) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
|
||||
@ -37,11 +35,9 @@ static int read_temp(void *dev, phydat_t *res)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_hum(void *dev, phydat_t *res)
|
||||
static int read_hum(const void *dev, phydat_t *res)
|
||||
{
|
||||
hdc1000_t *d = (hdc1000_t *)dev;
|
||||
|
||||
if (hdc1000_read(d, NULL, &(res->val[0])) != HDC1000_OK) {
|
||||
if (hdc1000_read((const hdc1000_t *)dev, NULL, &(res->val[0])) != HDC1000_OK) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
|
||||
|
@ -112,7 +112,7 @@ enum {
|
||||
* @return -ENOTSUP if the device does not support this operation
|
||||
* @return -ECANCELED on other errors
|
||||
*/
|
||||
typedef int(*saul_read_t)(void *dev, phydat_t *res);
|
||||
typedef int(*saul_read_t)(const void *dev, phydat_t *res);
|
||||
|
||||
/**
|
||||
* @brief Write a value (a set of values) to a device
|
||||
@ -132,7 +132,7 @@ typedef int(*saul_read_t)(void *dev, phydat_t *res);
|
||||
* @return -ENOTSUP if the device does not support this operation
|
||||
* @return -ECANCELED on other errors
|
||||
*/
|
||||
typedef int(*saul_write_t)(void *dev, phydat_t *data);
|
||||
typedef int(*saul_write_t)(const void *dev, phydat_t *data);
|
||||
|
||||
/**
|
||||
* @brief Definition of the RIOT actuator/sensor interface
|
||||
@ -146,7 +146,7 @@ typedef struct {
|
||||
/**
|
||||
* @brief Default not supported function
|
||||
*/
|
||||
int saul_notsup(void *dev, phydat_t *dat);
|
||||
int saul_notsup(const void *dev, phydat_t *dat);
|
||||
|
||||
/**
|
||||
* @brief Helper function converts a class ID to a string
|
||||
@ -156,7 +156,7 @@ int saul_notsup(void *dev, phydat_t *dat);
|
||||
* @return string representation of the device class
|
||||
* @return NULL if class ID is not known
|
||||
*/
|
||||
const char *saul_class_to_str(uint8_t class_id);
|
||||
const char *saul_class_to_str(const uint8_t class_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -25,10 +25,9 @@
|
||||
|
||||
static float temperature;
|
||||
|
||||
static int read_temperature(void *dev, phydat_t *res)
|
||||
static int read_temperature(const void *dev, phydat_t *res)
|
||||
{
|
||||
io1_xplained_t *d = (io1_xplained_t *)dev;
|
||||
io1_xplained_read_temperature(d, &temperature);
|
||||
io1_xplained_read_temperature((const io1_xplained_t *)dev, &temperature);
|
||||
res->val[0] = (int)(temperature * 100.0);
|
||||
res->unit = UNIT_TEMP_C;
|
||||
res->scale = -2;
|
||||
|
@ -23,10 +23,9 @@
|
||||
#include "saul.h"
|
||||
#include "isl29020.h"
|
||||
|
||||
static int read(void *dev, phydat_t *res)
|
||||
static int read(const void *dev, phydat_t *res)
|
||||
{
|
||||
isl29020_t *d = (isl29020_t *)dev;
|
||||
res->val[0] = (int16_t)isl29020_read(d);
|
||||
res->val[0] = (int16_t)isl29020_read((const isl29020_t *)dev);
|
||||
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
|
||||
res->unit = UNIT_CD;
|
||||
res->scale = 0;
|
||||
|
@ -25,12 +25,11 @@
|
||||
|
||||
|
||||
|
||||
static int read_temperature(void *dev, phydat_t *res)
|
||||
static int read_temperature(const void *dev, phydat_t *res)
|
||||
{
|
||||
int16_t temperature;
|
||||
jc42_t *d = (jc42_t *)dev;
|
||||
|
||||
jc42_get_temperature(d, &temperature);
|
||||
jc42_get_temperature((const jc42_t *)dev, &temperature);
|
||||
res->val[0] = temperature;
|
||||
res->unit = UNIT_TEMP_C;
|
||||
res->scale = -2;
|
||||
|
@ -23,10 +23,9 @@
|
||||
#include "saul.h"
|
||||
#include "l3g4200d.h"
|
||||
|
||||
static int read(void *dev, phydat_t *res)
|
||||
static int read(const void *dev, phydat_t *res)
|
||||
{
|
||||
l3g4200d_t *d = (l3g4200d_t *)dev;
|
||||
l3g4200d_read(d, (l3g4200d_data_t *)res);
|
||||
l3g4200d_read((const l3g4200d_t *)dev, (l3g4200d_data_t *)res);
|
||||
res->unit = UNIT_DPS;
|
||||
res->scale = 0;
|
||||
return 3;
|
||||
|
@ -24,12 +24,11 @@
|
||||
#include "saul.h"
|
||||
#include "lis3dh.h"
|
||||
|
||||
static int read_acc(void *dev, phydat_t *res)
|
||||
static int read_acc(const void *dev, phydat_t *res)
|
||||
{
|
||||
lis3dh_data_t xyz;
|
||||
|
||||
lis3dh_t *d = (lis3dh_t *)dev;
|
||||
int err = lis3dh_read_xyz(d, &xyz);
|
||||
int err = lis3dh_read_xyz((const lis3dh_t *)dev, &xyz);
|
||||
if (err != 0) {
|
||||
/* Something went wrong in the LIS3DH driver */
|
||||
return -ECANCELED;
|
||||
|
@ -23,10 +23,9 @@
|
||||
#include "saul.h"
|
||||
#include "lps331ap.h"
|
||||
|
||||
static int read(void *dev, phydat_t *res)
|
||||
static int read(const void *dev, phydat_t *res)
|
||||
{
|
||||
lps331ap_t *d = (lps331ap_t *)dev;
|
||||
res->val[0] = (int16_t)lps331ap_read_pres(d);
|
||||
res->val[0] = (int16_t)lps331ap_read_pres((const lps331ap_t *)dev);
|
||||
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
|
||||
res->unit = UNIT_BAR;
|
||||
res->scale = -3;
|
||||
|
@ -23,9 +23,9 @@
|
||||
#include "saul.h"
|
||||
#include "lsm303dlhc.h"
|
||||
|
||||
static int read_acc(void *dev, phydat_t *res)
|
||||
static int read_acc(const void *dev, phydat_t *res)
|
||||
{
|
||||
lsm303dlhc_t *d = (lsm303dlhc_t *)dev;
|
||||
const lsm303dlhc_t *d = (const lsm303dlhc_t *)dev;
|
||||
lsm303dlhc_read_acc(d, (lsm303dlhc_3d_data_t *)res);
|
||||
|
||||
/* normalize result */
|
||||
@ -39,9 +39,10 @@ static int read_acc(void *dev, phydat_t *res)
|
||||
return 3;
|
||||
}
|
||||
|
||||
static int read_mag(void *dev, phydat_t *res)
|
||||
static int read_mag(const void *dev, phydat_t *res)
|
||||
{
|
||||
lsm303dlhc_t *d = (lsm303dlhc_t *)dev;
|
||||
const lsm303dlhc_t *d = (const lsm303dlhc_t *)dev;
|
||||
|
||||
lsm303dlhc_read_mag(d, (lsm303dlhc_3d_data_t *)res);
|
||||
|
||||
/* normalize results */
|
||||
|
@ -17,9 +17,9 @@
|
||||
#include "lsm6dsl.h"
|
||||
#include "saul.h"
|
||||
|
||||
static int read_acc(void *dev, phydat_t *res)
|
||||
static int read_acc(const void *dev, phydat_t *res)
|
||||
{
|
||||
int ret = lsm6dsl_read_acc(dev, (lsm6dsl_3d_data_t *)res);
|
||||
int ret = lsm6dsl_read_acc((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res);
|
||||
if (ret < 0) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
@ -30,9 +30,9 @@ static int read_acc(void *dev, phydat_t *res)
|
||||
return 3;
|
||||
}
|
||||
|
||||
static int read_gyro(void *dev, phydat_t *res)
|
||||
static int read_gyro(const void *dev, phydat_t *res)
|
||||
{
|
||||
int ret = lsm6dsl_read_gyro(dev, (lsm6dsl_3d_data_t *)res);
|
||||
int ret = lsm6dsl_read_gyro((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res);
|
||||
if (ret < 0) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
@ -49,7 +49,6 @@ const saul_driver_t lsm6dsl_saul_acc_driver = {
|
||||
.type = SAUL_SENSE_ACCEL,
|
||||
};
|
||||
|
||||
|
||||
const saul_driver_t lsm6dsl_saul_gyro_driver = {
|
||||
.read = read_gyro,
|
||||
.write = saul_notsup,
|
||||
|
@ -24,9 +24,9 @@
|
||||
#include "saul.h"
|
||||
#include "mag3110.h"
|
||||
|
||||
static int read_mag(void *dev, phydat_t *res)
|
||||
static int read_mag(const void *dev, phydat_t *res)
|
||||
{
|
||||
mag3110_read((mag3110_t *)dev, (mag3110_data_t *)res);
|
||||
mag3110_read((const mag3110_t *)dev, (mag3110_data_t *)res);
|
||||
|
||||
res->unit = UNIT_GS;
|
||||
res->scale = 2;
|
||||
|
@ -25,9 +25,9 @@
|
||||
#include "saul.h"
|
||||
#include "mma8x5x.h"
|
||||
|
||||
static int read_acc(void *dev, phydat_t *res)
|
||||
static int read_acc(const void *dev, phydat_t *res)
|
||||
{
|
||||
mma8x5x_read((mma8x5x_t *)dev, (mma8x5x_data_t *)res);
|
||||
mma8x5x_read((const mma8x5x_t *)dev, (mma8x5x_data_t *)res);
|
||||
|
||||
res->unit = UNIT_G;
|
||||
res->scale = -3;
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "periph/adc.h"
|
||||
|
||||
|
||||
static int read_adc(void *dev, phydat_t *res)
|
||||
static int read_adc(const void *dev, phydat_t *res)
|
||||
{
|
||||
const saul_adc_params_t *params = *((const saul_adc_params_t **)dev);
|
||||
res->val[0] = adc_sample(params->line, params->res);
|
||||
|
@ -25,9 +25,9 @@
|
||||
#include "periph/gpio.h"
|
||||
|
||||
|
||||
static int read(void *dev, phydat_t *res)
|
||||
static int read(const void *dev, phydat_t *res)
|
||||
{
|
||||
gpio_t pin = *((gpio_t *)dev);
|
||||
gpio_t pin = *((const gpio_t *)dev);
|
||||
res->val[0] = (gpio_read(pin)) ? 1 : 0;
|
||||
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
|
||||
res->unit = UNIT_BOOL;
|
||||
@ -35,9 +35,9 @@ static int read(void *dev, phydat_t *res)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int write(void *dev, phydat_t *state)
|
||||
static int write(const void *dev, phydat_t *state)
|
||||
{
|
||||
gpio_t pin = *((gpio_t *)dev);
|
||||
gpio_t pin = *((const gpio_t *)dev);
|
||||
gpio_write(pin, state->val[0]);
|
||||
return 1;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include "saul.h"
|
||||
|
||||
int saul_notsup(void *dev, phydat_t *dat)
|
||||
int saul_notsup(const void *dev, phydat_t *dat)
|
||||
{
|
||||
(void)dev;
|
||||
(void)dat;
|
||||
|
@ -26,7 +26,7 @@
|
||||
* This is surely not the most beautiful implementation of a stringification
|
||||
* function, but works...
|
||||
*/
|
||||
const char *saul_class_to_str(uint8_t class_id)
|
||||
const char *saul_class_to_str(const uint8_t class_id)
|
||||
{
|
||||
switch (class_id) {
|
||||
case SAUL_CLASS_UNDEF: return "CLASS_UNDEF";
|
||||
|
@ -22,22 +22,18 @@
|
||||
|
||||
#include "si70xx.h"
|
||||
|
||||
static int read_temperature(void *dev, phydat_t *res)
|
||||
static int read_temperature(const void *dev, phydat_t *res)
|
||||
{
|
||||
si70xx_t *d = (si70xx_t *)dev;
|
||||
|
||||
res->val[0] = (int32_t) si70xx_get_temperature(d);
|
||||
res->val[0] = (int32_t) si70xx_get_temperature((const si70xx_t *)dev);
|
||||
res->unit = UNIT_TEMP_C;
|
||||
res->scale = -2;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_relative_humidity(void *dev, phydat_t *res)
|
||||
static int read_relative_humidity(const void *dev, phydat_t *res)
|
||||
{
|
||||
si70xx_t *d = (si70xx_t *)dev;
|
||||
|
||||
res->val[0] = (int32_t) si70xx_get_relative_humidity(d);
|
||||
res->val[0] = (int32_t) si70xx_get_relative_humidity((const si70xx_t *)dev);
|
||||
res->unit = UNIT_PERCENT;
|
||||
res->scale = -2;
|
||||
|
||||
|
@ -23,12 +23,11 @@
|
||||
#include "saul.h"
|
||||
#include "tcs37727.h"
|
||||
|
||||
static int read(void *dev, phydat_t *res)
|
||||
static int read(const void *dev, phydat_t *res)
|
||||
{
|
||||
tcs37727_t *d = (tcs37727_t *)dev;
|
||||
tcs37727_data_t val;
|
||||
|
||||
tcs37727_read(d, &val);
|
||||
tcs37727_read((const tcs37727_t *)dev, &val);
|
||||
|
||||
res->val[0] = (int16_t)val.red;
|
||||
res->val[1] = (int16_t)val.green;
|
||||
|
@ -23,9 +23,10 @@
|
||||
#include "saul.h"
|
||||
#include "tmp006.h"
|
||||
|
||||
static int read_temp(void *dev, phydat_t *res)
|
||||
static int read_temp(const void *dev, phydat_t *res)
|
||||
{
|
||||
if (tmp006_read_temperature((tmp006_t *)dev, &res->val[0], &res->val[1]) != TMP006_OK) {
|
||||
if (tmp006_read_temperature((const tmp006_t *)dev, &res->val[0],
|
||||
&res->val[1]) != TMP006_OK) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
res->val[2] = 0;
|
||||
|
@ -23,11 +23,9 @@
|
||||
#include "tsl2561.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
static int read_illuminance(void *dev, phydat_t *res)
|
||||
static int read_illuminance(const void *dev, phydat_t *res)
|
||||
{
|
||||
tsl2561_t *d = (tsl2561_t *)dev;
|
||||
|
||||
res->val[0] = tsl2561_read_illuminance(d);
|
||||
res->val[0] = tsl2561_read_illuminance((const tsl2561_t *)dev);
|
||||
res->unit = UNIT_LUX;
|
||||
res->scale = 0;
|
||||
return 1;
|
||||
|
@ -24,11 +24,9 @@
|
||||
#include "veml6070.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
static int read_uv(void *dev, phydat_t *res)
|
||||
static int read_uv(const void *dev, phydat_t *res)
|
||||
{
|
||||
veml6070_t *d = (veml6070_t *)dev;
|
||||
|
||||
res->val[0] = veml6070_read_uv(d);
|
||||
res->val[0] = veml6070_read_uv((const veml6070_t *)dev);
|
||||
res->unit = UNIT_NONE;
|
||||
res->scale = -1;
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user