fix colours in Page drawing
This commit is contained in:
parent
7700efdacb
commit
99c68a8363
@ -1,3 +1,5 @@
|
|||||||
|
0.8.2
|
||||||
|
- fix background colour in Page drawing
|
||||||
0.8.1
|
0.8.1
|
||||||
- clean up
|
- clean up
|
||||||
0.8.0
|
0.8.0
|
||||||
|
@ -41,9 +41,12 @@ class Chip(metaclass=abc.ABCMeta):
|
|||||||
@color.setter
|
@color.setter
|
||||||
def color(self, rgb):
|
def color(self, rgb):
|
||||||
"""set (R, G, B) colour """
|
"""set (R, G, B) colour """
|
||||||
self.options['color'] = {
|
if isinstance(rgb, int):
|
||||||
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
self.options['color'] = rgb
|
||||||
}
|
else:
|
||||||
|
self.options['color'] = {
|
||||||
|
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def background_color(self):
|
def background_color(self):
|
||||||
@ -53,9 +56,12 @@ class Chip(metaclass=abc.ABCMeta):
|
|||||||
@background_color.setter
|
@background_color.setter
|
||||||
def background_color(self, rgb):
|
def background_color(self, rgb):
|
||||||
"""set (R, G, B) background colour """
|
"""set (R, G, B) background colour """
|
||||||
self.options['background_color'] = {
|
if isinstance(rgb, int):
|
||||||
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
self.options['background_color'] = rgb
|
||||||
}
|
else:
|
||||||
|
self.options['background_color'] = {
|
||||||
|
'R': rgb[0], 'G': rgb[1], 'B': rgb[2]
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def auto_flush(self):
|
def auto_flush(self):
|
||||||
|
@ -16,7 +16,8 @@ def test1():
|
|||||||
print(drv.width, drv.height)
|
print(drv.width, drv.height)
|
||||||
lcd = CharLCD(drv.width, drv.height, drv, 0, 0)
|
lcd = CharLCD(drv.width, drv.height, drv, 0, 0)
|
||||||
lcd.init()
|
lcd.init()
|
||||||
lcd.write('First')
|
lcd.write('First Line')
|
||||||
|
lcd.write(' it is not', 0, 0)
|
||||||
|
|
||||||
lcd.write('HD44780', 6, 3)
|
lcd.write('HD44780', 6, 3)
|
||||||
lcd.flush()
|
lcd.flush()
|
||||||
|
@ -9,6 +9,8 @@ class Page(Pixel, metaclass=abc.ABCMeta):
|
|||||||
self.driver = driver
|
self.driver = driver
|
||||||
Pixel.__init__(self, driver)
|
Pixel.__init__(self, driver)
|
||||||
self.buffer = []
|
self.buffer = []
|
||||||
|
self.options['color'] = 1
|
||||||
|
self.options['background_color'] = 0
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""init page"""
|
"""init page"""
|
||||||
@ -17,11 +19,21 @@ class Page(Pixel, metaclass=abc.ABCMeta):
|
|||||||
else:
|
else:
|
||||||
self.buffer = [[0] * (self.width // 8) for x in range(self.height)]
|
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):
|
def draw_pixel(self, pos_x, pos_y, color=None):
|
||||||
"""draw a pixel at x,y"""
|
"""draw a pixel at x,y"""
|
||||||
if color is None:
|
if color is None:
|
||||||
color = self.options['color']
|
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()
|
self.flush()
|
||||||
|
|
||||||
def draw_line(self, pos_x1, pos_y1, pos_x2, pos_y2):
|
def draw_line(self, pos_x1, pos_y1, pos_x2, pos_y2):
|
||||||
|
@ -35,13 +35,6 @@ class NJU6450(Page, Chip):
|
|||||||
self.driver.cmd(0xB8 | pos_y, 1)
|
self.driver.cmd(0xB8 | pos_y, 1)
|
||||||
self.driver.cmd(0x00 | (pos_x - width//2), 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):
|
def flush(self, force=None):
|
||||||
"""flush buffer to device
|
"""flush buffer to device
|
||||||
:force - boolean|None"""
|
:force - boolean|None"""
|
||||||
|
@ -22,13 +22,6 @@ class NullPage(Page, Chip):
|
|||||||
Page.init(self)
|
Page.init(self)
|
||||||
Chip.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):
|
def flush(self, force=None):
|
||||||
"""flush buffer to device
|
"""flush buffer to device
|
||||||
:force - boolean|None"""
|
:force - boolean|None"""
|
||||||
|
@ -76,13 +76,6 @@ class SSD1306(Page, Chip):
|
|||||||
self.driver.cmd(0x14) # enable charge pump
|
self.driver.cmd(0x14) # enable charge pump
|
||||||
self.driver.cmd(0xaf) # turn on panel
|
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):
|
def flush(self, force=None):
|
||||||
"""flush buffer to device
|
"""flush buffer to device
|
||||||
:force - boolean|None"""
|
:force - boolean|None"""
|
||||||
|
@ -216,6 +216,17 @@ class TestPageDrawing(object):
|
|||||||
buffer[5][1] = 8
|
buffer[5][1] = 8
|
||||||
assert_equal(self.lcd.buffer, buffer)
|
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):
|
def draw_buffer(self, buffer):
|
||||||
for page in range(2):
|
for page in range(2):
|
||||||
print(page)
|
print(page)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[bdist_wheel]
|
[bdist_wheel]
|
||||||
universal = 1
|
universal = 0
|
||||||
[metadata]
|
[metadata]
|
||||||
description-file = readme.md
|
description-file = readme.md
|
||||||
|
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ def read(*paths):
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='gfxlcd',
|
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.',
|
description='gfxlcd is a handler for graphical lcds: ILI9328, SSD1306, NJU6450, touch panel: AD7843 @ Raspberry Pi.',
|
||||||
keywords=[
|
keywords=[
|
||||||
'gfxlcd', 'raspberry pi' ,'ili9328' ,'ssd1306', 'nju6450', 'lcd', 'graphical lcd', 'touch panel', 'ad7843',
|
'gfxlcd', 'raspberry pi' ,'ili9328' ,'ssd1306', 'nju6450', 'lcd', 'graphical lcd', 'touch panel', 'ad7843',
|
||||||
|
Loading…
Reference in New Issue
Block a user