diff --git a/APP_Framework/Applications/sensor_app/altitude_bmp180.c b/APP_Framework/Applications/sensor_app/altitude_bmp180.c index 36fc811b0..a9ea40ca6 100644 --- a/APP_Framework/Applications/sensor_app/altitude_bmp180.c +++ b/APP_Framework/Applications/sensor_app/altitude_bmp180.c @@ -30,7 +30,7 @@ void AltitudeBmp180(void) int32 altitude; struct SensorQuantity *p_altitude = SensorQuantityFind(SENSOR_QUANTITY_BMP180_ALTITUDE, SENSOR_QUANTITY_ALTITUDE); SensorQuantityOpen(p_altitude); - altitude = SensorQuantityRead(p_altitude); + altitude = SensorQuantityReadValue(p_altitude); printf("Altitude Pressure : %d Pa\n", altitude); diff --git a/APP_Framework/Applications/sensor_app/ch4_as830.c b/APP_Framework/Applications/sensor_app/ch4_as830.c index b5b5e215e..cd16ebe5a 100644 --- a/APP_Framework/Applications/sensor_app/ch4_as830.c +++ b/APP_Framework/Applications/sensor_app/ch4_as830.c @@ -31,6 +31,6 @@ void Ch4As830(void) { struct SensorQuantity *ch4 = SensorQuantityFind(SENSOR_QUANTITY_AS830_CH4, SENSOR_QUANTITY_CH4); SensorQuantityOpen(ch4); - printf("CH4 : %d %%LTL\n", SensorQuantityRead(ch4)); + printf("CH4 : %d %%LTL\n", SensorQuantityReadValue(ch4)); SensorQuantityClose(ch4); } \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/co2_g8s.c b/APP_Framework/Applications/sensor_app/co2_g8s.c index d19a25ab2..d62f4c0f5 100644 --- a/APP_Framework/Applications/sensor_app/co2_g8s.c +++ b/APP_Framework/Applications/sensor_app/co2_g8s.c @@ -31,6 +31,6 @@ void Co2G8s(void) { struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_G8S_CO2, SENSOR_QUANTITY_CO2); SensorQuantityOpen(co2); - printf("CO2 : %d ppm\n", SensorQuantityRead(co2)); + printf("CO2 : %d ppm\n", SensorQuantityReadValue(co2)); SensorQuantityClose(co2); } \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/co2_zg09.c b/APP_Framework/Applications/sensor_app/co2_zg09.c index 74e11d2b4..0b08cadd1 100644 --- a/APP_Framework/Applications/sensor_app/co2_zg09.c +++ b/APP_Framework/Applications/sensor_app/co2_zg09.c @@ -31,6 +31,6 @@ void Co2Zg09(void) { struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_ZG09_CO2, SENSOR_QUANTITY_CO2); SensorQuantityOpen(co2); - printf("CO2 : %d ppm\n", SensorQuantityRead(co2)); + printf("CO2 : %d ppm\n", SensorQuantityReadValue(co2)); SensorQuantityClose(co2); } \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/hcho_tb600b_wq_hcho1os.c b/APP_Framework/Applications/sensor_app/hcho_tb600b_wq_hcho1os.c index e0988ecac..3f4522b69 100644 --- a/APP_Framework/Applications/sensor_app/hcho_tb600b_wq_hcho1os.c +++ b/APP_Framework/Applications/sensor_app/hcho_tb600b_wq_hcho1os.c @@ -34,7 +34,7 @@ void HchoTb600bHcho1os(void) SensorQuantityOpen(hcho); int32_t result = 0; - result = SensorQuantityRead(hcho); + result = SensorQuantityReadValue(hcho); printf("tvoc concentration is : %dppb\n", result); SensorQuantityClose(hcho); diff --git a/APP_Framework/Applications/sensor_app/humidity_hs300x.c b/APP_Framework/Applications/sensor_app/humidity_hs300x.c index d582e393f..01e7bbd6e 100644 --- a/APP_Framework/Applications/sensor_app/humidity_hs300x.c +++ b/APP_Framework/Applications/sensor_app/humidity_hs300x.c @@ -35,7 +35,7 @@ void HumiHs300x(void) struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI); SensorQuantityOpen(humi); for (i = 0; i < 100; i ++) { - humidity = SensorQuantityRead(humi); + humidity = SensorQuantityReadValue(humi); printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10); PrivTaskDelay(5000); } diff --git a/APP_Framework/Applications/sensor_app/iaq_tb600b_iaq10.c b/APP_Framework/Applications/sensor_app/iaq_tb600b_iaq10.c index 9f4a1dc43..09545d34b 100644 --- a/APP_Framework/Applications/sensor_app/iaq_tb600b_iaq10.c +++ b/APP_Framework/Applications/sensor_app/iaq_tb600b_iaq10.c @@ -40,7 +40,7 @@ void IaqTb600bIaq10(void) SensorQuantityOpen(iaq); int32_t result = 0; - result = SensorQuantityRead(iaq); + result = SensorQuantityReadValue(iaq); printf("Gas concentration is : %dppb\n", result); SensorQuantityClose(iaq); diff --git a/APP_Framework/Applications/sensor_app/pm10_0_ps5308.c b/APP_Framework/Applications/sensor_app/pm10_0_ps5308.c index 5d6408808..a7f173b28 100644 --- a/APP_Framework/Applications/sensor_app/pm10_0_ps5308.c +++ b/APP_Framework/Applications/sensor_app/pm10_0_ps5308.c @@ -33,6 +33,6 @@ void Pm100Ps5308(void) struct SensorQuantity *pm10_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM10, SENSOR_QUANTITY_PM); SensorQuantityOpen(pm10_0); PrivTaskDelay(2000); - printf("PM10 : %d ug/m³\n", SensorQuantityRead(pm10_0)); + printf("PM10 : %d ug/m³\n", SensorQuantityReadValue(pm10_0)); SensorQuantityClose(pm10_0); } \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/pm1_0_ps5308.c b/APP_Framework/Applications/sensor_app/pm1_0_ps5308.c index e0c80680e..dc9448bc8 100644 --- a/APP_Framework/Applications/sensor_app/pm1_0_ps5308.c +++ b/APP_Framework/Applications/sensor_app/pm1_0_ps5308.c @@ -33,6 +33,6 @@ void Pm10Ps5308(void) struct SensorQuantity *pm1_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM1_0, SENSOR_QUANTITY_PM); SensorQuantityOpen(pm1_0); 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); } \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/pm2_5_ps5308.c b/APP_Framework/Applications/sensor_app/pm2_5_ps5308.c index 23aaca509..672826be2 100644 --- a/APP_Framework/Applications/sensor_app/pm2_5_ps5308.c +++ b/APP_Framework/Applications/sensor_app/pm2_5_ps5308.c @@ -33,6 +33,6 @@ void Pm25Ps5308(void) struct SensorQuantity *pm2_5 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM2_5, SENSOR_QUANTITY_PM); SensorQuantityOpen(pm2_5); 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); } \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/temperature_hs300x.c b/APP_Framework/Applications/sensor_app/temperature_hs300x.c index f6e461405..83f8594b1 100644 --- a/APP_Framework/Applications/sensor_app/temperature_hs300x.c +++ b/APP_Framework/Applications/sensor_app/temperature_hs300x.c @@ -35,7 +35,7 @@ void TempHs300x(void) struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP); SensorQuantityOpen(temp); for (i = 0; i < 100; i ++) { - temperature = SensorQuantityRead(temp); + temperature = SensorQuantityReadValue(temp); if (temperature > 0) printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10); else diff --git a/APP_Framework/Applications/sensor_app/tvoc_tb600b_tvoc10.c b/APP_Framework/Applications/sensor_app/tvoc_tb600b_tvoc10.c index 81cb965c2..c3fe7d7f6 100644 --- a/APP_Framework/Applications/sensor_app/tvoc_tb600b_tvoc10.c +++ b/APP_Framework/Applications/sensor_app/tvoc_tb600b_tvoc10.c @@ -34,7 +34,7 @@ void TvocTb600bTvoc10(void) SensorQuantityOpen(tvoc); int32_t result = 0; - result = SensorQuantityRead(tvoc); + result = SensorQuantityReadValue(tvoc); printf("tvoc concentration is : %dppb\n", result); SensorQuantityClose(tvoc); diff --git a/APP_Framework/Applications/sensor_app/voice_d124.c b/APP_Framework/Applications/sensor_app/voice_d124.c index b86bf2360..033e6dfcf 100644 --- a/APP_Framework/Applications/sensor_app/voice_d124.c +++ b/APP_Framework/Applications/sensor_app/voice_d124.c @@ -30,7 +30,7 @@ void VoiceD124(void) struct SensorQuantity *voice = SensorQuantityFind(SENSOR_QUANTITY_D124_VOICE, SENSOR_QUANTITY_VOICE); SensorQuantityOpen(voice); 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)); SensorQuantityClose(voice); } \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/winddirection_qs_fx.c b/APP_Framework/Applications/sensor_app/winddirection_qs_fx.c index d5032718b..bef5b54c3 100644 --- a/APP_Framework/Applications/sensor_app/winddirection_qs_fx.c +++ b/APP_Framework/Applications/sensor_app/winddirection_qs_fx.c @@ -30,7 +30,7 @@ void WindDirectionQsFx(void) struct SensorQuantity *wind_direction = SensorQuantityFind(SENSOR_QUANTITY_QS_FX_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION); SensorQuantityOpen(wind_direction); PrivTaskDelay(2000); - uint16 result = SensorQuantityRead(wind_direction); + uint16 result = SensorQuantityReadValue(wind_direction); printf("wind direction : %d degree\n", result); SensorQuantityClose(wind_direction); } diff --git a/APP_Framework/Applications/sensor_app/windspeed_qs_fs.c b/APP_Framework/Applications/sensor_app/windspeed_qs_fs.c index 72b91db6e..e3d3b959b 100644 --- a/APP_Framework/Applications/sensor_app/windspeed_qs_fs.c +++ b/APP_Framework/Applications/sensor_app/windspeed_qs_fs.c @@ -30,7 +30,7 @@ void WindSpeedQsFs(void) struct SensorQuantity *wind_speed = SensorQuantityFind(SENSOR_QUANTITY_QS_FS_WINDSPEED, SENSOR_QUANTITY_WINDSPEED); SensorQuantityOpen(wind_speed); PrivTaskDelay(2000); - uint16 result = SensorQuantityRead(wind_speed); + uint16 result = SensorQuantityReadValue(wind_speed); printf("wind speed : %d.%d m/s\n", result/10, result%10); SensorQuantityClose(wind_speed); } diff --git a/APP_Framework/Framework/sensor/sensor.c b/APP_Framework/Framework/sensor/sensor.c index 372acb74d..225b2014c 100644 --- a/APP_Framework/Framework/sensor/sensor.c +++ b/APP_Framework/Framework/sensor/sensor.c @@ -314,7 +314,7 @@ int SensorQuantityClose(struct SensorQuantity *quant) * @param quant - sensor quantity pointer * @return quantity value */ -int SensorQuantityRead(struct SensorQuantity *quant) +int SensorQuantityReadValue(struct SensorQuantity *quant) { if (!quant) return -1; @@ -332,6 +332,29 @@ int SensorQuantityRead(struct SensorQuantity *quant) 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 * @param quant - sensor quantity pointer diff --git a/APP_Framework/Framework/sensor/sensor.h b/APP_Framework/Framework/sensor/sensor.h index 4ec9b6480..6287dd0e9 100644 --- a/APP_Framework/Framework/sensor/sensor.h +++ b/APP_Framework/Framework/sensor/sensor.h @@ -44,20 +44,29 @@ extern "C" { #endif /* Sensor ability */ -#define SENSOR_ABILITY_CO2 ((uint32_t)(1 << SENSOR_QUANTITY_CO2)) -#define SENSOR_ABILITY_TEMP ((uint32_t)(1 << SENSOR_QUANTITY_TEMP)) -#define SENSOR_ABILITY_HUMI ((uint32_t)(1 << SENSOR_QUANTITY_HUMI)) -#define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO)) -#define SENSOR_ABILITY_CO ((uint32_t)(1 << SENSOR_QUANTITY_CO)) -#define SENSOR_ABILITY_PM ((uint32_t)(1 << SENSOR_QUANTITY_PM)) -#define SENSOR_ABILITY_VOICE ((uint32_t)(1 << SENSOR_QUANTITY_VOICE)) -#define SENSOR_ABILITY_CH4 ((uint32_t)(1 << SENSOR_QUANTITY_CH4)) -#define SENSOR_ABILITY_IAQ ((uint32_t)(1 << SENSOR_QUANTITY_IAQ)) -#define SENSOR_ABILITY_TVOC ((uint32_t)(1 << SENSOR_QUANTITY_TVOC)) -#define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO)) +#define SENSOR_ABILITY_CO2 ((uint32_t)(1 << SENSOR_QUANTITY_CO2)) +#define SENSOR_ABILITY_TEMP ((uint32_t)(1 << SENSOR_QUANTITY_TEMP)) +#define SENSOR_ABILITY_HUMI ((uint32_t)(1 << SENSOR_QUANTITY_HUMI)) +#define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO)) +#define SENSOR_ABILITY_CO ((uint32_t)(1 << SENSOR_QUANTITY_CO)) +#define SENSOR_ABILITY_PM ((uint32_t)(1 << SENSOR_QUANTITY_PM)) +#define SENSOR_ABILITY_VOICE ((uint32_t)(1 << SENSOR_QUANTITY_VOICE)) +#define SENSOR_ABILITY_CH4 ((uint32_t)(1 << SENSOR_QUANTITY_CH4)) +#define SENSOR_ABILITY_IAQ ((uint32_t)(1 << SENSOR_QUANTITY_IAQ)) +#define SENSOR_ABILITY_TVOC ((uint32_t)(1 << SENSOR_QUANTITY_TVOC)) +#define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO)) #define SENSOR_ABILITY_WINDSPEED ((uint32_t)(1 << SENSOR_QUANTITY_WINDSPEED)) #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 { uint32_t ability; /* Bitwise OR of sensor ability */ @@ -76,16 +85,17 @@ struct SensorDone { }; struct SensorDevice { - char *name; /* Name of sensor */ - struct SensorProductInfo *info; /* Sensor model info */ + char *name; /* Name of sensor */ + struct SensorProductInfo *info; /* Sensor model info */ struct SensorDone *done; - int fd; /* File descriptor */ - int status; /* Sensor work mode */ + int fd; /* File descriptor */ + int status; /* Sensor work mode */ uint8_t buffer[SENSOR_RECEIVE_BUFFSIZE]; /* Buffer for read data */ - int ref_cnt; /* Reference count */ - DoublelistType quant_list; /* Sensor quantity link */ - struct DoublelistNode link; /* Sensors link node */ + int ref_cnt; /* Reference count */ + DoublelistType quant_list; /* Sensor quantity link */ + struct DoublelistNode link; /* Sensors link node */ + void *private_data; /* user define private data */ }; enum SensorQuantityType { @@ -102,7 +112,17 @@ enum SensorQuantityType { SENSOR_QUANTITY_WINDSPEED, SENSOR_QUANTITY_WINDDIRECTION, 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, }; @@ -122,6 +142,7 @@ struct SensorQuantity { struct SensorDevice *sdev; int32_t (*ReadValue)(struct SensorQuantity *quant); + int32_t (*ReadDecimalPoint)(struct SensorQuantity *quant); struct DoublelistNode quant_link; struct DoublelistNode link; @@ -135,7 +156,8 @@ int SensorQuantityRegister(struct SensorQuantity *quant); int SensorQuantityUnregister(struct SensorQuantity *quant); int SensorQuantityOpen(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); uint32_t Crc16(uint8_t * data, uint8_t length);