forked from KyleMay/Ford-FG-ICC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HVACDisplay.py
330 lines (273 loc) · 10.4 KB
/
HVACDisplay.py
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Ford FG HVAC Display - Socketcan Conversion for RPi - see licence in git repo
# Created by Kyle May in 2018 - https://github.com/KyleMay/Ford-FG-ICC
# Forked 2021 - https://github.com/jakka351/Ford-FG-ICC
# https://github.com/jakka351/can0swc | https://github.com/jakka351/FG-Falcon
##############################################################################
#
##################
os.environ['KIVY_GL_BACKEND'] = 'gl'
from kivy.app import App
from kivy.uix.button import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.config import Config
from kivy.clock import mainthread
from kivy.core.window import Window
from enum import Enum
import time
#import serial
import threading
from threading import Thread
import can
import os
import sys, traceback
##############################################################################
bus = can.interface.Bus(channel='vcan0', bustype='socketcan')
Config.set('graphics', 'fullscreen', 'auto')
Config.write()
class Vent(Enum):
auto = 1
face = 2
foot = 3
demister = 4
face_foot = 5
foot_demister = 6
class Trinary(Enum):
auto = 1
on = 2
off = 3
class MyLayout(BoxLayout):
outside_temperature = 0
requested_temperature = 0
fan_speed = 10
auto = False
vent = Vent.auto
recirculation = Trinary.auto
ac_on = False
rear_demist_on = False
vent_source = StringProperty()
recirculation_source = StringProperty()
rear_demist_source = StringProperty()
ac_source = StringProperty()
requested_temperature_source = StringProperty()
requested_temperature_string = StringProperty()
fan_speed_source = StringProperty()
time = StringProperty()
outside_temperature_string = StringProperty()
auto_string = StringProperty()
@mainthread
def update_layout(self):
self.update_vent()
self.update_recirculation()
self.update_rear_demist()
self.update_ac()
self.update_requested_temperature()
self.update_fan_speed()
self.update_time()
self.update_outside_temperature()
self.update_auto()
@mainthread
def update_vent(self):
if self.vent == Vent.auto:
self.vent_source = 'img/pos_auto.png'
elif self.vent == Vent.face:
self.vent_source = 'img/pos_face.png'
elif self.vent == Vent.foot:
self.vent_source = 'img/pos_floor.png'
elif self.vent == Vent.demister:
self.vent_source = 'img/screen.png'
elif self.vent == Vent.face_foot:
self.vent_source = 'img/pos_face_floor.png'
elif self.vent == Vent.foot_demister:
self.vent_source = 'img/pos_floor_screen.png'
def update_recirculation(self):
if self.recirculation == Trinary.auto:
self.recirculation_source = 'img/recirculation_auto.png'
elif self.recirculation == Trinary.on:
self.recirculation_source = 'img/recirculation_on.png'
elif self.recirculation == Trinary.off:
self.recirculation_source = 'img/recirculation_off.png'
def update_rear_demist(self):
if self.rear_demist_on:
self.rear_demist_source = 'img/rear_demist_on.png'
else:
self.rear_demist_source = 'img/rear_demist_off.png'
def update_ac(self):
if self.ac_on:
self.ac_source = 'img/air_con_on.png'
else:
self.ac_source = 'img/air_con_off.png'
def update_requested_temperature(self):
self.requested_temperature_string = str(self.requested_temperature) + "º"
if self.requested_temperature < 20:
self.requested_temperature_source = 'img/temperature_cool.png'
elif self.requested_temperature > 24:
self.requested_temperature_source = 'img/temperature_hot.png'
else:
self.requested_temperature_source = 'img/temperature_warm.png'
def update_fan_speed(self):
if self.fan_speed == 0:
self.fan_speed_source = 'img/fan_auto.png'
elif self.fan_speed == -1:
self.fan_speed_source = 'img/fan_0.png'
elif self.fan_speed == 1:
self.fan_speed_source = 'img/fan_1.png'
elif self.fan_speed == 2:
self.fan_speed_source = 'img/fan_2.png'
elif self.fan_speed == 3:
self.fan_speed_source = 'img/fan_3.png'
elif self.fan_speed == 4:
self.fan_speed_source = 'img/fan_4.png'
elif self.fan_speed == 5:
self.fan_speed_source = 'img/fan_5.png'
elif self.fan_speed == 6:
self.fan_speed_source = 'img/fan_6.png'
elif self.fan_speed == 7:
self.fan_speed_source = 'img/fan_7.png'
elif self.fan_speed == 8:
self.fan_speed_source = 'img/fan_8.png'
elif self.fan_speed == 9:
self.fan_speed_source = 'img/fan_9.png'
elif self.fan_speed == 10:
self.fan_speed_source = 'img/fan_10.png'
def update_time(self):
self.time = time.strftime('%H:%M')
def update_outside_temperature(self):
self.outside_temperature_string = "Outside: " + str(self.outside_temperature) + "º"
def update_auto(self):
self.auto_string = "Auto" if self.auto else "Semi-auto"
class HVACApp(App):
def build(self):
self.layout = MyLayout()
return self.layout
def on_start(self):
self.layout.requested_temperature = 0
self.layout.vent = Vent.face_foot
self.layout.recirculation = Trinary.off
self.layout.ac_on = False
self.layout.rear_demist_on = False
self.layout.fan_speed = 0
self.layout.outside_temperature = 0
self.layout.update_layout()
cr = CANReader()
cr.layout = self.layout
threading.Thread(target=cr.setup, args=()).start()
class CANReader():
#Vent Status
ventCAN = 0
#AC Temp
acTempCAN = 0
#Outside Temp
outsideTempCAN = 0
#Fan Speed
fanSpeedCAN = 0
def setup(self):
global bus
try:
bus = can.Bus(bustype='socketcan_native', channel="vcan0", bitrate="125000")
except OSError:
print(' can0 interface not found. check wiring and config.')
sys.exit() #quits if no can interface
def msgbuffer(self):
global q, ventCAN, ,acTempCAN, outsideTempCAN, fanSpeedCAN
while True:
message = bus.recv()
if message.arbitration_id == 0x353:
q.put(message)
def msgreader
while True:
for i in range(8):
while(q.empty() == True): # Assign to CAN properties
pass
message = q.get()
if message.arbitration_id == 0x353:
ventCAN = message.data[0]
acTempCAN = message.data[3]
outsideTempCAN = message.data[4]
fanSpeedCAN = message.data[7]
# Can't get this to work :(
# def update_rear_demister_status(self):
# self.layout.rear_demist_on = self.code1027X1 >= 4
# self.layout.update_layout()
def update_fan_status(self):
fanspeedcode = self.fanSpeedCAN
auto_fan = False
if fanspeedcode >= 144:
fanspeedcode -= 144
if fanspeedcode >= 128:
# Above 128 = Automatic Fan Speed
auto_fan = True
fanspeedcode = fanspeedcode - 128
self.layout.fan_speed = -1 if auto_fan else fanspeedcode
self.layout.update_layout()
def update_temperature_status(self):
self.layout.requested_temperature = self.acTempCAN
self.layout.update_layout()
def update_outside_temperature_status(self):
self.layout.outside_temperature = self.outsideTempCAN
self.layout.update_layout()
def update_vent_status(self):
demister_on = False
foot_on = False
face_on = False
ac_on = False
recirculation = Trinary.auto
# AC
ac_on = get_bit(self.ventCAN, 7) == 0
# Front demister
demister_on = get_bit(self.ventCAN, 2) == 1
# Foot
foot_on = get_bit(self.ventCAN, 3) == 1
# Face
face_on = get_bit(self.ventCAN, 4) == 1
# Recirculation, auto if b == 0 and c == 0. b = on, c = off
if get_bit(self.ventCAN, 5) == 0 and get_bit(self.ventCAN, 6) == 0:
recirculation = Trinary.auto
if get_bit(self.ventCAN, 6) == 1:
recirculation = Trinary.on
elif get_bit(self.ventCAN, 5) == 1:
recirculation = Trinary.off
# Update layout
if foot_on and face_on:
self.layout.vent = Vent.face_foot
elif foot_on and demister_on:
self.layout.vent = Vent.foot_demister
elif foot_on:
self.layout.vent = Vent.foot
elif demister_on:
self.layout.vent = Vent.demister
elif face_on:
self.layout.vent = Vent.face
else:
self.layout.vent = Vent.auto
self.layout.ac_on = ac_on
self.layout.recirculation = recirculation
self.layout.update_layout()
def get_bit(byteval,idx):
#get_bit from socketcan??
return int(((byteval&(1<<idx))!=0))
if __name__ == "__main__":
setup()
q = queue.Queue() #
rx = Thread(target = msgbuffer)
rx.start()
msgreader()
Window.size = (600, 480)
Window.fullscreen = True
app = HVACApp()
app.run()
i
# This file is part of Ford FG HVAC Display.
# Ford FG HVAC Display is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Ford FG HVAC Display is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Ford FG HVAC Display. If not, see <https://www.gnu.org/licenses/>.
l