fix colours in Page drawing

This commit is contained in:
Bartosz Kościów 2017-07-09 18:44:04 +02:00
parent 7700efdacb
commit 99c68a8363
11 changed files with 44 additions and 33 deletions

View File

@ -1,3 +1,5 @@
0.8.2
- fix background colour in Page drawing
0.8.1
- clean up
0.8.0

View File

@ -41,6 +41,9 @@ class Chip(metaclass=abc.ABCMeta):
@color.setter
def color(self, rgb):
"""set (R, G, B) colour """
if isinstance(rgb, int):
self.options['color'] = rgb
else:
self.options['color'] = {
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
}
@ -53,6 +56,9 @@ class Chip(metaclass=abc.ABCMeta):
@background_color.setter
def background_color(self, rgb):
"""set (R, G, B) background colour """
if isinstance(rgb, int):
self.options['background_color'] = rgb
else:
self.options['background_color'] = {
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
}

View File

@ -16,7 +16,8 @@ def test1():
print(drv.width, drv.height)
lcd = CharLCD(drv.width, drv.height, drv, 0, 0)
lcd.init()
lcd.write('First')
lcd.write('First Line')
lcd.write(' it is not', 0, 0)
lcd.write('HD44780', 6, 3)
lcd.flush()

View File

@ -9,6 +9,8 @@ class Page(Pixel, metaclass=abc.ABCMeta):
self.driver = driver
Pixel.__init__(self, driver)
self.buffer = []
self.options['color'] = 1
self.options['background_color'] = 0
def init(self):
"""init page"""
@ -17,11 +19,21 @@ class Page(Pixel, metaclass=abc.ABCMeta):
else:
self.buffer = [[0] * (self.width // 8) for x in range(self.height)]
def _convert_color(self, color):
"""convert color to available one"""
if color == 0:
return 0
return 1
def draw_pixel(self, pos_x, pos_y, color=None):
"""draw a pixel at x,y"""
if color is None:
color = self.options['color']
self.buffer[pos_x][pos_y//8] |= self._convert_color(color) << (pos_y % 8)
if self._convert_color(color) == 1:
self.buffer[pos_x][pos_y//8] |= 1 << (pos_y % 8)
else:
self.buffer[pos_x][pos_y//8] &= ~(1 << (pos_y % 8))
self.flush()
def draw_line(self, pos_x1, pos_y1, pos_x2, pos_y2):

View File

@ -35,13 +35,6 @@ class NJU6450(Page, Chip):
self.driver.cmd(0xB8 | pos_y, 1)
self.driver.cmd(0x00 | (pos_x - width//2), 1)
def _convert_color(self, color):
"""convert color to avaiable one"""
if color['R'] == 0 and color['G'] == 0 and color['B'] == 0:
return 0
return 1
def flush(self, force=None):
"""flush buffer to device
:force - boolean|None"""

View File

@ -22,13 +22,6 @@ class NullPage(Page, Chip):
Page.init(self)
Chip.init(self)
def _convert_color(self, color):
"""convert color to avaiable one"""
if color['R'] == 0 and color['G'] == 0 and color['B'] == 0:
return 0
return 1
def flush(self, force=None):
"""flush buffer to device
:force - boolean|None"""

View File

@ -76,13 +76,6 @@ class SSD1306(Page, Chip):
self.driver.cmd(0x14) # enable charge pump
self.driver.cmd(0xaf) # turn on panel
def _convert_color(self, color):
"""convert color to avaiable one"""
if color['R'] == 0 and color['G'] == 0 and color['B'] == 0:
return 0
return 1
def flush(self, force=None):
"""flush buffer to device
:force - boolean|None"""

View File

@ -216,6 +216,17 @@ class TestPageDrawing(object):
buffer[5][1] = 8
assert_equal(self.lcd.buffer, buffer)
def test_draw_pixels_clear_then(self):
self.lcd.draw_pixel(1, 1)
self.lcd.draw_pixel(2, 1)
self.lcd.draw_pixel(2, 2)
buffer = self.get_buffer()
buffer[2][0] = 4
self.lcd.draw_pixel(1, 1, self.lcd.background_color)
self.lcd.draw_pixel(2, 1, self.lcd.background_color)
self.draw_buffer(self.lcd.buffer)
assert_equal(self.lcd.buffer, buffer)
def draw_buffer(self, buffer):
for page in range(2):
print(page)

View File

@ -1,4 +1,4 @@
[bdist_wheel]
universal = 1
universal = 0
[metadata]
description-file = readme.md

View File

@ -13,7 +13,7 @@ def read(*paths):
setup(
name='gfxlcd',
version='0.8.1',
version='0.8.2',
description='gfxlcd is a handler for graphical lcds: ILI9328, SSD1306, NJU6450, touch panel: AD7843 @ Raspberry Pi.',
keywords=[
'gfxlcd', 'raspberry pi' ,'ili9328' ,'ssd1306', 'nju6450', 'lcd', 'graphical lcd', 'touch panel', 'ad7843',

2
tests3
View File

@ -1,2 +1,2 @@
chmod 644 gfxlcd/tests/*.py
python3 -m nose --with-specplugin
python3 -m nose --with-specplugin $1