HD44780 for NJU and SSD

This commit is contained in:
Bartosz Kościów 2017-07-08 22:16:15 +02:00
parent f2c059dcc7
commit d7a2904a7f
6 changed files with 75 additions and 10 deletions

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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)

View File

@ -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"""

View File

@ -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)