commit
d6969a7a1e
@ -1 +1,2 @@
|
||||
__author__ = 'kosci'
|
||||
"""GfxLCD module"""
|
||||
__author__ = 'Bartosz Kosciow'
|
||||
|
@ -1 +1,2 @@
|
||||
__author__ = 'kosci'
|
||||
"""abstracts/interfaces"""
|
||||
__author__ = 'Bartosz Kosciow'
|
||||
|
@ -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
|
||||
|
@ -1,7 +1,9 @@
|
||||
"""Interface for communication driver"""
|
||||
import abc
|
||||
|
||||
|
||||
class Driver(metaclass=abc.ABCMeta):
|
||||
"""Driver interface"""
|
||||
@abc.abstractmethod
|
||||
def init(self):
|
||||
"""initialize a device"""
|
||||
|
@ -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)
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import RPi.GPIO
|
||||
import sys
|
||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||
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)
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
import random
|
||||
import sys
|
||||
sys.path.append("../../")
|
||||
from gfxlcd.driver.nju6450.gpio import GPIO
|
||||
from gfxlcd.driver.nju6450.nju6450 import NJU6450
|
||||
|
||||
@ -17,6 +19,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)
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import RPi.GPIO
|
||||
import sys
|
||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||
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)
|
||||
|
||||
|
||||
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
|
||||
|
@ -1,7 +1,8 @@
|
||||
import random
|
||||
from driver.ssd1306.spi import SPI
|
||||
from driver.ssd1306.ssd1306 import SSD1306
|
||||
|
||||
import sys
|
||||
sys.path.append("../../")
|
||||
from gfxlcd.driver.ssd1306.spi import SPI
|
||||
from gfxlcd.driver.ssd1306.ssd1306 import SSD1306
|
||||
|
||||
|
||||
def hole(x, y):
|
||||
@ -18,13 +19,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 +90,3 @@ o.flush(True)
|
||||
# o.draw_pixels(46, 9, 25)
|
||||
# o.draw_pixels(47, 9, 5)
|
||||
# o.draw_pixels(48, 9, 3)
|
||||
|
||||
|
@ -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):
|
||||
@ -37,6 +40,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
|
||||
|
@ -1 +1,2 @@
|
||||
__author__ = 'kosci'
|
||||
"""drawing module"""
|
||||
__author__ = 'Bartosz Kosciow'
|
||||
|
@ -1,41 +1,49 @@
|
||||
"""Area drawing algorithm"""
|
||||
import itertools
|
||||
from gfxlcd.drawing.pixel import Pixel
|
||||
|
||||
|
||||
class Area(Pixel):
|
||||
"""Page drawing algorithm"""
|
||||
def __init__(self):
|
||||
Pixel.__init__(self)
|
||||
"""Area drawing algorithm"""
|
||||
def __init__(self, driver):
|
||||
self.driver = driver
|
||||
Pixel.__init__(self, driver)
|
||||
|
||||
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):
|
||||
def _set_area(self, pos_x1, pos_y1, pos_x2, pos_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(pos_x1, None)
|
||||
self.driver.cmd(0x0021, None)
|
||||
self.driver.data(pos_y1, None)
|
||||
self.driver.cmd(0x0050, None)
|
||||
self.driver.data(pos_x1, None)
|
||||
self.driver.cmd(0x0052, None)
|
||||
self.driver.data(pos_y1, None)
|
||||
self.driver.cmd(0x0051, None)
|
||||
self.driver.data(pos_x2, None)
|
||||
self.driver.cmd(0x0053, None)
|
||||
self.driver.data(pos_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)
|
||||
@ -49,66 +57,66 @@ 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
|
||||
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(y1 + (idx * offset_y)),
|
||||
int(pos_x1 + delta_x),
|
||||
int(pos_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(pos_x1 + (idx * offset_x)),
|
||||
int(pos_y1 + delta_y),
|
||||
int(step)
|
||||
)
|
||||
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):
|
||||
"""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):
|
||||
|
@ -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_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):
|
||||
|
@ -1,8 +1,11 @@
|
||||
"""Common drawing functions"""
|
||||
import math
|
||||
|
||||
|
||||
class Pixel(object):
|
||||
def __init__(self):
|
||||
"""Pixel class"""
|
||||
def __init__(self, driver):
|
||||
self.driver = driver
|
||||
self.options['color'] = {
|
||||
'R': 255, 'G': 255, 'B': 255
|
||||
}
|
||||
@ -10,27 +13,35 @@ class Pixel(object):
|
||||
'R': 0, 'G': 0, 'B': 0,
|
||||
}
|
||||
|
||||
def draw_rect(self, x1, y1, x2, 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)
|
||||
def draw_pixel(self, pos_x, pos_y):
|
||||
"""dummy fuction"""
|
||||
pass
|
||||
|
||||
def draw_circle(self, x, y, radius):
|
||||
def draw_line(self, pos_x1, pos_y1, pos_x2, pos_y2):
|
||||
"""dummy fuction"""
|
||||
pass
|
||||
|
||||
def draw_rect(self, pos_x1, pos_y1, pos_x2, pos_y2):
|
||||
"""draw a rectangle"""
|
||||
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, 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
|
||||
@ -38,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
|
||||
@ -48,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
|
||||
|
@ -1 +1,2 @@
|
||||
__author__ = 'kosci'
|
||||
"""driver module"""
|
||||
__author__ = 'Bartosz Kosciow'
|
||||
|
@ -1 +1,2 @@
|
||||
__author__ = 'kosci'
|
||||
"""driver/ili9325 module"""
|
||||
__author__ = 'Bartosz Kosciow'
|
||||
|
@ -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)
|
@ -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"""
|
||||
|
@ -1 +1,2 @@
|
||||
__author__ = 'kosci'
|
||||
"""driver/nju6450 module"""
|
||||
__author__ = 'Bartosz Kosciow'
|
||||
|
@ -1,11 +1,13 @@
|
||||
"""NJU6450 gpio driver class"""
|
||||
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 driver"""
|
||||
def __init__(self):
|
||||
self.pins = {
|
||||
'A0': 17,
|
||||
@ -44,15 +46,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"""
|
||||
|
@ -1,3 +1,4 @@
|
||||
"""NJU6450 chip"""
|
||||
from gfxlcd.drawing.page import Page
|
||||
from gfxlcd.abstract.chip import Chip
|
||||
|
||||
@ -6,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"""
|
||||
@ -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)
|
||||
if pos_x < self.width/2:
|
||||
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"""
|
||||
|
@ -1 +1,2 @@
|
||||
__author__ = 'kosci'
|
||||
"""driver/ssd1306 module"""
|
||||
__author__ = 'Bartosz Kosciow'
|
@ -1,13 +1,13 @@
|
||||
import spidev
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
"""SPI+GPIO connection driver for SSD1306"""
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
"""SSD1306 chip driver"""
|
||||
from gfxlcd.drawing.page import Page
|
||||
from gfxlcd.abstract.chip import Chip
|
||||
|
||||
@ -6,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"""
|
||||
@ -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
|
||||
|
||||
@ -35,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
|
||||
@ -70,11 +72,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)
|
||||
|
6
gfxlcd/tests/dummy_test.py
Normal file
6
gfxlcd/tests/dummy_test.py
Normal file
@ -0,0 +1,6 @@
|
||||
from nose.tools import assert_equal
|
||||
|
||||
|
||||
class DummyTest(object):
|
||||
def test_init(self):
|
||||
assert_equal(1, 1)
|
24
readme.md
24
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:
|
||||
|
||||
|
4
tox.ini
4
tox.ini
@ -10,8 +10,8 @@ deps=
|
||||
flake8
|
||||
pylint
|
||||
whitelist_externals = /bin/bash
|
||||
commands= nosetests --with-xunit --xunit-file=junit-{envname}.xml charlcd/tests
|
||||
rm flake8-{envname}.log
|
||||
commands= nosetests --with-xunit --xunit-file=junit-{envname}.xml gfxlcd/tests
|
||||
rm flake8-{envname}.log -f
|
||||
/bin/bash -c "flake8 --output-file=flake8-{envname}.log gfxlcd || :"
|
||||
/bin/bash -c "pylint gfxlcd > pylint-{envname}.log || :"
|
||||
[flake8]
|
||||
|
Loading…
Reference in New Issue
Block a user