add function for get voltage from value
authorJeonghoon Park <jh1979.park@samsung.com>
Fri, 27 Jul 2018 02:48:34 +0000 (11:48 +0900)
committerJeonghoon Park <jh1979.park@samsung.com>
Fri, 27 Jul 2018 02:49:01 +0000 (11:49 +0900)
src/co2.c

index 85cb843..f02bd2f 100644 (file)
--- a/src/co2.c
+++ b/src/co2.c
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-#include <co2-sensor.h>
 #include <tizen.h>
 #include <service_app.h>
 #include <stdio.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)
@@ -48,6 +52,15 @@ 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;
@@ -78,6 +91,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));
 
                sensor_data_set_uint(ad->co2_data, avg);
 
@@ -141,6 +155,8 @@ static bool handle_get_request(st_things_get_request_message_s* req_msg, st_thin
        retv_if(!g_ad, false);
 
        if (0 == strcmp(req_msg->resource_uri, SENSOR_URI_CO2)) {
+               _D("query : %s, property: %s", req_msg->query, req_msg->property_key);
+
                if (req_msg->has_property_key(req_msg, SENSOR_KEY_CO2)) {
                        unsigned int value = 0;
                        sensor_data_get_uint(g_ad->co2_data, &value);