Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- """
- recalbox_clcd.py
- Author : Godhunter74 with a lot of of inspiration and work from zzeromin, member of Raspberrypi Village
- Creation Date: Mar 08, 2017
- Blog : https://forum.recalbox.com/topic/5777/relier-%C3%A0-un-%C3%A9cran-et-afficher-du-texte and original work : http://rasplay.org, http://forums.rasplay.org/, https://zzeromin.tumblr.com/
- Thanks to : zzeromin smyani, zerocool, GreatKStar
- Free and open for all to use. But put credit where credit is due.
- #Reference:
- I2C_LCD_driver developed by: Denis Pleic ( https://gist.github.com/DenisFromHR/cc863375a6e19dce359d )
- IP_Script Developed by: AndyPi ( http://andypi.co.uk/ )
- lcdScroll Developed by: Eric Pavey ( https://bitbucket.org/AK_Eric/my-pi-projects/src/28302f8f5657599e29cb5d55573d192b9fa30265/Adafruit_CharLCDPlate/lcdScroll.py?at=master&fileviewer=file-view-default )
- #Notice:
- recalbox_clcd.py require I2C_LCD_driver.py, lcdScroll.py
- Small script written in Python for recalbox project (https://www.recalbox.com/)
- running on Raspberry Pi 1,2,3, which displays all neccessary info on a 16x2 LCD display
- #Features:
- 1. Current date and time, IP address of eth0, wlan0
- 2. CPU temperature and speed
- 3. Emulation and ROM information extracet from gamelist !!!!!!!!!! YOU MUST SCRAPP YOUR ROMS !!!!!!!!!!!!!
- """
- import I2C_LCD_driver
- import os
- from os import popen
- from sys import exit
- from subprocess import *
- from time import *
- from datetime import datetime
- from lcdScroll import Scroller
- import string
- def run_cmd(cmd):
- # runs whatever is in the cmd variable in the terminal
- p = Popen(cmd, shell=True, stdout=PIPE)
- output = p.communicate()[0]
- return output
- def get_cpu_temp():
- # get the cpu temp
- tempFile = open("/sys/class/thermal/thermal_zone0/temp")
- cpu_temp = tempFile.read()
- tempFile.close()
- return float(cpu_temp)/1000
- def get_cpu_speed():
- # get the cpu speed
- tempFile = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")
- cpu_speed = tempFile.read()
- tempFile.close()
- return float(cpu_speed)/1000
- def getTextInside (fullText, textBefore, textAfter, index) :
- begin = -1
- end = -1
- if index < len(fullText[index:]) - len(textBefore):
- begin = fullText[index:].find(textBefore) #on cherche le debut
- if len(fullText[index:]) >= begin +len(textBefore)+len(textAfter):
- end = fullText[index+begin +len(textBefore):].find(textAfter) #on cherche la fin
- if begin ==-1 or end ==-1 : #-1 = pas trouve, trouve est forcement entre 0 et len(fullText)-1
- return (index, "pas_trouve") # si on a pas retrouve le debut ou la fin on retourne une chaine vide
- else:
- return (index + begin+ end + len(textAfter), fullText[index + begin+ len(textBefore): index + begin+ len(textBefore)+ end]) # sinon on retourne ce qui se trouve entre les 2
- mylcd = I2C_LCD_driver.lcd()
- mylcd.lcd_clear()
- #get ip address of eth0 connection
- cmdeth = "ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1"
- #get ip address of wlan0 connection
- cmd = "ip addr show wlan0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1"
- #cmd = "ip addr show wlan1 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1"
- old_Temp = new_Temp = get_cpu_temp()
- old_Speed = new_Speed = get_cpu_speed()
- #draw icons not existing in [a-z]
- icons = [
- [ 0b00000, 0b11111, 0b11011, 0b10001, 0b10001, 0b10001, 0b11111, 0b00000 ], # Ethernet
- [ 0b00000, 0b00000, 0b00001, 0b00001, 0b00101, 0b00101, 0b10101, 0b00000 ] # Wireless
- ]
- # Load logo chars (icons)
- mylcd.lcd_load_custom_chars(icons)
- #display first message on screen
- mylcd.lcd_display_string("PI STATION 2", 1, 1) #firstline
- mylcd.lcd_display_string("Pwd by RECALBOX", 2, 1) #secondline
- sleep(5) # 5 sec delay
- mylcd.lcd_clear()
- # display a second message on screen
- mylcd.lcd_display_string("www.recalbox.com", 1, 1) #firstline
- mylcd.lcd_display_string("RECALBOX", 2, 3) #secondline
- sleep(5) # 5 sec delay
- mylcd.lcd_clear() #delete strings on screen
- while 1:
- mylcd.lcd_clear()
- sec = 0
- while ( sec < 5 ) :
- # wlan ip address
- ipaddr = run_cmd(cmd).replace("\n","")
- # selection of wlan or eth address
- length = len(ipaddr)
- space = ""
- if length == 0 :
- ipaddr = run_cmd(cmdeth).replace("\n","")
- if len(ipaddr) == 0 :
- ipaddr = unichr(0)+unichr(1)+" Not connected"
- else:
- if len(ipaddr) == 15 :
- ipaddr = unichr(0)+run_cmd(cmdeth)
- else :
- for i in range( 15-len(ipaddr) ) :
- space = space + " "
- ipaddr = unichr(0)+space+run_cmd(cmdeth)
- else :
- if len(ipaddr) == 15 :
- ipaddr = unichr(1)+run_cmd(cmd)
- else :
- for i in range( 15-len(ipaddr) ) :
- space = space + " "
- ipaddr = unichr(1)+space+run_cmd(cmd)
- #print datetime.now().strftime( "%b %d %H:%M:%S" )
- #print "IP " + str( ipaddr )
- #display the third message
- mylcd.lcd_display_string( datetime.now().strftime( "%b %d %H:%M:%S" ), 1, 0 )
- mylcd.lcd_display_string( ipaddr, 2, 0 )
- sec = sec + 1
- sleep(1)
- mylcd.lcd_clear()
- sec = 0
- while ( sec < 5 ) :
- space = ""
- # cpu Temp & Speed information
- new_Temp = get_cpu_temp()
- new_Speed = int( get_cpu_speed() )
- if old_Temp != new_Temp or old_Speed != new_Speed :
- old_Temp = new_Temp
- old_Speed = new_Speed
- #print "CPU Temp: " + str( new_Temp )
- #print "CPU Speed: " + str( new_Speed )
- for i in range( 5 - len( str(new_Speed) ) ) :
- space = space + " "
- mylcd.lcd_display_string( "CPU Temp :" + str( new_Temp ), 1, 0 )
- mylcd.lcd_display_string( "CPU Speed: " + space + str( new_Speed ), 2, 0 )
- sec = sec + 1
- sleep(1)
- mylcd.lcd_clear()
- sec = 0
- while ( sec < 1 ) :
- # show system & rom file information
- # system = f.readline()
- result = run_cmd("ps | grep emulatorlauncher.py | grep -v 'c python' | grep -v grep")
- (index, systeme) = getTextInside( result, "-system ", " -rom ",0)
- #~ index = 0
- (index,rom ) = getTextInside( result, "-rom ", " -emulator ",0)
- #print "systeme [" + systeme + "]"
- #print "rom [" + rom + "]"
- nom_rom= os.path.basename(rom)
- nom_rom= "./"+nom_rom
- #print "nom_rom ["+nom_rom +"]"
- f=open("/recalbox/share/roms/"+ systeme + "/gamelist.xml", 'r') # on ouvre le fichier
- # ici on considere que le fichier est dans le meme repertoire mais tu peux aller le chercher ou tu veux avec un chemin absolu ex= "/mondossier/gamelist.xml" ou relatif ex= "../mondossier/gamelist.xml"
- buf = f.read() # on lit tout ce qu'il y a dedans (stocke dans un buffer en RAM)
- f.close() #on ferme le fichier
- (index,gameData) = getTextInside( buf, "<path>" + nom_rom, "</game>",0)
- #print gameData
- #initialize all the <balise> to extract from gamelist
- name = ""
- desc = ""
- image = ""
- rating = ""
- releasedate = ""
- developer = ""
- publisher = ""
- genre = ""
- players = ""
- if gameData != "pas_trouve": # on a trouve le nom , on peut chercher aussi les autres
- (index2,name) = getTextInside( gameData, "<name>","</name>",0) # name
- (index2,desc) = getTextInside( gameData, "<desc>","</desc>",0) #desc
- (index2,image) = getTextInside( gameData, "<image>","</image>",0) #image
- (index2,rating) = getTextInside( gameData, "<rating>","</rating>",0) #rating
- (index2,releasedate) = getTextInside( gameData, "<releasedate>","</releasedate>",0) # releasedate
- (index2,developer) = getTextInside( gameData, "<developer>","</developer>",0) #developer
- (index2,publisher) = getTextInside( gameData, "<publisher>","</publisher>",0) #publisher
- (index2,genre) = getTextInside( gameData, "<genre>","</genre>",0) #genre
- (index2,players) = getTextInside( gameData, "<players>","</players>",0) #players
- #print "name [" + name + "] description [" + desc + "] image [" + image + "] rating [" + str(rating) + "] releasedate [" + releasedate[:-11] + "] developer [" + developer + "] publisher [" + publisher + "] genre [" + genre + "] players [" + players + "]"
- mylcd.lcd_clear()
- firstline = name
- systemMap = {
- "Berrycade":"Berrycade",
- "fba":"FinalBurn Alpha",
- "gba":"GameBoy Advance",
- "kodi":"KODI",
- "mame-mame4all":"MAME4ALL",
- "mame-advmame":"AdvanceMAME",
- "mame-libretro":"MAME-libretro",
- "msx":"MSX",
- "nes":"Famicom", # Nintendo Entertainment System
- "psp":"PSPortable", # PlayStation Portable
- "psx":"Playstation",
- "ports":"Ports",
- "snes":"Super Famicom", # Super Nintendo Entertainment System
- "notice":"TURN OFF",
- }
- system = name[:15]
- plateforme = systemMap.get(systeme)
- rom = "Titre : " + name + " - Plateforme : " + plateforme + " - Genre : " + genre + " - " + "joueur(s) - Note : " + str(rating) + "% - Date de sortie : " + releasedate[:-11] + " par " + developer + " pour " + publisher + "."
- #print "firstline : [" + firstline + "]"
- #print "secondline : [" + secondline + "]"
- mylcd.lcd_display_string( "%s" %(rom), 2 )
- mylcd.lcd_display_string( "%s" %(system), 1, 0 )
- sleep(3)
- mylcd.lcd_clear()
- flag = "TURN OFF"
- lines = rom
- wait = 0
- speed = 0.1
- # Create scroller instance:
- scroller = Scroller(lines=lines)
- while True :
- if wait < 10 and systeme != flag:
- message = scroller.scroll()
- mylcd.lcd_display_string( "%s" %(system), 1, 0 )
- mylcd.lcd_display_string( "%s" %(message), 2 )
- sleep(speed)
- wait = wait + 0.1
- else :
- break
- sec = sec + 1
- sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement