Show temperature
This commit is contained in:
parent
297c69ab58
commit
5168f5d3de
|
@ -11,13 +11,18 @@
|
||||||
# 2) * * Both Sides
|
# 2) * * Both Sides
|
||||||
# 3) * Right Side
|
# 3) * Right Side
|
||||||
# 4) * Left Side
|
# 4) * Left Side
|
||||||
|
|
||||||
|
import colors
|
||||||
|
|
||||||
|
BLACK = [0, 0, 0]
|
||||||
|
|
||||||
|
|
||||||
class CharacterDisplay:
|
class CharacterDisplay:
|
||||||
|
|
||||||
def __init__(self, unicorn, minX=0, maxX=15):
|
def __init__(self, unicorn, minX=0, maxX=15):
|
||||||
self.unicorn = unicorn
|
self.unicorn = unicorn
|
||||||
self.minX = minX
|
self.minX = minX
|
||||||
self.maxX = maxX
|
self.maxX = maxX
|
||||||
self.black = [0, 0, 0]
|
|
||||||
|
|
||||||
self.digits = {
|
self.digits = {
|
||||||
0: self.displayZero,
|
0: self.displayZero,
|
||||||
|
@ -29,7 +34,17 @@ class CharacterDisplay:
|
||||||
6: self.displaySix,
|
6: self.displaySix,
|
||||||
7: self.displaySeven,
|
7: self.displaySeven,
|
||||||
8: self.displayEight,
|
8: self.displayEight,
|
||||||
9: self.displayNine
|
9: self.displayNine,
|
||||||
|
'0': self.displayZero,
|
||||||
|
'1': self.displayOne,
|
||||||
|
'2': self.displayTwo,
|
||||||
|
'3': self.displayThree,
|
||||||
|
'4': self.displayFour,
|
||||||
|
'5': self.displayFive,
|
||||||
|
'6': self.displaySix,
|
||||||
|
'7': self.displaySeven,
|
||||||
|
'8': self.displayEight,
|
||||||
|
'9': self.displayNine
|
||||||
}
|
}
|
||||||
|
|
||||||
def displayDigit(self, x, y, digit, color):
|
def displayDigit(self, x, y, digit, color):
|
||||||
|
@ -40,18 +55,30 @@ class CharacterDisplay:
|
||||||
def clearDigit(self, x, y):
|
def clearDigit(self, x, y):
|
||||||
for y1 in range(y, y-5, -1):
|
for y1 in range(y, y-5, -1):
|
||||||
for x1 in range(x, x+3):
|
for x1 in range(x, x+3):
|
||||||
self.setPixel(x1, y1, self.black)
|
self.setPixel(x1, y1, colors.BLACK)
|
||||||
|
|
||||||
self.unicorn.show()
|
self.unicorn.show()
|
||||||
|
|
||||||
def displayTimeDots(self, x, y, color):
|
def displayTimeDots(self, x, y, color):
|
||||||
self.setPixel(x, y, self.black)
|
self.setPixel(x, y, colors.BLACK)
|
||||||
self.setPixel(x, y-1, color)
|
self.setPixel(x, y-1, color)
|
||||||
self.setPixel(x, y-2, self.black)
|
self.setPixel(x, y-2, colors.BLACK)
|
||||||
self.setPixel(x, y-3, color)
|
self.setPixel(x, y-3, color)
|
||||||
self.setPixel(x, y-4, self.black)
|
self.setPixel(x, y-4, colors.BLACK)
|
||||||
self.unicorn.show()
|
self.unicorn.show()
|
||||||
|
|
||||||
|
def displayNegative(self, x, y, color):
|
||||||
|
self.setPixel(x, y, colors.BLACK)
|
||||||
|
self.setPixel(x, y-1, colors.BLACK)
|
||||||
|
self.setPixel(x+1, y, colors.BLACK)
|
||||||
|
self.setPixel(x+1, y-1, colors.BLACK)
|
||||||
|
self.setPixel(x, y-2, color)
|
||||||
|
self.setPixel(x+1, y-2, color)
|
||||||
|
self.setPixel(x, y-3, colors.BLACK)
|
||||||
|
self.setPixel(x, y-4, colors.BLACK)
|
||||||
|
self.setPixel(x+1, y-3, colors.BLACK)
|
||||||
|
self.setPixel(x+1, y-4, colors.BLACK)
|
||||||
|
|
||||||
def displayZero(self, x, y, color):
|
def displayZero(self, x, y, color):
|
||||||
self.fullLine(x, y, color)
|
self.fullLine(x, y, color)
|
||||||
self.bothSides(x, y-1, color)
|
self.bothSides(x, y-1, color)
|
||||||
|
|
12
chutney.py
12
chutney.py
|
@ -4,6 +4,7 @@ from character_display import CharacterDisplay
|
||||||
from signal import signal, SIGTERM
|
from signal import signal, SIGTERM
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from time_display import TimeDisplay
|
from time_display import TimeDisplay
|
||||||
|
from weather_display import WeatherDisplay
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import unicornhathd as unicorn
|
import unicornhathd as unicorn
|
||||||
|
@ -27,9 +28,20 @@ def main():
|
||||||
|
|
||||||
characterDisplay = CharacterDisplay(unicorn)
|
characterDisplay = CharacterDisplay(unicorn)
|
||||||
timeDisplay = TimeDisplay(characterDisplay, topRow=15)
|
timeDisplay = TimeDisplay(characterDisplay, topRow=15)
|
||||||
|
weatherDisplay = WeatherDisplay(characterDisplay, topRow=9, configFile='chutney.cfg')
|
||||||
|
|
||||||
|
x = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
timeDisplay.showTime()
|
timeDisplay.showTime()
|
||||||
|
|
||||||
|
if (x == 0):
|
||||||
|
weatherDisplay.showWeather()
|
||||||
|
print("weather updated")
|
||||||
|
|
||||||
|
x = x + 1
|
||||||
|
x = x % 120
|
||||||
|
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[DEFAULT]
|
[weather]
|
||||||
weather_user=user
|
host=host
|
||||||
weather_pass=password
|
user=user
|
||||||
weather_url=url
|
pass=password
|
||||||
weather_lat=lat
|
lat=lat
|
||||||
weather_lon=lon
|
lon=lon
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
BLACK = [0, 0, 0 ]
|
||||||
|
RED = [255, 0, 0 ]
|
||||||
|
PINK = [255, 0, 64 ]
|
||||||
|
BLUE = [0, 64, 128]
|
|
@ -1,3 +1,5 @@
|
||||||
|
import colors
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,8 +10,8 @@ class TimeDisplay:
|
||||||
self.topRow = topRow
|
self.topRow = topRow
|
||||||
self.currentHour = [-1, -1]
|
self.currentHour = [-1, -1]
|
||||||
self.currentMinute = [-1, -1]
|
self.currentMinute = [-1, -1]
|
||||||
self.currentColor = [0, 0, 0]
|
self.currentColor = colors.BLACK
|
||||||
self.color = [255, 0, 64]
|
self.color = colors.PINK
|
||||||
self.hourStartColumn = -1
|
self.hourStartColumn = -1
|
||||||
self.timeDotsColumn = 7
|
self.timeDotsColumn = 7
|
||||||
self.minuteStartColumn = 9
|
self.minuteStartColumn = 9
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
import colors
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
class WeatherDisplay:
|
||||||
|
def __init__(self, characterDisplay, topRow, configFile):
|
||||||
|
self.characterDisplay = characterDisplay
|
||||||
|
self.topRow = topRow
|
||||||
|
self.currentTemperature = [9, 9]
|
||||||
|
self.currentColor = colors.BLACK
|
||||||
|
self.color = colors.BLUE
|
||||||
|
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read(configFile)
|
||||||
|
|
||||||
|
self.host = config['weather'].get('host')
|
||||||
|
self.user = config['weather'].get('user')
|
||||||
|
self.password = config['weather'].get('pass')
|
||||||
|
self.lat = config['weather'].get('lat')
|
||||||
|
self.lon = config['weather'].get('lon')
|
||||||
|
|
||||||
|
print(self.host)
|
||||||
|
|
||||||
|
def showWeather(self):
|
||||||
|
self.showTemperature(self.getTemperatureCharacters(self.getTemperature()))
|
||||||
|
|
||||||
|
def showTemperature(self, temperature):
|
||||||
|
start = 6
|
||||||
|
|
||||||
|
for c in temperature:
|
||||||
|
if c == '-':
|
||||||
|
self.characterDisplay.displayNegative(start, self.topRow, self.color)
|
||||||
|
start = start + 3
|
||||||
|
else:
|
||||||
|
self.characterDisplay.displayDigit(start, self.topRow, c, self.color)
|
||||||
|
start = start + 4
|
||||||
|
|
||||||
|
|
||||||
|
def getTemperature(self):
|
||||||
|
return list(filter(lambda t: t["timestep"] == 'current', requests.get(f'https://{self.host}/api/weather?lat={self.lat}&lon={self.lon}&units=metric', auth=(self.user, self.password)).json()["tomorrow"]["data"]['timelines']))[0]["intervals"][0]["values"]["temperature"]
|
||||||
|
|
||||||
|
def getTemperatureCharacters(self, temperature):
|
||||||
|
return list(str(round(temperature)))
|
Loading…
Reference in New Issue