class Display(): def __init__(self): self.lcd = Adafruit_CharLCDPlate(busnum=1) def clear(self): self.lcd.clear() def start(self): self.lcd.begin(16, 2) self.lcd.backlight(self.lcd.ON) def stop(self): self.clear() self.lcd.backlight(self.lcd.OFF) def message(self, message=""): self.start() self.lcd.message(message) def button_pressed(self, button=None): if self.lcd.buttonPressed(button): time.sleep(.2) return(True) else: return(False) def button_left(self): return(self.button_pressed(self.lcd.LEFT)) def button_right(self): return(self.button_pressed(self.lcd.RIGHT)) def button_up(self): return(self.button_pressed(self.lcd.UP)) def button_down(self): return(self.button_pressed(self.lcd.DOWN)) def button_select(self): return(self.button_pressed(self.lcd.SELECT)) def blink_cursor(self): self.lcd.blink() def move_cursor(self, col=0, row=0): self.lcd.setCursor(col, row)
# Static parameters ---------- ---------- ---------- commands_list = ["Ping Target", "Reset Target", "Select Target", "Restart Program", "Restart System", "Shutdown System"] commands_list_emergency=["Restart Program", "Restart System", "Shutdown System"] ping_target_available=1 # enable command "Ping Target" (ping active target) reset_target_available=1 # enable command "Reset Target" (some games only accept in service menu) select_target_available=1 # enable command "Select Target" (select target from available targets) restart_program_available=1 # enable command "Restart Program" (restart pyhton program) restart_system_available=1 # enable command "Restart System" (restart raspberry pi) shutdown_system_available=1 # enable command "Shutdown System" (shutdown raspberry pi) sleep (sleep_message) # Startup wait ---------- ---------- ---------- # Wait for [OK] at startup if startup_wait is 1: lcd.setCursor(12, 1) lcd.message("[OK]") pressedButtons=[] while lcd.SELECT not in pressedButtons: # Handle SELECT if lcd.buttonPressed(lcd.SELECT): pressedButtons.append(lcd.SELECT) if lcd.SELECT in pressedButtons: pressedButtons.append(lcd.SELECT) lcd.clear() # Blink ON lcd.ToggleBlink() # Scan targets ---------- ---------- ---------- lcd.clear()
lcd.clear() lcd.message("Connecting...") try: triforcetools.connect(ips[curr_ip], 10703) except: lcd.clear() lcd.message("Error:\nConnect Failed") sleep(1) lcd.clear() lcd.message(selection) continue lcd.clear() lcd.message("Sending...") lcd.setCursor(10, 0) lcd.ToggleBlink() triforcetools.HOST_SetMode(0, 1) triforcetools.SECURITY_SetKeycode("\x00" * 8) triforcetools.DIMM_UploadFile(rom_dir + games[selection]) triforcetools.HOST_Restart() triforcetools.TIME_SetLimit(10 * 60 * 1000) triforcetools.disconnect() lcd.ToggleBlink() lcd.clear() lcd.message("Transfer\nComplete!") sleep(5) lcd.clear() lcd.message(selection)
from time import sleep from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate lcd = Adafruit_CharLCDPlate() lcd.begin(numcolumns, numrows) lcd.backlight(lcd.ON) lcd.message("LCD 20x4\nDemonstration") sleep(2) while True: #Text on each line alone. lcd.clear() lcd.setCursor(0,0) lcd.message("Line 1") sleep(1) lcd.clear() lcd.setCursor(0,1) lcd.message("Line 2") sleep(1) lcd.clear() lcd.setCursor(0,2) lcd.message("Line 3") sleep(1) lcd.clear() lcd.setCursor(0,3)
stationNew += 1 # Next station if cursorY < 1: cursorY += 1 # Move cursor else: listTop += 1 # Y-scroll xStation = 0 # Reset X-scroll elif stationNew > 0: # btnUp implied stationNew -= 1 # Prev station if cursorY > 0: cursorY -= 1 # Move cursor else: listTop -= 1 # Y-scroll xStation = 0 # Reset X-scroll staBtnTime = time.time() # Reset button time xStation = drawStations(stationNew, listTop, 0, staBtnTime) else: # Not in station menu if volSet is False: # Just entering volume-setting mode; init display lcd.setCursor(0, 1) volCurI = int((volCur - VOL_MIN) + 0.5) n = int(volCurI / 5) s = ( chr(6) + ' Volume ' + chr(5) * n + # Solid brick(s) chr(volCurI % 5) + # Fractional brick chr(0) * (6 - n)) # Spaces lcd.message(s) volSet = True volSpeed = 1.0 # Volume-setting mode now active (or was already there); # act on button press. if btnUp: volNew = volCur + volSpeed if volNew > VOL_MAX: volNew = VOL_MAX else:
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate lcd = Adafruit_CharLCDPlate() from core import SoCo from core import SonosDiscovery sonos = SoCo('10.0.1.205') lcd.begin(16, 2) lcd.clear() # MAX 40 / Scroll MAX 24 msg = "Sonos controller by Marc" mlen = 0 lcd.setCursor(0, 1) while True: tr = sonos.get_current_track_info() lcd.setCursor(0, 0) lcd.message(tr['artist']) msg = tr['title'] lcd.setCursor(0, 1) lcd.message(msg) sleep(3)
#!/usr/bin/python from time import sleep from os import path import glob import re from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate if __name__ == '__main__': lcd = Adafruit_CharLCDPlate() lcd.begin(16, 2) lcd.clear() lcd.message(" O3STECH \nRPi Scanner WIFI") sleep(3) lcd.clear() lcd.message("MAC dev Number \n") lcd.setCursor(9, 1) lcd.message("devices") newest_file = path.realpath(max(glob.iglob('*.nettxt'), key=path.getctime)) while True: sleep(5) with open(newest_file, "r") as f: result = re.findall("MAC (..:..:..:..:..:..)", f.read()) unique = list(set(result)) nbre_mac = len(unique) lcd.setCursor(0, 1) lcd.message(str(nbre_mac))
from time import sleep from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate lcd = Adafruit_CharLCDPlate() lcd.begin(numcolumns, numrows) lcd.backlight(lcd.ON) lcd.message("LCD 20x4\nDemonstration") sleep(2) while True: #Text on each line alone. lcd.clear() lcd.setCursor(0, 0) lcd.message("Line 1") sleep(1) lcd.clear() lcd.setCursor(0, 1) lcd.message("Line 2") sleep(1) lcd.clear() lcd.setCursor(0, 2) lcd.message("Line 3") sleep(1) lcd.clear() lcd.setCursor(0, 3)
global menu_fristdraw global menu_selected global menu_start global lcd_redraw print "deactivating menu" lcd_redraw = True menu_active = False menu_pointer = 1 menu_fristdraw = True menu_selected = 0 menu_start = 0 #INIT lcd.clear() lcd.setCursor(4,0) lcd.message("STARTING UP.") lcd.setCursor(0,1) lcd.message("Network [ ]") lcd.setCursor(0,2) lcd.message("Mopidy [ ]") if (spotify_active == True): lcd.setCursor(0,3) lcd.message("Spotify [ ]") #Wait for network to become available before continuing while (connected_to_network == False): network_check = int(Popen("ifconfig |grep \"inet addr:\" |wc -l", shell=True, stdout=PIPE, stderr=PIPE).stdout.read()) print network_check if (network_check > 1): lcd.setCursor(17,1)
lcd.backlight(lcd.VIOLET) try: triforcetools.connect(ips[curr_ip], 10703) except: lcd.clear() lcd.message("Error:\nConnect Failed") lcd.backlight(lcd.RED) sleep(1) lcd.clear() lcd.message(selection) continue lcd.clear() lcd.backlight(lcd.BLUE) lcd.message("Sending...") lcd.setCursor(10, 0) lcd.ToggleBlink() triforcetools.HOST_SetMode(0, 1) triforcetools.SECURITY_SetKeycode("\x00" * 8) triforcetools.DIMM_UploadFile(rom_dir+games[selection]) triforcetools.HOST_Restart() triforcetools.TIME_SetLimit(10*60*1000) triforcetools.disconnect() lcd.ToggleBlink() lcd.clear() lcd.message("Transfer\nComplete!") lcd.backlight(lcd.YELLOW) sleep(5) lcd.clear()
stationNew += 1 # Next station if cursorY < 1: cursorY += 1 # Move cursor else: listTop += 1 # Y-scroll xStation = 0 # Reset X-scroll elif stationNew > 0: # btnUp implied stationNew -= 1 # Prev station if cursorY > 0: cursorY -= 1 # Move cursor else: listTop -= 1 # Y-scroll xStation = 0 # Reset X-scroll staBtnTime = time.time() # Reset button time xStation = drawStations(stationNew, listTop, 0, staBtnTime) else: # Not in station menu if volSet is False: # Just entering volume-setting mode; init display lcd.setCursor(0, 1) volCurI = int((volCur - VOL_MIN) + 0.5) n = int(volCurI / 5) s = (chr(6) + ' Volume ' + chr(5) * n + # Solid brick(s) chr(volCurI % 5) + # Fractional brick chr(0) * (6 - n)) # Spaces lcd.message(s) volSet = True volSpeed = 1.0 # Volume-setting mode now active (or was already there); # act on button press. if btnUp: volNew = volCur + volSpeed if volNew > VOL_MAX: volNew = VOL_MAX else:
from time import sleep from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate lcd = Adafruit_CharLCDPlate() lcd.begin(numcolumns, numrows) lcd.backlight(lcd.ON) lcd.message("LCD 20x4\nDemonstration") sleep(2) while True: # Text on each line alone. lcd.clear() lcd.setCursor(0, 0) lcd.message("Line 1") sleep(1) lcd.clear() lcd.setCursor(0, 1) lcd.message("Line 2") sleep(1) lcd.clear() lcd.setCursor(0, 2) lcd.message("Line 3") sleep(1) lcd.clear() lcd.setCursor(0, 3)
#!/usr/bin/python from time import sleep from os import path import glob import re from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate if __name__ == '__main__': lcd = Adafruit_CharLCDPlate() lcd.begin(16, 2) lcd.clear() lcd.message(" O3STECH \nRPi Scanner WIFI") sleep (3) lcd.clear() lcd.message ("MAC dev Number \n") lcd.setCursor(9,1) lcd.message ("devices") newest_file = path.realpath(max(glob.iglob('*.nettxt') ,key= path.getctime)) while True : sleep(5) with open(newest_file ,"r") as f: result = re.findall("MAC (..:..:..:..:..:..)",f.read()) unique = list(set(result)) nbre_mac = len(unique) lcd.setCursor(0,1) lcd.message(str(nbre_mac))
] commands_list_emergency = [ "Restart Program", "Restart System", "Shutdown System" ] ping_target_available = 1 # enable command "Ping Target" (ping active target) reset_target_available = 1 # enable command "Reset Target" (some games only accept in service menu) select_target_available = 1 # enable command "Select Target" (select target from available targets) restart_program_available = 1 # enable command "Restart Program" (restart pyhton program) restart_system_available = 1 # enable command "Restart System" (restart raspberry pi) shutdown_system_available = 1 # enable command "Shutdown System" (shutdown raspberry pi) sleep(sleep_message) # Startup wait ---------- ---------- ---------- # Wait for [OK] at startup if startup_wait is 1: lcd.setCursor(12, 1) lcd.message("[OK]") pressedButtons = [] while lcd.SELECT not in pressedButtons: # Handle SELECT if lcd.buttonPressed(lcd.SELECT): pressedButtons.append(lcd.SELECT) if lcd.SELECT in pressedButtons: pressedButtons.append(lcd.SELECT) lcd.clear() # Blink ON lcd.ToggleBlink() # Scan targets ---------- ---------- ---------- lcd.clear()
#Aubrey added: Strip it properly: times = statusLines[1].split(']', 1)[1].strip() times = times.split(' ', 1)[1].strip() times = times.split(' ', 1)[0].strip() times = times.split('/', 1)[0].strip() # Aubrey - Changed the Statusline with VOL/TM: infoLine = statusLines[2].split(':', 1)[1].strip() infoLine = infoLine.split('%', 1)[0].strip() times = ('TM=' + times + ' Vol=' + infoLine + '%') else: songName = '' playStatus = '[stopped]' times = '0:00/0:00 (0%)' lcd.setCursor(0, 0) # Without scolling of text #lcd.message((playStatus + ' ' + songName)[0:16] + '\n' + (time + ' ')[0:16]) # with scolling text # artistSong = (playStatus + ' ' + songName) # Aubrey - Stripped [playing] from status artistSong = (songName) if artistSong != lastArtistSong: scroller.setNewText(artistSong) lastArtistSong = artistSong # Aubrey - If the songname is shorter than 16, just display it, else, scroll it... if songName != '': if len(songName) < 16: lcd.message(artistSong + ' \n' +
class DisplayIPAddressDaemon: # initialize the LCD plate # use busnum = 0 for raspi version 1 (256MB) # and busnum = 1 for raspi version 2 (512MB) LCD = "" # lcd = "" # Define a queue to communicate with worker thread LCD_QUEUE = "" # Globals astring = "" setscroll = "" # Buttons NONE = 0x00 SELECT = 0x01 RIGHT = 0x02 DOWN = 0x04 UP = 0x08 LEFT = 0x10 UP_AND_DOWN = 0x0C LEFT_AND_RIGHT = 0x12 def __init__(self): self.LCD = Adafruit_CharLCDPlate(busnum = 0) # self.lcd = Adafruit_CharLCDPlate() self.LCD_QUEUE = Queue() self.stdin_path = '/dev/null' self.stdout_path = '/dev/tty' self.stderr_path = '/dev/tty' self.pidfile_path = '/var/run/testdaemon.pid' self.pidfile_timeout = 5 # ---------------------------- # WORKER THREAD # ---------------------------- # Define a function to run in the worker thread def update_lcd(self,q): while True: msg = q.get() # if we're falling behind, skip some LCD updates while not q.empty(): q.task_done() msg = q.get() self.LCD.setCursor(0,0) self.LCD.message(msg) q.task_done() return # ---------------------------- # MAIN LOOP # ---------------------------- def run(self): global astring, setscroll # Setup AdaFruit LCD Plate self.LCD.begin(16,2) self.LCD.clear() self.LCD.backlight(self.LCD.ON) # Create the worker thread and make it a daemon worker = Thread(target=self.update_lcd, args=(self.LCD_QUEUE,)) worker.setDaemon(True) worker.start() self.display_ipaddr() def delay_milliseconds(self, milliseconds): seconds = milliseconds / float(1000) # divide milliseconds by 1000 for seconds sleep(seconds) # ---------------------------- # DISPLAY TIME AND IP ADDRESS # ---------------------------- def display_ipaddr(self): show_eth0 = "ip addr show eth0 | cut -d/ -f1 | awk '/inet/ {printf \"e%15.15s\", $2}'" ipaddr = self.run_cmd(show_eth0) self.LCD.backlight(self.LCD.ON) i = 29 muting = False keep_looping = True while (keep_looping): # Every 1/2 second, update the time display i += 1 #if(i % 10 == 0): if(i % 5 == 0): self.LCD_QUEUE.put(datetime.now().strftime('%b %d %H:%M:%S\n')+ ipaddr, True) # Every 3 seconds, update ethernet or wi-fi IP address if(i == 60): ipaddr = self.run_cmd(show_eth0) i = 0 self.delay_milliseconds(99) # ---------------------------- def run_cmd(self,cmd): p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT) output = p.communicate()[0] return output