diff --git a/gfxlcd/abstract/chip.py b/gfxlcd/abstract/chip.py index 8bbca39..37e00bd 100644 --- a/gfxlcd/abstract/chip.py +++ b/gfxlcd/abstract/chip.py @@ -19,16 +19,14 @@ class Chip(metaclass=abc.ABCMeta): """get width""" if self.rotation == 0 or self.rotation == 180: return self._width - else: - return self._height + return self._height @property def height(self): """get height""" if self.rotation == 0 or self.rotation == 180: return self._height - else: - return self._width + return self._width @abc.abstractmethod def _convert_color(self, color): diff --git a/gfxlcd/abstract/font.py b/gfxlcd/abstract/font.py index 2501ba4..47b96f1 100644 --- a/gfxlcd/abstract/font.py +++ b/gfxlcd/abstract/font.py @@ -3,6 +3,7 @@ import abc class Font(metaclass=abc.ABCMeta): + """Font abstract""" font = [] # Dictionary with hex that describe each char size = (0, 0) @@ -12,8 +13,3 @@ class Font(metaclass=abc.ABCMeta): def get(self, letter): """return array with letter""" return self.font[ord(letter)] - - @property - def size(self): - """get font size""" - return self.size diff --git a/gfxlcd/abstract/touch.py b/gfxlcd/abstract/touch.py index e299262..beac999 100644 --- a/gfxlcd/abstract/touch.py +++ b/gfxlcd/abstract/touch.py @@ -1,12 +1,13 @@ """Touch panel interface""" -import spidev # pylint: disable=I0011,F0401 import abc -import RPi.GPIO +import spidev # pylint: disable=I0011,F0401 +import RPi.GPIO # pylint: disable=I0011,F0401 class Touch(metaclass=abc.ABCMeta): """Touch class""" - def __init__(self, width, height, int_pin=None, callback=None, cs_pin=None, spi=0, speed=1000000): + def __init__(self, width, height, int_pin=None, + callback=None, cs_pin=None, spi=0, speed=1000000): self.width = width self.height = height self.spi = spidev.SpiDev() @@ -30,7 +31,8 @@ class Touch(metaclass=abc.ABCMeta): if self.int_pin: RPi.GPIO.setup(self.int_pin, RPi.GPIO.IN) RPi.GPIO.add_event_detect( - self.int_pin, RPi.GPIO.BOTH, callback=self._interrupt, bouncetime=self.bouncetime + self.int_pin, RPi.GPIO.BOTH, callback=self._interrupt, + bouncetime=self.bouncetime ) if self.cs_pin: RPi.GPIO.setup(self.cs_pin, RPi.GPIO.OUT) @@ -53,7 +55,7 @@ class Touch(metaclass=abc.ABCMeta): def _calculate_avr(self, points): """calculate x,y by average""" - if len(points) == 0: + if not points: return None sum_x = 0 sum_y = 0 @@ -67,5 +69,4 @@ class Touch(metaclass=abc.ABCMeta): """checks if point is in range""" if self.rotate == 0 or self.rotate == 180: return 0 <= pos_x <= self.width and 0 <= pos_y <= self.height - else: - return 0 <= pos_y <= self.width and 0 <= pos_x <= self.height + return 0 <= pos_y <= self.width and 0 <= pos_x <= self.height diff --git a/gfxlcd/drawing/page.py b/gfxlcd/drawing/page.py index 17d93d5..9f0edc4 100644 --- a/gfxlcd/drawing/page.py +++ b/gfxlcd/drawing/page.py @@ -1,3 +1,4 @@ +"""Page drawing algorithm""" import abc from gfxlcd.drawing.pixel import Pixel diff --git a/gfxlcd/drawing/pixel.py b/gfxlcd/drawing/pixel.py index 4dca13d..1a7ed2f 100644 --- a/gfxlcd/drawing/pixel.py +++ b/gfxlcd/drawing/pixel.py @@ -160,4 +160,3 @@ class Pixel(object): pos_x + bit, pos_y + row, self.background_color ) data >>= 1 - diff --git a/gfxlcd/driver/ad7843/ad7843.py b/gfxlcd/driver/ad7843/ad7843.py index 1f516c9..0c5beb8 100644 --- a/gfxlcd/driver/ad7843/ad7843.py +++ b/gfxlcd/driver/ad7843/ad7843.py @@ -1,10 +1,12 @@ -import RPi.GPIO +"""Driver for AD7843 touch panel""" +import RPi.GPIO # pylint: disable=I0011,F0401 from gfxlcd.abstract.touch import Touch class AD7843(Touch): """AD7843 class""" - def __init__(self, width, height, int_pin=None, callback=None, cs_pin=None, spi=0, speed=1000000): + def __init__(self, width, height, int_pin=None, + callback=None, cs_pin=None, spi=0, speed=1000000): super().__init__(width, height, int_pin, callback, cs_pin, spi, speed) self.correction = { 'x': 364, @@ -16,20 +18,32 @@ class AD7843(Touch): def _get_xy(self, offset_x, offset_y): """correct x and y""" if self.rotate == 0: - return int((offset_x - self.correction['x']) / self.correction['ratio_x']), \ - int((offset_y - self.correction['y']) / self.correction['ratio_y']) + return int( + (offset_x - self.correction['x']) / self.correction['ratio_x'] + ), int( + (offset_y - self.correction['y']) / self.correction['ratio_y'] + ) if self.rotate == 90: - return self.height - int((offset_y - self.correction['y']) / self.correction['ratio_y']), \ - int((offset_x - self.correction['x']) / self.correction['ratio_x']) + return self.height - int( + (offset_y - self.correction['y']) / self.correction['ratio_y'] + ), int( + (offset_x - self.correction['x']) / self.correction['ratio_x'] + ) if self.rotate == 180: - return self.width - int((offset_x - self.correction['x']) / self.correction['ratio_x']), \ - self.height - int((offset_y - self.correction['y']) / self.correction['ratio_y']) + return self.width - int( + (offset_x - self.correction['x']) / self.correction['ratio_x'] + ), self.height - int( + (offset_y - self.correction['y']) / self.correction['ratio_y'] + ) if self.rotate == 270: - return int((offset_y - self.correction['y']) / self.correction['ratio_y']), \ - self.width - int((offset_x - self.correction['x']) / self.correction['ratio_x']) + return int( + (offset_y - self.correction['y']) / self.correction['ratio_y'] + ), self.width - int( + (offset_x - self.correction['x']) / self.correction['ratio_x'] + ) def get_position(self): """get touch coords""" diff --git a/gfxlcd/driver/hd44780.py b/gfxlcd/driver/hd44780.py index 8f74075..1ad9caa 100644 --- a/gfxlcd/driver/hd44780.py +++ b/gfxlcd/driver/hd44780.py @@ -6,6 +6,7 @@ from charlcd.abstract.flush_event_interface import FlushEvent class HD44780(BaseDriver, FlushEvent): + """HD44780 driver for GfxLCD""" def __init__(self, gfxlcd, lcd_flush=False): """Class init""" self.gfxlcd = gfxlcd @@ -39,11 +40,11 @@ class HD44780(BaseDriver, FlushEvent): if char < 100: return char -= 100 - y = char // self.width - x = char - (y*self.width) + pos_y = char // self.width + pos_x = char - (pos_y * self.width) self.position = { - 'x': x * self.font.size[0], - 'y': y * self.font.size[1] + 'x': pos_x * self.font.size[0], + 'y': pos_y * self.font.size[1] } def shutdown(self): diff --git a/gfxlcd/driver/ili9486/ili9486.py b/gfxlcd/driver/ili9486/ili9486.py index 2d5d693..cfbcae6 100644 --- a/gfxlcd/driver/ili9486/ili9486.py +++ b/gfxlcd/driver/ili9486/ili9486.py @@ -1,5 +1,4 @@ """ILI9486 chip driver""" -import time from gfxlcd.drawing.area import Area from gfxlcd.abstract.chip import Chip @@ -27,34 +26,34 @@ class ILI9486(Area, Chip): Chip.init(self) self.driver.reset() - #Read Display MADCTL + # Read Display MADCTL self.driver.cmd(0x0b, None) self.driver.data(0x00, None) self.driver.data(0x00, None) - #Sleep OUT + # Sleep OUT self.driver.cmd(0x11, None) - #Interface Pixel Format + # Interface Pixel Format self.driver.cmd(0x3a, None) self.driver.data(0x55, None) #0x66 5-6-5 / 55 6-6-6 - #Memory Access Control ( + # Memory Access Control ( self.driver.cmd(0x36, None) self.driver.data(self.rotations[self.rotation], None) - #Power Control 3 (For Normal Mode) + # Power Control 3 (For Normal Mode) self.driver.cmd(0xc2, None) self.driver.data(0x44, None) - #VCOM Control + # VCOM Control self.driver.cmd(0xc5, None) self.driver.data(0x00, None) self.driver.data(0x00, None) self.driver.data(0x00, None) self.driver.data(0x00, None) - #PGAMCTRL(Positive Gamma Control) + # PGAMCTRL(Positive Gamma Control) self.driver.cmd(0xe0, None) self.driver.data(0x0F, None) self.driver.data(0x1F, None) @@ -72,7 +71,7 @@ class ILI9486(Area, Chip): self.driver.data(0x0D, None) self.driver.data(0x00, None) - #NGAMCTRL (Negative Gamma Correction) + # NGAMCTRL (Negative Gamma Correction) self.driver.cmd(0xe1, None) self.driver.data(0x0F, None) self.driver.data(0x32, None) @@ -90,7 +89,7 @@ class ILI9486(Area, Chip): self.driver.data(0x20, None) self.driver.data(0x00, None) - #Digital Gamma Control 1 + # Digital Gamma Control 1 self.driver.cmd(0xe2, None) self.driver.data(0x0F, None) self.driver.data(0x32, None) @@ -108,10 +107,10 @@ class ILI9486(Area, Chip): self.driver.data(0x20, None) self.driver.data(0x00, None) - #Sleep OUT + # Sleep OUT self.driver.cmd(0x11, None) - #Display ON + # Display ON self.driver.cmd(0x29, None) def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2): diff --git a/gfxlcd/driver/ili9486/spi.py b/gfxlcd/driver/ili9486/spi.py index ed7afc9..af8e2c4 100644 --- a/gfxlcd/driver/ili9486/spi.py +++ b/gfxlcd/driver/ili9486/spi.py @@ -1,6 +1,6 @@ """SPI communication driver""" import time -import spidev +import spidev # pylint: disable=I0011,F0401 import RPi.GPIO # pylint: disable=I0011,F0401 from gfxlcd.abstract.driver import Driver RPi.GPIO.setmode(RPi.GPIO.BCM) diff --git a/gfxlcd/driver/nju6450/nju6450.py b/gfxlcd/driver/nju6450/nju6450.py index 673e123..f062d11 100644 --- a/gfxlcd/driver/nju6450/nju6450.py +++ b/gfxlcd/driver/nju6450/nju6450.py @@ -3,7 +3,6 @@ from gfxlcd.drawing.page import Page from gfxlcd.abstract.chip import Chip - class NJU6450(Page, Chip): """Class for an LCD with NJU6450 chip""" def __init__(self, width, height, driver, auto_flush=False): @@ -81,6 +80,6 @@ class NJU6450(Page, Chip): pos_x1, pos_y1 = self.width - pos_x1 - 1, self.height - pos_y1 - 1 pos_x2, pos_y2 = self.width - pos_x2 - 1, self.height - pos_y2 - 1 if self.rotation == 270: - pos_x1, pos_y1 = pos_y1 , self.width - pos_x1 - 1 - pos_x2, pos_y2 = pos_y2 , self.width - pos_x2 - 1 + pos_x1, pos_y1 = pos_y1, self.width - pos_x1 - 1 + pos_x2, pos_y2 = pos_y2, self.width - pos_x2 - 1 Page.fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2) diff --git a/gfxlcd/driver/null/area_driver.py b/gfxlcd/driver/null/area_driver.py index a27be79..adf7457 100644 --- a/gfxlcd/driver/null/area_driver.py +++ b/gfxlcd/driver/null/area_driver.py @@ -1,5 +1,4 @@ """Area driver """ -import time from gfxlcd.abstract.driver import Driver @@ -32,7 +31,9 @@ class AreaDriver(Driver): def data(self, data, enable): """send data to display""" app_x, app_y = self.pointer - self.buffer[self.area['start_x'] + app_x][self.area['start_y'] + app_y] = data + self.buffer[ + self.area['start_x'] + app_x][self.area['start_y'] + app_y + ] = data self._inc_pointer() def _inc_pointer(self): @@ -47,4 +48,3 @@ class AreaDriver(Driver): app_y = 0 self.pointer = (app_x, app_y) - diff --git a/gfxlcd/driver/xpt2046/xpt2046.py b/gfxlcd/driver/xpt2046/xpt2046.py index 44d68a6..7397131 100644 --- a/gfxlcd/driver/xpt2046/xpt2046.py +++ b/gfxlcd/driver/xpt2046/xpt2046.py @@ -1,4 +1,5 @@ -import RPi.GPIO +"""XPT2046 touch pabel driver""" +import RPi.GPIO # pylint: disable=I0011,F0401 from gfxlcd.abstract.touch import Touch diff --git a/gfxlcd/font/__init__.py b/gfxlcd/font/__init__.py index 7c2d50b..b4eaaa2 100644 --- a/gfxlcd/font/__init__.py +++ b/gfxlcd/font/__init__.py @@ -1 +1,2 @@ -__author__ = 'kosci' +"""font module""" +__author__ = 'Bartosz Kosciow' diff --git a/gfxlcd/font/font8x8.py b/gfxlcd/font/font8x8.py index a269c01..5d82910 100644 --- a/gfxlcd/font/font8x8.py +++ b/gfxlcd/font/font8x8.py @@ -1,3 +1,4 @@ +"""font 8x8""" from gfxlcd.abstract.font import Font @@ -16,7 +17,7 @@ class Font8x8(Font): [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0008 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0009 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+000A - + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+000B [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+000C [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+000D @@ -27,7 +28,7 @@ class Font8x8(Font): [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0012 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0013 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0014 - + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0015 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0016 [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0017 @@ -38,7 +39,7 @@ class Font8x8(Font): [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+001C [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+001D [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+001E - + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+001F [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0020 (space) [0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00], # U+0021 (!) @@ -49,7 +50,7 @@ class Font8x8(Font): [0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00], # U+0026 (&) [0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00], # U+0027 (') [0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00], # U+0028 (() - + [0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00], # U+0029 ()) [0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00], # U+002A (*) [0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00], # U+002B (+) @@ -60,7 +61,7 @@ class Font8x8(Font): [0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00], # U+0030 (0) [0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00], # U+0031 (1) [0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00], # U+0032 (2) - + [0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00], # U+0033 (3) [0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00], # U+0034 (4) [0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00], # U+0035 (5) @@ -71,7 +72,7 @@ class Font8x8(Font): [0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00], # U+003A (:) [0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06], # U+003B (# ) [0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00], # U+003C (<) - + [0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00], # U+003D (=) [0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00], # U+003E (>) [0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00], # U+003F (?) @@ -82,7 +83,7 @@ class Font8x8(Font): [0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00], # U+0044 (D) [0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00], # U+0045 (E) [0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00], # U+0046 (F) - + [0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00], # U+0047 (G) [0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00], # U+0048 (H) [0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00], # U+0049 (I) @@ -93,7 +94,7 @@ class Font8x8(Font): [0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00], # U+004E (N) [0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00], # U+004F (O) [0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00], # U+0050 (P) - + [0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00], # U+0051 (Q) [0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00], # U+0052 (R) [0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00], # U+0053 (S) @@ -104,7 +105,7 @@ class Font8x8(Font): [0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00], # U+0058 (X) [0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00], # U+0059 (Y) [0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00], # U+005A (Z) - + [0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00], # U+005B ([) [0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00], # U+005C (\) [0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00], # U+005D (]) @@ -116,7 +117,7 @@ class Font8x8(Font): [0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00], # U+0063 (c) [0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00], # U+0064 (d) [0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00], # U+0065 (e) - + [0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00], # U+0066 (f) [0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F], # U+0067 (g) [0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00], # U+0068 (h) @@ -127,7 +128,7 @@ class Font8x8(Font): [0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00], # U+006D (m) [0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00], # U+006E (n) [0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00], # U+006F (o) - + [0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F], # U+0070 (p) [0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78], # U+0071 (q) [0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00], # U+0072 (r) @@ -139,7 +140,7 @@ class Font8x8(Font): [0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00], # U+0078 (x) [0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F], # U+0079 (y) [0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00], # U+007A (z) - + [0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00], # U+007B ([) [0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00], # U+007C (|) [0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00], # U+007D (])