refactoring pep8 & pylint
This commit is contained in:
parent
fc2e61c312
commit
af1ae95a53
@ -1,3 +1,4 @@
|
|||||||
|
"""Interface for communication driver"""
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
|
|
||||||
@ -20,4 +21,4 @@ class Driver(metaclass=abc.ABCMeta):
|
|||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def data(self, data, enable):
|
def data(self, data, enable):
|
||||||
"""sends data to device"""
|
"""sends data to device"""
|
||||||
pass
|
pass
|
||||||
|
@ -29,6 +29,7 @@ def draw_net(o):
|
|||||||
o.draw_line(0, s, o.width-1, s)
|
o.draw_line(0, s, o.width-1, s)
|
||||||
s += 10
|
s += 10
|
||||||
|
|
||||||
|
|
||||||
drv = GPIO()
|
drv = GPIO()
|
||||||
o = ILI9325(240, 320, drv)
|
o = ILI9325(240, 320, drv)
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import RPi.GPIO
|
import RPi.GPIO
|
||||||
import sys
|
import sys
|
||||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
|
||||||
sys.path.append("../../")
|
sys.path.append("../../")
|
||||||
from gfxlcd.driver.ili9325.gpio import GPIO as ILIGPIO
|
from gfxlcd.driver.ili9325.gpio import GPIO as ILIGPIO
|
||||||
from gfxlcd.driver.ili9325.ili9325 import ILI9325
|
from gfxlcd.driver.ili9325.ili9325 import ILI9325
|
||||||
import random
|
import random
|
||||||
|
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||||
|
|
||||||
|
|
||||||
def hole(o, x, y):
|
def hole(o, x, y):
|
||||||
@ -24,7 +24,7 @@ def hole(o, x, y):
|
|||||||
|
|
||||||
def draw_points(o):
|
def draw_points(o):
|
||||||
for _ in range(0, 50):
|
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):
|
def draw_net(o):
|
||||||
@ -37,6 +37,7 @@ def draw_net(o):
|
|||||||
o.draw_line(0, s, o.width-1, s)
|
o.draw_line(0, s, o.width-1, s)
|
||||||
s += 10
|
s += 10
|
||||||
|
|
||||||
|
|
||||||
lcd_tft = ILI9325(240, 320, ILIGPIO())
|
lcd_tft = ILI9325(240, 320, ILIGPIO())
|
||||||
lcd_tft.init()
|
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.draw_arc(131, 235, 5, 45, 135)
|
||||||
lcd_tft.fill_rect(195, 204, 205, 210)
|
lcd_tft.fill_rect(195, 204, 205, 210)
|
||||||
lcd_tft.draw_rect(180, 210, 220, 225)
|
lcd_tft.draw_rect(180, 210, 220, 225)
|
||||||
lcd_tft.fill_rect(180, 226, 220, 259)
|
lcd_tft.fill_rect(180, 226, 220, 259)
|
||||||
|
@ -17,6 +17,7 @@ def hole(x, y):
|
|||||||
o.draw_pixel(x, y + 3)
|
o.draw_pixel(x, y + 3)
|
||||||
o.draw_pixel(x+4, y + 3)
|
o.draw_pixel(x+4, y + 3)
|
||||||
|
|
||||||
|
|
||||||
drv = GPIO()
|
drv = GPIO()
|
||||||
o = NJU6450(122, 32, drv)
|
o = NJU6450(122, 32, drv)
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import RPi.GPIO
|
import RPi.GPIO
|
||||||
import sys
|
import sys
|
||||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
|
||||||
sys.path.append("../../")
|
sys.path.append("../../")
|
||||||
from gfxlcd.driver.nju6450.gpio import GPIO
|
from gfxlcd.driver.nju6450.gpio import GPIO
|
||||||
from gfxlcd.driver.nju6450.nju6450 import NJU6450
|
from gfxlcd.driver.nju6450.nju6450 import NJU6450
|
||||||
import random
|
import random
|
||||||
|
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||||
|
|
||||||
|
|
||||||
def hole(o, x, y):
|
def hole(o, x, y):
|
||||||
@ -24,7 +24,7 @@ def hole(o, x, y):
|
|||||||
|
|
||||||
def draw_points(o):
|
def draw_points(o):
|
||||||
for _ in range(0, 50):
|
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):
|
def draw_net(o):
|
||||||
@ -37,6 +37,7 @@ def draw_net(o):
|
|||||||
o.draw_line(0, s, o.width-1, s)
|
o.draw_line(0, s, o.width-1, s)
|
||||||
s += 10
|
s += 10
|
||||||
|
|
||||||
|
|
||||||
lcd_nju = NJU6450(122, 32, GPIO())
|
lcd_nju = NJU6450(122, 32, GPIO())
|
||||||
lcd_nju.init()
|
lcd_nju.init()
|
||||||
lcd_nju.auto_flush = False
|
lcd_nju.auto_flush = False
|
||||||
|
@ -3,7 +3,6 @@ from driver.ssd1306.spi import SPI
|
|||||||
from driver.ssd1306.ssd1306 import SSD1306
|
from driver.ssd1306.ssd1306 import SSD1306
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def hole(x, y):
|
def hole(x, y):
|
||||||
o.draw_pixel(x+1, y)
|
o.draw_pixel(x+1, y)
|
||||||
o.draw_pixel(x+2, 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, y + 3)
|
||||||
o.draw_pixel(x+4, y + 3)
|
o.draw_pixel(x+4, y + 3)
|
||||||
|
|
||||||
|
|
||||||
drv = SPI()
|
drv = SPI()
|
||||||
o = SSD1306(128, 64, drv)
|
o = SSD1306(128, 64, drv)
|
||||||
|
|
||||||
o.init()
|
o.init()
|
||||||
o.auto_flush = False
|
o.auto_flush = False
|
||||||
for _ in range(0, 50):
|
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(10, 10)
|
||||||
hole(15, 13)
|
hole(15, 13)
|
||||||
hole(18, 23)
|
hole(18, 23)
|
||||||
@ -87,4 +88,3 @@ o.flush(True)
|
|||||||
# o.draw_pixels(46, 9, 25)
|
# o.draw_pixels(46, 9, 25)
|
||||||
# o.draw_pixels(47, 9, 5)
|
# o.draw_pixels(47, 9, 5)
|
||||||
# o.draw_pixels(48, 9, 3)
|
# o.draw_pixels(48, 9, 3)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ def hole(o, x, y):
|
|||||||
|
|
||||||
def draw_points(o):
|
def draw_points(o):
|
||||||
for _ in range(0, 50):
|
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):
|
def draw_net(o):
|
||||||
@ -37,6 +37,7 @@ def draw_net(o):
|
|||||||
o.draw_line(0, s, o.width-1, s)
|
o.draw_line(0, s, o.width-1, s)
|
||||||
s += 10
|
s += 10
|
||||||
|
|
||||||
|
|
||||||
lcd_oled = SSD1306(128, 64, SPI())
|
lcd_oled = SSD1306(128, 64, SPI())
|
||||||
lcd_oled.init()
|
lcd_oled.init()
|
||||||
lcd_oled.auto_flush = False
|
lcd_oled.auto_flush = False
|
||||||
|
@ -1,41 +1,49 @@
|
|||||||
|
"""Area drawing algorithm"""
|
||||||
import itertools
|
import itertools
|
||||||
from gfxlcd.drawing.pixel import Pixel
|
from gfxlcd.drawing.pixel import Pixel
|
||||||
|
|
||||||
|
|
||||||
class Area(Pixel):
|
class Area(Pixel):
|
||||||
"""Page drawing algorithm"""
|
"""Area drawing algorithm"""
|
||||||
def __init__(self):
|
def __init__(self, driver):
|
||||||
|
self.driver = driver
|
||||||
Pixel.__init__(self)
|
Pixel.__init__(self)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
|
"""additional initialization"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def draw_pixel(self, x, y):
|
def draw_pixel(self, pos_x, pos_y):
|
||||||
"""draw one pixel"""
|
"""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)
|
self.driver.data(self._converted_color(), None)
|
||||||
|
|
||||||
def _set_area(self, x1, y1, x2, y2):
|
def _set_area(self, x1, y1, x2, y2):
|
||||||
"""select area to work with"""
|
"""select area to work with"""
|
||||||
self.driver.cmd_data(0x0020, x1)
|
self.driver.cmd(0x0020, None)
|
||||||
self.driver.cmd_data(0x0021, y1)
|
self.driver.data(x1, None)
|
||||||
self.driver.cmd_data(0x0050, x1)
|
self.driver.cmd(0x0021, None)
|
||||||
self.driver.cmd_data(0x0052, y1)
|
self.driver.data(y1, None)
|
||||||
self.driver.cmd_data(0x0051, x2)
|
self.driver.cmd(0x0050, None)
|
||||||
self.driver.cmd_data(0x0053, y2)
|
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)
|
self.driver.cmd(0x0022, None)
|
||||||
|
|
||||||
|
def _draw_vertical_line(self, pos_x, pos_y, length):
|
||||||
def _draw_vertical_line(self, x, y, length):
|
|
||||||
"""draw vertical line"""
|
"""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()
|
color = self._converted_color()
|
||||||
for _ in itertools.repeat(None, length):
|
for _ in itertools.repeat(None, length):
|
||||||
self.driver.data(color, None)
|
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"""
|
"""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()
|
color = self._converted_color()
|
||||||
for _ in itertools.repeat(None, length):
|
for _ in itertools.repeat(None, length):
|
||||||
self.driver.data(color, None)
|
self.driver.data(color, None)
|
||||||
@ -83,23 +91,23 @@ class Area(Pixel):
|
|||||||
length = height / step
|
length = height / step
|
||||||
steps = self._calculate_steps(length, step, height)
|
steps = self._calculate_steps(length, step, height)
|
||||||
|
|
||||||
dy = 0
|
delta_y = 0
|
||||||
dx = 0
|
delta_x = 0
|
||||||
for idx, step in enumerate(steps):
|
for idx, step in enumerate(steps):
|
||||||
if horizontal:
|
if horizontal:
|
||||||
self._draw_horizontal_line(
|
self._draw_horizontal_line(
|
||||||
int(x1 + dx),
|
int(x1 + delta_x),
|
||||||
int(y1 + (idx * offset_y)),
|
int(y1 + (idx * offset_y)),
|
||||||
int(step)
|
int(step)
|
||||||
)
|
)
|
||||||
dx += step * offset_x
|
delta_x += step * offset_x
|
||||||
else:
|
else:
|
||||||
self._draw_vertical_line(
|
self._draw_vertical_line(
|
||||||
int(x1 + (idx * offset_x)),
|
int(x1 + (idx * offset_x)),
|
||||||
int(y1 + dy),
|
int(y1 + delta_y),
|
||||||
int(step)
|
int(step)
|
||||||
)
|
)
|
||||||
dy += step * offset_y
|
delta_y += step * offset_y
|
||||||
|
|
||||||
def fill_rect(self, x1, y1, x2, y2):
|
def fill_rect(self, x1, y1, x2, y2):
|
||||||
"""fill an area"""
|
"""fill an area"""
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
|
"""GPIO communication driver"""
|
||||||
import time
|
import time
|
||||||
import RPi.GPIO
|
import RPi.GPIO # pylint: disable=I0011,F0401
|
||||||
from gfxlcd.abstract.driver import Driver
|
from gfxlcd.abstract.driver import Driver
|
||||||
|
|
||||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||||
|
|
||||||
|
|
||||||
class GPIO(Driver):
|
class GPIO(Driver):
|
||||||
|
"""GPIO communication driver"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.pins = {
|
self.pins = {
|
||||||
'RS': 27,
|
'RS': 27,
|
||||||
@ -46,10 +47,10 @@ class GPIO(Driver):
|
|||||||
RPi.GPIO.output(self.pins[pin], value)
|
RPi.GPIO.output(self.pins[pin], value)
|
||||||
bits >>= 1
|
bits >>= 1
|
||||||
|
|
||||||
def cmd(self, char, enable):
|
def cmd(self, data, enable):
|
||||||
"""send command to display"""
|
"""send command to display"""
|
||||||
RPi.GPIO.output(self.pins['RS'], 0)
|
RPi.GPIO.output(self.pins['RS'], 0)
|
||||||
self.send(char, enable)
|
self.send(data, enable)
|
||||||
|
|
||||||
def send(self, char, enable):
|
def send(self, char, enable):
|
||||||
"""send 16bit as 2*8bit"""
|
"""send 16bit as 2*8bit"""
|
||||||
@ -64,9 +65,3 @@ class GPIO(Driver):
|
|||||||
"""send data to display"""
|
"""send data to display"""
|
||||||
RPi.GPIO.output(self.pins['RS'], 1)
|
RPi.GPIO.output(self.pins['RS'], 1)
|
||||||
self.send(data, enable)
|
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)
|
|
@ -1,27 +1,30 @@
|
|||||||
|
"""ILI9325 chip driver"""
|
||||||
import time
|
import time
|
||||||
from gfxlcd.drawing.area import Area
|
from gfxlcd.drawing.area import Area
|
||||||
from gfxlcd.abstract.chip import Chip
|
from gfxlcd.abstract.chip import Chip
|
||||||
|
|
||||||
|
|
||||||
class ILI9325(Area, Chip):
|
class ILI9325(Area, Chip):
|
||||||
"""CLass for ILI9325 based LCD"""
|
"""Class for ILI9325 based LCD"""
|
||||||
def __init__(self, width, height, driver):
|
def __init__(self, width, height, driver):
|
||||||
Chip.__init__(self, width, height, driver, True)
|
Chip.__init__(self, width, height, driver, True)
|
||||||
Area.__init__(self)
|
Area.__init__(self, driver)
|
||||||
|
|
||||||
def _converted_background_color(self):
|
def _converted_background_color(self):
|
||||||
"""color from 8-8-8 to 5-6-5"""
|
"""color from 8-8-8 to 5-6-5"""
|
||||||
rgb = self.options['background_color']['R'] << 16 | \
|
rgb = self.options['background_color']['R'] << 16 | \
|
||||||
self.options['background_color']['G'] << 8 | \
|
self.options['background_color']['G'] << 8 | \
|
||||||
self.options['background_color']['B']
|
self.options['background_color']['B']
|
||||||
return ((rgb & 0x00f80000) >> 8) | ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3)
|
return ((rgb & 0x00f80000) >> 8) |\
|
||||||
|
((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3)
|
||||||
|
|
||||||
def _converted_color(self):
|
def _converted_color(self):
|
||||||
"""color from 8-8-8 to 5-6-5"""
|
"""color from 8-8-8 to 5-6-5"""
|
||||||
rgb = self.options['color']['R'] << 16 | \
|
rgb = self.options['color']['R'] << 16 | \
|
||||||
self.options['color']['G'] << 8 | \
|
self.options['color']['G'] << 8 | \
|
||||||
self.options['color']['B']
|
self.options['color']['B']
|
||||||
return ((rgb & 0x00f80000) >> 8) | ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3)
|
return ((rgb & 0x00f80000) >> 8) |\
|
||||||
|
((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""init display"""
|
"""init display"""
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import time
|
import time
|
||||||
import RPi.GPIO
|
import RPi.GPIO # pylint: disable=I0011,F0401
|
||||||
from gfxlcd.abstract.driver import Driver
|
from gfxlcd.abstract.driver import Driver
|
||||||
|
|
||||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
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['E1'], 1)
|
||||||
RPi.GPIO.output(self.pins['E2'], 1)
|
RPi.GPIO.output(self.pins['E2'], 1)
|
||||||
|
|
||||||
def cmd(self, char, enable):
|
def cmd(self, data, enable):
|
||||||
"""send command"""
|
"""send command"""
|
||||||
RPi.GPIO.output(self.pins['A0'], 0)
|
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"""
|
"""send data"""
|
||||||
RPi.GPIO.output(self.pins['A0'], 1)
|
RPi.GPIO.output(self.pins['A0'], 1)
|
||||||
self.send(char, enable)
|
self.send(data, enable)
|
||||||
|
|
||||||
def send(self, data, enable):
|
def send(self, data, enable):
|
||||||
"""Write to gpio"""
|
"""Write to gpio"""
|
||||||
@ -66,4 +66,4 @@ class GPIO(Driver):
|
|||||||
RPi.GPIO.output(self.pins['E'+str(enable+1)], 1)
|
RPi.GPIO.output(self.pins['E'+str(enable+1)], 1)
|
||||||
time.sleep(0.00025)
|
time.sleep(0.00025)
|
||||||
RPi.GPIO.output(self.pins['E1'], 0)
|
RPi.GPIO.output(self.pins['E1'], 0)
|
||||||
RPi.GPIO.output(self.pins['E2'], 0)
|
RPi.GPIO.output(self.pins['E2'], 0)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
"""NJU6450 chip"""
|
||||||
from gfxlcd.drawing.page import Page
|
from gfxlcd.drawing.page import Page
|
||||||
from gfxlcd.abstract.chip import Chip
|
from gfxlcd.abstract.chip import Chip
|
||||||
|
|
||||||
@ -20,14 +21,14 @@ class NJU6450(Page, Chip):
|
|||||||
self.driver.cmd(cmd, 0)
|
self.driver.cmd(cmd, 0)
|
||||||
self.driver.cmd(cmd, 1)
|
self.driver.cmd(cmd, 1)
|
||||||
|
|
||||||
def set_xy(self, x, y):
|
def set_xy(self, pos_x, pos_y):
|
||||||
"""set xy pos"""
|
"""set xy pos"""
|
||||||
if x < self.width/2:
|
if x < self.width/2:
|
||||||
self.driver.cmd(0xB8 | y, 0)
|
self.driver.cmd(0xB8 | pos_y, 0)
|
||||||
self.driver.cmd(0x00 | x, 0)
|
self.driver.cmd(0x00 | pos_x, 0)
|
||||||
else:
|
else:
|
||||||
self.driver.cmd(0xB8 | y, 1)
|
self.driver.cmd(0xB8 | pos_y, 1)
|
||||||
self.driver.cmd(0x00 | (x - self.width//2), 1)
|
self.driver.cmd(0x00 | (pos_x - self.width//2), 1)
|
||||||
|
|
||||||
def _converted_background_color(self):
|
def _converted_background_color(self):
|
||||||
"""convert RGB background to available color"""
|
"""convert RGB background to available color"""
|
||||||
@ -50,4 +51,4 @@ class NJU6450(Page, Chip):
|
|||||||
if i < self.width/2:
|
if i < self.width/2:
|
||||||
self.driver.data(self.get_page_value(i, j), 0)
|
self.driver.data(self.get_page_value(i, j), 0)
|
||||||
else:
|
else:
|
||||||
self.driver.data(self.get_page_value(i, j), 1)
|
self.driver.data(self.get_page_value(i, j), 1)
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import spidev
|
"""SPI+GPIO connection driver for SSD1306"""
|
||||||
import RPi.GPIO as GPIO
|
import spidev # pylint: disable=I0011,F0401
|
||||||
|
import RPi.GPIO as GPIO # pylint: disable=I0011,F0401
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
|
||||||
import time
|
import time
|
||||||
from gfxlcd.abstract.driver import Driver
|
from gfxlcd.abstract.driver import Driver
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
|
|
||||||
class SPI(Driver):
|
class SPI(Driver):
|
||||||
|
"""SPI driver"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.pins = {
|
self.pins = {
|
||||||
'RST': 13,
|
'RST': 13,
|
||||||
@ -22,7 +22,7 @@ class SPI(Driver):
|
|||||||
GPIO.output(self.pins[pin], 0)
|
GPIO.output(self.pins[pin], 0)
|
||||||
|
|
||||||
spi = spidev.SpiDev()
|
spi = spidev.SpiDev()
|
||||||
spi.open(0,0)
|
spi.open(0, 0)
|
||||||
spi.max_speed_hz = 8000000
|
spi.max_speed_hz = 8000000
|
||||||
spi.mode = 0
|
spi.mode = 0
|
||||||
self.spi = spi
|
self.spi = spi
|
||||||
@ -46,4 +46,3 @@ class SPI(Driver):
|
|||||||
GPIO.output(self.pins['DC'], 1)
|
GPIO.output(self.pins['DC'], 1)
|
||||||
self.spi.xfer2([data])
|
self.spi.xfer2([data])
|
||||||
GPIO.output(self.pins['DC'], 0)
|
GPIO.output(self.pins['DC'], 0)
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
"""SSD1306 chip driver"""
|
||||||
from gfxlcd.drawing.page import Page
|
from gfxlcd.drawing.page import Page
|
||||||
from gfxlcd.abstract.chip import Chip
|
from gfxlcd.abstract.chip import Chip
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ class SSD1306(Page, Chip):
|
|||||||
self.driver.cmd(0xb0) # set page address
|
self.driver.cmd(0xb0) # set page address
|
||||||
self.driver.cmd(0x81) # set contrast control register
|
self.driver.cmd(0x81) # set contrast control register
|
||||||
self.driver.cmd(0xff)
|
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(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
|
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):
|
for i in range(0, self.width):
|
||||||
self.driver.data(self.get_page_value(i, j))
|
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"""
|
"""set area to work on"""
|
||||||
self.driver.cmd(0x22)
|
self.driver.cmd(0x22)
|
||||||
self.driver.cmd(0xb0 + y1)
|
self.driver.cmd(0xb0 + pos_y1)
|
||||||
self.driver.cmd(0xb0 + y2)
|
self.driver.cmd(0xb0 + pos_y2)
|
||||||
self.driver.cmd(0x21)
|
self.driver.cmd(0x21)
|
||||||
self.driver.cmd(x1)
|
self.driver.cmd(pos_x1)
|
||||||
self.driver.cmd(x2)
|
self.driver.cmd(pos_x2)
|
||||||
|
Loading…
Reference in New Issue
Block a user