-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuzzer.cpp
More file actions
68 lines (56 loc) · 1.15 KB
/
Copy pathbuzzer.cpp
File metadata and controls
68 lines (56 loc) · 1.15 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
//
// C++ Implementation: Buzzer
//
// Description:
//
//
// Author: Jacek Kosek <jacek.kosek@pwr.wroc.pl>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include <QString>
#include <QSettings>
#include <QFile>
#include "buzzer.h"
#include "types.h"
Buzzer::Buzzer(QObject *parent)
: QThread(parent), quit(false)
{
}
Buzzer::~Buzzer()
{
quit = true;
cond.wakeOne();
wait();
}
void Buzzer::beep(int msecArg) {
QMutexLocker locker(&mutex);
msec = msecArg;
if (!isRunning())
start();
else
cond.wakeOne();
}
void Buzzer::run()
{
mutex.lock();
int msecTime = msec;
mutex.unlock();
QSettings system(SysConfigFileName, QSettings::IniFormat);
QString gpioName = QString("/proc/gpio/GPIO") +
QString(system.value("beeperGPIO","16").toString());
qDebug("nazwa: %s",qPrintable(gpioName));
QFile file(gpioName);
file.open( QIODevice::WriteOnly|QIODevice::Text| QIODevice::Unbuffered );
file.write("GPIO",5);
file.write("out",4);
while (!quit) {
file.write("set",4);
msleep(msecTime);
file.write("clear",6);
QMutexLocker locker(&mutex);
cond.wait(&mutex);
msecTime = msec;
}
}