diff options
author | Jeonghoon Park <jh1979.park@samsung.com> | 2018-07-27 15:39:00 +0900 |
---|---|---|
committer | Jeonghoon Park <jh1979.park@samsung.com> | 2018-07-27 15:39:00 +0900 |
commit | d79a9c940a7524a09ab41ea3bb7dd1c276e67b21 (patch) | |
tree | 68d3c63c3e2a098e964e2c453e448239f898718a | |
parent | 871c85d487247a2cac7217f84f0114c4d7878f5d (diff) | |
download | st-things-co2-meter-d79a9c940a7524a09ab41ea3bb7dd1c276e67b21.tar.gz st-things-co2-meter-d79a9c940a7524a09ab41ea3bb7dd1c276e67b21.tar.bz2 st-things-co2-meter-d79a9c940a7524a09ab41ea3bb7dd1c276e67b21.zip |
add not implemented fuctions for co2 sensor to use as self study part
-rw-r--r-- | inc/co2-sensor.h | 13 | ||||
-rw-r--r-- | src/co2-sensor.c | 33 | ||||
-rw-r--r-- | src/co2.c | 18 |
3 files changed, 41 insertions, 23 deletions
diff --git a/inc/co2-sensor.h b/inc/co2-sensor.h index 6a4322e..404437a 100644 --- a/inc/co2-sensor.h +++ b/inc/co2-sensor.h @@ -24,8 +24,17 @@ * @return 0 on success, otherwise a negative error value * */ -extern int co2_sensor_read(int ch_num, unsigned int *out_value); -extern void co2_sensor_close(void); +int co2_sensor_read(int ch_num, unsigned int *out_value); + +/* release resource */ +void co2_sensor_close(void); + +/* utility functions */ +double co2_sensor_value_to_voltage(unsigned int value); + +/* Not implemented, please see c source code */ +int co2_sensor_voltage_to_ppm(double voltage); +int co2_sensor_value_to_ppm(unsigned int value); #endif /* __CO2_SENSOR_H__ */ diff --git a/src/co2-sensor.c b/src/co2-sensor.c index caa055c..5f0abc2 100644 --- a/src/co2-sensor.c +++ b/src/co2-sensor.c @@ -14,14 +14,13 @@ * limitations under the License. */ -#include <stdlib.h> -#include <unistd.h> #include <peripheral_io.h> -#include <sys/time.h> - #include "adc-mcp3008.h" #include "log.h" +#define CO2_SENSOR_REF_VOLTAGE (5) +#define CO2_SENSOR_VALUE_MAX (1024) + static bool initialized = false; void co2_sensor_close(void) @@ -48,3 +47,29 @@ int co2_sensor_read(int ch_num, unsigned int *out_value) return 0; } +double co2_sensor_value_to_voltage(unsigned int value) +{ + double v = 0; + + v = (double)value * CO2_SENSOR_REF_VOLTAGE / CO2_SENSOR_VALUE_MAX; + + return v; +} + +/* Not implemented, please see c source code */ +int co2_sensor_voltage_to_ppm(double voltage) +{ + int ppm = 0; + + /* Make this function yourself */ + /* Please ref. 'Theory' section in https://sandboxelectronics.com/?p=147#Theory */ + + return ppm; +} + +int co2_sensor_value_to_ppm(unsigned int value) +{ + /* You can use this function after implementing co2_sensor_voltage_to_ppm() function */ + return co2_sensor_voltage_to_ppm(co2_sensor_value_to_voltage(value)); +} + @@ -16,10 +16,8 @@ #include <tizen.h> #include <service_app.h> -#include <stdio.h> #include <string.h> #include <stdlib.h> -#include <pthread.h> #include <Ecore.h> #include "st_things.h" @@ -33,11 +31,6 @@ #define SENSOR_KEY_RANGE "range" #define SENSOR_CH_CO2 (0) -#define SENSOR_REF_VOLTAGE (5) -#define SENSOR_VALUE_MAX (1024) -#define SENSOR_CO2_V_ZP (0.471) -#define SENSOR_CO2_V_RA (0.030) - #define SENSOR_THRESHOLD_CO2 (650) #define SENSOR_GATHER_INTERVAL (0.05f) @@ -52,15 +45,6 @@ typedef struct app_data_s { static app_data *g_ad = NULL; -static double __value_to_voltage(unsigned int value) -{ - double v = 0; - - v = (double)value * SENSOR_REF_VOLTAGE / SENSOR_VALUE_MAX; - - return v; -} - static Eina_Bool __get_co2(void *data) { int ret = 0; @@ -91,7 +75,7 @@ static Eina_Bool __get_co2(void *data) avg = sum/SENSOR_GATHER_COUNT; _D("co2 avg value - %u", avg); - _D("co2 avg voltage - %.2lfv", __value_to_voltage(avg)); + _D("co2 avg voltage - %.2lfv", co2_sensor_value_to_voltage(avg)); sensor_data_set_uint(ad->co2_data, avg); |