-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxscroller.py
346 lines (281 loc) · 13.5 KB
/
maxscroller.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
331
332
333
334
335
336
337
#!/usr/bin/python
#
# original code from adafruit, see below copyrights
# hacked version for bioreactor one
#
#--------------------------------------------------------------------------------------------
# -- 031616 -- converting temp to fahrenhight, and logging
# -- 031816 -- adding in the led libraries to do a simple test, hopefully will add scrolling display
# -- 031816 -- well, attempt at creating a font library for the 8x8 screen,
# since they aint one.
# -- 031916 -- (b) reverse the current characters
# -- (g) open the log, and get the temp in f and humidity in h, with dec
# -- then build the logic to display the right character.
# -- (s) implement the rest of the characters
# -- 032116 -- just received the max7219, branching to max2719_scroller,
# -- attempting to intgrate the new display and add time
# -- (s) add feature for weather, stocks, and headlines.
# -- also removed the adafruit webIDE, checking it didn't catasrophically
# -- fuck up anything else with it.. also upgrading and updating... fingers crossed...
#---------------------------------------------------------------------------------------------------
#
# .=-.-. _,.---._ ,---.
# _..---. /==/_ /,-.' , - `. _.-. .--.' \ _..---.
# .' .'.-. \|==|, |/==/_, , - \ .-,.'| \==\-/\ \ .' .'.-. \
# /==/- '=' /|==| |==| .=. |==|, | /==/-|_\ | /==/- '=' /
# |==|-, ' |==|- |==|_ : ;=: - |==|- | \==\, - \ |==|-, '
# |==| .=. \|==| ,|==| , '=' |==|, | /==/ - ,| |==| .=. \
# /==/- '=' ,|==|- |\==\ - ,_ /|==|- `-._/==/- /\ - \ /==/- '=' ,|
# |==| - //==/. / '.='. - .' /==/ - , ,|==\ _.\=\.-'|==| - /
# `-._`.___,' `--`-` `--`--'' `--`-----' `--` `-._`.___,'
# _,.---._ .-._ ,----.
# ,-.' , - `. /==/ \ .-._ ,-.--` , \
# /==/_, , - \|==|, \/ /, /==|- _.-`
# |==| .=. |==|- \| ||==| `.-.
# |==|_ : ;=: - |==| , | -/==/_ , /
# |==| , '=' |==| - _ |==| .-'
# \==\ - ,_ /|==| /\ , |==|_ ,`-._
# '.='. - .' /==/, | |- /==/ , /
# `--`--'' `--`./ `--`--`-----``
#
# ,--.--------. ,--.--------. ,--.--------.
# /==/, - , -\ /==/, - , -\ /==/, - , -\
# \==\.-. - ,-./ \==\.-. - ,-./ \==\.-. - ,-./
# `--`--------` `--`--------` `--`--------`
#
# ,----. ,---.--. ,-.--, ,---.--.
# _.-. ,-.--` , \ _,..---._ / -_ \==\.--.-. /=/, .'/ -_ \==\
# .-,.'| |==|- _.-`/==/, - \ |` / \/==/\==\ -\/=/- / |` / \/==/
# |==|, | |==| `.-.|==| _ _\ \ \ /==/ \==\ `-' ,/ \ \ /==/
# |==|- | /==/_ , /|==| .=. | / \==/ |==|, - | / \==/
# |==|, | |==| .-' |==|,| | -| /. / \==\ /==/ , \ /. / \==\
# |==|- `-._|==|_ ,`-._|==| '=' / | _ \_/\==\/==/, .--, - \| _ \_/\==\
# /==/ - , ,/==/ , /|==|-, _`/ \ . - /==/\==\- \/=/ , /\ . - /==/
# `--`-----'`--`-----`` `-.`.____.' '----`--` `--`-' `--` '----`--`
#
#--------------------------------------------------------------------------------
# Copyleft (c) 2016 Alchemy Computing
# Copyright (c) 2014 Adafruit Industries
# Hacker: Justin Knox
# legal shit---------------------------------------------------------------------
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# end of legal shit---------------------------------------------------------------
#---------------------------------------------------
# .__ __
# |__| _____ ______ ____________/ |_ ______
# | |/ \\____ \ / _ \_ __ \ __\/ ___/
# | | Y Y \ |_> > <_> ) | \/| | \___ \
# |__|__|_| / __/ \____/|__| |__| /____ >
# \/|__| \/
#
#---------------------------------------------------
import time
import datetime
import max7219.led as led
import time
from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT
from random import randrange
from collections import deque
#----------------------------------------------------
# .__
# _____ _____ |__| ____
# / \\__ \ | |/ \
# | Y Y \/ __ \| | | \
# |__|_| (____ /__|___| /
# \/ \/ \/
#----------------------------------------------------
# ===========================================================================
# 8x8 Pixel Example
#
# ===========================================================================
toggle = True
sleepCount = 0
print "-----=-=-=-------=- bioreactor-one - montior-one -=---------=-=-=--------"
print " .... testing .... pixels ... LEDS .................... "
print "-------=---------=---------------------------------=-----------=----------"
print "Press CTRL+Z to exit"
print "--------------------------------------------------------------------------"
device = led.matrix(cascaded=1)
device.orientation(180)
#device.show_message("-----=-=-=-------=- bioreactor-one - montior-one -=---------=-=-=--------\
# \
# .... testing .... pixels ... LEDS .................... \
# ", font=proportional(CP437_FONT))
#
# open the log for reading values
#----------------------------------------------------------------------------------
print "-----=-=-=-------=- bioreactor-one - montior-one -=---------=-=-=--------"
tempValFlog = open("/home/pi/curr_F.log", "r");
print "Opening log... .", tempValFlog.name, " ...in..", tempValFlog.mode, "..access mode."
tempValHlog = open("/home/pi/curr_H.log", "r");
print "Opening log... .", tempValHlog.name, " ...in..", tempValHlog.mode, "..access mode."
print "-------=---------=---------------------------------=-----------=----------"
print " press CTL-Z to exit "
print "--------------------------------------------------------------------------"
prevFloatFval = 0
prevFloatHval = 0
scrollon = True
#device.show_message(" Welcome to BioLabOne - AlchemyComputing ")
while(scrollon):
print "-----=-=-=-------=- bioreactor-one - montior-one -=---------=-=-=--------"
tempValFlog = open("/home/pi/curr_F.log", "r");
print "Opening log... .", tempValFlog.name, " ...in..", tempValFlog.mode, "..access mode."
tempValHlog = open("/home/pi/curr_H.log", "r");
print "Opening log... .", tempValHlog.name, " ...in..", tempValHlog.mode, "..access mode."
#----------------------------------------------------------------------------------
# 032116 -- new strategy is to open the log, check for a new value,
# -- if there's no new value, close the log, and wait half a second
# -- if there is a new value, display the new value, and close the log!
#----------------------------------------------------------------------------------
currentF = tempValFlog.read(5)
currentH = tempValHlog.read(5)
print "Got values..."
print "....current from log F: ", currentF
print "....current fom log H: ", currentH
print "--------------------"
#--------------------------------------------------------
# closing the log just in case simple_logger.py needs it
#--------------------------------------------------------
print "Closing log...", tempValFlog.name
print "Closing log...", tempValHlog.name
tempValFlog.close()
tempValHlog.close()
print " ", tempValFlog.closed
print " ", tempValHlog.closed
print "--------------------------=-=-=-=-=-=------------------------------------------"
# 032216 -- converting back in the old code that grabbed the decimal values
#first we have to isolate the 100's place, in this case 0
#if the 100's is 0, then we'll display a space
#then lets grab the 10's, 1's and the decimal portion.
#also, we gotta typecast the shit out of this cause of pythons implicit typing...
hundyPlaceFval = int(float(currentF) / 100)
tensPlaceFval = int(float(currentF) / 10)
onesPlaceFval = int( float(currentF) - (hundyPlaceFval*100 + tensPlaceFval*10) )
decimalPlaceFval = int((float(currentF) - ( hundyPlaceFval + tensPlaceFval + onesPlaceFval )) * 10)
decimalPlaceFval /= 100
#lets see what we got
print 'F hundy', int(hundyPlaceFval)
print 'F tens', int(tensPlaceFval)
print 'F ones', int(onesPlaceFval)
print 'F deci', int(decimalPlaceFval)
#now lets do the Humidity's
hundyPlaceHval = int(float(currentH) / 100)
tensPlaceHval = int(float(currentH) / 10)
onesPlaceHval = int( float(currentH) - (hundyPlaceHval*100 + tensPlaceHval*10) )
decimalPlaceHval = int((float(currentH) - ( hundyPlaceHval + tensPlaceHval + onesPlaceHval )) * 10)
decimalPlaceHval /= 100
#lets see what we got
print '\n'
print 'H hundy', int(hundyPlaceHval)
print 'H tens', int(tensPlaceHval)
print 'H ones', int(onesPlaceHval)
print 'H deci', int(decimalPlaceHval)
floatFval = float(hundyPlaceFval*100 + tensPlaceFval*10 + onesPlaceFval + decimalPlaceFval/10)
floatHval = float(hundyPlaceHval*100 + tensPlaceHval*10 + onesPlaceHval + decimalPlaceHval/10)
#-------------- always display the values --------------------------------------------
device.show_message( " F: " )
device.show_message( str( floatFval ) )
device.letter(0, 248)
device.show_message( " H: " )
device.show_message( str( floatHval ) )
device.show_message("%")
device.show_message( time.strftime("%c"))
#------------------------------------------code below only shows when temp changes
#-----------------------------------------------------------------------show fahrenheit
#device.show_message( "Fahrenheit = " )
if( floatFval > (0.1 + prevFloatFval ) ):
#device.letter(0, 176);time.sleep(1)
#device.letter(0, 177);time.sleep(1)
#device.letter(0, 219);time.sleep(1)
#device.letter(0, 219);time.sleep(1)
#device.letter(0, 177);time.sleep(1)
#device.letter(0, 176);time.sleep(1)
device.show_message( " +F: " )
device.show_message( str( floatFval ) )
device.letter(0, 248)
sleepCount = 0
if( floatFval < (0.1 - prevFloatFval) ):
#device.letter(0, 176);time.sleep(1)
#device.letter(0, 177);time.sleep(1)
#device.letter(0, 219);time.sleep(1)
#device.letter(0, 219);time.sleep(1)
#device.letter(0, 177);time.sleep(1)
#device.letter(0, 176);time.sleep(1)
device.show_message( " -F: " )
device.show_message( str( floatFval ) )
device.letter(0, 248)
sleepCount = 0
if( floatFval == ( prevFloatFval ) ):
if(sleepCount<6):
device.show_message( " - - - " )
sleepCount+=1
#-----------------------------------------------------------------------one by one display
#if(hundyPlaceFval!=0):
# device.show_message( str(hundyPlaceFval ) )
#device.show_message( str(tensPlaceFval ) )
#device.show_message( str(onesPlaceFval ) )
#device.show_message(".")
#device.show_message( str(decimalPlaceFval ) )
#------------------------------------------------------------------------show humidity
#device.show_message( "Humidity = " )
if( floatHval > (0.1 + prevFloatHval) ):
#device.letter(0, 176);time.sleep(1)
#device.letter(0, 177);time.sleep(1)
#device.letter(0, 219);time.sleep(1)
#device.letter(0, 219);time.sleep(1)
#device.letter(0, 177);time.sleep(1)
#device.letter(0, 176);time.sleep(1)
device.show_message( " +H: " )
device.show_message( str( floatHval ) )
device.show_message("%")
sleepCount = 0
if( floatHval < (0.1 - prevFloatHval) ):
#device.letter(0, 176);time.sleep(1)
#device.letter(0, 177);time.sleep(1)
#device.letter(0, 219);time.sleep(1)
#device.letter(0, 219);time.sleep(1)
#device.letter(0, 177);time.sleep(1)
#device.letter(0, 176);time.sleep(1)
device.show_message( " -H: " )
device.show_message( str( floatHval ) )
device.show_message("%")
sleepCount = 0
if( floatHval == ( prevFloatHval ) ):
if(sleepCount<4):
device.show_message( "- - - " )
sleepCount+=1
#------------------------------------------------------------------------go to sleep
if(sleepCount > 3):
sleepCount-=1
print "Sleeping ... ", sleepCount
time.sleep(3)
#------------------------------------------------------------------------single message method
#-----------------------------------------------------------------------one by one display
#if(hundyPlaceHval!=0):
# device.show_message( str(hundyPlaceHval ) )
#device.show_message( str(tensPlaceHval ) )
#device.show_message( str(onesPlaceHval ) )
#device.show_message(".")
#device.show_message( str(decimalPlaceHval ) )
prevFloatFval = floatFval
prevFloatHval = floatHval
#time.sleep(3)
#device.show_message( "Current Time: ")
#device.show_message( time.strftime("%c"))
#tempRSSfeed = open("/home/pi/feeds/feeds.db", "r")
#feedData = tempRSSfeed.read(end)
#device.show_message( feedData)