Merge pull request #14 from bkosciow/hd44780

Hd44780
This commit is contained in:
Bartosz 2017-07-08 19:44:55 +02:00 committed by GitHub
commit dacf104f3a
6 changed files with 180 additions and 1 deletions

View File

@ -1,3 +1,5 @@
0.8.0
- HD44780 emulation via driver
0.7.0 0.7.0
- add draw_text function - add draw_text function
- add font 8x8 as default - add font 8x8 as default

View File

@ -0,0 +1,36 @@
import sys
sys.path.append("../../")
import RPi.GPIO as GPIO # NOQA pylint: disable=I0011,F0401
from charlcd.buffered import CharLCD # NOQA
from gfxlcd.driver.ili9325.gpio import GPIO as ILIGPIO
from gfxlcd.driver.ili9325.ili9325 import ILI9325
from gfxlcd.driver.hd44780 import HD44780
GPIO.setmode(GPIO.BCM)
def test1():
"""demo """
ili_drv = ILIGPIO()
ili_drv.pins['LED'] = 6
ili_drv.pins['CS'] = 18
lcd = ILI9325(240, 320, ili_drv)
lcd.auto_flush = False
lcd.rotation = 0
drv = HD44780(lcd)
lcd = CharLCD(drv.width, drv.height, drv, 0, 0)
lcd.init()
lcd.write('-!Second blarg!')
lcd.write("-second line", 0, 1)
lcd.flush()
lcd.write('/* ', 19, 0)
lcd.write('|*|', 19, 1)
lcd.write(' */', 19, 2)
lcd.flush()
lcd.write('BUM', 19, 5)
lcd.flush()
test1()

73
gfxlcd/driver/hd44780.py Normal file
View File

@ -0,0 +1,73 @@
"""Driver for CharLCD module
allows graphical LCD to work as character LCD
"""
from charlcd.drivers.base import BaseDriver
from charlcd.abstract import lcd as char_lcd
class HD44780(BaseDriver):
def __init__(self, gfxlcd):
"""Class init"""
self.gfxlcd = gfxlcd
self.mode = 0
self.initialized = False
self.font = self.gfxlcd.options['font']
self.width = self.gfxlcd.width // self.font.size[0]
self.height = self.gfxlcd.height // self.font.size[1]
self.pins = {
'E2': None
}
self.position = {
'x': 0,
'y': 0
}
def init(self):
"""init function"""
if self.initialized:
return
char_lcd.LCD_LINES = []
for address in range(self.height):
char_lcd.LCD_LINES.append(100 + (address * self.width))
self.gfxlcd.init()
self.initialized = True
def cmd(self, char, enable=0):
"""write command - set cursor position"""
if char < 100:
return
char -= 100
y = char // self.width
x = char - (y*self.width)
self.position = {
'x': x * self.font.size[0],
'y': y * self.font.size[1]
}
def shutdown(self):
"""shutdown procedure"""
pass
def send(self, enable=0):
"""send ack command"""
pass
def write(self, char, enable=0):
"""write data to lcd"""
pass
def char(self, char, enable=0):
"""write char to lcd"""
self.gfxlcd.draw_text(
self.position['x'], self.position['y'], char
)
self._increase_x()
def set_mode(self, mode):
"""sets driver mode. 4/8 bit"""
self.mode = mode
def _increase_x(self):
self.position['x'] += self.font.size[0]

View File

@ -0,0 +1,42 @@
__author__ = 'kosci'
import sys
from nose.tools import assert_equal
sys.path.append("../../")
from gfxlcd.driver.null.null_page import NullPage
from gfxlcd.driver.hd44780 import HD44780
from charlcd.buffered import CharLCD
class TestChip(object):
def setUp(self):
self.gfx_lcd = NullPage(132, 16, None, False)
self.drv = HD44780(self.gfx_lcd)
self.output = [" ".ljust(16, " ") for i in range(0, 2)]
def get_lcd(self):
lcd = CharLCD(self.drv.width, self.drv.height, self.drv, 0, 0)
lcd.init()
return lcd
def test_get_size_in_chars(self):
assert_equal(16, self.drv.width)
assert_equal(2, self.drv.height)
def test_init_small_hd44780(self):
lcd = CharLCD(self.drv.width, self.drv.height, self.drv, 0, 0)
lcd.init()
def test_write_to_buffer(self):
lcd = self.get_lcd()
lcd.write('Hello')
lcd.write(' world', 0, 1)
self.output[0] = "Hello" + " ".ljust(11, " ")
self.output[1] = " world" + " ".ljust(6, " ")
assert_equal(lcd.buffer, self.output)
def test_flush(self):
lcd = self.get_lcd()
lcd.write('Hello')
lcd.write(' world', 0, 1)
lcd.flush()

View File

@ -15,12 +15,18 @@ And for touch panels:
- ad7843 via SPI, uses irq or not - ad7843 via SPI, uses irq or not
- ad7846/xpt2046 - ad7846/xpt2046
Bonus
- HD44780 emulation (works with CharLCD)
On NJU and SSD uses buffer to keep current content as help for page operations. On NJU and SSD uses buffer to keep current content as help for page operations.
Wiring is below Wiring is below
Demos are in demos directory Demos are in demos directory
LCD initialization LCD initialization
=== ===
## SSD1306 ## SSD1306
@ -269,3 +275,23 @@ Default:
G9 ----------------- LCD_CS G9 ----------------- LCD_CS
G7 ----------------- TP_CS G7 ----------------- TP_CS
HD44780 emulation
===
This driver can work with CharLCD and emulate char LCD
ili_drv = ILIGPIO()
ili_drv.pins['LED'] = 6
ili_drv.pins['CS'] = 18
lcd = ILI9325(240, 320, ili_drv)
lcd.auto_flush = False
lcd.rotation = 0
drv = HD44780(lcd)
lcd = CharLCD(drv.width, drv.height, drv, 0, 0)
lcd.init()
lcd.write('-!Second blarg!')
lcd.write("-second line", 0, 1)
lcd.flush()

View File

@ -13,7 +13,7 @@ def read(*paths):
setup( setup(
name='gfxlcd', name='gfxlcd',
version='0.6.0', version='0.8.0',
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',