Screen fully working

TODO : Daemon mode to run in background.
This commit is contained in:
Phyks (Lucas Verney) 2013-12-09 22:20:50 +01:00
parent d256a78fef
commit 85185e4d81

View File

@ -1,4 +1,5 @@
#! /usr/bin/env python3.3 #! /usr/bin/env python3.3
#-*- coding: utf-8 -*-
# Auteur : Phyks (phyks@phyks.me) # Auteur : Phyks (phyks@phyks.me)
# Site web : http://phyks.me # Site web : http://phyks.me
@ -15,7 +16,10 @@ import sys
import urllib3 import urllib3
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import datetime import datetime
import wiringpi2 import wiringpi2 as wp2
import time as time_lib
wp2.wiringPiSetup()
# =========== # ===========
# Pins du LCD # Pins du LCD
@ -27,8 +31,8 @@ PIN_DC = 5
PIN_SDIN = 6 PIN_SDIN = 6
PIN_SCLK = 7 PIN_SCLK = 7
LCD_C = HIGH LCD_C = 0
LCD_D = LOW LCD_D = 1
LCD_X = 84 LCD_X = 84
LCD_Y = 48 LCD_Y = 48
@ -134,16 +138,16 @@ ASCII = [
def writeLCD(dc, data): def writeLCD(dc, data):
wiringpi2.digitalWrite(PIN_DC, dc) wp2.digitalWrite(PIN_DC, dc)
wiringpi2.digitalWrite(PIN_SCE, LOW) wp2.digitalWrite(PIN_SCE, 0)
wiringpi2.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data) wp2.shiftOut(PIN_SDIN, PIN_SCLK, 1, data)
wiringpi2.digitalWrite(PIN_SCE, HIGH) wp2.digitalWrite(PIN_SCE, 1)
def characterLCD(character): def characterLCD(character):
writeLCD(LCD_D, 0x00) writeLCD(LCD_D, 0x00)
for i in range(0, 5): for i in range(0, 5):
writeLCD(ASCII[character - 0x20][i]) writeLCD(LCD_D, ASCII[ord(character) - 0x20][i])
writeLCD(LCD_D, 0x00) writeLCD(LCD_D, 0x00)
@ -151,27 +155,32 @@ def stringLCD(string):
for character in string: for character in string:
characterLCD(character) characterLCD(character)
# X ranges from 0 to 84
# Y ranges from 0 to 5
def gotoXYLCD(x, y):
writeLCD(0, 0x80 | x)
writeLCD(0, 0x40 | y)
def initLCD(): def initLCD():
wiringpi2.pinMode(PIN_SCE, OUTPUT) wp2.pinMode(PIN_SCE, 1)
wiringpi2.pinMode(PIN_RESET, OUTPUT) wp2.pinMode(PIN_RESET, 1)
wiringpi2.pinMode(PIN_DC, OUTPUT) wp2.pinMode(PIN_DC, 1)
wiringpi2.pinMode(PIN_SDIN, OUTPUT) wp2.pinMode(PIN_SDIN, 1)
wiringpi2.pinMode(PIN_SCLK, OUTPUT) wp2.pinMode(PIN_SCLK, 1)
wiringpi2.digitalWrite(PIN_RESET, LOW) wp2.digitalWrite(PIN_RESET, 0)
wiringpi2.digitalWrite(PIN_RESET, HIGH) wp2.digitalWrite(PIN_RESET, 1)
wiringpi2.writeLCD(LCD_C, 0x21) # LCD Extended commands writeLCD(LCD_C, 0x21) # LCD Extended commands
wiringpi2.writeLCD(LCD_C, 0x98) # Set LCD Vop (contrast) writeLCD(LCD_C, 0x98) # Set LCD Vop (contrast)
wiringpi2.writeLCD(LCD_C, 0x04) # Set Temp coefficient writeLCD(LCD_C, 0x04) # Set Temp coefficient
wiringpi2.writeLCD(LCD_C, 0x13) # LCD bias mode (1:48) writeLCD(LCD_C, 0x13) # LCD bias mode (1:48)
wiringpi2.writeLCD(LCD_C, 0x0C) # LCD in normal mode writeLCD(LCD_C, 0x0C) # LCD in normal mode
wiringpi2.writeLCD(LCD_C, 0x20) writeLCD(LCD_C, 0x20)
wiringpi2.writeLCD(LCD_C, 0x0C) writeLCD(LCD_C, 0x0C)
def clearLCD(): def clearLCD():
for i in range(0, LCD_X*LCD_Y/8): for i in range(0, int(LCD_X*LCD_Y/8)):
writeLCD(LCD_D, 0x00) writeLCD(LCD_D, 0x00)
characterLCD(' ') characterLCD(' ')
@ -192,6 +201,10 @@ base_url = ('http://www.velib.paris.fr/service/stationdetails/paris/')
# Initialisation des librairies # Initialisation des librairies
# ============================= # =============================
http = urllib3.PoolManager() http = urllib3.PoolManager()
initLCD()
clearLCD()
gotoXYLCD(0,0)
stringLCD("Loading...")
# ==== # ====
# Date # Date
@ -269,8 +282,62 @@ if r.status == 200:
# ============================ # ============================
# Afficher les infos à l'écran # Afficher les infos à l'écran
# ============================ # ============================
running = True
while running:
for station in stations:
clearLCD()
gotoXYLCD(0, 0)
stringLCD("Station:")
gotoXYLCD(0, 1)
stringLCD(str(station))
gotoXYLCD(0, 3)
stringLCD("Avail.: "+str(available[station]))
gotoXYLCD(0, 5)
stringLCD("Free: "+str(free[station]))
time_lib.sleep(2)
clearLCD()
gotoXYLCD(0, 0)
stringLCD("[Weather]")
gotoXYLCD(0, 1)
stringLCD("Now:")
gotoXYLCD(0, 2)
stringLCD(weather_now.capitalize())
gotoXYLCD(0, 4)
stringLCD(str(temp_now)+"C")
time_lib.sleep(2)
clearLCD()
gotoXYLCD(0, 0)
stringLCD("[Weather]")
gotoXYLCD(0, 1)
stringLCD("In 3h:")
gotoXYLCD(0, 2)
stringLCD(weather_3h.capitalize())
gotoXYLCD(0, 4)
stringLCD(str(temp_3h)+"C")
time_lib.sleep(2)
clearLCD()
gotoXYLCD(0, 0)
stringLCD("[Weather]")
gotoXYLCD(0, 1)
stringLCD("In 6h:")
gotoXYLCD(0, 2)
stringLCD(weather_6h.capitalize())
gotoXYLCD(0, 4)
stringLCD(str(temp_6h)+"C")
time_lib.sleep(2)
clearLCD()
gotoXYLCD(0, 0)
stringLCD("[Weather]")
gotoXYLCD(0, 1)
stringLCD("In 9h:")
gotoXYLCD(0, 2)
stringLCD(weather_9h.capitalize())
gotoXYLCD(0, 4)
stringLCD(str(temp_9h)+"C")
time_lib.sleep(2)
wiringpi2.wiringPiSetup
initLCD()
clearLCD() clearLCD()