app: use range [0..255] for slider, send temperatures updates
[apps/hvac.git] / app / HVAC.qml
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 import QtQuick 2.6
18 import QtQuick.Layouts 1.1
19 import QtQuick.Controls 2.0
20 import AGL.Demo.Controls 1.0
21 import 'api' as API
22
23 ApplicationWindow {
24     id: root
25
26     API.Binding {
27         id: binding
28         url: bindingAddress
29         onFanSpeedChanged: fanSpeedSlider.value = fanSpeed
30     }
31
32     ColumnLayout {
33         anchors.fill: parent
34         anchors.topMargin: width / 10
35         anchors.bottomMargin: width / 10
36         RowLayout {
37             Layout.fillHeight: true
38             Layout.alignment: Qt.AlignHCenter
39             Image {
40                 source: './images/HMI_HVAC_Fan_Icon.svg'
41             }
42             Item {
43                 width: root.width * 0.8
44                 Slider {
45                     id: fanSpeedSlider
46                     anchors.left: parent.left
47                     anchors.right: parent.right
48                     anchors.verticalCenter: parent.verticalCenter
49                     from: 0.0
50                     to: 255.0
51                     stepSize: 1.0
52                     onValueChanged: {
53                         binding.fanSpeed = value
54                     }
55                 }
56                 Label {
57                     anchors.left: fanSpeedSlider.left
58                     anchors.top: fanSpeedSlider.bottom
59                     font.pixelSize: 32
60                     text: 'FAN SPEED'
61                 }
62             }
63         }
64         RowLayout {
65             Layout.fillHeight: true
66             Layout.fillWidth: true
67             Layout.alignment: Layout.Center
68             spacing: 20
69             ColumnLayout {
70                 Layout.fillWidth: true
71                 spacing: 20
72                 SeatHeatButton {
73                     id: leftSeat
74                     side: 'Left'
75                 }
76                 HeatDegree {
77                     enabled: leftSeat.headLevel > 0
78                     onCurrentItemChanged: {
79                         console.log("Left Temp changed",degree)
80                         binding.leftTemperature = degree
81                     }
82                 }
83             }
84             ColumnLayout {
85                 Layout.fillWidth: true
86                 spacing: 20
87                 ToggleButton {
88                     onImage: './images/HMI_HVAC_Active.svg'
89                     offImage: './images/HMI_HVAC_Inactive.svg'
90                     Label {
91                         anchors.centerIn: parent
92                         color: parent.checked ? '#66FF99' : '#848286'
93                         text: 'A/C'
94                         font.pixelSize: parent.height / 3
95                     }
96                     onCheckedChanged: {
97                         console.debug('A/C', checked)
98                     }
99                 }
100                 ToggleButton {
101                     onImage: './images/HMI_HVAC_Active.svg'
102                     offImage: './images/HMI_HVAC_Inactive.svg'
103                     Label {
104                         anchors.centerIn: parent
105                         color: parent.checked ? '#66FF99' : '#848286'
106                         text: 'AUTO'
107                         font.pixelSize: parent.height / 3
108                     }
109                     onCheckedChanged: {
110                         console.debug('AUTO', checked)
111                     }
112                 }
113                 ToggleButton {
114                     onImage: './images/HMI_HVAC_Circulation_Active.svg'
115                     offImage: './images/HMI_HVAC_Circulation_Inactive.svg'
116                     onCheckedChanged: {
117                         console.debug('Circulation', checked)
118                     }
119                 }
120             }
121
122             ColumnLayout {
123                 Layout.fillWidth: true
124                 spacing: 20
125                 SeatHeatButton {
126                     id: rightSeat
127                     side: 'Right'
128                 }
129                 HeatDegree {
130                     enabled: rightSeat.headLevel > 0
131                     onCurrentItemChanged: {
132                         console.log("Right Temp changed",degree)
133                         binding.rightTemperature = degree
134                     }
135                 }
136             }
137         }
138
139         RowLayout {
140             Layout.fillHeight: true
141             Layout.alignment: Qt.AlignHCenter
142             spacing: root.width / 20
143             Repeater {
144                 model: ['AirDown', 'AirUp', 'AirRight', 'Rear', 'Front']
145                 ToggleButton {
146                     onImage: './images/HMI_HVAC_%1_Active.svg'.arg(model.modelData)
147                     offImage: './images/HMI_HVAC_%1_Inactive.svg'.arg(model.modelData)
148                     onCheckedChanged: {
149                         console.debug(model.modelData, checked)
150                     }
151                 }
152             }
153         }
154     }
155 }