driver for hd44780 and CharLCD
This commit is contained in:
parent
3246ac1d92
commit
968780ef37
36
gfxlcd/demos/ili9325_hd44780.py
Normal file
36
gfxlcd/demos/ili9325_hd44780.py
Normal 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
73
gfxlcd/driver/hd44780.py
Normal 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]
|
||||||
|
|
42
gfxlcd/tests/test_hd44780.py
Normal file
42
gfxlcd/tests/test_hd44780.py
Normal 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()
|
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ def read(*paths):
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='gfxlcd',
|
name='gfxlcd',
|
||||||
version='0.6.0',
|
version='0.7.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',
|
||||||
|
Loading…
Reference in New Issue
Block a user