-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpioworker.cpp
97 lines (76 loc) · 2.28 KB
/
gpioworker.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
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
#include "gpioworker.h"
//Needs a GPIOWorker pointer to call the toogleMusic signals, since signals can't be static.
GPIOWorker *GPIOWorker::GPIOPtr_ = NULL;
GPIOWorker::GPIOWorker()
{
// pointer to the class so the interrupts function can call the class function
GPIOWorker::GPIOPtr_ = this;
}
void GPIOWorker::run()
{
/** DEBUG **/
//qDebug() << "Hello from GPIO Thread" << thread()->currentThreadId();
interruptInit(); //init interrupts
while(1)
{}
}
void GPIOWorker::turnOnDisplay(bool shouldTurnOn)
{
// Turn off/on display here
if(shouldTurnOn)
QProcess::execute("sudo bash -c \"echo 0 > /sys/class/backlight/rpi_backlight/bl_power\"");
else
QProcess::execute("sudo bash -c \"echo 1 > /sys/class/backlight/rpi_backlight/bl_power\"");
}
void GPIOWorker::myInterruptCamera(void )
{
if(!CameraOn_)
{
/** DEBUG **/
//qDebug() << "Starting Camera\n";
currentCamera_ = new Camera();
currentCamera_->start(); //Start Camera thread
CameraOn_ = true; // Camera on
sleep(1);
}
else
{
/** DEBUG **/
//qDebug() << "Turning off Camera\n";s
currentCamera_->terminate(); //destorys Camera thread
currentCamera_ = NULL; //NO floating pointers!
CameraOn_ = false; //Camera off
}
}
void GPIOWorker::myInterruptDisplay(void)
{
if(DisplayOn_)
{
DisplayOn_ = false;
turnOnDisplay(DisplayOn_); //turns off display
}
else
{
DisplayOn_ = true;
turnOnDisplay(DisplayOn_); //turns on display
}
//Signaling soundworker with turning on music
emit toggleMusic(DisplayOn_);
}
void GPIOWorker::interruptInit(void)
{
setenv("WIRINGPI_GPIOMEM", "1", 1); //makes sure that is 1 at GPIOMEN
wiringPiSetup(); //Calls wiriringpiSetup
//Set pin 17 to trigger at rising edge, and to call InterruptCamera
wiringPiISR(0, INT_EDGE_RISING,&InterruptCamera);
//Set pin 18 to trigger at rising edge, and to call InterruptCamera
wiringPiISR(1, INT_EDGE_RISING,&InterruptDisplay);
}
void InterruptCamera(void)
{
GPIOWorker::GPIOPtr_->myInterruptCamera(); //kalder interrruptCamera
}
void InterruptDisplay(void)
{
GPIOWorker::GPIOPtr_->myInterruptDisplay(); //kalder interruptDisplay
}