def get_device(self, actual_args=None): """ Create device from command-line arguments and return it. """ if actual_args is None: actual_args = sys.argv[1:] # actual_args = ['--display', 'ssd1306', '--width', '128', # '--height', '64', '--i2c-port', '1', '--i2c-address', '0x3c'] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) print(self.display_settings(args)) # create device # display ssd1306 --width 128 --height 64 --i2c-port 1 --i2c-address 0x3c try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) return device
def parse_args(): actual_args = sys.argv[1:] parser = cmdline.create_parser(description="Display text on display.") parser.add_argument("--text", type=str, default="Text on the screen!", help="Text to display on screen.") args = parser.parse_args() if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) print(args) print(display_settings(args)) print('-' * 60) try: args.device = cmdline.create_device(args) except error.Error as e: parser.error(e) return args
def get_device(actual_args=None): """ Create device from command-line arguments and return it. """ if actual_args is None: actual_args = sys.argv[1:] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) print("FOTOMETRIA POR EMISSAO POR CAPTURA DE IMAGENS FIRMWARE VER 1.0.7") print("Analises dos elementos por processamento de imagem") print("Elementos de analises") print("Sodio (Na), Calcio (C), Potassio (K) e Litio (Li)") print("Aguarde, iniciando ......") # create device try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) return device
def __init__(self, display, font_size=16): self.display = display resource_package = __name__ resource_path = '' static_path = pkg_resources.resource_filename(resource_package, resource_path) self.font_size = font_size self.font_size_px = int(font_size * 1.33333333) self.font = ImageFont.truetype('%s/font/FreeSans.ttf' % static_path, self.font_size) self.fith_logo = self.load_image('%s/font/FITH_Logo.jpg' % static_path) self.lock = "\ua5c3" try: parser = cmdline.create_parser( description='FITHINATOR display args') conf = cmdline.load_config('%s/conf/%s.conf' % (static_path, display)) args = parser.parse_args(conf) except FileNotFoundError: conf = ['--display=%s' % display] args = parser.parse_args(conf) try: self.device = cmdline.create_device(args) except error.Error as e: parser.error(e) self.device = None self.max_char = int(self.device.width // self.textsize("A")[0])
def get_device(actual_args=None): """ Create device from command-line arguments and return it. """ if actual_args is None: actual_args = sys.argv[1:] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) args # create device try: args.width = 128 args.height = 128 args.display = 'sh1106' args.rotate = 2 device = cmdline.create_device(args) print(display_settings(device, args)) return device except error.Error as e: parser.error(e) return None
def __init__(self, hoplite, display): self.display = display self.h = hoplite self.debug = self.h.debug resource_package = __name__ resource_path = '' static_path = pkg_resources.resource_filename(resource_package, resource_path) self.font = ImageFont.truetype('%s/font/OpenSans-Regular.ttf' % static_path, 16) if self.display == None: utils.debug_msg(self, "Display not found, using default of st7735") self.display = 'st7735' try: parser = cmdline.create_parser(description='HOPLITE display args') conf = cmdline.load_config('%s/conf/%s.conf' % (static_path, display)) args = parser.parse_args(conf) except FileNotFoundError: conf = ['--display=%s' % display] args = parser.parse_args(conf) try: self.device = cmdline.create_device(args) except error.Error as e: parser.error(e) self.device = None
def get_args(): actual_args = sys.argv[1:] parser = create_parser() args = parser.parse_args(actual_args) if args.config: config = load_config(args.config) args = parser.parse_args(config + actual_args) return args
def test_load_config_file_parse(): """ :py:func:`luma.core.cmdline.load_config` parses a text file and returns a list of arguments. """ result = cmdline.load_config(test_config_file) assert result == [ '--display=capture', '--width=800', '--height=8600', '--spi-bus-speed=16000000' ]
def get_device(actual_args=None): """ Create device from command-line arguments and return it. """ logging.debug("Entering the get_device routine for checking for a display") global device_type device_type = "NEO" # we start assuming a NEO global port port = 0 #we start assuming a NEO globals.screen_enable[3] = 0 #assuming neo we only have one battery parser = cmdline.create_parser(description='luma.examples arguments') with open("/proc/cpuinfo", encoding='utf8') as f: filx = f.read() if ("Raspberry" in filx): if ("Compute Module" in filx): port = 10 device_type = "CM" globals.screen_enable[3] = 1 #we assume multi-battery else: #all other Raspberry Pi version other than compute modules port = 1 device_type = "PI" else: globals.screen_enable[ 3] = 0 #Just make sure that we have only one battery for NEO f.close() # for NEO we use i2c-port 0. For Pi's other than compute modules we use i2c-port 1 or 10 for CM logging.info("get device has determined were on i2c port# " + str(port)) args = parser.parse_args(['--i2c-port', str(port)]) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) # create device # logging.info("now we will try to connect to the display "+str(args)) try: device = cmdline.create_device(args) except error.Error as e: logging.info('no display device found') device = None return device
def get_device(deviceName): from luma.core import cmdline, error """ Create device from command-line arguments and return it. """ actual_args = ['-d', deviceName] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) # create device try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) return device
def get_device(actual_args=None): actual_args = ['-d', 'sh1106', '-i', 'spi', '--width', '128', '--height', '64'] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) #print(display_settings(args)) # create device try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) return device
def get_device(actual_args=None): """ Create device from command-line arguments and return it. """ actual_args = ['--interface', 'spi', '--d', 'ssd1306'] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) # create device try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) return device
def main() -> None: logging.basicConfig(level=logging.INFO, format="%(message)s") logging.getLogger("PIL").setLevel(logging.ERROR) parser = cmdline.create_parser( description="Display FQDN and IP on the OLED") parser.add_argument("--font", default="/usr/share/fonts/TTF/ProggySquare.ttf", help="Font path") parser.add_argument("--font-size", default=16, type=int, help="Font size") parser.add_argument("--interval", default=5, type=int, help="Screens interval") options = parser.parse_args(sys.argv[1:]) if options.config: config = cmdline.load_config(options.config) options = parser.parse_args(config + sys.argv[1:]) device = cmdline.create_device(options) font = ImageFont.truetype(options.font, options.font_size) display_types = cmdline.get_display_types() if options.display not in cmdline.get_display_types()["emulator"]: _logger.info("Iface: %s", options.interface) _logger.info("Display: %s", options.display) _logger.info("Size: %dx%d", device.width, device.height) try: summary = True while True: with canvas(device) as draw: if summary: text = f"{socket.getfqdn()}\nUp: {_get_uptime()}" else: text = f"Iface: %s\n%s" % (_get_ip()) draw.multiline_text((0, 0), text, font=font, fill="white") summary = (not summary) time.sleep(options.interval) except (SystemExit, KeyboardInterrupt): pass
def getDevice(self, actual_args=None): """ Create device from command-line arguments and return it. """ if actual_args is None: actual_args = sys.argv[1:] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) # create device try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) return device
def get_device(actual_args=None): if actual_args is None: actual_args = sys.argv[1:] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) print(display_settings(args)) # create device try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) return device
def get_device(actual_args=["-i", "spi", "--display", "sh1106"]): """ Create device from command-line arguments and return it. """ if actual_args is None: actual_args = sys.argv[1:] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) if args.config: # load config from file config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) print(display_settings(args)) # create device try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) return device
display = data['oledDisplay']['value'] model = data['model']['value'] except: display = '1' model = 'DAC' try: if display == '2': device = ssd1306(port=1, address=0x3C) isScroll = False isColour = False elif display == '3': actual_args = ['-f', '/home/volumio/nanosound_oled/ssd1351.conf'] parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(actual_args) config = cmdline.load_config(args.config) args = parser.parse_args(config + actual_args) device = cmdline.create_device(args) isColour = True elif display == 'N': isColour = False hasOLED = False else: device = sh1106(port=1, address=0x3C) isScroll = False isColour = False hasOLED = True except: hasOLED = False
if lib_name is not None: lib_version = cmdline.get_library_version(lib_name) else: lib_name = lib_version = 'unknown' import luma.core version = 'luma.{} {} (luma.core {})'.format(lib_name, lib_version, luma.core.__version__) return 'Version: {}\nDisplay: {}\n{}Dimensions: {} x {}\n{}'.format( version, args.display, iface, args.width, args.height, '-' * 60) #read in config file and setup device parser = cmdline.create_parser(description=None) conf = cmdline.load_config("./lcd.conf") args = parser.parse_args(conf) print(print(display_settings(args))) print("testing") try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) def posn(angle, arm_length): dx = int(math.cos(math.radians(angle)) * arm_length) dy = int(math.sin(math.radians(angle)) * arm_length) return (dx, dy)
def main() -> None: logging.basicConfig(level=logging.INFO, format="%(message)s") logging.getLogger("PIL").setLevel(logging.ERROR) parser = cmdline.create_parser( description="Display FQDN and IP on the OLED") parser.add_argument("--font", default="/usr/share/fonts/TTF/ProggySquare.ttf", help="Font path") ### srepac change - to make it fit into 3 lines on small oled or 5 lines on big oled -- each row limited to 19 chars parser.add_argument("--font-size", default=15, type=int, help="Font size") parser.add_argument("--interval", default=5, type=int, help="Screens interval") options = parser.parse_args(sys.argv[1:]) if options.config: config = cmdline.load_config(options.config) options = parser.parse_args(config + sys.argv[1:]) device = cmdline.create_device(options) font = ImageFont.truetype(options.font, options.font_size) display_types = cmdline.get_display_types() if options.display not in cmdline.get_display_types()["emulator"]: _logger.info("Iface: %s", options.interface) _logger.info("Display: %s", options.display) _logger.info("Size: %dx%d", device.width, device.height) try: ### srepac changes to show during service start up with canvas(device) as draw: text = f"kvmd-oled.64\nby srepac\n\nInitializing...\n" draw.multiline_text((0, 0), text, font=font, fill="white", align="center") screen = 0 ### while True: with canvas(device) as draw: ### srepac changes to have different screens using modulo division (up to 5 lines per screen) rem = screen % 3 if rem == 0: ### first page is fqdn, model number, image (v2-hdmi, v2-hdmiusb, etc...) + kvmd ver, and date x = os.popen(" date +\"%D %H:%M %Z\" ") date = x.read().replace('\n', '') x = os.popen( " pistat | grep Pi | awk '{print $4, $5, $6, $7, $8, $9}' | sed -e 's/ Model //g' -e 's/ / /g'" ) model = x.read().replace('\n', '') x = os.popen( " pacman -Q | grep kvmd-platform | cut -d'-' -f3,4 ") img = x.read().replace('\n', '') x = os.popen( " pacman -Q | grep kvmd' ' | awk '{print $NF}' | sed 's/-[1-9]//g' " ) kvmdver = x.read().replace('\n', '') x = os.popen( " free -m | grep Mem: | awk '{print \"RAM:\", $3 \"/\" $2 \" MB\"}' " ) ram = x.read().replace('\n', '') #x = os.popen(" pacman -Q | grep ustreamer | awk '{print $NF}' | sed 's/-[1-9]//g' ") #ustreamer = x.read().replace('\n', '') # ALTERNATE screen which includes ustreamer version #text = f"{socket.getfqdn()}\nPi {model}\n{img} v{kvmdver}\nustreamer v{ustreamer}\n{date}" text = f"{socket.getfqdn()}\nPi {model}\n{img} v{kvmdver}\n{ram}\n{date}" elif rem == 1: ### 2nd page shows both eth/wlan IP, SSID, and cpu/gpu temps x = os.popen(" pistat | grep temp | cut -d' ' -f 3 ") temps = x.read().replace('\n', ' ') connstatus = os.popen( " count=0; ethip=$( ip -o a show | grep -v inet6 | awk '{print $2, $4}' | cut -d'/' -f1 | egrep 'eth|br' ); ssid=$( netctl-auto list | grep '*' | awk -F\- '{print $NF}' ) ; if [[ \"$ethip\" != \"\" ]]; then printf \"%s %s\n\" $ethip; count+=1; else echo \"LAN not connected\"; fi; if [[ \"$ssid\" == \"\" ]]; then echo \"Wifi not connected\" ; else echo \"SSID $ssid\"; count+=1; fi ; if [[ $count -gt 0 ]]; then printf \"%s %s\n\" $( ip -o a show | grep -v inet6 | awk '{print $2, $4}' | cut -d'/' -f1 | egrep 'tailscale|wlan' | sed 's/tailscale/ts/g' ); fi " ) text = f"Temp {temps}\n{connstatus.read()}" else: ### last page shows uptime, load avgs, and sd card usage % and free space x = os.popen( " for i in `mount | grep mmc | awk '{print $1}' | sort | grep -v p1`; do echo -n `df -h $i | grep -v Filesystem | sort | awk '{print $1, $5, $4}' | sed -e 's+/dev/mmcblk0++g' -e 's+p3+msd+' -e 's+p2+/+' -e 's+p1+/boot+'`' '; mount | grep $i | awk '{print $NF}' | awk -F, '{print $1}' | sed 's/(//g'; done " ) sdcard = x.read() load1, load5, load15 = os.getloadavg() x = os.popen( " num=$( uptime | awk -F'user' '{print $1}' | awk '{print $NF}' ); if [[ $num -gt 1 || $num -eq 0 ]]; then echo $num users; else echo $num user; fi " ) users = x.read().replace('\n', '') text = f"{_get_uptime()}, {users}\n{load1}, {load5}, {load15}\n---storage---\n{sdcard}" screen += 1 draw.multiline_text((0, 0), text, font=font, fill="white") time.sleep(options.interval) except (SystemExit, KeyboardInterrupt): pass