e = int(options_pop('e')) rw = options_pop('rw', 'None') rw = None if rw == 'None' else int(rw) bl = options_pop('bl', 'None') bl = None if bl == 'None' else int(bl) # Parse data pins into a list pins_data = {} pins_data = data.split(',') # Convert data pins to int pins_data = [int(pin) for pin in pins_data] lcd = gpio.CharLCD(pin_rs=rs, pin_rw=rw, pin_e=e, pins_data=pins_data, pin_backlight=bl, numbering_mode=numbering_mode, cols=cols, rows=rows, charmap=charmap) else: print_usage( 'Connection type %s is not supported. Must be either i2c or gpio' % lcdmode) # Run selected test if test == 'show_charmap': show_charmap.run(lcd, rows, cols) elif test == 'testsuite': if cols == 20 and rows == 4: testsuite_20x4.run(lcd)
# Parse command line parameters if len(sys.argv) < 2: print_usage() if sys.argv[1] == 'i2c': if len(sys.argv) != 4: print_usage() lcd = i2c.CharLCD(int(sys.argv[2], 16), cols=16, rows=2, charmap=sys.argv[3]) elif sys.argv[1] == 'gpio': if len(sys.argv) != 3: print_usage() lcd = gpio.CharLCD(cols=16, rows=2, charmap=sys.argv[2]) else: print_usage() input('Display should be blank. ') lcd.cursor_mode = CursorMode.blink input('The cursor should now blink. ') lcd.cursor_mode = CursorMode.line input('The cursor should now be a line. ') lcd.write_string('Hello world!') input('"Hello world!" should be on the LCD. ') assert lcd.cursor_pos == (0, 12), 'cursor_pos should now be (0, 12)'
def run(): if len(sys.argv) < 3: print_usage() lcdmode = sys.argv[1] test = sys.argv[2] # Parse options into a dictionary try: options = dict([arg.split('=', 1) for arg in sys.argv[3:]]) except ValueError: print_usage( 'Malformed option detected, must be in the form option=value') # Common options cols = int(options_pop('cols')) rows = int(options_pop('rows')) charmap = options_pop('charmap', 'A00') if lcdmode == 'i2c': from RPLCD import i2c if len(sys.argv) < 5: print_usage() # i2c options, pop all required options, pass remaining options to expander_params i2c_expander = options_pop('expander') address = int(options_pop('addr'), 16) port = int(options_pop('port', '1')) try: lcd = i2c.CharLCD(i2c_expander, address, port=port, charmap=charmap, cols=cols, rows=rows, expander_params=options) except IOError: print_usage( 'IOError: Usually caused by the wrong i2c address/port ' 'or device not connected properly') elif lcdmode == 'gpio': import RPi.GPIO as GPIO from RPLCD import gpio if len(sys.argv) < 8: print_usage() # gpio options mode = options_pop('mode') if mode == 'BCM': numbering_mode = GPIO.BCM elif mode == 'BOARD': numbering_mode = GPIO.BOARD else: print_usage( 'Invalid GPIO numbering mode: %s, must be either BOARD or BCM' % mode) data = options_pop('data') rs = int(options_pop('rs')) e = int(options_pop('e')) rw = options_pop('rw', 'None') rw = None if rw == 'None' else int(rw) bl = options_pop('bl', 'None') bl = None if bl == 'None' else int(bl) # Parse data pins into a list pins_data = {} pins_data = data.split(',') # Convert data pins to int pins_data = [int(pin) for pin in pins_data] lcd = gpio.CharLCD(pin_rs=rs, pin_rw=rw, pin_e=e, pins_data=pins_data, pin_backlight=bl, numbering_mode=numbering_mode, cols=cols, rows=rows, charmap=charmap) elif lcdmode == 'pigpio': from pigpio import pi from RPLCD import pigpio if len(sys.argv) < 7: print_usage() # pigpio options host = options_pop('host') port = options_pop('port') if host == 'None': pi = pi() elif port == 'None': pi = pi(host) else: pi = pi(host, port) data = options_pop('data') rs = int(options_pop('rs')) e = int(options_pop('e')) rw = options_pop('rw', 'None') rw = None if rw == 'None' else int(rw) bl = options_pop('bl', 'None') bl = None if bl == 'None' else int(bl) # Parse data pins into a list pins_data = {} pins_data = data.split(',') # Convert data pins to int pins_data = [int(pin) for pin in pins_data] lcd = pigpio.CharLCD(pi, pin_rs=rs, pin_rw=rw, pin_e=e, pins_data=pins_data, pin_backlight=bl, cols=cols, rows=rows, charmap=charmap) else: print_usage( 'Connection type %s is not supported. Must be either i2c, gpio or pigpio' % lcdmode) # Run selected test if test == 'show_charmap': show_charmap.run(lcd, rows, cols) elif test == 'testsuite': if cols == 20 and rows == 4: testsuite_20x4.run(lcd) elif cols == 16 and rows == 2: testsuite_16x2.run(lcd) else: print_usage('%sx%s displays are not supported in this test.' % (cols, rows)) else: print_usage('Test \'%s\' is not supported.' % test)
# Parse command line parameters if len(sys.argv) < 2: print_usage() if sys.argv[1] == 'i2c': if len(sys.argv) != 7: print_usage() cols, rows = int(sys.argv[4]), int(sys.argv[5]) lcd = i2c.CharLCD(sys.argv[2], int(sys.argv[3], 16), cols=cols, rows=rows, charmap=sys.argv[6]) elif sys.argv[1] == 'gpio': if len(sys.argv) != 4: print_usage() lcd = gpio.CharLCD(cols=cols, rows=rows, charmap=sys.argv[2]) else: print_usage() # Get max column index maxcol = cols - 1 numstr = '' lcd.backlight = True input('Display should be blank. ') lcd.cursor_mode = CursorMode.blink input('The cursor should now blink. ') lcd.cursor_mode = CursorMode.line input('The cursor should now be a line. ')
# Parse command line parameters if len(sys.argv) < 2: print_usage() if sys.argv[1] == 'i2c': if len(sys.argv) != 4: print_usage() lcd = i2c.CharLCD(int(sys.argv[2], 16), cols=20, rows=4, charmap=sys.argv[3]) elif sys.argv[1] == 'gpio': if len(sys.argv) != 3: print_usage() lcd = gpio.CharLCD(cols=20, rows=4, charmap=sys.argv[2]) else: print_usage() input('Display should be blank. ') lcd.cursor_mode = CursorMode.blink input('The cursor should now blink. ') lcd.cursor_mode = CursorMode.line input('The cursor should now be a line. ') lcd.write_string('Hello world!') input('"Hello world!" should be on the LCD. ') assert lcd.cursor_pos == (0, 12), 'cursor_pos should now be (0, 12)'