def read_now_playing(**kwargs): bufferSize = 1024 PATH = "/home/pi/shairport/now_playing" fifo = os.open(PATH, os.O_RDONLY) fd = os.fdopen(fifo, 'r', bufferSize) fields = [] while True: line = fd.readline() if not line or line == '\n': # print(u', '.join(fields)) send_to_display(fields, **kwargs) fields = [] continue field = line.strip().split('=') # print(field) fields.append(field[1].decode('utf-8')) fd.close() os.close(fifo) lcd.cls()
def init(): lcd.init() lcd.cls() lcd.backlight(ON) wiringpi.pinMode(BUTTON_OK,INPUT) wiringpi.pinMode(BUTTON_FKEY,INPUT)
def Int_shutdown(gpio_id,val): print "Shutdown" ard.ser.write('2') os.system("sudo shutdown -h now") lcd.cls() lcd.gotorc(1,0) lcd.text("Apagando") sys.exit("Apagando")
def main(): lcd.init() lcd.cls() lcd.data(smiley) lcd.locate(2,2) lcd.data(ch) lcd.locate(3,0) lcd.text("c.a.h.") lcd.backlight(1)
def main(): lcd.init() lcd.cls() lcd.data(smiley) lcd.locate(2, 2) lcd.data(ch) lcd.locate(3, 0) lcd.text("c.a.h.") lcd.backlight(1)
def stats(): lcd.cls() lcd.locate(0,0) lcd.text(cpu_usage()) lcd.locate(0,1) lcd.text(mem_usage()) lcd.locate(0,2) lcd.text(disk_usage('/')) lcd.locate(0,3) lcd.text(network('eth0')) lcd.locate(0,4)
def value2lcd(date,id,desc,value): lcd.cls() lcd.locate(0,0) lcd.text(date) lcd.locate(0,1) lcd.text(id) lcd.locate(0,2) lcd.text(desc) lcd.locate(0,3) lcd.text("Temp: %s" % (value)) lcd.locate(0,4)
def value2lcd(date, id, desc, value): lcd.cls() lcd.locate(0, 0) lcd.text(date) lcd.locate(0, 1) lcd.text(id) lcd.locate(0, 2) lcd.text(desc) lcd.locate(0, 3) lcd.text("Temp: %s" % (value)) lcd.locate(0, 4)
def bitmaps(): im = Image.new("1", (84, 48)) for filename in ["small_font.png", "gnome.png", "gogol.png", "car.png"]: bitmap = Image.open("images/" + filename) im.paste(bitmap, (0, 0) + bitmap.size) lcd.cls() lcd.image(im, reverse=True) time.sleep(5) del bitmap del im
def demo(seconds): lcd.cls() lcd.text("Hello world!") lcd.locate(0, 4) lcd.text("Charlotte :-)") for loop in range(seconds * 4): lcd.locate(0, 1) lcd.text(time.strftime("%d %b %Y", time.localtime())) lcd.locate(0, 2) lcd.text(time.strftime("%H:%M:%S", time.localtime())) time.sleep(0.25)
def bitmaps(): im = Image.new('1', (84, 48)) for filename in ["small_font.png", "gnome.png", "gogol.png", "car.png"]: bitmap = Image.open("images/" + filename) im.paste(bitmap, (0, 0) + bitmap.size) lcd.cls() lcd.image(im, reverse=True) time.sleep(5) del bitmap del im
def main(): while 1: try: # Run main Client activity client = Client() client.run() except KeyboardInterrupt: # If Ctrl+C has been pressed # turn off the lcd backlight lcd.cls() lcd.backlight(0) # Exit from the program sys.exit(0)
def main(): while 1: try: # Run main Client activity client = Client() client.run() except KeyboardInterrupt: # If Ctrl+C has been pressed # turn off the lcd backlight lcd.cls() lcd.backlight(0); # Exit from the program sys.exit(0)
def main(): try: # Create a Client object client = Client() # Run it client.run() except KeyboardInterrupt: # if Ctrl+C has been pressed # turn off the lcd backlight lcd.backlight(0) lcd.cls() # exit from the program sys.exit(0)
def main(): try: # Create a Client object client = Client() # Run it client.run() except KeyboardInterrupt: # if Ctrl+C has been pressed # turn off the lcd backlight lcd.backlight(0); lcd.cls() # exit from the program sys.exit(0)
def lcd_blink(text): i=10 lcd.cls() lcd.locate(0,0) lcd.text(text) lcd.locate(0,1) while i<0: lcd.text("after %s sec" % (i)) if i%2: lcd.backlight(1) else: lcd.backlight(0) i-=1 time.sleep(1)
def lcd_blink(text): i = 10 lcd.cls() lcd.locate(0, 0) lcd.text(text) lcd.locate(0, 1) while i < 0: lcd.text("after %s sec" % (i)) if i % 2: lcd.backlight(1) else: lcd.backlight(0) i -= 1 time.sleep(1)
def update_display(self): ip_addr = ni.ifaddresses('eth0')[ni.AF_INET][0]['addr'] now = time() if now < self.display_expiry: im = Image.new('1', (84, 48)) draw = ImageDraw.Draw(im) draw.text((0, 5), self.latest_raw_val, font=disp_font, fill=1) draw.text((0, 0), ip_addr, font=disp_font_sm, fill=1) draw.text((5, 36), "mm to surface", font=disp_font_sm, fill=1) lcd.show_image(im) # clean up del draw del im lcd.set_contrast(disp_contrast_on) else: lcd.set_contrast(disp_contrast_off) lcd.cls()
def display(aToDisplay): aDisplay = [] lcd.cls() sToDisplay = '' for sId in aToDisplay.keys(): sToDisplay = sToDisplay + aToDisplay[sId] aDisplay = splitLineForLCD(sToDisplay, LCD_COLUMNS) y = 0 while len(aDisplay) > 0: sLine = aDisplay.pop(0) lcd.text(sLine) y = y + 1 if y >= LCD_LINES: y = 0 time.sleep(5) lcd.cls() lcd.locate(0, y)
def display(aToDisplay): aDisplay=[] lcd.cls() sToDisplay='' for sId in aToDisplay.keys(): sToDisplay=sToDisplay+aToDisplay[sId] aDisplay=splitLineForLCD(sToDisplay,LCD_COLUMNS) y=0 while len(aDisplay)>0: sLine=aDisplay.pop(0) lcd.text(sLine) y=y+1 if y >= LCD_LINES: y=0 time.sleep(5) lcd.cls() lcd.locate(0,y)
def run(self): while True: try: # Loop Clock / Temperature interchangeably # for 10 seconds each client = Clock() client.run() time.sleep(10) lcd.cls() client2 = Process() client2.run() time.sleep(10) lcd.cls() except KeyboardInterrupt: lcd.backlight(0) lcd.cls() sys.exit(0)
def run(self): while True: try: # Loop Clock / Temperature interchangeably # for 10 seconds each client = Clock() client.run() time.sleep(10) lcd.cls() client2 = Process() client2.run() time.sleep(10) lcd.cls() except KeyboardInterrupt: lcd.backlight(0); lcd.cls() sys.exit(0)
def onleft(self): lcd.cls() lcd.centre_text(0,'RPi-Monitor') lcd.centre_text(3,'key left')
def daemon(): client = InfluxDBClient('localhost', 8086, 'USER', 'PASSWORD', DBNAME, timeout=30) ow.init('localhost:4304') lcd.init() logging.debug("Daemon starting") logging.debug("Create INFLUX database: " + DBNAME) errors = 0 try: client.create_database(DBNAME) except InfluxDBClientError: logging.debug("%s DB already exist" % DBNAME) pass except: logging.exception("Error") lcd.text("Exception") try: client.create_retention_policy('awesome_policy', '3d', 3, default=True) except InfluxDBClientError: logging.debug("%s policy already exist" % DBNAME) pass for i in range(10): try: devices = ow.Sensor('/').sensorList() date = datetime.now() points = [] for o in read_dht11(): devices.append(o) devices.append(calc_power()) devices.append(read_max6675()) for sensor in devices: name = sensor.address try: value = float(sensor.value) except: value = float(ow.Sensor('/%s' % name).temperature11) desc = name json_body = { "time": date.strftime('%Y-%m-%dT%H:%M:%SZ'), "measurement": "rosma_temps", "tags": { "sensor": name, }, "fields": { "value": value } } points.append(json_body) value2lcd(date.strftime('%d/%m/%y %H:%M:%S'), name, desc, value) logging.debug(json_body) cms = EmonCms(cms_url) cms.append(name, value) #cms_status = cms.post() cms_status = True if cms_status: logging.debug("CMS Post ok") else: logging.debug("CMS Post failed") status = client.write_points(points) if status: lcd.text("Sent<-OK") logging.debug(status) else: lcd.text("Error!") logging.error(status) #Show status s = 0 lcd.cls() while s < sleep: lcdstatusupdate(len(devices), s) time.sleep(1) s += 1 except: logging.exception("Error occurred %s" % sys.exc_info()[1]) lcd.text("%s Exception!" % errors) time.sleep(1) if errors == 10: lcd_blink("Rebooting!") d = threading.Thread(name='beeper', target=beeper) d.setDaemon(True) d.start() #os.system("reboot") d.join() else: errors += 1 logging.debug("Daemon exiting") return (0)
def displayTime(): #Display Time lcd.gotorc(2, 0) lcd.text(time.strftime("%I:%M:%S", time.localtime())) time.sleep(0.25) lcd.cls()
except KeyError: pass def on_error(self, status_code): print >> sys.stderr, 'Encountered error with status code:', status_code putstr("Error: " + str(status_code), 0, 5) return True # Don't kill the stream def on_timeout(self): print >> sys.stderr, 'Timeout...' putstr("Error: Timeout", 0, 5) return True # Don't kill the stream try: lcd.init() lcd.cls() lcd.backlight(ON) putstr("Wearable Eject", 0, 0) putstr("Starting", 0, 5) auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth) putstr("Connect twtr.", 0, 5) me = api.me() putstr("Get profile. ", 0, 5) sapi = tweepy.streaming.Stream(auth, CustomStreamListener()) putstr("Start stream.", 0, 5) lcd.backlight(OFF) sapi.userstream()
def ondown(self): lcd.cls() lcd.centre_text(0,'RPi-Monitor') lcd.centre_text(3,'key down')
def display_main_screen(): lcd.cls() lcd.centre_text(1,actions.get_text(current))
def daemon(): client = InfluxDBClient('cms.emon.ee', 8086, 'USER', 'PASSWORD', DBNAME,timeout=30) ow.init('localhost:4304') lcd.init() logging.debug("Daemon starting") logging.debug("Create INFLUX database: " + DBNAME) errors = 0 try: client.create_database(DBNAME) except InfluxDBClientError: logging.debug("%s DB already exist" % DBNAME) pass except: logging.exception("Error") lcd.text("Exception") # try: # client.create_retention_policy('awesome_policy', '3d', 3, default=True) # except InfluxDBClientError: # logging.debug("%s policy already exist" % DBNAME) # pass while True: try: devices = ow.Sensor('/').sensorList() date = datetime.now() points=[] for o in read_dht11(): devices.append(o) devices.append(calc_power()) for sensor in devices: name = sensor.address try: value = float(sensor.value) except: value = float(ow.Sensor('/%s' % name).temperature11) desc = name json_body = { "time": date.strftime('%Y-%m-%dT%H:%M:%SZ'), "measurement": "rosma_temps", "tags": { "sensor": name, }, "fields": { "value": value } } points.append(json_body) value2lcd(date.strftime('%d/%m/%y %H:%M:%S'),name,desc,value) logging.debug(json_body) status=client.write_points(points) if status: lcd.text("Sent<-OK") logging.debug(status) else: lcd.text("Error!") logging.error(status) #Show status s=0 lcd.cls() while s<sleep: lcdstatusupdate(len(devices),s) time.sleep(1) s+=1 except: logging.exception("Error occurred %s" % sys.exc_info()[1]) lcd.text("%s Exception!" % errors) time.sleep(1) if errors == 10: lcd_blink("Rebooting!") d = threading.Thread(name='beeper', target=beeper) d.setDaemon(True) d.start() #os.system("reboot") d.join() else: errors += 1 logging.debug("Daemon exiting") return(0)
def onright(self): lcd.cls() lcd.centre_text(0,'RPi-Monitor') lcd.centre_text(3,'key right')
def __init__(self): lcd.init() lcd.backlight(1) lcd.cls()
def onenter(self): lcd.cls() lcd.centre_text(0,'RPi-Monitor') lcd.centre_text(3,'key enter')
, 834: (103.5, "SBS 러브 FM"), 835: ( 107.7, "SBS 파워 FM") , 822 :( 98.1 ,"CBS 표준 FM"), 821: ( 93.9, "CBS 음악 FM") , 823: ( 104.5, "EBS 라디오") , 820: ( 101.9, "BBS 불교방송"), 837: ( 95.1, "TBS 교통방송") # , 'MILITARY': 101.1 # , 'EASTPOLE': 106.9, 'AFN': 102.7, 'KYUNGKI': 99.9 # , 'YTNRADIO': 94.5, 'PYNGHWA': 104.5 } import json, requests import sys , time from PIL import Image,ImageDraw,ImageFont import pcd8544.lcd as lcd lcd.init() lcd.cls() # load an available True Type font font = ImageFont.truetype("/usr/share/fonts/truetype/unfonts-core/UnBatang.ttf", 14) # New b-w image #im = Image.new('1', (84,48)) # New drawable on image #draw = ImageDraw.Draw(im) tea = tea5767() global isHolding isHolding = False global old_val old_val = 0
def onup(self): lcd.cls() lcd.centre_text(0,'RPi-Monitor') lcd.centre_text(3,'key up')