Skip to content

Commit

Permalink
Added character maps, custom character support
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent committed Nov 20, 2010
1 parent f3f05fd commit 31d5b38
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 10 deletions.
46 changes: 46 additions & 0 deletions chars/CD.chr
@@ -0,0 +1,46 @@
.**..
*..*.
*...*
*.*.*
*.*.*
*...*
.*..*
..**.
-----
.**..
**.*.
*.*.*
*.*.*
*.*.*
*...*
.*..*
..**.
-----
.**..
*..*.
*.***
*.*.*
*.*.*
*...*
.*..*
..**.
-----
.**..
*..*.
*...*
*.***
*.***
*...*
.*..*
..**.
-----
.**..
*..*.
*...*
*.*.*
*.*.*
*..**
.*.**
..**.
-----

9 changes: 9 additions & 0 deletions chars/_blank.chr
@@ -0,0 +1,9 @@
.....
.....
.....
.....
.....
.....
.....
.....

9 changes: 9 additions & 0 deletions chars/guitar.chr
@@ -0,0 +1,9 @@
..#..
..#..
..#..
.###.
.###.
#####
#####
.###.

18 changes: 18 additions & 0 deletions chars/heart.chr
@@ -0,0 +1,18 @@
.....
.*.*.
*****
*****
.***.
.***.
..*..
.....
-----
.....
.*.*.
*.*.*
*...*
.*.*.
.*.*.
..*..
.....

9 changes: 9 additions & 0 deletions chars/mic.chr
@@ -0,0 +1,9 @@
.....
.###.
.###.
.###.
..#..
..#..
..#..
.....

9 changes: 9 additions & 0 deletions chars/notes.chr
@@ -0,0 +1,9 @@
.....
.####
.#..#
.#..#
.#..#
##.##
##.##
.....

34 changes: 24 additions & 10 deletions rubyX2040.rb
Expand Up @@ -3,7 +3,7 @@
require 'rubygems'
require 'serialport'

WRITE_DELAY = 0.003 # Number of seconds to wait between character bytes.
WRITE_DELAY = 0.005 # Number of seconds to wait between character bytes.
INSTRUCTION_DELAY = 0.01 # Number of seconds to wait between instruction bytes.
ROW_WIDTH = 20 # Number of characters that will fit on a line.
ROW_OFFSETS = [0x00, 0x40, 0x14, 0x54] # Offsets for ordering rows correctly.
Expand All @@ -20,7 +20,7 @@ def setup
# Entry mode set; increment cursor direction; do not automatically shift.
# Cursor/display shift; cursor move.
# Display On; cursor off; do not blink.
"\x38\x06\x10\x0c\x01".split().each do |byte|
"\x38\x06\x10\x0c\x01".split.each do |byte|
send_instruction(byte)
end
end
Expand All @@ -36,21 +36,21 @@ def set_cursor(pos)
pos = [row, pos]
end
# As an array of [row (1 - 4), column (1 - 20)]
send_bytes "\xfe" + (0b10000000 + ROW_OFFSETS[pos[0]-1] + pos[1]-1).chr
send_bytes ["\xfe", (0b10000000 + ROW_OFFSETS[pos[0]-1] + pos[1]-1).chr]
end

def send_bytes(str, delay=WRITE_DELAY)
def send_bytes(bytes, delay=WRITE_DELAY)
# Send a stream of bytes to the Pertelian.
# Also, sleep for delay seconds between sending each byte.
str.split('').each do |byte|
bytes.each do |byte|
@sp.write byte
sleep delay
end
end

def send_instruction(byte)
# Send an instruction byte to the Pertelian.
send_bytes ["\xfe", byte].to_s, INSTRUCTION_DELAY
send_bytes ["\xfe", byte], INSTRUCTION_DELAY
end

def power(on)
Expand All @@ -68,13 +68,27 @@ def clear
send_instruction("\x01")
end

def message(msg)
def message(msg, pos=nil)
set_cursor(pos) if pos
# Display a message.
send_bytes(msg)
send_bytes(msg.split(''))
end

def set_custom_character
#TODO
def load_char(mem_loc, char_data)
send_bytes ["\xfe", (0b01000000 + (8 * (mem_loc - 1))).chr]
send_bytes char_data
end

def write_char(mem_loc, pos=nil)
set_cursor(pos) if pos
send_bytes [(mem_loc-1).chr]
end

def load_char_from_file(filename, mem_loc, char_index=1)
rows = File.open(filename, 'r').read.split("-----\n")[char_index-1].split("\n")
# Map binary data based on presence of '#' character.
data = rows.map{|row| row.ljust(5).split('').inject(0b00000){|r, c| r = r << 1; r += 1 if c == "#" || c == "*"; r }.chr}
load_char(mem_loc, data)
end
end

0 comments on commit 31d5b38

Please sign in to comment.