Skip to content

Commit 100d482

Browse files
authored
Merge pull request #19 from fourstix/b_update_build
Black reformatted
2 parents 5034158 + fd545a3 commit 100d482

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

sparkfun_serlcd.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,21 @@
137137

138138
# private functions
139139

140+
140141
def _map_range(value, in_min, in_max, out_min, out_max):
141142
"""Map an integer value from a range into a value in another range."""
142143
result = (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
143144

144145
return int(result)
145146

147+
146148
# abstract base class
147149
class Sparkfun_SerLCD:
148150
"""Abstract base class for Sparkfun AVR-Based Serial LCD display.
149151
Use the appropriate driver communcation subclass Sparkfun_SerLCD_I2C()
150152
for I2C, Sparkfun_SerLCD_SPI() for SPI or Sparkfun_SerLCD_UART for UART.
151153
"""
154+
152155
# pylint: disable=too-many-instance-attributes
153156
# pylint: disable=too-many-public-methods
154157

@@ -210,7 +213,6 @@ def command(self, command):
210213
# Wait a bit longer for special display commands
211214
sleep(0.010)
212215

213-
214216
def clear(self):
215217
"""Clear the display"""
216218
self.command(_CLEAR_COMMAND)
@@ -338,7 +340,6 @@ def display(self, value):
338340
self._display_control &= ~_LCD_DISPLAYON
339341
self._special_command(_LCD_DISPLAYCONTROL | self._display_control)
340342

341-
342343
def cursor(self, value):
343344
"""Turn the underline cursor on and off."""
344345
if bool(value):
@@ -398,7 +399,7 @@ def set_i2c_address(self, new_address):
398399
data = bytearray()
399400
# Send contrast command
400401
data.append(_SETTING_COMMAND)
401-
data.append(_ADDRESS_COMMAND) # 0x19
402+
data.append(_ADDRESS_COMMAND) # 0x19
402403
data.append(new_address)
403404
self._write_bytes(data)
404405
# Update our own address so we can still talk to the display
@@ -409,19 +410,25 @@ def set_i2c_address(self, new_address):
409410

410411
def scroll_display_left(self, count=1):
411412
"""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+
)
413416

414417
def scroll_display_right(self, count=1):
415418
"""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+
)
417422

418423
def move_cursor_left(self, count=1):
419424
"""Move the cursor to the left"""
420425
self._special_command(_LCD_CURSORSHIFT | _LCD_CURSORMOVE | _LCD_MOVELEFT, count)
421426

422427
def move_cursor_right(self, count=1):
423428
"""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+
)
425432

426433
def splash_screen(self, enable):
427434
"""Enable or disable the splash screem."""
@@ -504,7 +511,6 @@ def _special_command(self, command, count=1):
504511
# Wait a bit longer for special display commands
505512
sleep(0.050)
506513

507-
508514
def _put_char(self, char):
509515
"""Send a character byte directly to display, no encoding"""
510516
data = bytearray()
@@ -515,45 +521,51 @@ def _put_char(self, char):
515521
# concrete subclass for I2C
516522
class Sparkfun_SerLCD_I2C(Sparkfun_SerLCD):
517523
"""Driver subclass for Sparkfun Serial Displays over I2C communication"""
524+
518525
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+
521529
self._i2c_device = i2c_device.I2CDevice(i2c, address)
522530
self._i2c = i2c
523531
super().__init__()
524532

525-
526533
def _write_bytes(self, data):
527534
with self._i2c_device as device:
528535
device.write(data)
529536

530537
def _change_i2c_address(self, addr):
531-
#pylint: disable=import-outside-toplevel
538+
# pylint: disable=import-outside-toplevel
532539
import adafruit_bus_device.i2c_device as i2c_device
540+
533541
self._i2c_device = i2c_device.I2CDevice(self._i2c, addr)
534542

543+
535544
# concrete subclass for SPI
536545
class Sparkfun_SerLCD_SPI(Sparkfun_SerLCD):
537546
"""Driver subclass for Sparkfun Serial LCD display over SPI communication"""
547+
538548
def __init__(self, spi, cs):
539-
#pylint: disable=import-outside-toplevel
549+
# pylint: disable=import-outside-toplevel
540550
import adafruit_bus_device.spi_device as spi_device
551+
541552
self._spi_device = spi_device.SPIDevice(spi, cs)
542553
super().__init__()
543554

544-
545555
def _write_bytes(self, data):
546556
with self._spi_device as device:
547-
#pylint: disable=no-member
557+
# pylint: disable=no-member
548558
device.write(data)
549559

550560
def _change_i2c_address(self, addr):
551561
# No i2c address change for SPI
552562
pass
553563

564+
554565
# concrete subclass for UART
555566
class Sparkfun_SerLCD_UART(Sparkfun_SerLCD):
556567
"""Driver subclass for Sparkfun Serial LCD display over Serial communication"""
568+
557569
def __init__(self, uart):
558570
self._uart = uart
559571
super().__init__()

0 commit comments

Comments
 (0)