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 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 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 createDevice(self, type='luma', chip='ssd1331', width='96', height='64', bus='spi', portNo='0', bgcolor="black", reset_pin='25', rotate_screen='2'): self.resolutionX = width self.resolutionY = height self.type = type self.chip = chip self.bus = bus self.portNumber = portNo if type == 'luma': try: args = ('-d' + chip, '--width=' + width, '--height=' + height, '-i' + bus, '--spi-device= ' + portNo, '--gpio-reset=' + reset_pin, '--rotate=' + self.rotate_conversion[rotate_screen]) parser = cmdline.create_parser( description='luma.examples arguments') args1 = parser.parse_args(args) self.device = cmdline.create_device(args1) self.image = ImageDraw.Draw self.background = Image.new("RGBA", self.device.size, "Black") return 0 except error.Error as e: return e
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) 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 get_device(self): parser = cmdline.create_parser(description='luma.examples arguments') #config = cmdline.load_config(args.config) config = [] config.append("--display=st7735") config.append("--interface=spi") config.append("--spi-bus-speed=16000000") config.append("--gpio-reset=24") config.append("--gpio-data-command=23") config.append("--gpio-backlight=18") config.append("--width=128") config.append("--height=128") config.append("--bgr") config.append("--h-offset=1") config.append("--v-offset=2") config.append("--backlight-active=high") config.append("--rotate=3") args = parser.parse_args(config) try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) return device
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 load_device(self): self.close() parser = cmdline.create_parser(description='default') args = parser.parse_args([]) try: self.device = cmdline.create_device(args) except error.Error as e: print('ERROR: ', parser.error(e))
def __init__(self, config): self.mode = None self.uis = {} self.cur_ui = None parser = cmdline.create_parser('') device_args = parser.parse_args(config['lcd_config'].split(' ')) try: lcd = cmdline.create_device(device_args) except error.Error as e: parser.error(e) for ui_type, ui_cls in self.__ui_types.iteritems(): self.uis[ui_type] = ui_cls(lcd, device_args, config)
def get_device(): """ Create device from command-line arguments and return it. """ parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args("") args.display = Driver 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(): parser = cmdline.create_parser(description='smartchime.luma') lumaConfig = [] for key, value in config['luma'].items(): lumaConfig.append(f"--{key}={value}") args = parser.parse_args(lumaConfig) # create device try: device = cmdline.create_device(args) return device except error.Error as e: parser.error(e) return None
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 __init__(self, title, menuItems, selected): self.titleFont = ImageFont.truetype("FreeSans.ttf", 14) self.unselectedFont = ImageFont.truetype("Piboto-Regular.ttf", 10) self.selectedFont = ImageFont.truetype("FreeSansBold.ttf", 20) self.title = title self.menuItems = menuItems self.selected = selected # Config config = Config() displayDef = config.get("display.config", MenuDisplay.defaultDisplayConfig) config.save() # create device parser = cmdline.create_parser(description='luma arguments') displayArgs = parser.parse_args(displayDef) try: self.device = cmdline.create_device(displayArgs) except error.Error as e: parser.error(e)
def test_create_parser(): """ :py:func:`luma.core.cmdline.create_parser` returns an argument parser instance. """ with patch.dict('sys.modules', **{ 'luma.emulator': Mock(), 'luma.emulator.render': Mock(), }): with patch('luma.core.cmdline.get_display_types') as mocka: mocka.return_value = { 'foo': ['a', 'b'], 'bar': ['c', 'd'], 'emulator': ['e', 'f'] } parser = cmdline.create_parser(description='test') args = parser.parse_args(['-f', test_config_file]) assert args.config == test_config_file
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(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(): """ Create device from command-line arguments and return it. """ config = load_config(EYES_LCD_CONFIG_FILE) parser = cmdline.create_parser(description='luma.examples arguments') args = parser.parse_args(config) # create device try: device = cmdline.create_device(args) except error.Error as e: parser.error(e) print(display_settings(args)) return device
def get_device(): # create parser parser = cmdline.create_parser(description='luma.examples arguments') # create arguments actual_args = [ '-d', 'pygame', '-i', 'spi', '--width', '128', '--height', '128' ] # parse arguments args = parser.parse_args(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): """ 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 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 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=["-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
def __init__(self): parser = cmdline.create_parser( description='') #description='luma.examples arguments' args = parser.parse_args([]) self.__mStateDeclarator = settings_store_client.StateDeclarator() # fc-list | grep Vera self.__mFontName = {} self.__mFontName[(True, True)] = "VeraBI.ttf" self.__mFontName[(True, False)] = "VeraBd.ttf" self.__mFontName[(False, True)] = "VeraIt.ttf" self.__mFontName[(False, False)] = "Vera.ttf" self.__mDevice = None # create device try: self.__mDevice = cmdline.create_device(args) self.__mDevice.clear() #create buffer self.__mBuffer = Image.new("RGB", self.__mDevice.size) self.__mBufferTmp = Image.new("RGB", self.__mDevice.size) self.__mHasPendingChanges = True self.__mPreviousBrightness = -1 rospy.Subscriber('/oled_display/draw_rect', grading_machine.msg.DisplayDrawRect, self.__onDrawRect) rospy.Subscriber('/oled_display/draw_text', grading_machine.msg.DisplayDrawText, self.__onDrawText) self.__mStateDeclarator.setState('i2c_display', 'ok') except: self.__mDevice = None rospy.logerr('Fail to initialize i2c oled display') self.__mStateDeclarator.setState('i2c_display', 'error')
def __get_device__(self): try: parser = cmdline.create_parser( description='luma.examples arguments') config = [] if True: config.append("--display=ssd1351") config.append("--interface=spi") config.append("--width=128") config.append("--height=128") config.append("--spi-bus-speed=16000000") config.append("--rotate=0") else: config.append("--display=st7735") config.append("--interface=spi") config.append("--spi-bus-speed=16000000") config.append("--gpio-reset=24") config.append("--gpio-data-command=23") config.append("--gpio-backlight=18") config.append("--width=128") config.append("--height=128") config.append("--bgr") config.append("--h-offset=1") config.append("--v-offset=2") config.append("--backlight-active=high") config.append("--rotate=0") args = parser.parse_args(config) print "parse complete" device = cmdline.create_device(args) print "device created" except error.Error as e: parser.error(e) return device
else: # crosses midnight return check_time >= Args.InactiveHours[ 0] or check_time <= Args.InactiveHours[1] # Checks that the user has allowed outputting to console. def print_safe(msg): if not Args.NoConsole: print(msg) ### ## Main ## Connects to the display and makes it update forever until ended by the user with a ctrl-c ### DisplayParser = cmdline.create_parser( description='Dynamically connect to either a vritual or physical display.') device = cmdline.create_device( DisplayParser.parse_args([ '--display', str(Args.Display), '--interface', 'spi', '--width', '256', '--rotate', str(Args.Rotation), '--max-frames', str(Args.maxframes) ])) if Args.Display == 'gifanim': device._filename = str(Args.filename) image_composition = ImageComposition(device) board = boardFixed(image_composition, Args.Delay, device) FontTime = ImageFont.truetype( "%s/resources/time.otf" % (os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe())))), 16)
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
with open('/data/configuration/miscellanea/nanosound/config.json') as f: data = json.load(f) 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:
gpio_RST=self.opts['gpio_reset'], gpio=self.gpio or GPIO) def ftdi_spi(self): from luma.core.interface.serial import ftdi_spi return ftdi_spi(device=self.opts['ftdi_device'], bus_speed_hz=self.opts['spi_bus_speed'], gpio_DC=self.opts['gpio_data_command'], gpio_RST=self.opts['gpio_reset']) def ftdi_i2c(self): from luma.core.interface.serial import ftdi_i2c return ftdi_i2c(address=self.opts['i2c_address']) parser = cmdline.create_parser(description='lcd test') args = parser.parse_args(sys.argv[1:]) args = { 'spi_cs_high': False, 'loop': 0, 'duration': 0.01, 'rotate': 0, 'mode': 'RGB', 'transform': 'scale2x', 'gpio_data_command': 23, 'ftdi_device': 'ftdi://::/1', 'i2c_port': 1, 'spi_bus_speed': 8000000, 'config': None, 'gpio_mode': None,