-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_2_dht
174 lines (150 loc) · 3.79 KB
/
text_2_dht
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls 1.4
import QtQuick.Extras 1.4
import QtQuick.Extras.Private 1.0
Window {
id: window
visible: true
width: 800
height: 480
color: "#000000"
// title: qsTr("Hello World")
visibility: "FullScreen"
/*Text {
id: temp
objectName: "temp"
x: 80
y: 73
width: 56 //560
height: 28 //289
color: "#fb6300"
text: qsTr("10.0")
font.letterSpacing: 0
style: Text.Sunken
font.weight: Font.Bold
font.family: "Arial"
font.italic: false
font.bold: false
renderType: Text.NativeRendering
font.pixelSize: 28
}
Text {
id: hum
objectName: "hum"
x: 587
y: 385
width: 12//
height: 7//
color: "#fb6300"
text: qsTr("10.0")
renderType: Text.NativeRendering
font.pixelSize: 60
}
Text {
id: temp1
objectName: "temp1"
x: 659
y: 123
width: 6
height: 5
color: "#fb6300"
text: qsTr("°C")
renderType: Text.NativeRendering
font.bold: false
font.weight: Font.Bold
font.pixelSize: 50
style: Text.Sunken
font.italic: false
font.family: "Arial"
}
Text {
id: temp2
x: 714
y: 390
width: 6
height: 6
color: "#fb6300"
text: qsTr("%")
renderType: Text.NativeRendering
font.italic: false
font.weight: Font.Bold
style: Text.Sunken
objectName: "temp1"
font.bold: false
font.pixelSize: 50
font.family: "Arial"
}
Rectangle {
x:210
y:156
color: "black"
CircularGauge {
value : gaugeVAL
style: CircularGaugeStyle {
needle: Rectangle {
y: outerRadius * 0.15
implicitWidth: outerRadius * 0.03
implicitHeight: outerRadius * 0.9
antialiasing: true
color: Qt.rgba(0.66, 0.3, 0, 1)
}
}
}
}*/
}
-------------------------
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QObject>
#include <QtQuick/QQuickView>
#include <QtQuick/QQuickItem>
#include <QQuickItem>
#include <QQuickView>
#include <QTimer>
#include "wiringPi.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
#include <wiringPiSPI.h>
QObject *item = NULL;
unsigned char gaugeVAL=50;
QObject *itemH = NULL;
int value = 10;
unsigned char buffer[100];
unsigned char temp = 0;
unsigned char SOC = 0;
static const int CHANNEL = 1;
void read_SPI(){
wiringPiSPIDataRW(CHANNEL, buffer, 2);
temp = buffer[0];
SOC = buffer[1];
item->setProperty("text",temp);
itemH->setProperty("text",SOC);
//item->setProperty("text",QString("%1").arg(temp));
//itemH->setProperty("text",QString("%1").arg(SOC));
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
wiringPiSetup();
setuid(getuid());
wiringPiSPISetup(CHANNEL, 4000000);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
// QObject *itemC = NULL;
// itemC = engine.rootObjects().at(0)->findChild<QQuickItem*>("temp1");
//itemC->setProperty("text",QString::fromUtf8("°C"));
item = engine.rootObjects().at(0)->findChild<QQuickItem*>("temp");
itemH = engine.rootObjects().at(0)->findChild<QQuickItem*>("hum");
QTimer timer;
QObject::connect(&timer,&QTimer::timeout,read_SPI);
timer.start(100);
return app.exec();
}