-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHardwareLayer.cpp
More file actions
148 lines (127 loc) · 3.02 KB
/
Copy pathHardwareLayer.cpp
File metadata and controls
148 lines (127 loc) · 3.02 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "HardwareLayer.h"
#include "QTimerEvent"
#include "QMessageBox"
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <linux/input.h>
#include "Log.h"
CHardwareLayer* CHardwareLayer::pHW=NULL;
CHardwareLayer::CHardwareLayer(QWidget* pWidgetSelector) :
QThread(0)
{
this->pWidgetSelector=pWidgetSelector;
timerKeyJoy=0;
lastVolume=-1;
pMixer=NULL;
fdKey = open("/dev/input/by-id/soc-noserial-event-kbd",O_RDONLY);
if(fdKey<=0)
{
CLog::Log("Can't open Keyboard device\n");
}
fdJoy = open("/dev/input/by-id/soc-noserial-event-joystick",O_RDONLY);
if(fdJoy<=0)
{
CLog::Log("Can't open Joystick device\n");
}
if(fdJoy && fdKey)
{
timerKeyJoy = startTimer(100);
}
isButtonDown=false;
//-F- Starting process
start();
}
CHardwareLayer::~CHardwareLayer()
{
close(fdKey);
close(fdJoy);
killTimer(timerKeyJoy);
exit();
delete pMixer;
}
void CHardwareLayer::CreateHardwareLayer(QWidget* pWidgetSelector)
{
if(!pHW)
{
pHW = new CHardwareLayer(pWidgetSelector);
}
}
void CHardwareLayer::timerEvent(QTimerEvent *ev)
{
if(ev->timerId()==timerKeyJoy)
{
struct input_event ev;
//-F- Button check
pollfd pollStruct = {fdKey,POLLIN,0};
while(poll(&pollStruct,1,0))
{
if(read (fdKey, &ev, sizeof(ev))==sizeof(ev))
{
if(ev.value)
{
OnButtonPress();
isButtonDown=true;
}
else
{
OnButtonRelease();
isButtonDown=false;
}
}
}
//-F- Joystick check
pollStruct.fd=fdJoy;
while(poll(&pollStruct,1,0))
{
struct input_event ev;
if(read (fdJoy, &ev, sizeof(ev))==sizeof(ev))
{
emit OnRotaryMoved(ev.value,isButtonDown);
}
}
}
}
void CHardwareLayer::SetVolume(int volume)
{
lastVolume=volume;
if(!pMixer)
{
pMixer=new QProcess(this);
//-F- Connecting amixer signals
connect(pMixer,SIGNAL(finished(int)),SLOT(OnMixerFinished(int)));
}
if(pMixer->state()==QProcess::NotRunning)
{
lastVolume=-1;
QString str;
str.setNum(volume);
pMixer->start("amixer", QStringList() << "sset"<<"DAC"<<str);
}
}
void CHardwareLayer::OnMixerFinished(int)
{
if(lastVolume>=0)
{
QString str;
str.setNum(lastVolume);
pMixer->start("amixer", QStringList() << "sset"<<"DAC"<<str);
}
}
void CHardwareLayer::SetBrightness(unsigned int brightness)
{
if(brightness>100)
{
return;
}
FILE* fdLight = fopen("/sys/devices/platform/stmp3xxx-bl/backlight/stmp3xxx-bl/brightness","wb");
if(fdLight<=0)
{
CLog::Log("Can't open backlight device\n");
}
else
{
fprintf(fdLight,"%u\n",brightness);
fclose(fdLight);
}
}