-
Notifications
You must be signed in to change notification settings - Fork 1
/
BeeperThread.cpp
51 lines (47 loc) · 1.17 KB
/
BeeperThread.cpp
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
#include "BeeperThread.h"
#if _WIN32
#define OUTPUT 0
#define LOW 0
#define HIGH 0
void digitalWrite(int,int){};
void pinMode(int,int){};
#else
#include <wiringPi.h>
#endif
quint8 BeeperThread::pin=4;
bool BeeperThread::pinInited=false;
BeeperThread::BeeperThread(QObject *parent):QThread(parent){
this->interval=100;
this->delay=100;
this->times=0;
if(!BeeperThread::pinInited){
BeeperThread::pinInited=true;
pinMode(BeeperThread::pin,OUTPUT);
}
}
BeeperThread::~BeeperThread(){
digitalWrite(BeeperThread::pin,LOW);
}
void BeeperThread::beep(quint32 times){
if(this->isRunning())
this->wait();
this->times=times;
this->start(TimeCriticalPriority);
}
void BeeperThread::run(){
while(this->times>0){
digitalWrite(BeeperThread::pin,HIGH);
this->msleep(this->delay);
digitalWrite(BeeperThread::pin,LOW);
this->msleep(this->interval);
this->times--;
if(this->thread()->isInterruptionRequested())
break;
}
}
void BeeperThread::setDelay(quint32 delay){
this->delay=delay;
}
void BeeperThread::setInterval(quint32 interval){
this->interval=interval;
}