system.cpp
1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "system.h"
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/rtc.h>
void System::setIP(System::IPData &data)
{
QString ifconfig = QString("ifconfig eth0 %1 netmask %2 up").arg(data.address, data.netmask);
QString route = QString("route del default; route add default gw %1").arg(data.gateway);
system(ifconfig.toLocal8Bit().constData());
system(route.toLocal8Bit().constData());
}
void System::setBacklight(int level)
{
static int last = -1;
if (level == last)
return;
last = level;
QString command = QString("echo %1 > /sys/class/backlight/backlight_lvds.19/brightness").arg(level);
system(command.toLocal8Bit().constData());
}
void System::setVolume(int percentage)
{
static int last = -1;
if (percentage == last)
return;
last = percentage;
QString command = QString("/usr/bin/amixer -c 0 sset 'PCM',0 %1% %1% on > /dev/null").arg(percentage);
system(command.toLocal8Bit().constData());
}
bool System::setRtcTime(QDateTime dt_tm){
int fd;
rtc_time rt;
rt.tm_year = dt_tm.date().year() - 1900;
rt.tm_mon = dt_tm.date().month()-1;
rt.tm_mday = dt_tm.date().day();
rt.tm_hour = dt_tm.time().hour();
rt.tm_min = dt_tm.time().minute();
rt.tm_sec = 0;
fd = open("/dev/rtc0", O_WRONLY);
if(fd <0){
return false;
}{
ioctl(fd, RTC_SET_TIME, &rt);
close(fd);
return true;
}
}