-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.cpp
More file actions
93 lines (81 loc) · 2.21 KB
/
button.cpp
File metadata and controls
93 lines (81 loc) · 2.21 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
#include "button.hpp"
#include "wiringPi.h"
#include <QDebug>
button::button(QObject* parent) : QObject(parent)
{
counter=0;
}
button::button(int pin_increase_input,int pin_decrease_input,int pin_mode_input, int pin_ring_input, Modbus *p)
{
pModbus = p;
counter=1;
now=0;
mode=false;
pin_increase=pin_increase_input;
pin_decrease=pin_decrease_input;
pin_mode=pin_mode_input;
pin_ring = pin_ring_input;
wiringPiSetup () ;
pinMode (pin_increase, INPUT) ;
pullUpDnControl(pin_increase,PUD_UP);
pinMode (pin_decrease, INPUT) ;
pullUpDnControl(pin_decrease,PUD_UP);
pinMode (pin_mode, INPUT) ;
pullUpDnControl(pin_mode,PUD_UP);
pinMode (pin_ring, INPUT) ;
pullUpDnControl(pin_ring,PUD_UP);
timer = new QTimer(this);
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(readValue()));
timer->start(100); //time specified in ms
}
void button::readValue()
{
static bool trigger_increase=false;
static bool trigger_decrease=false;
static bool trigger_mode=false;
static bool trigger_ring=false;
if (digitalRead(pin_increase)==0) {
trigger_increase=true;
}
if (trigger_increase==true)
{
if (digitalRead(pin_increase)==1)
{
counter++;trigger_increase=false;
if (counter>7) counter =1;
emit varChanged();
emit varChanged2();
}
}
if (digitalRead(pin_decrease)==0) {
trigger_decrease=true;
}
if (trigger_decrease==true)
{
if (digitalRead(pin_decrease)==1)
{
counter--;
if (counter == 0) counter =7;
trigger_decrease=false;
emit varChanged();
emit varChanged2();
qDebug()<< "button decreas press , varchanged";
}
}
if (digitalRead(pin_mode)==0) {
trigger_mode=true;
}
if (trigger_mode==true)
{
if (digitalRead(pin_mode)==1) {mode=!mode;trigger_mode=false;emit modeChanged();}
}
if (digitalRead(pin_ring)==0) {
trigger_ring=true;
}
if (trigger_ring==true)
{
if (digitalRead(pin_ring)==1) {
qDebug()<< "button ring press";
trigger_ring=false; pModbus->errVisible=!pModbus->errVisible; emit pModbus->errChanged();}
}
}