From 8089e60838e391c4d725c87d878c9b2cb1507955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 25 Apr 2017 19:08:48 +0200 Subject: [PATCH 1/9] doc + facke test --- gfxlcd/tests/dummy_test.py | 6 ++++++ readme.md | 24 ++++++++++++------------ tox.ini | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 gfxlcd/tests/dummy_test.py diff --git a/gfxlcd/tests/dummy_test.py b/gfxlcd/tests/dummy_test.py new file mode 100644 index 0000000..360a45d --- /dev/null +++ b/gfxlcd/tests/dummy_test.py @@ -0,0 +1,6 @@ +from nose.tools import assert_equal + + +class DummyTest(object): + def test_init(self): + assert_equal(1, 1) diff --git a/readme.md b/readme.md index 90cec37..f260d85 100644 --- a/readme.md +++ b/readme.md @@ -16,7 +16,7 @@ Wiring is below Initialization === -##SSD1306 +## SSD1306 ### SPI from driver.ssd1306.spi import SPI @@ -35,7 +35,7 @@ If you want to set your own pins: o = SSD1306(128, 64, drv) o.init() -##NJU6450 +## NJU6450 ### GPIO from gfxlcd.driver.nju6450.gpio import GPIO @@ -66,7 +66,7 @@ Custom wiring: o = NJU6450(122, 32, drv) o.init() -##ILI9325 +## ILI9325 ### GPIO from gfxlcd.driver.ili9325.gpio import GPIO @@ -99,17 +99,17 @@ Custom pins: Drawing functions === -draw_pixel +draw_pixel(x, y) -draw_line +draw_line(from_x, from_y, to_x, to_y) -draw_rect +draw_rect(x1, y1, x2, y2) -draw_circle +draw_circle(x1, y1, radius) -draw_arc +draw_arc(x1, y1, radius, from_angle, to_angle -fill_rect +fill_rect(x1, y1, x2, y2) Colours @@ -121,7 +121,7 @@ lcd.background_color = (r, g ,b) Wiring === -##SSD1306 +## SSD1306 ### SPI SPI wiring + 2 additional pins. Defaults: @@ -134,7 +134,7 @@ SPI wiring + 2 additional pins. Defaults: D/C ----------- G6 -##NJU6450 +## NJU6450 ### GPIO Default wiring: @@ -159,7 +159,7 @@ Default wiring: 17 (A) ------- +5V 18 (K) ------- GND -##ILI9325 +## ILI9325 ### GPIO Default: diff --git a/tox.ini b/tox.ini index 0b0eeda..c9340d5 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ deps= flake8 pylint whitelist_externals = /bin/bash -commands= nosetests --with-xunit --xunit-file=junit-{envname}.xml charlcd/tests +commands= nosetests --with-xunit --xunit-file=junit-{envname}.xml gfxlcd/tests rm flake8-{envname}.log /bin/bash -c "flake8 --output-file=flake8-{envname}.log gfxlcd || :" /bin/bash -c "pylint gfxlcd > pylint-{envname}.log || :" From fc2e61c312c6d371ad36714a64576f83f40b2a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 25 Apr 2017 19:13:06 +0200 Subject: [PATCH 2/9] tox.ini playing with file --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index c9340d5..41710dd 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,7 @@ deps= pylint whitelist_externals = /bin/bash commands= nosetests --with-xunit --xunit-file=junit-{envname}.xml gfxlcd/tests - rm flake8-{envname}.log + rm flake8-{envname}.log -f /bin/bash -c "flake8 --output-file=flake8-{envname}.log gfxlcd || :" /bin/bash -c "pylint gfxlcd > pylint-{envname}.log || :" [flake8] From af1ae95a5353e4741a328dc58189579e053c909c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 25 Apr 2017 20:22:17 +0200 Subject: [PATCH 3/9] refactoring pep8 & pylint --- gfxlcd/abstract/driver.py | 3 +- gfxlcd/demos/ili.py | 1 + gfxlcd/demos/ili_2.py | 7 +++-- gfxlcd/demos/nju.py | 1 + gfxlcd/demos/nju_2.py | 5 ++-- gfxlcd/demos/ssd.py | 6 ++-- gfxlcd/demos/ssd_2.py | 3 +- gfxlcd/drawing/area.py | 50 ++++++++++++++++++-------------- gfxlcd/driver/ili9325/gpio.py | 15 ++++------ gfxlcd/driver/ili9325/ili9325.py | 19 +++++++----- gfxlcd/driver/nju6450/gpio.py | 12 ++++---- gfxlcd/driver/nju6450/nju6450.py | 13 +++++---- gfxlcd/driver/ssd1306/spi.py | 13 ++++----- gfxlcd/driver/ssd1306/ssd1306.py | 13 +++++---- 14 files changed, 87 insertions(+), 74 deletions(-) diff --git a/gfxlcd/abstract/driver.py b/gfxlcd/abstract/driver.py index f928f24..f868593 100644 --- a/gfxlcd/abstract/driver.py +++ b/gfxlcd/abstract/driver.py @@ -1,3 +1,4 @@ +"""Interface for communication driver""" import abc @@ -20,4 +21,4 @@ class Driver(metaclass=abc.ABCMeta): @abc.abstractmethod def data(self, data, enable): """sends data to device""" - pass \ No newline at end of file + pass diff --git a/gfxlcd/demos/ili.py b/gfxlcd/demos/ili.py index 631b2a2..aa89fd6 100644 --- a/gfxlcd/demos/ili.py +++ b/gfxlcd/demos/ili.py @@ -29,6 +29,7 @@ def draw_net(o): o.draw_line(0, s, o.width-1, s) s += 10 + drv = GPIO() o = ILI9325(240, 320, drv) diff --git a/gfxlcd/demos/ili_2.py b/gfxlcd/demos/ili_2.py index 8280d2b..6bc7fd1 100644 --- a/gfxlcd/demos/ili_2.py +++ b/gfxlcd/demos/ili_2.py @@ -1,10 +1,10 @@ import RPi.GPIO import sys -RPi.GPIO.setmode(RPi.GPIO.BCM) sys.path.append("../../") from gfxlcd.driver.ili9325.gpio import GPIO as ILIGPIO from gfxlcd.driver.ili9325.ili9325 import ILI9325 import random +RPi.GPIO.setmode(RPi.GPIO.BCM) def hole(o, x, y): @@ -24,7 +24,7 @@ def hole(o, x, y): def draw_points(o): for _ in range(0, 50): - hole(o, random.randint(2,o.width - 10), random.randint(2,o.height-10)) + hole(o, random.randint(2, o.width-10), random.randint(2, o.height-10)) def draw_net(o): @@ -37,6 +37,7 @@ def draw_net(o): o.draw_line(0, s, o.width-1, s) s += 10 + lcd_tft = ILI9325(240, 320, ILIGPIO()) lcd_tft.init() @@ -95,4 +96,4 @@ lcd_tft.draw_line(131, 227, 135, 238) lcd_tft.draw_arc(131, 235, 5, 45, 135) lcd_tft.fill_rect(195, 204, 205, 210) lcd_tft.draw_rect(180, 210, 220, 225) -lcd_tft.fill_rect(180, 226, 220, 259) \ No newline at end of file +lcd_tft.fill_rect(180, 226, 220, 259) diff --git a/gfxlcd/demos/nju.py b/gfxlcd/demos/nju.py index 0c9f609..7ad9b09 100644 --- a/gfxlcd/demos/nju.py +++ b/gfxlcd/demos/nju.py @@ -17,6 +17,7 @@ def hole(x, y): o.draw_pixel(x, y + 3) o.draw_pixel(x+4, y + 3) + drv = GPIO() o = NJU6450(122, 32, drv) diff --git a/gfxlcd/demos/nju_2.py b/gfxlcd/demos/nju_2.py index 03736b9..52483c0 100644 --- a/gfxlcd/demos/nju_2.py +++ b/gfxlcd/demos/nju_2.py @@ -1,10 +1,10 @@ import RPi.GPIO import sys -RPi.GPIO.setmode(RPi.GPIO.BCM) sys.path.append("../../") from gfxlcd.driver.nju6450.gpio import GPIO from gfxlcd.driver.nju6450.nju6450 import NJU6450 import random +RPi.GPIO.setmode(RPi.GPIO.BCM) def hole(o, x, y): @@ -24,7 +24,7 @@ def hole(o, x, y): def draw_points(o): for _ in range(0, 50): - hole(o, random.randint(2,o.width - 10), random.randint(2,o.height-10)) + hole(o, random.randint(2, o.width-10), random.randint(2, o.height-10)) def draw_net(o): @@ -37,6 +37,7 @@ def draw_net(o): o.draw_line(0, s, o.width-1, s) s += 10 + lcd_nju = NJU6450(122, 32, GPIO()) lcd_nju.init() lcd_nju.auto_flush = False diff --git a/gfxlcd/demos/ssd.py b/gfxlcd/demos/ssd.py index bc8c230..1ccd70d 100644 --- a/gfxlcd/demos/ssd.py +++ b/gfxlcd/demos/ssd.py @@ -3,7 +3,6 @@ from driver.ssd1306.spi import SPI from driver.ssd1306.ssd1306 import SSD1306 - def hole(x, y): o.draw_pixel(x+1, y) o.draw_pixel(x+2, y) @@ -18,13 +17,15 @@ def hole(x, y): o.draw_pixel(x, y + 3) o.draw_pixel(x+4, y + 3) + drv = SPI() o = SSD1306(128, 64, drv) o.init() o.auto_flush = False for _ in range(0, 50): - hole(random.randint(2,120), random.randint(2,56)) + hole(random.randint(2, 120), random.randint(2, 56)) + hole(10, 10) hole(15, 13) hole(18, 23) @@ -87,4 +88,3 @@ o.flush(True) # o.draw_pixels(46, 9, 25) # o.draw_pixels(47, 9, 5) # o.draw_pixels(48, 9, 3) - diff --git a/gfxlcd/demos/ssd_2.py b/gfxlcd/demos/ssd_2.py index a5faba5..e01ca28 100644 --- a/gfxlcd/demos/ssd_2.py +++ b/gfxlcd/demos/ssd_2.py @@ -24,7 +24,7 @@ def hole(o, x, y): def draw_points(o): for _ in range(0, 50): - hole(o, random.randint(2,o.width - 10), random.randint(2,o.height-10)) + hole(o, random.randint(2, o.width- 10), random.randint(2, o.height-10)) def draw_net(o): @@ -37,6 +37,7 @@ def draw_net(o): o.draw_line(0, s, o.width-1, s) s += 10 + lcd_oled = SSD1306(128, 64, SPI()) lcd_oled.init() lcd_oled.auto_flush = False diff --git a/gfxlcd/drawing/area.py b/gfxlcd/drawing/area.py index 4bdb7a1..7c0127f 100644 --- a/gfxlcd/drawing/area.py +++ b/gfxlcd/drawing/area.py @@ -1,41 +1,49 @@ +"""Area drawing algorithm""" import itertools from gfxlcd.drawing.pixel import Pixel class Area(Pixel): - """Page drawing algorithm""" - def __init__(self): + """Area drawing algorithm""" + def __init__(self, driver): + self.driver = driver Pixel.__init__(self) def init(self): + """additional initialization""" pass - def draw_pixel(self, x, y): + def draw_pixel(self, pos_x, pos_y): """draw one pixel""" - self._set_area(x, y, x, y) + self._set_area(pos_x, pos_y, pos_x, pos_y) self.driver.data(self._converted_color(), None) def _set_area(self, x1, y1, x2, y2): """select area to work with""" - self.driver.cmd_data(0x0020, x1) - self.driver.cmd_data(0x0021, y1) - self.driver.cmd_data(0x0050, x1) - self.driver.cmd_data(0x0052, y1) - self.driver.cmd_data(0x0051, x2) - self.driver.cmd_data(0x0053, y2) + self.driver.cmd(0x0020, None) + self.driver.data(x1, None) + self.driver.cmd(0x0021, None) + self.driver.data(y1, None) + self.driver.cmd(0x0050, None) + self.driver.data(x1, None) + self.driver.cmd(0x0052, None) + self.driver.data(y1, None) + self.driver.cmd(0x0051, None) + self.driver.data(x2, None) + self.driver.cmd(0x0053, None) + self.driver.data(y2, None) self.driver.cmd(0x0022, None) - - def _draw_vertical_line(self, x, y, length): + def _draw_vertical_line(self, pos_x, pos_y, length): """draw vertical line""" - self._set_area(x, y, x, y + length) + self._set_area(pos_x, pos_y, pos_x, pos_y + length) color = self._converted_color() for _ in itertools.repeat(None, length): self.driver.data(color, None) - def _draw_horizontal_line(self, x, y, length): + def _draw_horizontal_line(self, pos_x, pos_y, length): """draw horizontal line""" - self._set_area(x, y, x + length, y) + self._set_area(pos_x, pos_y, pos_x + length, pos_y) color = self._converted_color() for _ in itertools.repeat(None, length): self.driver.data(color, None) @@ -83,23 +91,23 @@ class Area(Pixel): length = height / step steps = self._calculate_steps(length, step, height) - dy = 0 - dx = 0 + delta_y = 0 + delta_x = 0 for idx, step in enumerate(steps): if horizontal: self._draw_horizontal_line( - int(x1 + dx), + int(x1 + delta_x), int(y1 + (idx * offset_y)), int(step) ) - dx += step * offset_x + delta_x += step * offset_x else: self._draw_vertical_line( int(x1 + (idx * offset_x)), - int(y1 + dy), + int(y1 + delta_y), int(step) ) - dy += step * offset_y + delta_y += step * offset_y def fill_rect(self, x1, y1, x2, y2): """fill an area""" diff --git a/gfxlcd/driver/ili9325/gpio.py b/gfxlcd/driver/ili9325/gpio.py index afdf757..fa733d7 100644 --- a/gfxlcd/driver/ili9325/gpio.py +++ b/gfxlcd/driver/ili9325/gpio.py @@ -1,11 +1,12 @@ +"""GPIO communication driver""" import time -import RPi.GPIO +import RPi.GPIO # pylint: disable=I0011,F0401 from gfxlcd.abstract.driver import Driver - RPi.GPIO.setmode(RPi.GPIO.BCM) class GPIO(Driver): + """GPIO communication driver""" def __init__(self): self.pins = { 'RS': 27, @@ -46,10 +47,10 @@ class GPIO(Driver): RPi.GPIO.output(self.pins[pin], value) bits >>= 1 - def cmd(self, char, enable): + def cmd(self, data, enable): """send command to display""" RPi.GPIO.output(self.pins['RS'], 0) - self.send(char, enable) + self.send(data, enable) def send(self, char, enable): """send 16bit as 2*8bit""" @@ -64,9 +65,3 @@ class GPIO(Driver): """send data to display""" RPi.GPIO.output(self.pins['RS'], 1) self.send(data, enable) - - def cmd_data(self, cmd, data): - RPi.GPIO.output(self.pins['RS'], 0) - self.send(cmd, None) - RPi.GPIO.output(self.pins['RS'], 1) - self.send(data, None) \ No newline at end of file diff --git a/gfxlcd/driver/ili9325/ili9325.py b/gfxlcd/driver/ili9325/ili9325.py index 8282c8a..b260f01 100644 --- a/gfxlcd/driver/ili9325/ili9325.py +++ b/gfxlcd/driver/ili9325/ili9325.py @@ -1,27 +1,30 @@ +"""ILI9325 chip driver""" import time from gfxlcd.drawing.area import Area from gfxlcd.abstract.chip import Chip class ILI9325(Area, Chip): - """CLass for ILI9325 based LCD""" + """Class for ILI9325 based LCD""" def __init__(self, width, height, driver): Chip.__init__(self, width, height, driver, True) - Area.__init__(self) + Area.__init__(self, driver) def _converted_background_color(self): """color from 8-8-8 to 5-6-5""" rgb = self.options['background_color']['R'] << 16 | \ - self.options['background_color']['G'] << 8 | \ - self.options['background_color']['B'] - return ((rgb & 0x00f80000) >> 8) | ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) + self.options['background_color']['G'] << 8 | \ + self.options['background_color']['B'] + return ((rgb & 0x00f80000) >> 8) |\ + ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) def _converted_color(self): """color from 8-8-8 to 5-6-5""" rgb = self.options['color']['R'] << 16 | \ - self.options['color']['G'] << 8 | \ - self.options['color']['B'] - return ((rgb & 0x00f80000) >> 8) | ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) + self.options['color']['G'] << 8 | \ + self.options['color']['B'] + return ((rgb & 0x00f80000) >> 8) |\ + ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) def init(self): """init display""" diff --git a/gfxlcd/driver/nju6450/gpio.py b/gfxlcd/driver/nju6450/gpio.py index 7f1a27a..56633e2 100644 --- a/gfxlcd/driver/nju6450/gpio.py +++ b/gfxlcd/driver/nju6450/gpio.py @@ -1,5 +1,5 @@ import time -import RPi.GPIO +import RPi.GPIO # pylint: disable=I0011,F0401 from gfxlcd.abstract.driver import Driver RPi.GPIO.setmode(RPi.GPIO.BCM) @@ -44,15 +44,15 @@ class GPIO(Driver): RPi.GPIO.output(self.pins['E1'], 1) RPi.GPIO.output(self.pins['E2'], 1) - def cmd(self, char, enable): + def cmd(self, data, enable): """send command""" RPi.GPIO.output(self.pins['A0'], 0) - self.send(char, enable) + self.send(data, enable) - def data(self, char, enable): + def data(self, data, enable): """send data""" RPi.GPIO.output(self.pins['A0'], 1) - self.send(char, enable) + self.send(data, enable) def send(self, data, enable): """Write to gpio""" @@ -66,4 +66,4 @@ class GPIO(Driver): RPi.GPIO.output(self.pins['E'+str(enable+1)], 1) time.sleep(0.00025) RPi.GPIO.output(self.pins['E1'], 0) - RPi.GPIO.output(self.pins['E2'], 0) \ No newline at end of file + RPi.GPIO.output(self.pins['E2'], 0) diff --git a/gfxlcd/driver/nju6450/nju6450.py b/gfxlcd/driver/nju6450/nju6450.py index cb8128e..6395d19 100644 --- a/gfxlcd/driver/nju6450/nju6450.py +++ b/gfxlcd/driver/nju6450/nju6450.py @@ -1,3 +1,4 @@ +"""NJU6450 chip""" from gfxlcd.drawing.page import Page from gfxlcd.abstract.chip import Chip @@ -20,14 +21,14 @@ class NJU6450(Page, Chip): self.driver.cmd(cmd, 0) self.driver.cmd(cmd, 1) - def set_xy(self, x, y): + def set_xy(self, pos_x, pos_y): """set xy pos""" if x < self.width/2: - self.driver.cmd(0xB8 | y, 0) - self.driver.cmd(0x00 | x, 0) + self.driver.cmd(0xB8 | pos_y, 0) + self.driver.cmd(0x00 | pos_x, 0) else: - self.driver.cmd(0xB8 | y, 1) - self.driver.cmd(0x00 | (x - self.width//2), 1) + self.driver.cmd(0xB8 | pos_y, 1) + self.driver.cmd(0x00 | (pos_x - self.width//2), 1) def _converted_background_color(self): """convert RGB background to available color""" @@ -50,4 +51,4 @@ class NJU6450(Page, Chip): if i < self.width/2: self.driver.data(self.get_page_value(i, j), 0) else: - self.driver.data(self.get_page_value(i, j), 1) \ No newline at end of file + self.driver.data(self.get_page_value(i, j), 1) diff --git a/gfxlcd/driver/ssd1306/spi.py b/gfxlcd/driver/ssd1306/spi.py index 38e8e2c..c4d6f6e 100644 --- a/gfxlcd/driver/ssd1306/spi.py +++ b/gfxlcd/driver/ssd1306/spi.py @@ -1,13 +1,13 @@ -import spidev -import RPi.GPIO as GPIO - - -GPIO.setmode(GPIO.BCM) +"""SPI+GPIO connection driver for SSD1306""" +import spidev # pylint: disable=I0011,F0401 +import RPi.GPIO as GPIO # pylint: disable=I0011,F0401 import time from gfxlcd.abstract.driver import Driver +GPIO.setmode(GPIO.BCM) class SPI(Driver): + """SPI driver""" def __init__(self): self.pins = { 'RST': 13, @@ -22,7 +22,7 @@ class SPI(Driver): GPIO.output(self.pins[pin], 0) spi = spidev.SpiDev() - spi.open(0,0) + spi.open(0, 0) spi.max_speed_hz = 8000000 spi.mode = 0 self.spi = spi @@ -46,4 +46,3 @@ class SPI(Driver): GPIO.output(self.pins['DC'], 1) self.spi.xfer2([data]) GPIO.output(self.pins['DC'], 0) - diff --git a/gfxlcd/driver/ssd1306/ssd1306.py b/gfxlcd/driver/ssd1306/ssd1306.py index 52574f9..942abae 100644 --- a/gfxlcd/driver/ssd1306/ssd1306.py +++ b/gfxlcd/driver/ssd1306/ssd1306.py @@ -1,3 +1,4 @@ +"""SSD1306 chip driver""" from gfxlcd.drawing.page import Page from gfxlcd.abstract.chip import Chip @@ -25,7 +26,7 @@ class SSD1306(Page, Chip): self.driver.cmd(0xb0) # set page address self.driver.cmd(0x81) # set contrast control register self.driver.cmd(0xff) - self.driver.cmd(0xa1) # a0/a1 set segment re-map 127 to 0 a0:0 to seg127 + self.driver.cmd(0xa1) # a0/a1, a1 = segment 127 to 0, a0:0 to seg127 self.driver.cmd(0xc8) # c8/c0 set com(N-1)to com0 c0:com0 to com(N-1) self.driver.cmd(0xa6) # set normal display, a6 - normal, a7 - inverted @@ -70,11 +71,11 @@ class SSD1306(Page, Chip): for i in range(0, self.width): self.driver.data(self.get_page_value(i, j)) - def set_area(self, x1, y1, x2, y2): + def set_area(self, pos_x1, pos_y1, pos_x2, pos_y2): """set area to work on""" self.driver.cmd(0x22) - self.driver.cmd(0xb0 + y1) - self.driver.cmd(0xb0 + y2) + self.driver.cmd(0xb0 + pos_y1) + self.driver.cmd(0xb0 + pos_y2) self.driver.cmd(0x21) - self.driver.cmd(x1) - self.driver.cmd(x2) + self.driver.cmd(pos_x1) + self.driver.cmd(pos_x2) From 736bb0547b3d0ccd7bec9e583d6862f9555317bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 25 Apr 2017 20:46:00 +0200 Subject: [PATCH 4/9] refactoring pep8 & pylint --- gfxlcd/abstract/chip.py | 18 +++++--- gfxlcd/abstract/driver.py | 1 + gfxlcd/drawing/area.py | 66 +++++++++++++------------- gfxlcd/drawing/page.py | 79 ++++++++++++++++---------------- gfxlcd/drawing/pixel.py | 12 ++++- gfxlcd/driver/ili9325/gpio.py | 2 +- gfxlcd/driver/nju6450/gpio.py | 2 + gfxlcd/driver/nju6450/nju6450.py | 4 +- gfxlcd/driver/ssd1306/spi.py | 4 +- gfxlcd/driver/ssd1306/ssd1306.py | 2 +- 10 files changed, 105 insertions(+), 85 deletions(-) diff --git a/gfxlcd/abstract/chip.py b/gfxlcd/abstract/chip.py index f034abe..36eb407 100644 --- a/gfxlcd/abstract/chip.py +++ b/gfxlcd/abstract/chip.py @@ -1,7 +1,9 @@ +"""Chip interface""" import abc class Chip(metaclass=abc.ABCMeta): + """Chip class""" def __init__(self, width, height, driver, auto_flush): self.options = {} self._width = width @@ -31,20 +33,24 @@ class Chip(metaclass=abc.ABCMeta): @property def color(self): + """get RGB colour""" return self.options['color'] @color.setter def color(self, rgb): + """set (R, G, B) colour """ self.options['color'] = { 'R': rgb[0], 'G': rgb[1], 'B': rgb[2] } @property def background_color(self): + """get background colour""" return self.options['background_color'] @background_color.setter def background_color(self, rgb): + """set (R, G, B) background colour """ self.options['background_color'] = { 'R': rgb[0], 'G': rgb[1], 'B': rgb[2] } @@ -65,31 +71,31 @@ class Chip(metaclass=abc.ABCMeta): pass @abc.abstractmethod - def draw_pixel(self, x, y): + def draw_pixel(self, pos_x, pos_y): """draw a pixel at x,y""" pass @abc.abstractmethod - def draw_line(self, x1, y1, x2, y2): + def draw_line(self, pos_x1, pos_y1, pos_x2, pos_y2): """draw a line from point x1,y1 to x2,y2""" pass @abc.abstractmethod - def draw_rect(self, x1, y1, x2, y2): + def draw_rect(self, pos_x1, pos_y1, pos_x2, pos_y2): """draw a rectangle""" pass @abc.abstractmethod - def draw_circle(self, x, y, r): + def draw_circle(self, pos_x, pos_y, radius): """draw a circle""" pass @abc.abstractmethod - def draw_arc(self, x, y, radius, start, end): + def draw_arc(self, pos_x, pos_y, radius, start, end): """draw an arc""" pass @abc.abstractmethod - def fill_rect(self, x1, y1, x2, y2): + def fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2): """draw a filled rectangle""" pass diff --git a/gfxlcd/abstract/driver.py b/gfxlcd/abstract/driver.py index f868593..07876b6 100644 --- a/gfxlcd/abstract/driver.py +++ b/gfxlcd/abstract/driver.py @@ -3,6 +3,7 @@ import abc class Driver(metaclass=abc.ABCMeta): + """Driver interface""" @abc.abstractmethod def init(self): """initialize a device""" diff --git a/gfxlcd/drawing/area.py b/gfxlcd/drawing/area.py index 7c0127f..8fc1d19 100644 --- a/gfxlcd/drawing/area.py +++ b/gfxlcd/drawing/area.py @@ -7,7 +7,7 @@ class Area(Pixel): """Area drawing algorithm""" def __init__(self, driver): self.driver = driver - Pixel.__init__(self) + Pixel.__init__(self, driver) def init(self): """additional initialization""" @@ -18,20 +18,20 @@ class Area(Pixel): self._set_area(pos_x, pos_y, pos_x, pos_y) self.driver.data(self._converted_color(), None) - def _set_area(self, x1, y1, x2, y2): + def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2): """select area to work with""" self.driver.cmd(0x0020, None) - self.driver.data(x1, None) + self.driver.data(pos_x1, None) self.driver.cmd(0x0021, None) - self.driver.data(y1, None) + self.driver.data(pos_y1, None) self.driver.cmd(0x0050, None) - self.driver.data(x1, None) + self.driver.data(pos_x1, None) self.driver.cmd(0x0052, None) - self.driver.data(y1, None) + self.driver.data(pos_y1, None) self.driver.cmd(0x0051, None) - self.driver.data(x2, None) + self.driver.data(pos_x2, None) self.driver.cmd(0x0053, None) - self.driver.data(y2, None) + self.driver.data(pos_y2, None) self.driver.cmd(0x0022, None) def _draw_vertical_line(self, pos_x, pos_y, length): @@ -57,35 +57,35 @@ class Area(Pixel): return steps - def draw_line(self, x1, y1, x2, y2): + def draw_line(self, pos_x1, pos_y1, pos_x2, pos_y2): """draw diagonal line""" - width = abs(x2 - x1) - height = abs(y2 - y1) - if x1 == x2: + width = abs(pos_x2 - pos_x1) + height = abs(pos_y2 - pos_y1) + if pos_x1 == pos_x2: steps = [height] horizontal = False offset_x = offset_y = 0 - elif y1 == y2: + elif pos_y1 == pos_y2: steps = [width] horizontal = True offset_x = offset_y = 0 elif width > height: - if x2 < x1: - x1, x2 = x2, x1 - y1, y2 = y2, y1 - offset_y = 1 if y2 > y1 else -1 - offset_x = 1 if x2 > x1 else -1 + if pos_x2 < pos_x1: + pos_x1, pos_x2 = pos_x2, pos_x1 + pos_y1, pos_y2 = pos_y2, pos_y1 + offset_y = 1 if pos_y2 > pos_y1 else -1 + offset_x = 1 if pos_x2 > pos_x1 else -1 horizontal = True step = height length = width / step steps = self._calculate_steps(length, step, width) else: - if y2 < y1: - x1, x2 = x2, x1 - y1, y2 = y2, y1 - offset_y = 1 if y2 > y1 else -1 - offset_x = 1 if x2 > x1 else -1 + if pos_y2 < pos_y1: + pos_x1, pos_x2 = pos_x2, pos_x1 + pos_y1, pos_y2 = pos_y2, pos_y1 + offset_y = 1 if pos_y2 > pos_y1 else -1 + offset_x = 1 if pos_x2 > pos_x1 else -1 horizontal = False step = width length = height / step @@ -96,27 +96,27 @@ class Area(Pixel): for idx, step in enumerate(steps): if horizontal: self._draw_horizontal_line( - int(x1 + delta_x), - int(y1 + (idx * offset_y)), + int(pos_x1 + delta_x), + int(pos_y1 + (idx * offset_y)), int(step) ) delta_x += step * offset_x else: self._draw_vertical_line( - int(x1 + (idx * offset_x)), - int(y1 + delta_y), + int(pos_x1 + (idx * offset_x)), + int(pos_y1 + delta_y), int(step) ) delta_y += step * offset_y - def fill_rect(self, x1, y1, x2, y2): + def fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2): """fill an area""" - size = (abs(x2 - x1) + 1) * (abs(y2 - y1) + 1) + size = (abs(pos_x2 - pos_x1) + 1) * (abs(pos_y2 - pos_y1) + 1) self._set_area( - min(x1, x2), - min(y1, y2), - max(x1, x2), - max(y1, y2) + min(pos_x1, pos_x2), + min(pos_y1, pos_y2), + max(pos_x1, pos_x2), + max(pos_y1, pos_y2) ) color = self._converted_background_color() for _ in range(0, size): diff --git a/gfxlcd/drawing/page.py b/gfxlcd/drawing/page.py index 0844018..3ed8c57 100644 --- a/gfxlcd/drawing/page.py +++ b/gfxlcd/drawing/page.py @@ -4,17 +4,18 @@ from gfxlcd.drawing.pixel import Pixel class Page(Pixel, metaclass=abc.ABCMeta): """Page drawing algorithm""" - def __init__(self): - Pixel.__init__(self) + def __init__(self, driver): + self.driver = driver + Pixel.__init__(self, driver) self.buffer = [] def init(self): """init page""" self.buffer = [[0] * (self.height // 8) for x in range(self.width)] - def draw_pixel(self, x, y): + def draw_pixel(self, pos_x, pos_y): """draw a pixel at x,y""" - self.buffer[x][y//8] |= 1 << (y % 8) + self.buffer[pos_x][pos_y//8] |= 1 << (pos_y % 8) self.flush() def _calculate_steps(self, length, step, required_length): @@ -26,67 +27,67 @@ class Page(Pixel, metaclass=abc.ABCMeta): return steps - def draw_line(self, x1, y1, x2, y2): + def draw_line(self, pos_x1, pos_y1, pos_x2, pos_y2): """draw diagonal line""" - width = abs(x2 - x1) - height = abs(y2 - y1) - if x1 == x2: + width = abs(pos_x2 - pos_x1) + height = abs(pos_y2 - pos_y1) + if pos_x1 == pos_x2: steps = [height] horizontal = False offset_x = offset_y = 0 - elif y1 == y2: + elif pos_y1 == pos_y2: steps = [width] horizontal = True offset_x = offset_y = 0 elif width > height: - if x2 < x1: - x1, x2 = x2, x1 - y1, y2 = y2, y1 - offset_y = 1 if y2 > y1 else -1 - offset_x = 1 if x2 > x1 else -1 + if pos_x2 < pos_x1: + pos_x1, pos_x2 = pos_x2, pos_x1 + pos_y1, pos_y2 = pos_y2, pos_y1 + offset_y = 1 if pos_y2 > pos_y1 else -1 + offset_x = 1 if pos_x2 > pos_x1 else -1 horizontal = True step = height length = width / step steps = self._calculate_steps(length, step, width) else: - if y2 < y1: - x1, x2 = x2, x1 - y1, y2 = y2, y1 - offset_y = 1 if y2 > y1 else -1 - offset_x = 1 if x2 > x1 else -1 + if pos_y2 < pos_y1: + pos_x1, pos_x2 = pos_x2, pos_x1 + pos_y1, pos_y2 = pos_y2, pos_y1 + offset_y = 1 if pos_y2 > pos_y1 else -1 + offset_x = 1 if pos_x2 > pos_x1 else -1 horizontal = False step = width length = height / step steps = self._calculate_steps(length, step, height) - dy = 0 - dx = 0 + delta_y = 0 + delta_x = 0 for idx, step in enumerate(steps): if horizontal: for appendix in range(int(step)+1): self.draw_pixel( - int(x1 + dx + appendix), - int(y1 + (idx * offset_y)) + int(pos_x1 + delta_x + appendix), + int(pos_y1 + (idx * offset_y)) ) - dx += step * offset_x + delta_x += step * offset_x else: for appendix in range(int(step)+1): self.draw_pixel( - int(x1 + (idx * offset_x)), - int(y1 + dy + appendix) + int(pos_x1 + (idx * offset_x)), + int(pos_y1 + delta_y + appendix) ) - dy += step * offset_y + delta_y += step * offset_y - def fill_rect(self, x1, y1, x2, y2): + def fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2): """draw a filled rectangle""" - if y2 < y1: - y1, y2 = y2, y1 - if x2 < x1: - x1, x2 = x2, x1 - start_page = y1 // 8 - start_bit = y1 % 8 - end_page = y2 // 8 - end_bit = y2 % 8 + if pos_y2 < pos_y1: + pos_y1, pos_y2 = pos_y2, pos_y1 + if pos_x2 < pos_x1: + pos_x1, pos_x2 = pos_x2, pos_x1 + start_page = pos_y1 // 8 + start_bit = pos_y1 % 8 + end_page = pos_y2 // 8 + end_bit = pos_y2 % 8 rows = [] first_page = int(('0' * start_bit).rjust(8, '1'), 2) last_page = int('1' * (end_bit+1), 2) @@ -99,9 +100,9 @@ class Page(Pixel, metaclass=abc.ABCMeta): rows.append(first_page & last_page) page = start_page - for v in rows: - for x in range(x2-x1+1): - self.buffer[x1+x][page] |= v + for value in rows: + for x in range(pos_x2-pos_x1+1): + self.buffer[pos_x1+x][page] |= value page += 1 def get_page_value(self, column, page): diff --git a/gfxlcd/drawing/pixel.py b/gfxlcd/drawing/pixel.py index 2f6e81f..f07383e 100644 --- a/gfxlcd/drawing/pixel.py +++ b/gfxlcd/drawing/pixel.py @@ -1,8 +1,10 @@ +"""Common drawing functions""" import math class Pixel(object): - def __init__(self): + """Pixel class""" + def __init__(self, driver): self.options['color'] = { 'R': 255, 'G': 255, 'B': 255 } @@ -10,6 +12,14 @@ class Pixel(object): 'R': 0, 'G': 0, 'B': 0, } + def draw_pixel(self, pos_x, pos_y): + """dummy fuction""" + pass + + def draw_line(self, pos_x1, pos_y1, pos_x2, pos_y2): + """dummy fuction""" + pass + def draw_rect(self, x1, y1, x2, y2): """draw a rectangle""" self.draw_line(x1, y1, x2, y1) diff --git a/gfxlcd/driver/ili9325/gpio.py b/gfxlcd/driver/ili9325/gpio.py index fa733d7..4da591b 100644 --- a/gfxlcd/driver/ili9325/gpio.py +++ b/gfxlcd/driver/ili9325/gpio.py @@ -1,6 +1,6 @@ """GPIO communication driver""" import time -import RPi.GPIO # 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/gpio.py b/gfxlcd/driver/nju6450/gpio.py index 56633e2..5605e95 100644 --- a/gfxlcd/driver/nju6450/gpio.py +++ b/gfxlcd/driver/nju6450/gpio.py @@ -1,3 +1,4 @@ +"""NJU6450 gpio driver class""" import time import RPi.GPIO # pylint: disable=I0011,F0401 from gfxlcd.abstract.driver import Driver @@ -6,6 +7,7 @@ RPi.GPIO.setmode(RPi.GPIO.BCM) class GPIO(Driver): + """GPIO driver""" def __init__(self): self.pins = { 'A0': 17, diff --git a/gfxlcd/driver/nju6450/nju6450.py b/gfxlcd/driver/nju6450/nju6450.py index 6395d19..200ed15 100644 --- a/gfxlcd/driver/nju6450/nju6450.py +++ b/gfxlcd/driver/nju6450/nju6450.py @@ -7,7 +7,7 @@ class NJU6450(Page, Chip): """Class for an LCD with NJU6450 chip""" def __init__(self, width, height, driver, auto_flush=True): Chip.__init__(self, width, height, driver, auto_flush) - Page.__init__(self) + Page.__init__(self, driver) def init(self): """initialize display""" @@ -23,7 +23,7 @@ class NJU6450(Page, Chip): def set_xy(self, pos_x, pos_y): """set xy pos""" - if x < self.width/2: + if pos_x < self.width/2: self.driver.cmd(0xB8 | pos_y, 0) self.driver.cmd(0x00 | pos_x, 0) else: diff --git a/gfxlcd/driver/ssd1306/spi.py b/gfxlcd/driver/ssd1306/spi.py index c4d6f6e..94aa946 100644 --- a/gfxlcd/driver/ssd1306/spi.py +++ b/gfxlcd/driver/ssd1306/spi.py @@ -1,7 +1,7 @@ """SPI+GPIO connection driver for SSD1306""" -import spidev # pylint: disable=I0011,F0401 -import RPi.GPIO as GPIO # pylint: disable=I0011,F0401 import time +import spidev # pylint: disable=I0011,F0401 +import RPi.GPIO as GPIO # pylint: disable=I0011,F0401 from gfxlcd.abstract.driver import Driver GPIO.setmode(GPIO.BCM) diff --git a/gfxlcd/driver/ssd1306/ssd1306.py b/gfxlcd/driver/ssd1306/ssd1306.py index 942abae..88aff42 100644 --- a/gfxlcd/driver/ssd1306/ssd1306.py +++ b/gfxlcd/driver/ssd1306/ssd1306.py @@ -7,7 +7,7 @@ class SSD1306(Page, Chip): """Class for an LCD with SSD306 chip""" def __init__(self, width, height, driver, auto_flush=True): Chip.__init__(self, width, height, driver, auto_flush) - Page.__init__(self) + Page.__init__(self, driver) def init(self): """inits a device""" From 38a6bee88f217d859c5fb518b667df3fd9db50b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 25 Apr 2017 20:58:35 +0200 Subject: [PATCH 5/9] refactoring pep8 & pylint --- gfxlcd/__init__.py | 3 +- gfxlcd/abstract/__init__.py | 3 +- gfxlcd/demos/ili_2.py | 2 +- gfxlcd/demos/nju_2.py | 2 +- gfxlcd/demos/ssd_2.py | 9 ++++-- gfxlcd/drawing/__init__.py | 3 +- gfxlcd/drawing/page.py | 4 +-- gfxlcd/drawing/pixel.py | 47 ++++++++++++++++--------------- gfxlcd/driver/__init__.py | 3 +- gfxlcd/driver/ili9325/__init__.py | 3 +- gfxlcd/driver/nju6450/__init__.py | 3 +- gfxlcd/driver/nju6450/gpio.py | 2 +- gfxlcd/driver/ssd1306/__init__.py | 3 +- gfxlcd/driver/ssd1306/ssd1306.py | 3 +- 14 files changed, 51 insertions(+), 39 deletions(-) diff --git a/gfxlcd/__init__.py b/gfxlcd/__init__.py index 7c2d50b..3b83c1b 100644 --- a/gfxlcd/__init__.py +++ b/gfxlcd/__init__.py @@ -1 +1,2 @@ -__author__ = 'kosci' +"""GfxLCD module""" +__author__ = 'Bartosz Kosciow' diff --git a/gfxlcd/abstract/__init__.py b/gfxlcd/abstract/__init__.py index 7c2d50b..3dd8799 100644 --- a/gfxlcd/abstract/__init__.py +++ b/gfxlcd/abstract/__init__.py @@ -1 +1,2 @@ -__author__ = 'kosci' +"""abstracts/interfaces""" +__author__ = 'Bartosz Kosciow' \ No newline at end of file diff --git a/gfxlcd/demos/ili_2.py b/gfxlcd/demos/ili_2.py index 6bc7fd1..4d8d91d 100644 --- a/gfxlcd/demos/ili_2.py +++ b/gfxlcd/demos/ili_2.py @@ -1,9 +1,9 @@ import RPi.GPIO import sys +import random sys.path.append("../../") from gfxlcd.driver.ili9325.gpio import GPIO as ILIGPIO from gfxlcd.driver.ili9325.ili9325 import ILI9325 -import random RPi.GPIO.setmode(RPi.GPIO.BCM) diff --git a/gfxlcd/demos/nju_2.py b/gfxlcd/demos/nju_2.py index 52483c0..7b593ac 100644 --- a/gfxlcd/demos/nju_2.py +++ b/gfxlcd/demos/nju_2.py @@ -1,9 +1,9 @@ import RPi.GPIO import sys +import random sys.path.append("../../") from gfxlcd.driver.nju6450.gpio import GPIO from gfxlcd.driver.nju6450.nju6450 import NJU6450 -import random RPi.GPIO.setmode(RPi.GPIO.BCM) diff --git a/gfxlcd/demos/ssd_2.py b/gfxlcd/demos/ssd_2.py index e01ca28..cc7d4b9 100644 --- a/gfxlcd/demos/ssd_2.py +++ b/gfxlcd/demos/ssd_2.py @@ -1,10 +1,10 @@ import RPi.GPIO import sys -RPi.GPIO.setmode(RPi.GPIO.BCM) +import random sys.path.append("../../") from gfxlcd.driver.ssd1306.spi import SPI from gfxlcd.driver.ssd1306.ssd1306 import SSD1306 -import random +RPi.GPIO.setmode(RPi.GPIO.BCM) def hole(o, x, y): @@ -24,7 +24,10 @@ def hole(o, x, y): def draw_points(o): for _ in range(0, 50): - hole(o, random.randint(2, o.width- 10), random.randint(2, o.height-10)) + hole(o, + random.randint(2, o.width - 10), + random.randint(2, o.height - 10) + ) def draw_net(o): diff --git a/gfxlcd/drawing/__init__.py b/gfxlcd/drawing/__init__.py index 7c2d50b..d25812e 100644 --- a/gfxlcd/drawing/__init__.py +++ b/gfxlcd/drawing/__init__.py @@ -1 +1,2 @@ -__author__ = 'kosci' +"""drawing module""" +__author__ = 'Bartosz Kosciow' \ No newline at end of file diff --git a/gfxlcd/drawing/page.py b/gfxlcd/drawing/page.py index 3ed8c57..6e6ca58 100644 --- a/gfxlcd/drawing/page.py +++ b/gfxlcd/drawing/page.py @@ -101,8 +101,8 @@ class Page(Pixel, metaclass=abc.ABCMeta): page = start_page for value in rows: - for x in range(pos_x2-pos_x1+1): - self.buffer[pos_x1+x][page] |= value + for x_diff in range(pos_x2-pos_x1+1): + self.buffer[pos_x1+x_diff][page] |= value page += 1 def get_page_value(self, column, page): diff --git a/gfxlcd/drawing/pixel.py b/gfxlcd/drawing/pixel.py index f07383e..c2c22ac 100644 --- a/gfxlcd/drawing/pixel.py +++ b/gfxlcd/drawing/pixel.py @@ -5,6 +5,7 @@ import math class Pixel(object): """Pixel class""" def __init__(self, driver): + self.driver = driver self.options['color'] = { 'R': 255, 'G': 255, 'B': 255 } @@ -20,27 +21,27 @@ class Pixel(object): """dummy fuction""" pass - def draw_rect(self, x1, y1, x2, y2): + def draw_rect(self, pos_x1, pos_y1, pos_x2, pos_y2): """draw a rectangle""" - self.draw_line(x1, y1, x2, y1) - self.draw_line(x1, y2, x2, y2) - self.draw_line(x1, y1, x1, y2) - self.draw_line(x2, y1, x2, y2) + self.draw_line(pos_x1, pos_y1, pos_x2, pos_y1) + self.draw_line(pos_x1, pos_y2, pos_x2, pos_y2) + self.draw_line(pos_x1, pos_y1, pos_x1, pos_y2) + self.draw_line(pos_x2, pos_y1, pos_x2, pos_y2) - def draw_circle(self, x, y, radius): + def draw_circle(self, pos_x, pos_y, radius): """draw a circle""" err = 0 offset_x = radius offset_y = 0 while offset_x >= offset_y: - self.draw_pixel(x + offset_x, y + offset_y) - self.draw_pixel(x + offset_y, y + offset_x) - self.draw_pixel(x - offset_y, y + offset_x) - self.draw_pixel(x - offset_x, y + offset_y) - self.draw_pixel(x - offset_x, y - offset_y) - self.draw_pixel(x - offset_y, y - offset_x) - self.draw_pixel(x + offset_y, y - offset_x) - self.draw_pixel(x + offset_x, y - offset_y) + self.draw_pixel(pos_x + offset_x, pos_y + offset_y) + self.draw_pixel(pos_x + offset_y, pos_y + offset_x) + self.draw_pixel(pos_x - offset_y, pos_y + offset_x) + self.draw_pixel(pos_x - offset_x, pos_y + offset_y) + self.draw_pixel(pos_x - offset_x, pos_y - offset_y) + self.draw_pixel(pos_x - offset_y, pos_y - offset_x) + self.draw_pixel(pos_x + offset_y, pos_y - offset_x) + self.draw_pixel(pos_x + offset_x, pos_y - offset_y) if err <= 0: offset_y += 1 err += 2*offset_y + 1 @@ -48,7 +49,7 @@ class Pixel(object): offset_x -= 1 err -= 2*offset_x + 1 - def draw_arc(self, x, y, radius, start, end): + def draw_arc(self, pos_x, pos_y, radius, start, end): """draw an arc""" start = start * math.pi / 180 end = end * math.pi / 180 @@ -58,22 +59,22 @@ class Pixel(object): offset_y = 0 while offset_x >= offset_y: if start <= math.atan2(offset_y, offset_x) <= end: - self.draw_pixel(x + offset_x, y + offset_y) + self.draw_pixel(pos_x + offset_x, pos_y + offset_y) if start <= math.atan2(offset_x, offset_y) <= end: - self.draw_pixel(x + offset_y, y + offset_x) + self.draw_pixel(pos_x + offset_y, pos_y + offset_x) if start <= math.atan2(offset_x, -offset_y) <= end: - self.draw_pixel(x - offset_y, y + offset_x) + self.draw_pixel(pos_x - offset_y, pos_y + offset_x) if start <= math.atan2(offset_y, -offset_x) <= end: - self.draw_pixel(x - offset_x, y + offset_y) + self.draw_pixel(pos_x - offset_x, pos_y + offset_y) if start <= math.atan2(-offset_y, -offset_x) + 2*math.pi <= end: - self.draw_pixel(x - offset_x, y - offset_y) + self.draw_pixel(pos_x - offset_x, pos_y - offset_y) if start <= math.atan2(-offset_x, -offset_y) + 2*math.pi <= end: - self.draw_pixel(x - offset_y, y - offset_x) + self.draw_pixel(pos_x - offset_y, pos_y - offset_x) if start <= math.atan2(-offset_x, offset_y) + 2*math.pi <= end: - self.draw_pixel(x + offset_y, y - offset_x) + self.draw_pixel(pos_x + offset_y, pos_y - offset_x) if start <= math.atan2(-offset_y, offset_x) + 2*math.pi <= end: - self.draw_pixel(x + offset_x, y - offset_y) + self.draw_pixel(pos_x + offset_x, pos_y - offset_y) if err <= 0: offset_y += 1 diff --git a/gfxlcd/driver/__init__.py b/gfxlcd/driver/__init__.py index 7c2d50b..9e335e9 100644 --- a/gfxlcd/driver/__init__.py +++ b/gfxlcd/driver/__init__.py @@ -1 +1,2 @@ -__author__ = 'kosci' +"""driver module""" +__author__ = 'Bartosz Kosciow' \ No newline at end of file diff --git a/gfxlcd/driver/ili9325/__init__.py b/gfxlcd/driver/ili9325/__init__.py index 7c2d50b..95e8fad 100644 --- a/gfxlcd/driver/ili9325/__init__.py +++ b/gfxlcd/driver/ili9325/__init__.py @@ -1 +1,2 @@ -__author__ = 'kosci' +"""driver/ili9325 module""" +__author__ = 'Bartosz Kosciow' \ No newline at end of file diff --git a/gfxlcd/driver/nju6450/__init__.py b/gfxlcd/driver/nju6450/__init__.py index 7c2d50b..01b79d8 100644 --- a/gfxlcd/driver/nju6450/__init__.py +++ b/gfxlcd/driver/nju6450/__init__.py @@ -1 +1,2 @@ -__author__ = 'kosci' +"""driver/nju6450 module""" +__author__ = 'Bartosz Kosciow' \ No newline at end of file diff --git a/gfxlcd/driver/nju6450/gpio.py b/gfxlcd/driver/nju6450/gpio.py index 5605e95..b52d09b 100644 --- a/gfxlcd/driver/nju6450/gpio.py +++ b/gfxlcd/driver/nju6450/gpio.py @@ -1,6 +1,6 @@ """NJU6450 gpio driver class""" import time -import RPi.GPIO # 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/ssd1306/__init__.py b/gfxlcd/driver/ssd1306/__init__.py index 7c2d50b..31c4620 100644 --- a/gfxlcd/driver/ssd1306/__init__.py +++ b/gfxlcd/driver/ssd1306/__init__.py @@ -1 +1,2 @@ -__author__ = 'kosci' +"""driver/ssd1306 module""" +__author__ = 'Bartosz Kosciow' \ No newline at end of file diff --git a/gfxlcd/driver/ssd1306/ssd1306.py b/gfxlcd/driver/ssd1306/ssd1306.py index 88aff42..4b595a1 100644 --- a/gfxlcd/driver/ssd1306/ssd1306.py +++ b/gfxlcd/driver/ssd1306/ssd1306.py @@ -36,7 +36,8 @@ class SSD1306(Page, Chip): self.driver.cmd(0xd3) # set display offset self.driver.cmd(0x00) # not offset - self.driver.cmd(0xd5) # set display clock divide ratio/oscillator frequency + # set display clock divide ratio/oscillator frequency + self.driver.cmd(0xd5) self.driver.cmd(0x80) # set divide ratio self.driver.cmd(0xd9) # set pre-charge period From 52bbf25439764a1bcf33c5e89edaa61b25538155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 25 Apr 2017 21:03:46 +0200 Subject: [PATCH 6/9] refactoring pep8 & pylint --- gfxlcd/abstract/__init__.py | 2 +- gfxlcd/drawing/__init__.py | 2 +- gfxlcd/driver/__init__.py | 2 +- gfxlcd/driver/ili9325/__init__.py | 2 +- gfxlcd/driver/nju6450/__init__.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gfxlcd/abstract/__init__.py b/gfxlcd/abstract/__init__.py index 3dd8799..e57ef4e 100644 --- a/gfxlcd/abstract/__init__.py +++ b/gfxlcd/abstract/__init__.py @@ -1,2 +1,2 @@ """abstracts/interfaces""" -__author__ = 'Bartosz Kosciow' \ No newline at end of file +__author__ = 'Bartosz Kosciow' diff --git a/gfxlcd/drawing/__init__.py b/gfxlcd/drawing/__init__.py index d25812e..0dc2844 100644 --- a/gfxlcd/drawing/__init__.py +++ b/gfxlcd/drawing/__init__.py @@ -1,2 +1,2 @@ """drawing module""" -__author__ = 'Bartosz Kosciow' \ No newline at end of file +__author__ = 'Bartosz Kosciow' diff --git a/gfxlcd/driver/__init__.py b/gfxlcd/driver/__init__.py index 9e335e9..88a172e 100644 --- a/gfxlcd/driver/__init__.py +++ b/gfxlcd/driver/__init__.py @@ -1,2 +1,2 @@ """driver module""" -__author__ = 'Bartosz Kosciow' \ No newline at end of file +__author__ = 'Bartosz Kosciow' diff --git a/gfxlcd/driver/ili9325/__init__.py b/gfxlcd/driver/ili9325/__init__.py index 95e8fad..21bc6f7 100644 --- a/gfxlcd/driver/ili9325/__init__.py +++ b/gfxlcd/driver/ili9325/__init__.py @@ -1,2 +1,2 @@ """driver/ili9325 module""" -__author__ = 'Bartosz Kosciow' \ No newline at end of file +__author__ = 'Bartosz Kosciow' diff --git a/gfxlcd/driver/nju6450/__init__.py b/gfxlcd/driver/nju6450/__init__.py index 01b79d8..262f188 100644 --- a/gfxlcd/driver/nju6450/__init__.py +++ b/gfxlcd/driver/nju6450/__init__.py @@ -1,2 +1,2 @@ """driver/nju6450 module""" -__author__ = 'Bartosz Kosciow' \ No newline at end of file +__author__ = 'Bartosz Kosciow' From 5677f3ea22ae4310c2831014c28e4a22eedd0178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 25 Apr 2017 21:22:53 +0200 Subject: [PATCH 7/9] fix demos --- gfxlcd/demos/nju.py | 1 + gfxlcd/demos/ssd.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gfxlcd/demos/nju.py b/gfxlcd/demos/nju.py index 7ad9b09..cc2c3ff 100644 --- a/gfxlcd/demos/nju.py +++ b/gfxlcd/demos/nju.py @@ -1,4 +1,5 @@ import random +sys.path.append("../../") from gfxlcd.driver.nju6450.gpio import GPIO from gfxlcd.driver.nju6450.nju6450 import NJU6450 diff --git a/gfxlcd/demos/ssd.py b/gfxlcd/demos/ssd.py index 1ccd70d..a0ca52b 100644 --- a/gfxlcd/demos/ssd.py +++ b/gfxlcd/demos/ssd.py @@ -1,6 +1,7 @@ import random -from driver.ssd1306.spi import SPI -from driver.ssd1306.ssd1306 import SSD1306 +sys.path.append("../../") +from gfxlcd.driver.ssd1306.spi import SPI +from gfxlcd.driver.ssd1306.ssd1306 import SSD1306 def hole(x, y): From 1f50b69d5886db3c0aeda786e8501618e6a8086f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 25 Apr 2017 21:23:43 +0200 Subject: [PATCH 8/9] fix demos --- gfxlcd/demos/nju.py | 1 + gfxlcd/demos/ssd.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gfxlcd/demos/nju.py b/gfxlcd/demos/nju.py index cc2c3ff..dfbfafc 100644 --- a/gfxlcd/demos/nju.py +++ b/gfxlcd/demos/nju.py @@ -1,4 +1,5 @@ import random +import sys sys.path.append("../../") from gfxlcd.driver.nju6450.gpio import GPIO from gfxlcd.driver.nju6450.nju6450 import NJU6450 diff --git a/gfxlcd/demos/ssd.py b/gfxlcd/demos/ssd.py index a0ca52b..7b666cd 100644 --- a/gfxlcd/demos/ssd.py +++ b/gfxlcd/demos/ssd.py @@ -1,4 +1,5 @@ -import random +import randomimport sys + sys.path.append("../../") from gfxlcd.driver.ssd1306.spi import SPI from gfxlcd.driver.ssd1306.ssd1306 import SSD1306 From 17d540bf154de262861d95c1b5957466841f4344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 25 Apr 2017 21:24:28 +0200 Subject: [PATCH 9/9] fix demos --- gfxlcd/demos/ssd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gfxlcd/demos/ssd.py b/gfxlcd/demos/ssd.py index 7b666cd..74992e7 100644 --- a/gfxlcd/demos/ssd.py +++ b/gfxlcd/demos/ssd.py @@ -1,5 +1,5 @@ -import randomimport sys - +import random +import sys sys.path.append("../../") from gfxlcd.driver.ssd1306.spi import SPI from gfxlcd.driver.ssd1306.ssd1306 import SSD1306