add not implemented fuctions for co2 sensor to use as self study part
authorJeonghoon Park <jh1979.park@samsung.com>
Fri, 27 Jul 2018 06:39:00 +0000 (15:39 +0900)
committerJeonghoon Park <jh1979.park@samsung.com>
Fri, 27 Jul 2018 06:39:00 +0000 (15:39 +0900)
inc/co2-sensor.h
src/co2-sensor.c
src/co2.c

index 6a4322e..404437a 100644 (file)
   * @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__ */
 
index caa055c..5f0abc2 100644 (file)
  * 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));
+}
+
index f02bd2f..5fe4367 100644 (file)
--- a/src/co2.c
+++ b/src/co2.c
 
 #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"
 #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);