Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-hull committed Apr 11, 2017
1 parent 597b020 commit 18562e2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions luma/lcd/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class st7735(object):
DISPLAYON = 0x29
DISPLAYOFF = 0x28


class ht1621(object):
DISPLAYON = 0x06
DISPLAYOFF = 0x04
17 changes: 9 additions & 8 deletions luma/lcd/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ def command(self, cmd, *args):
self._serial_interface.data(list(args))


import time
@rpi_gpio
class ht1621(device):
def __init__(self, gpio=None, rotate=0, WR=11, DAT=10, CS=8, **kwargs):
Expand All @@ -244,10 +243,9 @@ def __init__(self, gpio=None, rotate=0, WR=11, DAT=10, CS=8, **kwargs):
self.command(0x30) # Internal RC oscillator @ 256KHz
self.command(0x52) # 1/2 Bias and 4 commons
self.command(0x02) # System enable
self.command(0x06) # Turn on Bias generator (LCD on)

#self.clear()
#self.show()
self.clear()
self.show()

def _configure(self, pin):
if pin is not None:
Expand Down Expand Up @@ -278,7 +276,6 @@ def display(self, image):

def command(self, cmd):
gpio = self._gpio
print(self._CS)
gpio.output(self._CS, gpio.LOW)
self._write_bits(0x80, 4) # Command mode
self._write_bits(cmd, 8)
Expand All @@ -294,14 +291,18 @@ def data(self, data):
gpio.output(self._CS, gpio.HIGH)

def _write_bits(self, value, num_bits):
print("_write_bits(0x{0:02x}, {1})".format(value, num_bits))
gpio = self._gpio

for _ in range(num_bits):
gpio.output(self._WR, gpio.LOW)
bit = gpio.HIGH if value & 0x80 > 0 else gpio.LOW
gpio.output(self._DAT, bit)
value <<= 1
print(bit)
gpio.output(self._WR, gpio.HIGH)

def cleanup(self):
"""
Attempt to reset the device & switching it off prior to exiting the
python process.
"""
super(ht1621, self).cleanup()
self._gpio.cleanup()
34 changes: 30 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,36 @@

from luma.lcd.device import ht1621
from luma.core.render import canvas
from luma.led_matrix.virtual import sevensegment
from luma.led_matrix.segment_mapper import _DIGITS, regular

device = ht1621()
# 0x3e = 0b0011 1110
# 0x6d = 0b0110 1101

def swap(byte, i, j):
x = ((byte >> i) ^ (byte >> j)) & 1
return byte ^ ((x << i) | (x << j))


def flip(mapper):
def wrapped(text, notfound="_"):
for byte in mapper(text, notfound):
yield swap(swap(byte, 0, 1), 4, 6)

return wrapped


device = sevensegment(ht1621(), mapper=flip(regular))

device.text = "HELLO"
time.sleep(5)

device.text = "123456"
time.sleep(5)

#for ch in _DIGITS.keys():
# print(ch)
# device.text = ch * 6
# time.sleep(1)

with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline="white")

time.sleep(10)

0 comments on commit 18562e2

Please sign in to comment.