Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
32c3 hd44780
#!/usr/bin/python
import sys
pin_s = 'RSPI_GPIO_7.txt'
pin_e = 'RSPI_GPIO_8.txt'
pin_db7 = 'RSPI_GPIO_18.txt'
pin_db6 = 'RSPI_GPIO_23.txt'
pin_db5 = 'RSPI_GPIO_24.txt'
pin_db4 = 'RSPI_GPIO_25.txt'
dotmatrix = {
# '00000000' : 'CLR',
# '00001000' : 'CLR2',
# '00100000' : ' ',
'00100000' : ' ',
'00100001' : '!',
'00100010' : '"',
'00100011' : '#',
'00100100' : '$',
'00100101' : '%',
'00100110' : '&',
'00100111' : "'",
'00101000' : '(',
'00101001' : ')',
'00101010' : '*',
'00101011' : '+',
'00101100' : ',',
'00101101' : '-',
'00101110' : '.',
'00101111' : '/',
'00110000' : '0',
'00110001' : '1',
'00110010' : '2',
'00110011' : '3',
'00110100' : '4',
'00110101' : '5',
'00110110' : '6',
'00110111' : '7',
'00111000' : '8',
'00111001' : '9',
'00111010' : ':',
'00111011' : ';',
'00111100' : '<',
'00111101' : '=',
'00111110' : '>',
'00111111' : '?',
'01000000' : '@',
'01000001' : 'A',
'01000010' : 'B',
'01000011' : 'C',
'01000100' : 'D',
'01000101' : 'E',
'01000110' : 'F',
'01000111' : 'G',
'01001000' : 'H',
'01001001' : 'I',
'01001010' : 'J',
'01001011' : 'K',
'01001100' : 'L',
'01001101' : 'M',
'01001110' : 'N',
'01001111' : 'O',
'01010000' : 'P',
'01010001' : 'Q',
'01010010' : 'R',
'01010011' : 'S',
'01010100' : 'T',
'01010101' : 'U',
'01010110' : 'V',
'01010111' : 'W',
'01011000' : 'X',
'01011001' : 'Y',
'01011010' : 'Z',
'01011011' : '[',
'01011100' : '(y)',
'01011101' : ']',
'01011110' : '^',
'01011111' : '_',
'01100000' : '`',
'01100001' : 'a',
'01100010' : 'b',
'01100011' : 'c',
'01100100' : 'd',
'01100101' : 'e',
'01100110' : 'f',
'01100111' : 'g',
'01101000' : 'h',
'01101001' : 'i',
'01101010' : 'j',
'01101011' : 'k',
'01101100' : 'l',
'01101101' : 'm',
'01101110' : 'n',
'01101111' : 'o',
'01110000' : 'p',
'01110001' : 'q',
'01110010' : 'r',
'01110011' : 's',
'01110100' : 't',
'01110101' : 'u',
'01110110' : 'v',
'01110111' : 'w',
'01111000' : 'x',
'01111001' : 'y',
'01111010' : 'z',
'01111011' : '{',
'01111100' : '|',
'01111101' : '}',
# '01111110' : '(right arrow)',
# '01111111' : '(left arrow)',
# Special characters, should not show up much, not complete
# '10100000' : ' ',
# '10100001' : '(square)',
# '10100101' : '.',
# '10101000' : '(tau)',
# '10101010' : '(I)',
# '10111111' : '(y)',
# '11101111' : '(oe)',
# '11110111' : '(pi)',
# '11111101' : '(div)',
# '11111111' : '(.)'
}
cursor = 0
disp = []
for i in range(104):
disp.append(' ')
def dump_display():
print disp[0:20]
print disp[20:40]
print disp[64:84]
print disp[84:104]
def dump_str():
print str.join('', disp[0:20])
print str.join('', disp[20:40])
print str.join('', disp[64:84])
print str.join('', disp[84:104])
def output_dotmatrix_char(val):
global cursor
global disp
if val in dotmatrix:
sys.stdout.write(dotmatrix[val])
disp[cursor] = dotmatrix[val]
cursor += 1
cursor = cursor % 104
else:
sys.stdout.write('?')
def output_special(val):
global cursor
global disp
if val == '00000001':
print 'CLRSCR'
cursor = 0
for i in range(104):
disp[i] = ' '
elif val == '00001100':
print 'Curs off, Blink off'
elif val == '00101000':
print '4-bit mode'
elif val == '00000110':
print 'Inc cursor, no display shift'
elif val[0:6] == '001100':
print '8-bit mode'
elif val[0] == '1':
pos = int('0b' + val[1:], 2)
pos = pos % 104
cursor = pos
print ' ;', val, 'move cursor to', pos
dump_display()
else:
print ' ;', val, '(special command)'
# Read one datafile and convert to floats
def get_data(filename):
fd = open(filename, 'r')
d1 = fd.readline().strip().split()
d2 = fd.readline().strip().split()
# Convert to floats
d1f = []
for v in d1:
d1f.append(float(v))
d2i = []
for v in d2:
# Add 0.1 before converting to integer to
# be sure a 1 doesn't get floored to 0
d2i.append(int(float(v) + 0.1))
fd.close()
return (d1f, d2i)
# Get value (0 or 1) from tup at time ts
def get_val_at(tup, ts):
last = 0
for i in range(len(tup[0])):
t = tup[0][i]
v = tup[1][i]
if t > ts:
return last
last = v
# Should not get here
return last
def try_shit(l_init, h_init, upflank, nibble_shift, d0, d1, d2, d3):
prev = upflank
low = l_init
high = h_init
hnibble = True
for i in range(l):
if (e_v[i] == upflank) and (prev == 1 - upflank):
#if (e_v[i] == upflank):
flank = e_t[i]
nibble = str(get_val_at(d0, flank)) + \
str(get_val_at(d1, flank)) + \
str(get_val_at(d2, flank)) + \
str(get_val_at(d3, flank))
select = get_val_at(s, flank)
if hnibble == True:
high = nibble
else:
low = nibble
if select == 1:
output_dotmatrix_char(high + low)
else:
output_special(high + low)
# Toggle high/low nibble
hnibble = not hnibble
prev = e_v[i]
print ''
s = (s_t, s_v) = get_data(pin_s)
e = (e_t, e_v) = get_data(pin_e)
d7 = (d7_t, d7_v) = get_data(pin_db7)
d6 = (d6_t, d6_v) = get_data(pin_db6)
d5 = (d5_t, d5_v) = get_data(pin_db5)
d4 = (d4_t, d4_v) = get_data(pin_db4)
l = len(e_t)
l_init = '0000'
h_init = '0000'
nibshift = 1
upflank = 1
try_shit(l_init, h_init, upflank, nibshift, d7, d6, d5, d4)
print ''
dump_str()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment