1、修改设备树
button1 {
label ="return";
linux,code=;
gpios=<&gpio2 1 GPIO_ACTIVE_LOW>;
gpio-key,wakeup;
};
添加gpio-key,wakeup字段,表示当该按键按下后会唤醒。
2、编写C程序power_test.c
首先了解下Linux下的电源状态
- On(on) S0 - Working
- Standby (standby) S1 - CPU and RAM are powered but not executed
- Suspend to RAM(mem) S3 - RAM is powered and the running content is saved to RAM
- Suspend to Disk,Hibernation(disk) S4 - All content is saved to Disk and power down
为了使效率高,我们采用休眠的时候写mem的方式,直接写进内存,唤醒的时候从内存读出,相对于标准方式和Disk方式要好
#include
#include
#include
#include
int main(void)
{
int fd;
char *cmd = "mem";
fd = open("/sys/power/state", O_WRONLY, 0666);
if(fd < 0)
{
printf("power off failed
");
return -1;
}
write(fd, cmd, strlen(cmd));
close(fd);
return 0;
}
其实程序的含义就是 echo mem > /sys/power/state,其实是一个意思。
将power_test.c交叉编译为power_test,并将power_test拷贝到/bin目录下。
3、QT APP上添加按键休眠的方法
void MainWindow::keyPressEvent(QKeyEvent *event)
{
....
//电源键
case Qt::Key_PowerDown:
//进入休眠状态
QProcess::startDetached("power_test");
setFocus();
break ;
...
}
4、成功实现产品的低功耗
参考:
https://blog.csdn.net/u014525494/article/details/80610364?utm_source=blogxgwz6
https://bbs.csdn.net/topics/390810878