Squashed 'LYNQ_PUBLIC/' content from commit 79d8f932f
git-subtree-dir: LYNQ_PUBLIC
git-subtree-split: 79d8f932fb4ebc4b5aec6c5ace97634912394272
Change-Id: If2527ba937f56fe989487bf71e996f7cfd9fbe61
diff --git a/common_src/lib/liblynq-qser-adc/liblynq_qser_adc.cpp b/common_src/lib/liblynq-qser-adc/liblynq_qser_adc.cpp
new file mode 100755
index 0000000..98f037f
--- /dev/null
+++ b/common_src/lib/liblynq-qser-adc/liblynq_qser_adc.cpp
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <liblog/lynq_deflog.h>
+#include "include/liblynq-qser-adc.h"
+#define USER_LOG_TAG "LIBLYNQ_QSER_ADC"
+#undef LOG_TAG
+#define LOG_TAG "LIBLYNQ_QSER_ADC"
+int qser_adc_show(ADC_CHANNEL_E qadc)
+{
+ int adc_value;
+ char cmd[1024];
+ char cmd_ret[1024];
+ FILE *fp;
+ switch(qadc)
+ {
+ case QADC_NONE:
+ {
+ LYERRLOG("function %s line %d\n", __FUNCTION__, __LINE__);
+ return 0;
+ }
+ case ADC0:
+ {
+ LYDBGLOG("function %s line %d\n", __FUNCTION__, __LINE__);
+ sprintf(cmd,"cat /sys/bus/iio/devices/iio:device1/in_voltage0_input");
+ break;
+ }
+ case ADC1:
+ {
+ LYDBGLOG("function %s line %d\n", __FUNCTION__, __LINE__);
+ sprintf(cmd,"cat /sys/bus/iio/devices/iio:device1/in_voltage1_input");
+ break;
+ }
+ case ADC2:
+ {
+ LYDBGLOG("function %s line %d\n", __FUNCTION__, __LINE__);
+ sprintf(cmd,"cat /sys/bus/iio/devices/iio:device1/in_voltage2_input");
+ break;
+ }
+ default:
+ {
+ LYERRLOG("input error\n");
+ return -1;
+ }
+ }
+ if((fp = popen(cmd,"r")) == NULL)
+ {
+ LYERRLOG("popen error!");
+ return -1;
+ }
+ if((fread(cmd_ret,sizeof(cmd_ret),1,fp))<0)
+ {
+ LYERRLOG("fread fail!");
+ fclose(fp);
+ return -1;
+ }
+ fclose(fp);
+
+ adc_value = atoi(cmd_ret);
+ if (adc_value < 0 || adc_value > 12000)
+ {
+ LYERRLOG("bad adc value %s!", cmd_ret);
+ return -1;
+ }
+
+ return adc_value;
+}