-
Notifications
You must be signed in to change notification settings - Fork 1
/
widget.cpp
executable file
·69 lines (63 loc) · 1.95 KB
/
widget.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
#include <QApplication>
#include <QtDebug>
#include <QFont>
#include <QPushButton>
#include <QWidget>
#include "widget.h"
#include "gpio.h"
#include "led.h"
#include "chestnut.h"
Widget::Widget(QWidget *parent)
: QWidget(parent) {
// setFixedSize(200, 120);
/* The old way over GPIO:
_blue_led = new Gpio(OVERO_GPIO_CHESTNUT_BLUE_LED, GPIO_DIR_OUTPUT);
*/
_blue_led = new Led(LED_BLUE);
QPushButton *ledButton = new QPushButton(tr("LED an/aus"), this);
ledButton->setGeometry(62, 40, 140, 30);
ledButton->setFont(QFont("Times", 18, QFont::Bold));
connect(ledButton, SIGNAL(clicked()),this, SLOT(on_toggle_gpio_led_blue_clicked()));
QPushButton *quitButton = new QPushButton(tr("Quit"), this);
quitButton->setGeometry(62, 80, 75, 30);
quitButton->setFont(QFont("Times", 18, QFont::Bold));
connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
/* The old way initialize GPIO Port
if (! _blue_led->init())
{
qWarning() << "Error initializing GPIO" << "\n";
}
*/
}
void Widget::on_toggle_gpio_led_blue_clicked()
{
LedState state = _blue_led->get_state();
if (state == LED_STATE_OFF)
_blue_led->set_state(LED_STATE_ON);
else
_blue_led->set_state(LED_STATE_OFF);
/* The old way
GpioState state = _blue_led->get_state();
if (state == GPIO_STATE_LOW) {
_blue_led->set_state(GPIO_STATE_HIGH);
} else {
_blue_led->set_state(GPIO_STATE_LOW);
}
*/
}
void Widget::on_toggle_gpio_led_red_clicked()
{
LedState state = _red_led->get_state();
if (state == LED_STATE_OFF)
_red_led->set_state(LED_STATE_ON);
else
_red_led->set_state(LED_STATE_OFF);
/* The old way
GpioState state = _red_led->get_state();
if (state == GPIO_STATE_LOW) {
_red_led->set_state(GPIO_STATE_HIGH);
} else {
_red_led->set_state(GPIO_STATE_LOW);
}
*/
}