-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcdOutput.py
98 lines (92 loc) · 3.49 KB
/
lcdOutput.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
import logging
import sys
import datetime
import time
import lcdCommands as lcd
import weatherData
import lcdDataFileUtils
import os
thisDir = os.path.dirname(os.path.realpath(__file__))
configFile = thisDir + "/config.json"
dataFile = thisDir + "/data.txt"
numMessages = 0
currTime = ""
wdDesc = ""
wdTempF = ""
date = ""
updateIteration = 0
def readDataFile():
f = open(dataFile, 'r')
firstLine = f.readline().strip()
secondLine = f.readline().strip()
return firstLine
def getTime():
now = datetime.datetime.now()
hour = int(now.strftime("%I"))
period = now.strftime("%p").lower()
timeStr = str(hour) + now.strftime(":%M") + period
return timeStr
def getDate():
now = datetime.datetime.now()
dateStr = str(now.month) + "/" + str(now.day)
return dateStr
logging.basicConfig(level=logging.DEBUG, filename="errors.txt")
try:
myLCD = lcd.LCDDisplay()
dataFileUtils = lcdDataFileUtils.LCDDataFileUtils(dataFile)
while 1:
try:
if myLCD.isConnected():
updateScreen = False
# get time every 3 seconds
nowTime = getTime()
if (nowTime != currTime):
currTime = nowTime
updateScreen = True
date = getDate()
# get weather data every 90 seconds (960 times a day)
if (updateIteration % 90 == 0):
updateIteration = 0
wd = weatherData.WeatherData()
if (wd.desc != wdDesc or wd.tempF != wdTempF):
wdDesc = wd.desc
wdTempF = wd.tempF
updateScreen = True
# if there's a loop command the loop the referenced message
loopMessage = dataFileUtils.getLoopCommandMessage()
if (loopMessage != ""):
stopLoop = False
while(not(stopLoop)):
myLCD.clearScreen()
myLCD.scrollTextLeftOnLine(loopMessage, 1, 0.2)
stopLoop = dataFileUtils.isStopLoopCommandPresent()
# if there's a show command the show the referenced message
showMessage = dataFileUtils.getShowCommandMessage()
if (showMessage != ""):
myLCD.clearScreen()
myLCD.scrollTextLeftOnLine(showMessage, 1, 0.2)
# get and show number of messages between time and date
num = dataFileUtils.getNumOfMessages()
if (num != numMessages):
updateScreen = True
numMessages = num
# only update the screen if there is data to update
if (updateScreen):
myLCD.clearScreen()
if (numMessages > 0):
myLCD.displayWordAtPos(str(numMessages), 8)
myLCD.displayWordOnLine(currTime , 1)
myLCD.rightJustifyTextOnLine(date, 1)
myLCD.rightJustifyTextOnLine(wdDesc, 2)
myLCD.displayWordOnLine(str(int(round(wdTempF))) + chr(223), 2)
updateIteration = updateIteration + 1
time.sleep(1)
else:
print "establishing connection..."
myLCD.getSerialConnection()
time.sleep(10)
except:
print "Error writing to bluetooth"
myLCD.disconnect()
except:
logging.exception("ERROR: ")