blob: 0c5334a01b7bfc428905b9ac428556519789d2e6 [file] [log] [blame]
xjde81d1d2021-11-25 15:01:52 +08001#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <stdbool.h>
5#include <unistd.h>
6#include <time.h>
7#include <lynq-system-own.h>
8
9void lynq_lpm_handler(int lpm_edge)
10{
11 FILE * fp = NULL;
12 char buft[32] = {0};
13 char * cmd="cat /sys/devices/platform/10005000.pinctrl/mt_gpio | grep 000: | cut -b 8";
14 //printf("[%s][%d]cmd=[%s]\n",__FUNCTION__,__LINE__,cmd);
15
16 fp = popen (cmd, "r");
17 if (fp) {
18 if (fgets(buft, sizeof(buft), fp) != NULL) {
19 //printf("[%s][%d]%s\n",__FUNCTION__,__LINE__,buft);
20 strtok(buft, "\n");
21
22 }
23 pclose(fp);
24 }
25 //printf("[%s][%d]last_state %d\n",__FUNCTION__,__LINE__,last_state);
26 if(atoi(buft)!=last_state){
27 last_state=atoi(buft);
28 lpm_edge=atoi(buft);
29 printf("[%s][%d]lpm_edge=%d\n",__FUNCTION__,__LINE__,lpm_edge);
30 }
31}
32
33int LYNQ_Lpm_Init (LYNQ_Lpm_Handler_T lynq_lpm_handler)
34{
35 LYNQ_Lpm_Handler=lynq_lpm_handler;
36 return 0;
37}
38int LYNQ_Lpm_Deinit (void)
39{
40 LYNQ_Lpm_Handler=NULL;
41 return 0;
42}
43
44void suspendOperatingSystem()
45{
46 system("killall -9 lynq-function-test");
47 system("echo 7 | emdlogger_ctrl");
48 system("/usr/bin/telephony &");
49 system("sleep 5");
50 system("sh /usr/bin/demoscript/DSDS/set_default_sim_all_except_data.sh 0");
51 system("sh /usr/bin/demoscript/Network_API/RadioOn.sh 0");
52 system("sh /usr/bin/demoscript/DSDS/set_default_sim_all_except_data.sh 1");
53 system("sh /usr/bin/demoscript/Network_API/RadioOn.sh 0");
54 system("echo mem > /sys/power/autosleep");
55}
56
57int LYNQ_Autosleep_Enable(int enable)
58{
59 if(enable){
60 suspendOperatingSystem();
61 }
62 return 0;
63}
64
65int LYNQ_SLP_WakeLock_Lock(const char *name)
66{
67 char gyCmd[64] = {0};
68 sprintf(gyCmd,"echo %s > /sys/power/wake_lock",name);
69 system(gyCmd);
70}
71
72int LYNQ_SLP_WakeLock_Unlock(const char *name)
73{
74 char gyCmd[64] = {0};
75 sprintf(gyCmd,"echo %s > /sys/power/wake_unlock",name);
76 system(gyCmd);
77}
78
79void LYNQ_Power_Mode(char *power_mode)
80{
81 char gyCmd[64] = {0};
82 sprintf(gyCmd,"sh /etc/powerscript/power_mode_own %s",power_mode);
83 system(gyCmd);
84}
85
86void LYNQ_Power_Down(int mode)
87{
88 if(mode){
89 system("reboot");
90 }else{
91 system("init 0");
92 }
93}
94
95int LYNQ_Adc_Show(int adc_num)
96{
97 FILE * fp = NULL;
98 char buft[32] = {0};
99 char * cmd="cat /sys/bus/iio/devices/iio:device0/in_voltage0_BATADC_input";
100 //printf("[%s][%d]cmd=[%s]\n",__FUNCTION__,__LINE__,cmd);
101
102 fp = popen (cmd, "r");
103 if (fp) {
104 if (fgets(buft, sizeof(buft), fp) != NULL) {
105 //printf("[%s][%d]%s\n",__FUNCTION__,__LINE__,buft);
106 strtok(buft, "\n");
107
108 }
109 pclose(fp);
110 }
111 return atoi(buft);
112}
113
114