Added a temperature display for weather. Currently can't show negative temps

This commit is contained in:
Remy Moll
2020-11-09 12:10:49 +01:00
parent b4ce9eadf9
commit f5499c144b
6 changed files with 70 additions and 39 deletions

View File

@@ -33,10 +33,10 @@ digits = {
##place of numbers, invariable
digit_position = [[2,4], [2,10], [9,4], [9,10]]
def time_converter():
def time_converter(time=datetime.datetime.now().strftime("%H%M")):
"""Converts 4-digit time to a pixel-matrix
returns: np.array((16, 16))"""
time = datetime.datetime.now().strftime("%H%M")
#time = datetime.datetime.now().strftime("%H%M")
pixels = np.zeros((16,16),dtype=np.uint8)
time = "0" * (4 - len(str(time))) + str(time)
time_split = [int(i) for i in time]
@@ -64,6 +64,27 @@ def date_converter():
return pixels
weather_categories = {
"cloud": "cloud",
"cloud_with_rain": "rain and cloud",
"thunder_cloud_rain": "thunder and cloud",
"droplet": "rain and cloud",
"cloud_snow": "snow and cloud",
"sun": "sun",
"Mist": "fog and clouds",
"Smoke": "Smoke",
"Haze": "Haze",
"Dust": "Dust",
"Fog": "fog",
"Sand": "Sand",
"Dust": "Dust",
"Ash": "Ash",
"Squal": "Squal",
"Tornado": "Tornado",
}
def weather_converter(name):
result = np.zeros((16,16))
cwd = __file__.replace("\\","/") # for windows
@@ -77,6 +98,7 @@ def weather_converter(name):
icon_loc = ["sun","moon","sun and clouds", "moon and clouds", "cloud","fog and clouds","2 clouds", "3 clouds", "rain and cloud", "rain and clouds", "rain and cloud and sun", "rain and cloud and moon", "thunder and cloud", "thunder and cloud and moon", "snow and cloud", "snow and cloud and moon", "fog","fog night"]
#ordered 1 2 \n 3 4 \ 5 5 ...
name = weather_categories[name]
try:
iy, ix = int(icon_loc.index(name)/2), icon_loc.index(name)%2
# x and y coords

View File

@@ -43,11 +43,11 @@ class OutputHandler():
c1 = self.primary
c2 = self.secondary
c3 = self.red
if len(colors) == 1:
if len(colors) > 0:
c1 = colors[0]
if len(colors) == 2:
if len(colors) > 1:
c2 = colors[1]
if len(colors) == 3:
if len(colors) > 2:
c3 = colors[2]
if len(colors) > 3:
print("Too many colors")
@@ -68,7 +68,6 @@ class OutputHandler():
return r3
def set_matrix_rgb(self, matrix, quadrant=1):
result = np.zeros((self.height, self.width,3))
if quadrant == 1:
@@ -83,14 +82,21 @@ class OutputHandler():
self.output.set_matrix(result)
def clock_face(self,weather):
def clock_face(self, weather):
"""weather as a dict"""
hour = converter.time_converter()
day = converter.date_converter()
face1 = hour + day
face1_3d = self.matrix_add_depth(face1)
print(weather)
if weather["show"] == "weather":
face2_3d = converter.weather_converter(weather["weather"])
else:
face2 = converter.time_converter(int(weather["low"]+weather["high"]))
face2 = np.concatenate((face2[:8,...],2*face2[8:,...]))
face2_3d = self.matrix_add_depth(face2,[[10,10,200],[200,10,10]])
face2_3d = converter.weather_converter(weather)
face = np.zeros((max(face1_3d.shape[0],face2_3d.shape[0]),face1_3d.shape[1]+face2_3d.shape[1],3))
face[:face1_3d.shape[0],:face1_3d.shape[1],...] = face1_3d

View File

@@ -131,6 +131,7 @@ class ClockFace(object):
self.run(output,(image, duration))
def show_message(self, *args):
"""Runs a text message over the screen. Obviously needs the text"""
# keep in mind, in this case args is a tuple of all words