class Screen: def __init__(self, rotation=0): self.text = PapirusTextPos(False, rotation=rotation) self.text.AddText("", x=0, y=5, size=36, Id="title", font_path=sans_font) self.text.AddText("", x=7, y=55, size=16, Id="body", font_path=sans_font) self.text.AddText("", x=7, y=75, size=16, Id="footer", font_path=sans_font) def update_header(self, text): self.text.UpdateText("title", text, font_path=sans_font) def update_body(self, text): self.text.UpdateText("body", text, font_path=bold_sans_font) def update_footer(self, text): self.text.UpdateText("footer", text, font_path=bold_sans_font) def write(self): self.text.WriteAll() def clear(self): self.text.Clear()
def main(): # TODO: load config from somewhere - config.py? Path from environment variable? # TODO: concept of ... pages? tabs? that are loaded in and registered. # TODO: instead of trying to use the tiny buttons on the papirus, is there # like a row of 5 keyboard keys? maybe nice cherry switches. # TODO: Parameterize lat/long in config; this is Ann Arbor, MI. latitude = 42.22 longitude = -83.74 timezone = tzlocal() rotation = 180 text = PapirusTextPos(autoUpdate=False, rotation=rotation) # TODO: Bitmap support requires using PapirusComposite instead of # PapirusTextPos. text.AddText("Today is", 0, 0, size=17, Id="date") text.AddText("Startup...", 93, 20, size=19, Id="startup") text.AddText("\u2600rise:", 0, 35, size=23, Id="sunrise_label") text.AddText("\u2600set:", 0, 57, size=23, Id="sunset_label") text.AddText("", 87, 35, size=23, Id="sunrise") text.AddText("", 87, 57, size=23, Id="sunset") text.AddText("Temp", 0, 80, size=14, Id="temp") text.WriteAll() text.RemoveText("startup") first_display = True while True: today = datetime.date.today() # TODO: Accommodate lack of sunrise/sunset like as far north as # Utqiaġvik - the city formerly known as Barrow, Alaska. # get_sunrise_sunset() returns those as None. sunrise_time, sunset_time = get_sunrise_sunset(latitude, longitude, today, timezone) text.UpdateText("date", "Today is {}".format(today.strftime("%A, %Y-%m-%d"))) text.UpdateText("sunrise", sunrise_time.strftime("%I:%M %p")) text.UpdateText("sunset", sunset_time.strftime("%I:%M %p")) # For testing the longest English day name. #text.UpdateText("date", "Today is {}".format(today.strftime("Wednesday, %Y-%m-%d"))) text.UpdateText( "temp", "Temp {}".format(get_temperature_forecast(latitude, longitude))) # Do a partial update on startup, and a full update each following hour. text.WriteAll(first_display) first_display = False # Wait until the next hour. now = datetime.datetime.now() next_hour = (now + datetime.timedelta(hours=1)).replace(microsecond=0, second=0, minute=0) wait_seconds = (next_hour - now).total_seconds() print("waiting {} seconds until next hour".format(wait_seconds)) time.sleep(wait_seconds)
vert_spacing * 4, font_size, Id="VPN", invert=inv) else: tunnel_went_down = True disp_text = "VPN is down - INSECURE" text.RemoveText("VPN") text.AddText(disp_text, 0, vert_spacing * 4, font_size, Id="VPN", invert=inv) if console_display: print(disp_text) text.UpdateText("VPN", disp_text) if have_inet and tunnel_went_down: disp_text = "Please update VPN config" if console_display: print(disp_text) text.RemoveText("date") text.AddText(disp_text, 0, vert_spacing * 5, font_size, Id="date", invert=inv) else: cur_time = datetime.now() disp_text = cur_time.strftime('%Y/%m/%d %I:%M:%S') if console_display: print(disp_text) text.RemoveText("date")
print list except TwythonError as e: print e print 'now my code continues' text.AddText("now my code continues", 0, 0, Id="Start") #this section tweets by randomly selecting id strings from the list, cleaning them update #(for somwe reason they are added to the list with some extra character) and retweets them #then removes them from the list countdown = TWEETNUM while (countdown <> 0): print 'The count is:', countdown try: toTweet = list[random.randint(0, len(list)) - 1] list.remove(toTweet) toTweet[2:19] print toTweet text.AddText("count", 0, 40, Id="Second") text.UpdateText("Second", "tweeting %s of %d" % (countdown, TWEETNUM)) twitter.retweet(id=toTweet) countdown = countdown - 1 sleep(randint(300, 600)) except TwythonError as e: print e text.Clear() print "all done" text.AddText("finished", 10, 35, Id="third")
text.AddText("", 0, 20, Id="2") text.AddText("", 0, 40, Id="3") text.AddText("", 0, 60, Id="4") text.WriteAll() waiting = True while True: gps.update() # Every 10 seconds print out current location details if there's a fix. current = time.monotonic() if (current - last_print >= 10.0): last_print = current if not gps.has_fix: # Try again if we don't have a fix yet. print("Waiting for fix...") if waiting is False: text.UpdateText("1", "Waiting") text.UpdateText("2", "") text.UpdateText("3", "") text.UpdateText("4", "") text.WriteAll() waiting = True continue text.UpdateText("1", "{:02}:{:02}:{:02}".format(gps.timestamp_utc.tm_hour, gps.timestamp_utc.tm_min, gps.timestamp_utc.tm_sec)) waiting = False # We have a fix! (gps.has_fix is true) # Print out details about the fix like location, date, etc. print("=" * 40) # Print a separator line. print( "Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format( gps.timestamp_utc.tm_mon, # Grab parts of the time from the gps.timestamp_utc.tm_mday, # struct_time object that holds
weekday = date.today() day_Name = date.strftime(weekday, '%A') day_month_year = date.strftime(weekday, '%Y %b %-d') weekday2 = datetime.date.today() + datetime.timedelta(days=1) day2 = date.strftime(weekday2, '%A') try: screen.clear() print("Summary: "+currentCondFormatted+"\nTemperture: "+temp+" ") text.AddText((day_Name) + ' ' + (day_month_year), 0, 0, 18, Id="Line1", fontPath='/home/pi/weather-pi-data/fonts/Roboto-Black.ttf') text.AddText((temp) + ' ' + (humidity) + '\n' + (tempsToday), 0, 19, 14, Id="Line2", fontPath='/home/pi/weather-pi-data/fonts/Roboto-Bold.ttf') text.AddText((daily_conditions) + '\n' + (day2) + ' - ' + (tempsTomorrow) + ' ' + (summary2), 0, 53, 10, Id="Lin3", fontPath='/home/pi/weather-pi-data/fonts/ElecSign.ttf') except: text.UpdateText("Line1", "Connection Error!") try: while True: display() sleep(300) # 5 minutes text.Clear() except (KeyboardInterrupt, SystemExit): text.RemoveText("Line2") text.RemoveText("Line3") screen.clear() text.UpdateText("Line1", "Exiting...\nGoodbye!") sleep(2) screen.clear() os._exit(1)
def main(argv): global SIZE GPIO.setmode(GPIO.BCM) GPIO.setup(SW1, GPIO.IN) GPIO.setup(SW2, GPIO.IN) GPIO.setup(SW3, GPIO.IN) GPIO.setup(SW4, GPIO.IN) if SW5 != -1: GPIO.setup(SW5, GPIO.IN) papirus = PapirusTextPos(False, rotation=int(argv[0]) if len(sys.argv) > 1 else 0) cdrom = '' i = 0 files = [] papirus.AddText('USB Gadget ISO Loader\n\nREDRAW CDROM UP DOWN SELECT', 0, 0, Id='browser', size=12) papirus.AddText('Status Unknown', 0, 55, Id='status', size=20) papirus.AddText('', 160, 55, Id='cdrom', size=12) papirus.AddText('Please select a disk.', 0, 80, Id='selected', size=12) papirus.WriteAll() while True: press = False if GPIO.input(SW5) == False: papirus.WriteAll() if GPIO.input(SW4) == False: if not cdrom: cdrom = ' cdrom=y' papirus.UpdateText('cdrom', 'cdrom') else: cdrom = '' papirus.UpdateText('cdrom', '') press = True if GPIO.input(UP) == False: press = True i = i - 1 if GPIO.input(DOWN) == False: press = True i = i + 1 if GPIO.input(SELECT) == False: os.system('rmmod g_mass_storage') status = os.system('modprobe g_mass_storage file="%s" stall=0 %s' % ('/'.join((iso_dir, file)), cdrom)) papirus.UpdateText('selected', file) if cdrom: type = 'CDROM ' else: type = 'DISK ' cdrom = '' papirus.UpdateText('cdrom', '') if (status == 0): papirus.UpdateText('status', type + 'OK') else: papirus.UpdateText('status', type + 'Fail!') papirus.WriteAll(True) if press is False: sleep(0.1) continue try: file = files[i] except IndexError: files = natural_sort(os.listdir(iso_dir)) if (i > 0): i = 0 else: i = -1 if not files: papirus.UpdateText('browser', 'No files found') file = files[i] papirus.UpdateText( 'browser', '%s\n%s\n%s\n%s' % (safe_index(files, i), safe_index(files, i + 1), safe_index(files, i + 2), safe_index(files, i + 3))) papirus.WriteAll(True) sleep(0.1)
GPIO.setup(switch, GPIO.IN) GPIO.add_event_detect(switch, GPIO.FALLING, callback=buttonPressed) #start the other threads bat_thread = batlife() weather_thread = weather() phone_thread = phone() refresh_thread = refreshScreen() time_thread = updateTime() bat_thread.start() weather_thread.start() phone_thread.start() refresh_thread.start() time_thread.start() fonaLock.acquire() #setup the fona. Make sure it is working fona.write(b'AT\n') fona.readline() #read the cmd I just sent result = fona.readline().strip( ) #read the result and strip the nonprinting characters fonaLock.release() print(result) if (not result == "OK"): sys.exit() while (True): msg = raw_input('Enter message:') lasttxt = msg papi.UpdateText("result", msg) papi.papirus.display(papi.image) papi.papirus.partial_update()
class papirus_cont(object): def __init__(self): self.papi = PapirusTextPos(False) self.papi.Clear() self.papi.AddText("DATE:", 0, 0, Id="datetext") self.papi.AddText("00-00 00:00", 60, 0, Id="date-time") self.papi.AddText("TEMP:", 0, 20, Id="temptext") self.papi.AddText("00.000", 60, 20, Id="temp") self.papi.AddText("HUME:", 0, 40, Id="humtext") self.papi.AddText("00.000", 60, 40, Id="hum") self.papi.AddText("PRES:", 0, 60, Id="presstxt") self.papi.AddText("0000", 60, 60, Id="press") self.papi.AddText("Initializing", 0, 80, Id="ip") self.papi.WriteAll() def set_new_datetime(self): self.now_time = datetime.now() self.papi.UpdateText("date-time", (self.now_time.strftime('%m-%d %H:%M'))) def set_temp(self, temp): self.papi.UpdateText("temp", "{0:.3f}".format(temp) + "[deg]") def set_hum(self, hum): self.papi.UpdateText("hum", "{0:.3f}".format(hum) + "[%]") def set_press(self, press): self.papi.UpdateText("press", "{0:.1f}".format(press) + "[hpa]") def set_ipaddress(self): self.ip = "0.0.0.0" try: #socket.AF_INET:IVv4のアドレス, socket.SOCK_DGRAM:UDPネットワークの #IPv6の場合はAF_INET→IF_INET6 self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #タイムアウトを10秒 self.s.settimeout(10) #ipアドレス8.8.8.8:80に接続します。 # 8.8.8.8はgoogle Public DNSPCのIP。 # 外のアドレスなら何でもいいです。 self.s.connect(("8.8.8.8", 80)) #今の接続のソケット名を取得します。 self.ip = self.s.getsockname()[0] #IPアドレス表示 #print(self.ip) except socket.error: #ネットワークがエラーだったり無かったら self.ip = 'No Internet' #print('No Internet') #print(type(self.ip)) self.papi.UpdateText("ip", self.ip) def get_network_state(self): return self.ip def update(self): self.papi.WriteAll()
#!/usr/bin/env python from papirus import PapirusTextPos papi = PapirusTextPos() papi.AddText("00-00 00:00", 0, 0, Id="date-time") papi.AddText("00.000", 0, 20, Id="temp") #papi.Add papi.UpdateText("Start", "New Text")
# Initial Screen Draw status = server.status() text = PapirusTextPos() text.AddText("= OtterCraft =", 5, 10, Id="Title") text.AddText(str(status.latency) + "ms", 5, 32, Id="Ping") text.AddText(str(status.players.online) + " players", 5, 54, Id="Count") print("Initial Query + Screen Drawing Complete!") loopStat = True loopCount = 1 failedCount = 0 while loopStat: try: # Board Stat Updates status = server.status() text.UpdateText("Ping", str(status.latency) + "ms") text.UpdateText("Count", str(status.players.online) + " players") print("=================") print("Ping = " + str(status.latency)) print("Players = " + str(status.players.online)) print("Loop Count: " + str(loopCount)) print("Failed Loop Count: " + str(failedCount)) print("=================") loopCount = loopCount + 1 sleep(timer) except: # Failed! failedCount = failedCount + 1 text.UpdateText("Ping", str(0) + "ms") text.UpdateText("Count", "FAILED" + " players") print("=================")