* @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__ */
* 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)
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));
+}
+
#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)
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;
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);