change SensorQuantityRead with SensorQuantityReadValue for sensor framework

This commit is contained in:
Liu_Weichao 2022-08-31 10:54:54 +08:00
parent f55022fc46
commit b5b3cb9ca7
17 changed files with 81 additions and 36 deletions

View File

@ -30,7 +30,7 @@ void AltitudeBmp180(void)
int32 altitude; int32 altitude;
struct SensorQuantity *p_altitude = SensorQuantityFind(SENSOR_QUANTITY_BMP180_ALTITUDE, SENSOR_QUANTITY_ALTITUDE); struct SensorQuantity *p_altitude = SensorQuantityFind(SENSOR_QUANTITY_BMP180_ALTITUDE, SENSOR_QUANTITY_ALTITUDE);
SensorQuantityOpen(p_altitude); SensorQuantityOpen(p_altitude);
altitude = SensorQuantityRead(p_altitude); altitude = SensorQuantityReadValue(p_altitude);
printf("Altitude Pressure : %d Pa\n", altitude); printf("Altitude Pressure : %d Pa\n", altitude);

View File

@ -31,6 +31,6 @@ void Ch4As830(void)
{ {
struct SensorQuantity *ch4 = SensorQuantityFind(SENSOR_QUANTITY_AS830_CH4, SENSOR_QUANTITY_CH4); struct SensorQuantity *ch4 = SensorQuantityFind(SENSOR_QUANTITY_AS830_CH4, SENSOR_QUANTITY_CH4);
SensorQuantityOpen(ch4); SensorQuantityOpen(ch4);
printf("CH4 : %d %%LTL\n", SensorQuantityRead(ch4)); printf("CH4 : %d %%LTL\n", SensorQuantityReadValue(ch4));
SensorQuantityClose(ch4); SensorQuantityClose(ch4);
} }

View File

@ -31,6 +31,6 @@ void Co2G8s(void)
{ {
struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_G8S_CO2, SENSOR_QUANTITY_CO2); struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_G8S_CO2, SENSOR_QUANTITY_CO2);
SensorQuantityOpen(co2); SensorQuantityOpen(co2);
printf("CO2 : %d ppm\n", SensorQuantityRead(co2)); printf("CO2 : %d ppm\n", SensorQuantityReadValue(co2));
SensorQuantityClose(co2); SensorQuantityClose(co2);
} }

View File

@ -31,6 +31,6 @@ void Co2Zg09(void)
{ {
struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_ZG09_CO2, SENSOR_QUANTITY_CO2); struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_ZG09_CO2, SENSOR_QUANTITY_CO2);
SensorQuantityOpen(co2); SensorQuantityOpen(co2);
printf("CO2 : %d ppm\n", SensorQuantityRead(co2)); printf("CO2 : %d ppm\n", SensorQuantityReadValue(co2));
SensorQuantityClose(co2); SensorQuantityClose(co2);
} }

View File

@ -34,7 +34,7 @@ void HchoTb600bHcho1os(void)
SensorQuantityOpen(hcho); SensorQuantityOpen(hcho);
int32_t result = 0; int32_t result = 0;
result = SensorQuantityRead(hcho); result = SensorQuantityReadValue(hcho);
printf("tvoc concentration is : %dppb\n", result); printf("tvoc concentration is : %dppb\n", result);
SensorQuantityClose(hcho); SensorQuantityClose(hcho);

View File

@ -35,7 +35,7 @@ void HumiHs300x(void)
struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI); struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI);
SensorQuantityOpen(humi); SensorQuantityOpen(humi);
for (i = 0; i < 100; i ++) { for (i = 0; i < 100; i ++) {
humidity = SensorQuantityRead(humi); humidity = SensorQuantityReadValue(humi);
printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10); printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10);
PrivTaskDelay(5000); PrivTaskDelay(5000);
} }

View File

@ -40,7 +40,7 @@ void IaqTb600bIaq10(void)
SensorQuantityOpen(iaq); SensorQuantityOpen(iaq);
int32_t result = 0; int32_t result = 0;
result = SensorQuantityRead(iaq); result = SensorQuantityReadValue(iaq);
printf("Gas concentration is : %dppb\n", result); printf("Gas concentration is : %dppb\n", result);
SensorQuantityClose(iaq); SensorQuantityClose(iaq);

View File

@ -33,6 +33,6 @@ void Pm100Ps5308(void)
struct SensorQuantity *pm10_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM10, SENSOR_QUANTITY_PM); struct SensorQuantity *pm10_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM10, SENSOR_QUANTITY_PM);
SensorQuantityOpen(pm10_0); SensorQuantityOpen(pm10_0);
PrivTaskDelay(2000); PrivTaskDelay(2000);
printf("PM10 : %d ug/m³\n", SensorQuantityRead(pm10_0)); printf("PM10 : %d ug/m³\n", SensorQuantityReadValue(pm10_0));
SensorQuantityClose(pm10_0); SensorQuantityClose(pm10_0);
} }

View File

@ -33,6 +33,6 @@ void Pm10Ps5308(void)
struct SensorQuantity *pm1_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM1_0, SENSOR_QUANTITY_PM); struct SensorQuantity *pm1_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM1_0, SENSOR_QUANTITY_PM);
SensorQuantityOpen(pm1_0); SensorQuantityOpen(pm1_0);
PrivTaskDelay(2000); PrivTaskDelay(2000);
printf("PM1.0 : %d ug/m³\n", SensorQuantityRead(pm1_0)); printf("PM1.0 : %d ug/m³\n", SensorQuantityReadValue(pm1_0));
SensorQuantityClose(pm1_0); SensorQuantityClose(pm1_0);
} }

View File

@ -33,6 +33,6 @@ void Pm25Ps5308(void)
struct SensorQuantity *pm2_5 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM2_5, SENSOR_QUANTITY_PM); struct SensorQuantity *pm2_5 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM2_5, SENSOR_QUANTITY_PM);
SensorQuantityOpen(pm2_5); SensorQuantityOpen(pm2_5);
PrivTaskDelay(2000); PrivTaskDelay(2000);
printf("PM2.5 : %d ug/m³\n", SensorQuantityRead(pm2_5)); printf("PM2.5 : %d ug/m³\n", SensorQuantityReadValue(pm2_5));
SensorQuantityClose(pm2_5); SensorQuantityClose(pm2_5);
} }

View File

@ -35,7 +35,7 @@ void TempHs300x(void)
struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP); struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP);
SensorQuantityOpen(temp); SensorQuantityOpen(temp);
for (i = 0; i < 100; i ++) { for (i = 0; i < 100; i ++) {
temperature = SensorQuantityRead(temp); temperature = SensorQuantityReadValue(temp);
if (temperature > 0) if (temperature > 0)
printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10); printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10);
else else

View File

@ -34,7 +34,7 @@ void TvocTb600bTvoc10(void)
SensorQuantityOpen(tvoc); SensorQuantityOpen(tvoc);
int32_t result = 0; int32_t result = 0;
result = SensorQuantityRead(tvoc); result = SensorQuantityReadValue(tvoc);
printf("tvoc concentration is : %dppb\n", result); printf("tvoc concentration is : %dppb\n", result);
SensorQuantityClose(tvoc); SensorQuantityClose(tvoc);

View File

@ -30,7 +30,7 @@ void VoiceD124(void)
struct SensorQuantity *voice = SensorQuantityFind(SENSOR_QUANTITY_D124_VOICE, SENSOR_QUANTITY_VOICE); struct SensorQuantity *voice = SensorQuantityFind(SENSOR_QUANTITY_D124_VOICE, SENSOR_QUANTITY_VOICE);
SensorQuantityOpen(voice); SensorQuantityOpen(voice);
PrivTaskDelay(2000); PrivTaskDelay(2000);
uint16 result = SensorQuantityRead(voice); uint16 result = SensorQuantityReadValue(voice);
printf("voice : %d.%d dB\n", result/(10*voice->value.decimal_places), result%(10*voice->value.decimal_places)); printf("voice : %d.%d dB\n", result/(10*voice->value.decimal_places), result%(10*voice->value.decimal_places));
SensorQuantityClose(voice); SensorQuantityClose(voice);
} }

View File

@ -30,7 +30,7 @@ void WindDirectionQsFx(void)
struct SensorQuantity *wind_direction = SensorQuantityFind(SENSOR_QUANTITY_QS_FX_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION); struct SensorQuantity *wind_direction = SensorQuantityFind(SENSOR_QUANTITY_QS_FX_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION);
SensorQuantityOpen(wind_direction); SensorQuantityOpen(wind_direction);
PrivTaskDelay(2000); PrivTaskDelay(2000);
uint16 result = SensorQuantityRead(wind_direction); uint16 result = SensorQuantityReadValue(wind_direction);
printf("wind direction : %d degree\n", result); printf("wind direction : %d degree\n", result);
SensorQuantityClose(wind_direction); SensorQuantityClose(wind_direction);
} }

View File

@ -30,7 +30,7 @@ void WindSpeedQsFs(void)
struct SensorQuantity *wind_speed = SensorQuantityFind(SENSOR_QUANTITY_QS_FS_WINDSPEED, SENSOR_QUANTITY_WINDSPEED); struct SensorQuantity *wind_speed = SensorQuantityFind(SENSOR_QUANTITY_QS_FS_WINDSPEED, SENSOR_QUANTITY_WINDSPEED);
SensorQuantityOpen(wind_speed); SensorQuantityOpen(wind_speed);
PrivTaskDelay(2000); PrivTaskDelay(2000);
uint16 result = SensorQuantityRead(wind_speed); uint16 result = SensorQuantityReadValue(wind_speed);
printf("wind speed : %d.%d m/s\n", result/10, result%10); printf("wind speed : %d.%d m/s\n", result/10, result%10);
SensorQuantityClose(wind_speed); SensorQuantityClose(wind_speed);
} }

View File

@ -314,7 +314,7 @@ int SensorQuantityClose(struct SensorQuantity *quant)
* @param quant - sensor quantity pointer * @param quant - sensor quantity pointer
* @return quantity value * @return quantity value
*/ */
int SensorQuantityRead(struct SensorQuantity *quant) int SensorQuantityReadValue(struct SensorQuantity *quant)
{ {
if (!quant) if (!quant)
return -1; return -1;
@ -332,6 +332,29 @@ int SensorQuantityRead(struct SensorQuantity *quant)
return result; return result;
} }
/**
* @description: Read quantity decimal point
* @param quant - sensor quantity pointer
* @return decimal point num, 0: 0 1: 0.1 2: 0.01 3: 0.001
*/
int SensorQuantityReadDecimalPoint(struct SensorQuantity *quant)
{
if (!quant)
return -1;
int decimal_point = 0;
struct SensorDevice *sdev = quant->sdev;
if (!sdev)
return -1;
if (quant->ReadValue != NULL) {
decimal_point = quant->ReadDecimalPoint(quant);
}
return decimal_point;
}
/** /**
* @description: Configure quantity mode * @description: Configure quantity mode
* @param quant - sensor quantity pointer * @param quant - sensor quantity pointer

View File

@ -44,20 +44,29 @@ extern "C" {
#endif #endif
/* Sensor ability */ /* Sensor ability */
#define SENSOR_ABILITY_CO2 ((uint32_t)(1 << SENSOR_QUANTITY_CO2)) #define SENSOR_ABILITY_CO2 ((uint32_t)(1 << SENSOR_QUANTITY_CO2))
#define SENSOR_ABILITY_TEMP ((uint32_t)(1 << SENSOR_QUANTITY_TEMP)) #define SENSOR_ABILITY_TEMP ((uint32_t)(1 << SENSOR_QUANTITY_TEMP))
#define SENSOR_ABILITY_HUMI ((uint32_t)(1 << SENSOR_QUANTITY_HUMI)) #define SENSOR_ABILITY_HUMI ((uint32_t)(1 << SENSOR_QUANTITY_HUMI))
#define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO)) #define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO))
#define SENSOR_ABILITY_CO ((uint32_t)(1 << SENSOR_QUANTITY_CO)) #define SENSOR_ABILITY_CO ((uint32_t)(1 << SENSOR_QUANTITY_CO))
#define SENSOR_ABILITY_PM ((uint32_t)(1 << SENSOR_QUANTITY_PM)) #define SENSOR_ABILITY_PM ((uint32_t)(1 << SENSOR_QUANTITY_PM))
#define SENSOR_ABILITY_VOICE ((uint32_t)(1 << SENSOR_QUANTITY_VOICE)) #define SENSOR_ABILITY_VOICE ((uint32_t)(1 << SENSOR_QUANTITY_VOICE))
#define SENSOR_ABILITY_CH4 ((uint32_t)(1 << SENSOR_QUANTITY_CH4)) #define SENSOR_ABILITY_CH4 ((uint32_t)(1 << SENSOR_QUANTITY_CH4))
#define SENSOR_ABILITY_IAQ ((uint32_t)(1 << SENSOR_QUANTITY_IAQ)) #define SENSOR_ABILITY_IAQ ((uint32_t)(1 << SENSOR_QUANTITY_IAQ))
#define SENSOR_ABILITY_TVOC ((uint32_t)(1 << SENSOR_QUANTITY_TVOC)) #define SENSOR_ABILITY_TVOC ((uint32_t)(1 << SENSOR_QUANTITY_TVOC))
#define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO)) #define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO))
#define SENSOR_ABILITY_WINDSPEED ((uint32_t)(1 << SENSOR_QUANTITY_WINDSPEED)) #define SENSOR_ABILITY_WINDSPEED ((uint32_t)(1 << SENSOR_QUANTITY_WINDSPEED))
#define SENSOR_ABILITY_WINDDIRECTION ((uint32_t)(1 << SENSOR_QUANTITY_WINDDIRECTION)) #define SENSOR_ABILITY_WINDDIRECTION ((uint32_t)(1 << SENSOR_QUANTITY_WINDDIRECTION))
#define SENSOR_ABILITY_ALTITUDE ((uint32_t)(1 << SENSOR_QUANTITY_ALTITUDE)) #define SENSOR_ABILITY_ALTITUDE ((uint32_t)(1 << SENSOR_QUANTITY_ALTITUDE))
#define SENSOR_ABILITY_O3 ((uint32_t)(1 << SENSOR_QUANTITY_O3))
#define SENSOR_ABILITY_O2 ((uint32_t)(1 << SENSOR_QUANTITY_O2))
#define SENSOR_ABILITY_NO2 ((uint32_t)(1 << SENSOR_QUANTITY_NO2))
#define SENSOR_ABILITY_SO2 ((uint32_t)(1 << SENSOR_QUANTITY_SO2))
#define SENSOR_ABILITY_NH3 ((uint32_t)(1 << SENSOR_QUANTITY_NH3))
#define SENSOR_ABILITY_CH20 ((uint32_t)(1 << SENSOR_QUANTITY_CH20))
#define SENSOR_ABILITY_C2H5OH ((uint32_t)(1 << SENSOR_QUANTITY_C2H5OH))
#define SENSOR_ABILITY_AQS ((uint32_t)(1 << SENSOR_QUANTITY_AQS))
#define SENSOR_ABILITY_PM1 ((uint32_t)(1 << SENSOR_QUANTITY_PM1))
struct SensorProductInfo { struct SensorProductInfo {
uint32_t ability; /* Bitwise OR of sensor ability */ uint32_t ability; /* Bitwise OR of sensor ability */
@ -76,16 +85,17 @@ struct SensorDone {
}; };
struct SensorDevice { struct SensorDevice {
char *name; /* Name of sensor */ char *name; /* Name of sensor */
struct SensorProductInfo *info; /* Sensor model info */ struct SensorProductInfo *info; /* Sensor model info */
struct SensorDone *done; struct SensorDone *done;
int fd; /* File descriptor */ int fd; /* File descriptor */
int status; /* Sensor work mode */ int status; /* Sensor work mode */
uint8_t buffer[SENSOR_RECEIVE_BUFFSIZE]; /* Buffer for read data */ uint8_t buffer[SENSOR_RECEIVE_BUFFSIZE]; /* Buffer for read data */
int ref_cnt; /* Reference count */ int ref_cnt; /* Reference count */
DoublelistType quant_list; /* Sensor quantity link */ DoublelistType quant_list; /* Sensor quantity link */
struct DoublelistNode link; /* Sensors link node */ struct DoublelistNode link; /* Sensors link node */
void *private_data; /* user define private data */
}; };
enum SensorQuantityType { enum SensorQuantityType {
@ -102,7 +112,17 @@ enum SensorQuantityType {
SENSOR_QUANTITY_WINDSPEED, SENSOR_QUANTITY_WINDSPEED,
SENSOR_QUANTITY_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION,
SENSOR_QUANTITY_ALTITUDE, SENSOR_QUANTITY_ALTITUDE,
SENSOR_QUANTITY_O3,
SENSOR_QUANTITY_O2,
SENSOR_QUANTITY_NO2,
SENSOR_QUANTITY_SO2,
SENSOR_QUANTITY_NH3,
SENSOR_QUANTITY_CH20,
SENSOR_QUANTITY_C2H5OH,
SENSOR_QUANTITY_AQS,
SENSOR_QUANTITY_PM1,
/* ...... */ /* ...... */
SENSIR_QUANTITY_INTEGRATION,
SENSOR_QUANTITY_END, SENSOR_QUANTITY_END,
}; };
@ -122,6 +142,7 @@ struct SensorQuantity {
struct SensorDevice *sdev; struct SensorDevice *sdev;
int32_t (*ReadValue)(struct SensorQuantity *quant); int32_t (*ReadValue)(struct SensorQuantity *quant);
int32_t (*ReadDecimalPoint)(struct SensorQuantity *quant);
struct DoublelistNode quant_link; struct DoublelistNode quant_link;
struct DoublelistNode link; struct DoublelistNode link;
@ -135,7 +156,8 @@ int SensorQuantityRegister(struct SensorQuantity *quant);
int SensorQuantityUnregister(struct SensorQuantity *quant); int SensorQuantityUnregister(struct SensorQuantity *quant);
int SensorQuantityOpen(struct SensorQuantity *quant); int SensorQuantityOpen(struct SensorQuantity *quant);
int SensorQuantityClose(struct SensorQuantity *quant); int SensorQuantityClose(struct SensorQuantity *quant);
int SensorQuantityRead(struct SensorQuantity *quant); int SensorQuantityReadValue(struct SensorQuantity *quant);
int SensorQuantityReadDecimalPoint(struct SensorQuantity *quant);
int SensorQuantityControl(struct SensorQuantity *quant, int cmd); int SensorQuantityControl(struct SensorQuantity *quant, int cmd);
uint32_t Crc16(uint8_t * data, uint8_t length); uint32_t Crc16(uint8_t * data, uint8_t length);