5
5
author: Thomas Kaulke, [email protected]
6
6
"""
7
7
8
+ # TODO: improve and fix imports, load vars from global lib!!!
9
+ # from __future__ import absolute_import
10
+ # import conf.lib_global as lib
8
11
import subprocess
9
12
from time import sleep
10
13
from PIL import Image , ImageFont , ImageDraw
11
- from lib_oled96 import Ssd1306
12
14
from smbus import SMBus
13
- from ...conf .lib_global import commit_id , cloned_branch , bot_dir
15
+ from lib_oled96 import Ssd1306
16
+
17
+
18
+ latest_release = '/greenhouseLatestRelease.id'
19
+ commit_id = '/greenhouseRepoCommit.id'
20
+ cloned_branch = '/greenhouseRepoBranch.name'
21
+ bot_dir = '/home/pi/scripts/TelegramBot/'
14
22
15
23
16
24
# Display setup, methods and members
24
32
switch_time = 15
25
33
26
34
27
- def get_last_commit ():
28
- commit = None
29
- branch = None
35
+ def __get_release ():
36
+ try :
37
+ release = open (str (latest_release )).read ()
38
+ if release is None :
39
+ release = '-----'
40
+ else :
41
+ release = release
42
+ except Exception :
43
+ release = '-----'
44
+ return release
45
+ return release
46
+
30
47
48
+ def __get_last_commit ():
31
49
try :
32
50
commit = open (str (commit_id )).read ()
33
51
if commit is None :
@@ -47,7 +65,7 @@ def get_last_commit():
47
65
return build
48
66
49
67
50
- def get_core_temp ():
68
+ def __get_core_temp ():
51
69
temp = int (open ('/sys/class/thermal/thermal_zone0/temp' ).read ())
52
70
one = str (temp ).__getitem__ (0 )
53
71
two = str (temp ).__getitem__ (1 )
@@ -60,23 +78,23 @@ def get_core_temp():
60
78
font2 = ImageFont .truetype (str (bot_dir ) + 'peripherals/oled/fonts/FreeSans.ttf' , 12 )
61
79
62
80
63
- def animate (time ):
81
+ def __animate (time ):
64
82
# Display clear
65
83
oled .cls ()
66
84
oled .display ()
67
85
# header
68
- draw .text ((18 , top ), "GREENHOUSE" , font = font , fill = 1 )
86
+ draw .text ((left , top ), "GREENHOUSE v" + __get_release () , font = font , fill = 1 )
69
87
# build
70
- draw .text ((left , top + 18 ), "Build: " + get_last_commit (), font = font2 , fill = 1 )
88
+ draw .text ((left , top + 18 ), "Build: " + __get_last_commit (), font = font2 , fill = 1 )
71
89
# line
72
90
draw .line ((left , top + 35 , oled .width - left + 128 , top + 35 ), fill = 1 )
73
91
# core temp
74
- draw .text ((left , top + 45 ), "Core Temperature: " + get_core_temp (), font = font2 , fill = 1 )
92
+ draw .text ((left , top + 45 ), "Core Temperature: " + __get_core_temp (), font = font2 , fill = 1 )
75
93
oled .display ()
76
94
sleep (time )
77
95
78
96
79
- def show_pi (time ):
97
+ def __show_pi (time ):
80
98
oled .cls ()
81
99
# image inverted
82
100
draw .rectangle ((32 , top - 3 , 95 , 63 ), outline = 1 , fill = 1 )
@@ -85,7 +103,7 @@ def show_pi(time):
85
103
sleep (time )
86
104
87
105
88
- def show_state (time ):
106
+ def __show_state (time ):
89
107
oled .cls ()
90
108
oled .display ()
91
109
"""
@@ -116,9 +134,9 @@ def show_state(time):
116
134
while True :
117
135
118
136
try :
119
- animate (switch_time )
120
- show_pi (3 )
121
- show_state (switch_time )
137
+ __animate (switch_time )
138
+ __show_pi (3 )
139
+ __show_state (switch_time )
122
140
123
141
except KeyboardInterrupt :
124
142
print ('Oled interrupted.' )
0 commit comments