137
137
138
138
# private functions
139
139
140
+
140
141
def _map_range (value , in_min , in_max , out_min , out_max ):
141
142
"""Map an integer value from a range into a value in another range."""
142
143
result = (value - in_min ) * (out_max - out_min ) / (in_max - in_min ) + out_min
143
144
144
145
return int (result )
145
146
147
+
146
148
# abstract base class
147
149
class Sparkfun_SerLCD :
148
150
"""Abstract base class for Sparkfun AVR-Based Serial LCD display.
149
151
Use the appropriate driver communcation subclass Sparkfun_SerLCD_I2C()
150
152
for I2C, Sparkfun_SerLCD_SPI() for SPI or Sparkfun_SerLCD_UART for UART.
151
153
"""
154
+
152
155
# pylint: disable=too-many-instance-attributes
153
156
# pylint: disable=too-many-public-methods
154
157
@@ -210,7 +213,6 @@ def command(self, command):
210
213
# Wait a bit longer for special display commands
211
214
sleep (0.010 )
212
215
213
-
214
216
def clear (self ):
215
217
"""Clear the display"""
216
218
self .command (_CLEAR_COMMAND )
@@ -338,7 +340,6 @@ def display(self, value):
338
340
self ._display_control &= ~ _LCD_DISPLAYON
339
341
self ._special_command (_LCD_DISPLAYCONTROL | self ._display_control )
340
342
341
-
342
343
def cursor (self , value ):
343
344
"""Turn the underline cursor on and off."""
344
345
if bool (value ):
@@ -398,7 +399,7 @@ def set_i2c_address(self, new_address):
398
399
data = bytearray ()
399
400
# Send contrast command
400
401
data .append (_SETTING_COMMAND )
401
- data .append (_ADDRESS_COMMAND ) # 0x19
402
+ data .append (_ADDRESS_COMMAND ) # 0x19
402
403
data .append (new_address )
403
404
self ._write_bytes (data )
404
405
# Update our own address so we can still talk to the display
@@ -409,19 +410,25 @@ def set_i2c_address(self, new_address):
409
410
410
411
def scroll_display_left (self , count = 1 ):
411
412
"""Scroll the display to the left"""
412
- self ._special_command (_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVELEFT , count )
413
+ self ._special_command (
414
+ _LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVELEFT , count
415
+ )
413
416
414
417
def scroll_display_right (self , count = 1 ):
415
418
"""Scroll the display to the right"""
416
- self ._special_command (_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVERIGHT , count )
419
+ self ._special_command (
420
+ _LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVERIGHT , count
421
+ )
417
422
418
423
def move_cursor_left (self , count = 1 ):
419
424
"""Move the cursor to the left"""
420
425
self ._special_command (_LCD_CURSORSHIFT | _LCD_CURSORMOVE | _LCD_MOVELEFT , count )
421
426
422
427
def move_cursor_right (self , count = 1 ):
423
428
"""Scroll the display to the right"""
424
- self ._special_command (_LCD_CURSORSHIFT | _LCD_CURSORMOVE | _LCD_MOVERIGHT , count )
429
+ self ._special_command (
430
+ _LCD_CURSORSHIFT | _LCD_CURSORMOVE | _LCD_MOVERIGHT , count
431
+ )
425
432
426
433
def splash_screen (self , enable ):
427
434
"""Enable or disable the splash screem."""
@@ -504,7 +511,6 @@ def _special_command(self, command, count=1):
504
511
# Wait a bit longer for special display commands
505
512
sleep (0.050 )
506
513
507
-
508
514
def _put_char (self , char ):
509
515
"""Send a character byte directly to display, no encoding"""
510
516
data = bytearray ()
@@ -515,45 +521,51 @@ def _put_char(self, char):
515
521
# concrete subclass for I2C
516
522
class Sparkfun_SerLCD_I2C (Sparkfun_SerLCD ):
517
523
"""Driver subclass for Sparkfun Serial Displays over I2C communication"""
524
+
518
525
def __init__ (self , i2c , address = DEFAULT_I2C_ADDR ):
519
- #pylint: disable=import-outside-toplevel
520
- import adafruit_bus_device .i2c_device as i2c_device
526
+ # pylint: disable=import-outside-toplevel
527
+ import adafruit_bus_device .i2c_device as i2c_device
528
+
521
529
self ._i2c_device = i2c_device .I2CDevice (i2c , address )
522
530
self ._i2c = i2c
523
531
super ().__init__ ()
524
532
525
-
526
533
def _write_bytes (self , data ):
527
534
with self ._i2c_device as device :
528
535
device .write (data )
529
536
530
537
def _change_i2c_address (self , addr ):
531
- #pylint: disable=import-outside-toplevel
538
+ # pylint: disable=import-outside-toplevel
532
539
import adafruit_bus_device .i2c_device as i2c_device
540
+
533
541
self ._i2c_device = i2c_device .I2CDevice (self ._i2c , addr )
534
542
543
+
535
544
# concrete subclass for SPI
536
545
class Sparkfun_SerLCD_SPI (Sparkfun_SerLCD ):
537
546
"""Driver subclass for Sparkfun Serial LCD display over SPI communication"""
547
+
538
548
def __init__ (self , spi , cs ):
539
- #pylint: disable=import-outside-toplevel
549
+ # pylint: disable=import-outside-toplevel
540
550
import adafruit_bus_device .spi_device as spi_device
551
+
541
552
self ._spi_device = spi_device .SPIDevice (spi , cs )
542
553
super ().__init__ ()
543
554
544
-
545
555
def _write_bytes (self , data ):
546
556
with self ._spi_device as device :
547
- #pylint: disable=no-member
557
+ # pylint: disable=no-member
548
558
device .write (data )
549
559
550
560
def _change_i2c_address (self , addr ):
551
561
# No i2c address change for SPI
552
562
pass
553
563
564
+
554
565
# concrete subclass for UART
555
566
class Sparkfun_SerLCD_UART (Sparkfun_SerLCD ):
556
567
"""Driver subclass for Sparkfun Serial LCD display over Serial communication"""
568
+
557
569
def __init__ (self , uart ):
558
570
self ._uart = uart
559
571
super ().__init__ ()
0 commit comments