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
|
import abc
|
||||||
|
|
||||||
|
|
||||||
class Chip(metaclass=abc.ABCMeta):
|
class Chip(metaclass=abc.ABCMeta):
|
||||||
|
"""Chip class"""
|
||||||
def __init__(self, width, height, driver, auto_flush):
|
def __init__(self, width, height, driver, auto_flush):
|
||||||
self.options = {}
|
self.options = {}
|
||||||
self._width = width
|
self._width = width
|
||||||
@ -31,20 +33,24 @@ class Chip(metaclass=abc.ABCMeta):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def color(self):
|
def color(self):
|
||||||
|
"""get RGB colour"""
|
||||||
return self.options['color']
|
return self.options['color']
|
||||||
|
|
||||||
@color.setter
|
@color.setter
|
||||||
def color(self, rgb):
|
def color(self, rgb):
|
||||||
|
"""set (R, G, B) colour """
|
||||||
self.options['color'] = {
|
self.options['color'] = {
|
||||||
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def background_color(self):
|
def background_color(self):
|
||||||
|
"""get background colour"""
|
||||||
return self.options['background_color']
|
return self.options['background_color']
|
||||||
|
|
||||||
@background_color.setter
|
@background_color.setter
|
||||||
def background_color(self, rgb):
|
def background_color(self, rgb):
|
||||||
|
"""set (R, G, B) background colour """
|
||||||
self.options['background_color'] = {
|
self.options['background_color'] = {
|
||||||
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
||||||
}
|
}
|
||||||
@ -65,31 +71,31 @@ class Chip(metaclass=abc.ABCMeta):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def draw_pixel(self, x, y):
|
def draw_pixel(self, pos_x, pos_y):
|
||||||
"""draw a pixel at x,y"""
|
"""draw a pixel at x,y"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@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"""
|
"""draw a line from point x1,y1 to x2,y2"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@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"""
|
"""draw a rectangle"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def draw_circle(self, x, y, r):
|
def draw_circle(self, pos_x, pos_y, radius):
|
||||||
"""draw a circle"""
|
"""draw a circle"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@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"""
|
"""draw an arc"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@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"""
|
"""draw a filled rectangle"""
|
||||||
pass
|
pass
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
"""Interface for communication driver"""
|
||||||
import abc
|
import abc
|
||||||
|
|
||||||
|
|
||||||
class Driver(metaclass=abc.ABCMeta):
|
class Driver(metaclass=abc.ABCMeta):
|
||||||
|
"""Driver interface"""
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def init(self):
|
def init(self):
|
||||||
"""initialize a device"""
|
"""initialize a device"""
|
||||||
@ -20,4 +22,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)
|
import random
|
||||||
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
|
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)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import random
|
import random
|
||||||
|
import sys
|
||||||
|
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
|
||||||
|
|
||||||
@ -17,6 +19,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)
|
import random
|
||||||
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
|
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
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import random
|
import random
|
||||||
from driver.ssd1306.spi import SPI
|
import sys
|
||||||
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):
|
def hole(x, y):
|
||||||
@ -18,13 +19,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 +90,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)
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import RPi.GPIO
|
import RPi.GPIO
|
||||||
import sys
|
import sys
|
||||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
import random
|
||||||
sys.path.append("../../")
|
sys.path.append("../../")
|
||||||
from gfxlcd.driver.ssd1306.spi import SPI
|
from gfxlcd.driver.ssd1306.spi import SPI
|
||||||
from gfxlcd.driver.ssd1306.ssd1306 import SSD1306
|
from gfxlcd.driver.ssd1306.ssd1306 import SSD1306
|
||||||
import random
|
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||||
|
|
||||||
|
|
||||||
def hole(o, x, y):
|
def hole(o, x, y):
|
||||||
@ -24,7 +24,10 @@ 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 +40,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 +1,2 @@
|
|||||||
__author__ = 'kosci'
|
"""drawing module"""
|
||||||
|
__author__ = 'Bartosz Kosciow'
|
||||||
|
@ -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):
|
||||||
Pixel.__init__(self)
|
self.driver = driver
|
||||||
|
Pixel.__init__(self, driver)
|
||||||
|
|
||||||
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, pos_x1, pos_y1, pos_x2, pos_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(pos_x1, None)
|
||||||
self.driver.cmd_data(0x0050, x1)
|
self.driver.cmd(0x0021, None)
|
||||||
self.driver.cmd_data(0x0052, y1)
|
self.driver.data(pos_y1, None)
|
||||||
self.driver.cmd_data(0x0051, x2)
|
self.driver.cmd(0x0050, None)
|
||||||
self.driver.cmd_data(0x0053, y2)
|
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)
|
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)
|
||||||
@ -49,66 +57,66 @@ class Area(Pixel):
|
|||||||
|
|
||||||
return steps
|
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"""
|
"""draw diagonal line"""
|
||||||
width = abs(x2 - x1)
|
width = abs(pos_x2 - pos_x1)
|
||||||
height = abs(y2 - y1)
|
height = abs(pos_y2 - pos_y1)
|
||||||
if x1 == x2:
|
if pos_x1 == pos_x2:
|
||||||
steps = [height]
|
steps = [height]
|
||||||
horizontal = False
|
horizontal = False
|
||||||
offset_x = offset_y = 0
|
offset_x = offset_y = 0
|
||||||
elif y1 == y2:
|
elif pos_y1 == pos_y2:
|
||||||
steps = [width]
|
steps = [width]
|
||||||
horizontal = True
|
horizontal = True
|
||||||
offset_x = offset_y = 0
|
offset_x = offset_y = 0
|
||||||
elif width > height:
|
elif width > height:
|
||||||
if x2 < x1:
|
if pos_x2 < pos_x1:
|
||||||
x1, x2 = x2, x1
|
pos_x1, pos_x2 = pos_x2, pos_x1
|
||||||
y1, y2 = y2, y1
|
pos_y1, pos_y2 = pos_y2, pos_y1
|
||||||
offset_y = 1 if y2 > y1 else -1
|
offset_y = 1 if pos_y2 > pos_y1 else -1
|
||||||
offset_x = 1 if x2 > x1 else -1
|
offset_x = 1 if pos_x2 > pos_x1 else -1
|
||||||
horizontal = True
|
horizontal = True
|
||||||
step = height
|
step = height
|
||||||
length = width / step
|
length = width / step
|
||||||
steps = self._calculate_steps(length, step, width)
|
steps = self._calculate_steps(length, step, width)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if y2 < y1:
|
if pos_y2 < pos_y1:
|
||||||
x1, x2 = x2, x1
|
pos_x1, pos_x2 = pos_x2, pos_x1
|
||||||
y1, y2 = y2, y1
|
pos_y1, pos_y2 = pos_y2, pos_y1
|
||||||
offset_y = 1 if y2 > y1 else -1
|
offset_y = 1 if pos_y2 > pos_y1 else -1
|
||||||
offset_x = 1 if x2 > x1 else -1
|
offset_x = 1 if pos_x2 > pos_x1 else -1
|
||||||
horizontal = False
|
horizontal = False
|
||||||
step = width
|
step = width
|
||||||
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(pos_x1 + delta_x),
|
||||||
int(y1 + (idx * offset_y)),
|
int(pos_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(pos_x1 + (idx * offset_x)),
|
||||||
int(y1 + dy),
|
int(pos_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, pos_x1, pos_y1, pos_x2, pos_y2):
|
||||||
"""fill an area"""
|
"""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(
|
self._set_area(
|
||||||
min(x1, x2),
|
min(pos_x1, pos_x2),
|
||||||
min(y1, y2),
|
min(pos_y1, pos_y2),
|
||||||
max(x1, x2),
|
max(pos_x1, pos_x2),
|
||||||
max(y1, y2)
|
max(pos_y1, pos_y2)
|
||||||
)
|
)
|
||||||
color = self._converted_background_color()
|
color = self._converted_background_color()
|
||||||
for _ in range(0, size):
|
for _ in range(0, size):
|
||||||
|
@ -4,17 +4,18 @@ from gfxlcd.drawing.pixel import Pixel
|
|||||||
|
|
||||||
class Page(Pixel, metaclass=abc.ABCMeta):
|
class Page(Pixel, metaclass=abc.ABCMeta):
|
||||||
"""Page drawing algorithm"""
|
"""Page drawing algorithm"""
|
||||||
def __init__(self):
|
def __init__(self, driver):
|
||||||
Pixel.__init__(self)
|
self.driver = driver
|
||||||
|
Pixel.__init__(self, driver)
|
||||||
self.buffer = []
|
self.buffer = []
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""init page"""
|
"""init page"""
|
||||||
self.buffer = [[0] * (self.height // 8) for x in range(self.width)]
|
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"""
|
"""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()
|
self.flush()
|
||||||
|
|
||||||
def _calculate_steps(self, length, step, required_length):
|
def _calculate_steps(self, length, step, required_length):
|
||||||
@ -26,67 +27,67 @@ class Page(Pixel, metaclass=abc.ABCMeta):
|
|||||||
|
|
||||||
return steps
|
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"""
|
"""draw diagonal line"""
|
||||||
width = abs(x2 - x1)
|
width = abs(pos_x2 - pos_x1)
|
||||||
height = abs(y2 - y1)
|
height = abs(pos_y2 - pos_y1)
|
||||||
if x1 == x2:
|
if pos_x1 == pos_x2:
|
||||||
steps = [height]
|
steps = [height]
|
||||||
horizontal = False
|
horizontal = False
|
||||||
offset_x = offset_y = 0
|
offset_x = offset_y = 0
|
||||||
elif y1 == y2:
|
elif pos_y1 == pos_y2:
|
||||||
steps = [width]
|
steps = [width]
|
||||||
horizontal = True
|
horizontal = True
|
||||||
offset_x = offset_y = 0
|
offset_x = offset_y = 0
|
||||||
elif width > height:
|
elif width > height:
|
||||||
if x2 < x1:
|
if pos_x2 < pos_x1:
|
||||||
x1, x2 = x2, x1
|
pos_x1, pos_x2 = pos_x2, pos_x1
|
||||||
y1, y2 = y2, y1
|
pos_y1, pos_y2 = pos_y2, pos_y1
|
||||||
offset_y = 1 if y2 > y1 else -1
|
offset_y = 1 if pos_y2 > pos_y1 else -1
|
||||||
offset_x = 1 if x2 > x1 else -1
|
offset_x = 1 if pos_x2 > pos_x1 else -1
|
||||||
horizontal = True
|
horizontal = True
|
||||||
step = height
|
step = height
|
||||||
length = width / step
|
length = width / step
|
||||||
steps = self._calculate_steps(length, step, width)
|
steps = self._calculate_steps(length, step, width)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if y2 < y1:
|
if pos_y2 < pos_y1:
|
||||||
x1, x2 = x2, x1
|
pos_x1, pos_x2 = pos_x2, pos_x1
|
||||||
y1, y2 = y2, y1
|
pos_y1, pos_y2 = pos_y2, pos_y1
|
||||||
offset_y = 1 if y2 > y1 else -1
|
offset_y = 1 if pos_y2 > pos_y1 else -1
|
||||||
offset_x = 1 if x2 > x1 else -1
|
offset_x = 1 if pos_x2 > pos_x1 else -1
|
||||||
horizontal = False
|
horizontal = False
|
||||||
step = width
|
step = width
|
||||||
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:
|
||||||
for appendix in range(int(step)+1):
|
for appendix in range(int(step)+1):
|
||||||
self.draw_pixel(
|
self.draw_pixel(
|
||||||
int(x1 + dx + appendix),
|
int(pos_x1 + delta_x + appendix),
|
||||||
int(y1 + (idx * offset_y))
|
int(pos_y1 + (idx * offset_y))
|
||||||
)
|
)
|
||||||
dx += step * offset_x
|
delta_x += step * offset_x
|
||||||
else:
|
else:
|
||||||
for appendix in range(int(step)+1):
|
for appendix in range(int(step)+1):
|
||||||
self.draw_pixel(
|
self.draw_pixel(
|
||||||
int(x1 + (idx * offset_x)),
|
int(pos_x1 + (idx * offset_x)),
|
||||||
int(y1 + dy + appendix)
|
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"""
|
"""draw a filled rectangle"""
|
||||||
if y2 < y1:
|
if pos_y2 < pos_y1:
|
||||||
y1, y2 = y2, y1
|
pos_y1, pos_y2 = pos_y2, pos_y1
|
||||||
if x2 < x1:
|
if pos_x2 < pos_x1:
|
||||||
x1, x2 = x2, x1
|
pos_x1, pos_x2 = pos_x2, pos_x1
|
||||||
start_page = y1 // 8
|
start_page = pos_y1 // 8
|
||||||
start_bit = y1 % 8
|
start_bit = pos_y1 % 8
|
||||||
end_page = y2 // 8
|
end_page = pos_y2 // 8
|
||||||
end_bit = y2 % 8
|
end_bit = pos_y2 % 8
|
||||||
rows = []
|
rows = []
|
||||||
first_page = int(('0' * start_bit).rjust(8, '1'), 2)
|
first_page = int(('0' * start_bit).rjust(8, '1'), 2)
|
||||||
last_page = int('1' * (end_bit+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)
|
rows.append(first_page & last_page)
|
||||||
|
|
||||||
page = start_page
|
page = start_page
|
||||||
for v in rows:
|
for value in rows:
|
||||||
for x in range(x2-x1+1):
|
for x_diff in range(pos_x2-pos_x1+1):
|
||||||
self.buffer[x1+x][page] |= v
|
self.buffer[pos_x1+x_diff][page] |= value
|
||||||
page += 1
|
page += 1
|
||||||
|
|
||||||
def get_page_value(self, column, page):
|
def get_page_value(self, column, page):
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
|
"""Common drawing functions"""
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
|
||||||
class Pixel(object):
|
class Pixel(object):
|
||||||
def __init__(self):
|
"""Pixel class"""
|
||||||
|
def __init__(self, driver):
|
||||||
|
self.driver = driver
|
||||||
self.options['color'] = {
|
self.options['color'] = {
|
||||||
'R': 255, 'G': 255, 'B': 255
|
'R': 255, 'G': 255, 'B': 255
|
||||||
}
|
}
|
||||||
@ -10,27 +13,35 @@ class Pixel(object):
|
|||||||
'R': 0, 'G': 0, 'B': 0,
|
'R': 0, 'G': 0, 'B': 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
def draw_rect(self, x1, y1, x2, y2):
|
def draw_pixel(self, pos_x, pos_y):
|
||||||
"""draw a rectangle"""
|
"""dummy fuction"""
|
||||||
self.draw_line(x1, y1, x2, y1)
|
pass
|
||||||
self.draw_line(x1, y2, x2, y2)
|
|
||||||
self.draw_line(x1, y1, x1, y2)
|
|
||||||
self.draw_line(x2, y1, x2, y2)
|
|
||||||
|
|
||||||
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"""
|
"""draw a circle"""
|
||||||
err = 0
|
err = 0
|
||||||
offset_x = radius
|
offset_x = radius
|
||||||
offset_y = 0
|
offset_y = 0
|
||||||
while offset_x >= offset_y:
|
while offset_x >= offset_y:
|
||||||
self.draw_pixel(x + offset_x, y + offset_y)
|
self.draw_pixel(pos_x + offset_x, pos_y + offset_y)
|
||||||
self.draw_pixel(x + offset_y, y + offset_x)
|
self.draw_pixel(pos_x + offset_y, pos_y + offset_x)
|
||||||
self.draw_pixel(x - offset_y, y + offset_x)
|
self.draw_pixel(pos_x - offset_y, pos_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(x - offset_x, y - offset_y)
|
self.draw_pixel(pos_x - offset_x, pos_y - offset_y)
|
||||||
self.draw_pixel(x - offset_y, y - offset_x)
|
self.draw_pixel(pos_x - offset_y, pos_y - offset_x)
|
||||||
self.draw_pixel(x + offset_y, y - offset_x)
|
self.draw_pixel(pos_x + offset_y, pos_y - offset_x)
|
||||||
self.draw_pixel(x + offset_x, y - offset_y)
|
self.draw_pixel(pos_x + offset_x, pos_y - offset_y)
|
||||||
if err <= 0:
|
if err <= 0:
|
||||||
offset_y += 1
|
offset_y += 1
|
||||||
err += 2*offset_y + 1
|
err += 2*offset_y + 1
|
||||||
@ -38,7 +49,7 @@ class Pixel(object):
|
|||||||
offset_x -= 1
|
offset_x -= 1
|
||||||
err -= 2*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"""
|
"""draw an arc"""
|
||||||
start = start * math.pi / 180
|
start = start * math.pi / 180
|
||||||
end = end * math.pi / 180
|
end = end * math.pi / 180
|
||||||
@ -48,22 +59,22 @@ class Pixel(object):
|
|||||||
offset_y = 0
|
offset_y = 0
|
||||||
while offset_x >= offset_y:
|
while offset_x >= offset_y:
|
||||||
if start <= math.atan2(offset_y, offset_x) <= end:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
if err <= 0:
|
||||||
offset_y += 1
|
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 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 +1,2 @@
|
|||||||
__author__ = 'kosci'
|
"""driver/nju6450 module"""
|
||||||
|
__author__ = 'Bartosz Kosciow'
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
|
"""NJU6450 gpio driver class"""
|
||||||
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 driver"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.pins = {
|
self.pins = {
|
||||||
'A0': 17,
|
'A0': 17,
|
||||||
@ -44,15 +46,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 +68,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
|
||||||
|
|
||||||
@ -6,7 +7,7 @@ class NJU6450(Page, Chip):
|
|||||||
"""Class for an LCD with NJU6450 chip"""
|
"""Class for an LCD with NJU6450 chip"""
|
||||||
def __init__(self, width, height, driver, auto_flush=True):
|
def __init__(self, width, height, driver, auto_flush=True):
|
||||||
Chip.__init__(self, width, height, driver, auto_flush)
|
Chip.__init__(self, width, height, driver, auto_flush)
|
||||||
Page.__init__(self)
|
Page.__init__(self, driver)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""initialize display"""
|
"""initialize display"""
|
||||||
@ -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 pos_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 +1,2 @@
|
|||||||
__author__ = 'kosci'
|
"""driver/ssd1306 module"""
|
||||||
|
__author__ = 'Bartosz Kosciow'
|
@ -1,13 +1,13 @@
|
|||||||
import spidev
|
"""SPI+GPIO connection driver for SSD1306"""
|
||||||
import RPi.GPIO as GPIO
|
|
||||||
|
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
|
||||||
import time
|
import time
|
||||||
|
import spidev # pylint: disable=I0011,F0401
|
||||||
|
import RPi.GPIO as GPIO # pylint: disable=I0011,F0401
|
||||||
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
|
||||||
|
|
||||||
@ -6,7 +7,7 @@ class SSD1306(Page, Chip):
|
|||||||
"""Class for an LCD with SSD306 chip"""
|
"""Class for an LCD with SSD306 chip"""
|
||||||
def __init__(self, width, height, driver, auto_flush=True):
|
def __init__(self, width, height, driver, auto_flush=True):
|
||||||
Chip.__init__(self, width, height, driver, auto_flush)
|
Chip.__init__(self, width, height, driver, auto_flush)
|
||||||
Page.__init__(self)
|
Page.__init__(self, driver)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""inits a device"""
|
"""inits a device"""
|
||||||
@ -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
|
||||||
|
|
||||||
@ -35,7 +36,8 @@ class SSD1306(Page, Chip):
|
|||||||
self.driver.cmd(0xd3) # set display offset
|
self.driver.cmd(0xd3) # set display offset
|
||||||
self.driver.cmd(0x00) # not 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(0x80) # set divide ratio
|
||||||
|
|
||||||
self.driver.cmd(0xd9) # set pre-charge period
|
self.driver.cmd(0xd9) # set pre-charge period
|
||||||
@ -70,11 +72,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)
|
||||||
|
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
|
Initialization
|
||||||
===
|
===
|
||||||
##SSD1306
|
## SSD1306
|
||||||
### SPI
|
### SPI
|
||||||
|
|
||||||
from driver.ssd1306.spi import 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 = SSD1306(128, 64, drv)
|
||||||
o.init()
|
o.init()
|
||||||
|
|
||||||
##NJU6450
|
## NJU6450
|
||||||
### GPIO
|
### GPIO
|
||||||
|
|
||||||
from gfxlcd.driver.nju6450.gpio import GPIO
|
from gfxlcd.driver.nju6450.gpio import GPIO
|
||||||
@ -66,7 +66,7 @@ Custom wiring:
|
|||||||
o = NJU6450(122, 32, drv)
|
o = NJU6450(122, 32, drv)
|
||||||
o.init()
|
o.init()
|
||||||
|
|
||||||
##ILI9325
|
## ILI9325
|
||||||
### GPIO
|
### GPIO
|
||||||
|
|
||||||
from gfxlcd.driver.ili9325.gpio import GPIO
|
from gfxlcd.driver.ili9325.gpio import GPIO
|
||||||
@ -99,17 +99,17 @@ Custom pins:
|
|||||||
|
|
||||||
Drawing functions
|
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
|
Colours
|
||||||
@ -121,7 +121,7 @@ lcd.background_color = (r, g ,b)
|
|||||||
Wiring
|
Wiring
|
||||||
===
|
===
|
||||||
|
|
||||||
##SSD1306
|
## SSD1306
|
||||||
### SPI
|
### SPI
|
||||||
SPI wiring + 2 additional pins. Defaults:
|
SPI wiring + 2 additional pins. Defaults:
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ SPI wiring + 2 additional pins. Defaults:
|
|||||||
D/C ----------- G6
|
D/C ----------- G6
|
||||||
|
|
||||||
|
|
||||||
##NJU6450
|
## NJU6450
|
||||||
### GPIO
|
### GPIO
|
||||||
Default wiring:
|
Default wiring:
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ Default wiring:
|
|||||||
17 (A) ------- +5V
|
17 (A) ------- +5V
|
||||||
18 (K) ------- GND
|
18 (K) ------- GND
|
||||||
|
|
||||||
##ILI9325
|
## ILI9325
|
||||||
### GPIO
|
### GPIO
|
||||||
Default:
|
Default:
|
||||||
|
|
||||||
|
4
tox.ini
4
tox.ini
@ -10,8 +10,8 @@ deps=
|
|||||||
flake8
|
flake8
|
||||||
pylint
|
pylint
|
||||||
whitelist_externals = /bin/bash
|
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
|
rm flake8-{envname}.log -f
|
||||||
/bin/bash -c "flake8 --output-file=flake8-{envname}.log gfxlcd || :"
|
/bin/bash -c "flake8 --output-file=flake8-{envname}.log gfxlcd || :"
|
||||||
/bin/bash -c "pylint gfxlcd > pylint-{envname}.log || :"
|
/bin/bash -c "pylint gfxlcd > pylint-{envname}.log || :"
|
||||||
[flake8]
|
[flake8]
|
||||||
|
Loading…
Reference in New Issue
Block a user