-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
77 lines (66 loc) · 1.44 KB
/
mainwindow.cpp
File metadata and controls
77 lines (66 loc) · 1.44 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
#include <string>
#include <iostream>
#include <fstream>
#include <QtGui>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#define PWM_0 "/sys/class/leds/led-pwm0/brightness"
#define PWM_1 "/sys/class/leds/led-pwm1/brightness"
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowFlags(Qt::CustomizeWindowHint);
}
MainWindow::~MainWindow()
{
delete ui;
}
static bool led(const char *dev, string& brightness)
{
if ( "" == brightness) {
ifstream ifs(dev);
if (!ifs) {
return false;
}
ifs >> brightness;
} else {
ofstream ofs(dev);
if (!ofs) {
return false;
}
ofs << brightness;
}
return true;
}
static void toggleLed(const char *dev)
{
string b("");
led(dev, b);
if ("0" == b) {
b = "127";
} else {
b = "0";
}
led(dev, b);
}
void MainWindow::on_pushButton_1_clicked()
{
toggleLed(PWM_0);
}
void MainWindow::on_pushButton_2_clicked()
{
toggleLed(PWM_1);
}
void MainWindow::on_pushButton_3_clicked()
{
qApp->quit();
}
void MainWindow::on_pushButton_4_clicked()
{
QMessageBox::about(this, tr("About YY"),
tr("<h2>YY 1.0</h2>"
"<p>Copy right © 2011 YuanYing Tech. Inc."));
}