diff --git a/gfxlcd/abstract/chip.py b/gfxlcd/abstract/chip.py index 6e1eb64..8bbca39 100644 --- a/gfxlcd/abstract/chip.py +++ b/gfxlcd/abstract/chip.py @@ -85,7 +85,7 @@ class Chip(metaclass=abc.ABCMeta): pass @abc.abstractmethod - def draw_pixel(self, pos_x, pos_y): + def draw_pixel(self, pos_x, pos_y, color=None): """draw a pixel at x,y""" pass diff --git a/gfxlcd/demos/nju_hd44780.py b/gfxlcd/demos/nju_hd44780.py new file mode 100644 index 0000000..afb0b36 --- /dev/null +++ b/gfxlcd/demos/nju_hd44780.py @@ -0,0 +1,28 @@ +import sys +sys.path.append("../../") +import RPi.GPIO # NOQA pylint: disable=I0011,F0401 +from charlcd.buffered import CharLCD # NOQA +from gfxlcd.driver.nju6450.gpio import GPIO +from gfxlcd.driver.nju6450.nju6450 import NJU6450 +from gfxlcd.driver.hd44780 import HD44780 +RPi.GPIO.setmode(RPi.GPIO.BCM) + + +def test1(): + """demo """ + lcd = NJU6450(122, 32, GPIO()) + + drv = HD44780(lcd, True) + print(drv.width, drv.height) + lcd = CharLCD(drv.width, drv.height, drv, 0, 0) + lcd.init() + lcd.write('First') + + lcd.write('HD44780', 6, 3) + lcd.flush() + lcd.write('/* ', 12, 0) + lcd.write('|*|', 12, 1) + lcd.write(' */', 12, 2) + lcd.flush() + +test1() diff --git a/gfxlcd/demos/ssd_hd44780.py b/gfxlcd/demos/ssd_hd44780.py new file mode 100644 index 0000000..d64d365 --- /dev/null +++ b/gfxlcd/demos/ssd_hd44780.py @@ -0,0 +1,28 @@ +import sys +sys.path.append("../../") +import RPi.GPIO # NOQA pylint: disable=I0011,F0401 +from charlcd.buffered import CharLCD # NOQA +from gfxlcd.driver.ssd1306.spi import SPI +from gfxlcd.driver.ssd1306.ssd1306 import SSD1306 +from gfxlcd.driver.hd44780 import HD44780 +RPi.GPIO.setmode(RPi.GPIO.BCM) + + +def test1(): + """demo """ + lcd = SSD1306(128, 64, SPI()) + + drv = HD44780(lcd, True) + print(drv.width, drv.height) + lcd = CharLCD(drv.width, drv.height, drv, 0, 0) + lcd.init() + lcd.write('First') + + lcd.write('HD44780', 6, 3) + lcd.flush() + lcd.write('/* ', 12, 0) + lcd.write('|*|', 12, 1) + lcd.write(' */', 12, 2) + lcd.flush() + +test1() diff --git a/gfxlcd/driver/hd44780.py b/gfxlcd/driver/hd44780.py index 3386c1e..8f74075 100644 --- a/gfxlcd/driver/hd44780.py +++ b/gfxlcd/driver/hd44780.py @@ -2,15 +2,16 @@ allows graphical LCD to work as character LCD """ from charlcd.drivers.base import BaseDriver -from charlcd.abstract import lcd as char_lcd +from charlcd.abstract.flush_event_interface import FlushEvent -class HD44780(BaseDriver): - def __init__(self, gfxlcd): +class HD44780(BaseDriver, FlushEvent): + def __init__(self, gfxlcd, lcd_flush=False): """Class init""" self.gfxlcd = gfxlcd self.mode = 0 self.initialized = False + self.lcd_flush = lcd_flush self.font = self.gfxlcd.options['font'] self.width = self.gfxlcd.width // self.font.size[0] self.height = self.gfxlcd.height // self.font.size[1] @@ -73,3 +74,11 @@ class HD44780(BaseDriver): def get_line_address(self, idx): return self.address[idx] + + def pre_flush(self, buffer): + pass + + def post_flush(self, buffer): + """called after flush()""" + if self.lcd_flush: + self.gfxlcd.flush(True) diff --git a/gfxlcd/driver/nju6450/nju6450.py b/gfxlcd/driver/nju6450/nju6450.py index 682f8ae..673e123 100644 --- a/gfxlcd/driver/nju6450/nju6450.py +++ b/gfxlcd/driver/nju6450/nju6450.py @@ -6,7 +6,7 @@ from gfxlcd.abstract.chip import Chip class NJU6450(Page, 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=False): Chip.__init__(self, width, height, driver, auto_flush) Page.__init__(self, driver) self.rotation = 0 @@ -62,7 +62,7 @@ class NJU6450(Page, Chip): else: self.driver.data(self.get_page_value(i, j), 1) - def draw_pixel(self, pos_x, pos_y): + def draw_pixel(self, pos_x, pos_y, color=None): """draw a pixel at x,y""" if self.rotation == 90: pos_x, pos_y = self.height - pos_y - 1, pos_x @@ -70,7 +70,7 @@ class NJU6450(Page, Chip): pos_x, pos_y = self.width - pos_x - 1, self.height - pos_y - 1 if self.rotation == 270: pos_x, pos_y = pos_y, self.width - pos_x - 1 - Page.draw_pixel(self, pos_x, pos_y) + Page.draw_pixel(self, pos_x, pos_y, color) def fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2): """draw a filled rectangle""" diff --git a/gfxlcd/driver/ssd1306/ssd1306.py b/gfxlcd/driver/ssd1306/ssd1306.py index 2f3b8c4..fd5ffa8 100644 --- a/gfxlcd/driver/ssd1306/ssd1306.py +++ b/gfxlcd/driver/ssd1306/ssd1306.py @@ -24,7 +24,7 @@ class SSD1306(Page, Chip): } } - def __init__(self, width, height, driver, auto_flush=True): + def __init__(self, width, height, driver, auto_flush=False): Chip.__init__(self, width, height, driver, auto_flush) Page.__init__(self, driver) self.rotation = 0 @@ -107,8 +107,8 @@ class SSD1306(Page, Chip): self.driver.cmd(pos_x1) self.driver.cmd(pos_x2) - def draw_pixel(self, pos_x, pos_y): + def draw_pixel(self, pos_x, pos_y, color=None): """draw a pixel at x,y""" if self.rotation == 90 or self.rotation == 270: pos_x, pos_y = pos_y, pos_x - Page.draw_pixel(self, pos_x, pos_y) + Page.draw_pixel(self, pos_x, pos_y, color)