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()
#!/usr/bin/env python3 from netifaces import interfaces, ifaddresses, AF_INET from papirus import PapirusTextPos from datetime import datetime import subprocess import socket import re import time console_display = False inv = False text = PapirusTextPos(False, 0) text.Clear() text.autoUpdate = False text.partialUpdates = True font_size = 15 vert_spacing = font_size + 1 cur_time = datetime.now() text_time = cur_time.strftime('%Y/%m/%d %I:%M:%S') disp_text = "web - http://secure.pi" if console_display: print(disp_text) text.AddText(disp_text, 0, vert_spacing * 0, font_size, Id="web") disp_text = "wifi- " if console_display: print(disp_text) text.AddText(disp_text, 0, vert_spacing * 1, font_size, Id="wifi") disp_text = "wlan- " if console_display: print(disp_text) text.AddText(disp_text, 0, vert_spacing * 2, font_size, Id="wlan0") disp_text = "wan - " if console_display: print(disp_text) text.AddText(disp_text, 0, vert_spacing * 3, font_size, Id="Pub") disp_text = "VPN is "
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()
GPIO.setup(button2, GPIO.IN) GPIO.setup(button3, GPIO.IN) GPIO.setup(button4, GPIO.IN) menu = 0 size1 = 11 size2 = 17 dir_path = os.path.dirname(os.path.realpath(__file__)) int_ip = get_lan_ip() myip = ipgetter.myip() screen = PapirusTextPos(False) screen.AddText("Starting Appliance", 20, 70, size2, FONT_FILE) screen.WriteAll() ext_ip = 'External: ' + myip int_ip = 'Internal: ' + int_ip speed_test_log = dir_path + '/speedtest.txt' screen.Clear() graph_code = dir_path + '/ImageDemo.py temp.png' speed_test_code = dir_path + '/speedtest.sh' show_menu() try: while True: #Primary Menu Options if (menu == 0 and GPIO.input(button1) == False): speed_test() menu = 1 if (menu == 0 and GPIO.input(button2) == False): graph_it() menu = 1 if (menu == 0 and GPIO.input(button3) == False): scan4it() menu = 1
def main(): logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') ch.setFormatter(formatter) logger.addHandler(ch) if os.path.exists(r"/home/mikey/logs/watch.log"): fh = logging.FileHandler(filename=r"/home/mikey/logs/watch.log") fh.setLevel(logging.DEBUG) fh.setFormatter(formatter) logger.addHandler(fh) my_511_token = sys.argv[1] # giving time for device service to startup, which is needed before init of Papirus time.sleep(20) try: global key # Running as root only needed for older Raspbians without /dev/gpiomem if not (os.path.exists('/dev/gpiomem') and os.access('/dev/gpiomem', os.R_OK | os.W_OK)): user = os.getuid() if user != 0: print('Please run script as root') sys.exit() shutdown_button = Button(SW1, pull_up=False) north_transit_button = Button(SW2, pull_up=False) south_transit_button = Button(SW3, pull_up=False) weather_button = Button(SW4, pull_up=False) button5 = Button(SW5, pull_up=False) font_path = "/home/mikey/nasalization-rg.ttf" text_size = 60 text = PapirusTextPos(rotation=0) text.Clear() old_time = datetime.datetime.now().strftime("%H:%M") text.AddText(old_time, size=text_size, fontPath=font_path) logger.info("Entering watch loop") while True: # Define button press action (Note: inverted logic w.r.t. gpiozero) shutdown_button.when_released = setkey north_transit_button.when_released = setkey south_transit_button.when_released = setkey weather_button.when_released = setkey button5.when_released = setkey # check key key = getkey() if key == 'none': new_time = datetime.datetime.now().strftime("%H:%M") if old_time == new_time: time.sleep(1) continue text.Clear() text.AddText(new_time, size=text_size, fontPath=font_path) old_time = new_time time.sleep(.3) elif key == "shutdown": logger.info("shutting down") text.Clear() text.AddText("Bye :)", size=text_size, fontPath=font_path) time.sleep(2) shutdown_path = __file__.split("/")[:-1] shutdown_path = "/".join(shutdown_path) # if started script manually, from the scripts directory, will see blank path to file if shutdown_path == "": shutdown_path = "." subprocess.Popen( ['sudo', '{}/shutdown.sh'.format(shutdown_path)]) sys.exit() elif key == "n_transit": logger.info("getting n_transit") n_transit = get_northbound_arrivals(my_511_token=my_511_token) display_arivals(text, n_transit, logger, font_path) key = 'none' old_time = "fake time" elif key == "s_transit": logger.info("getting s_transit") s_transit = get_southbound_arrivals(my_511_token) display_arivals(text, s_transit, logger, font_path) key = 'none' old_time = "fake time" elif key == "weather": logger.info("getting weather") weather = get_sf_weather() text.Clear() text.AddText(weather, size=15, fontPath=font_path) time.sleep(7) key = 'none' old_time = "fake time" elif key == "button5": logger.info("button 5 pressed") key = 'none' except KeyboardInterrupt as e: logger.exception("keyboard interupt caught", exc_info=e) except Exception as e: logger.info("exception occured") logger.exception("Exception occured", exc_info=e)
import PrintScreen as PS import Services as SV Units = "°K" STOP = False SLEEP = False BearerAUTH = "" conf = configparser.ConfigParser() conf.read("config.cfg") if os.path.exists('/etc/default/epd-fuse'): from papirus import PapirusTextPos TextPAPIRUS = PapirusTextPos(False) TextPAPIRUS.Clear() def Main(): #Fonction Coeur try: if conf["TWITTER"]["TwitterAPI"] != "" and conf["TWITTER"]["twitterapisecret"] != "": global BearerAUTH BearerRAW = os.popen("curl -u '"+ conf["TWITTER"]["TwitterAPI"] + ":" + conf["TWITTER"]["TwitterAPISecret"] + "' --data 'grant_type=client_credentials' 'https://api.twitter.com/oauth2/token'").read() BearerJSON = json.loads(BearerRAW) BearerAUTH = BearerJSON["access_token"] while True: global STOP #global SLEEP #if SLEEP: #GUI ONLY #je dors #while SLEEP: #if STOP: