-
Notifications
You must be signed in to change notification settings - Fork 1
/
motionsensor.cpp
90 lines (78 loc) · 2.64 KB
/
motionsensor.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
#include "motionsensor.h"
#include "ui_motionsensor.h"
MotionSensor::MotionSensor(QWidget *parent, const char *title)
: SensorInterface(parent)
, ui(new Ui::MotionSensor)
, useCounter(false)
, showLeds(false)
{
ui->setupUi(this);
ui->check->setDisabled(true);
setCheckBox(ui->check);
ui->groupBox->setTitle(title);
connectTooltipTo(ui->groupBox);
statusLED = ui->statusLED;
// Connect the button and the checkbox
connect(this, &MotionSensor::valueChanged, this, &MotionSensor::updateUi);
connect(this, &SensorInterface::ledChanged,this, &MotionSensor::updateLed);
connect(ui->button, &QPushButton::pressed, this, &SensorInterface::activateManualControl);
connect(ui->button, &QPushButton::released, this, &MotionSensor::toggleState);
connect(ui->check, &QCheckBox::stateChanged, this, &SensorInterface::checkBoxClicked);
}
MotionSensor::~MotionSensor()
{
delete ui;
}
/**
* Change state of the motion sensor and update color.
*/
void MotionSensor::toggleState()
{
updateUi(currentValue == 0 ? 1 : 0);
}
/**
* @brief MotionSensor::updateUi signal receiver method when a value changes
* @param newValue
*/
void MotionSensor::updateUi(int newValue)
{
currentValue = newValue;
if (!minMaxSet)
minMaxSet = true;
// use counter is for hall effect sensor
if (useCounter)
ui->label->setText(QString::number(counter));
if (max == 1 && currentValue) {
ui->button->setStyleSheet("QPushButton {background-color: #A3C1DA; color: red;}");
ui->button->setText("MOTION");
}
else if (max == 2 && currentValue == 1) {
ui->button->setStyleSheet("QPushButton {background-color: #A3C1DA; color: red;}");
ui->button->setText("TILT");
}
else if (max == 2 && currentValue == 2) {
ui->button->setStyleSheet("QPushButton {background-color: #AA5555; color: black;}");
ui->button->setText("SHAKE");
}
else {
ui->button->setStyleSheet("QPushButton {background-color: #909090; color: black;}");
ui->button->setText("IDLE");
}
}
/**
* @brief MotionSensor::updateLed signal receiver method when the led state changes
* @param ledValue
*/
void MotionSensor::updateLed(bool ledValue)
{
char styleheet[100];
setLedOn(ledValue);
if (showLeds) {
sprintf(styleheet, "background-color:#0000%02x;", led1);
ui->ledL->setStyleSheet(styleheet);
sprintf(styleheet, "background-color:#0000%02x;", led2);
ui->ledR->setStyleSheet(styleheet);
sprintf(styleheet, "background-color:#0000%02x;", led3);
ui->ledB->setStyleSheet(styleheet);
}
}