Permalink
Browse files

Added character maps, custom character support

  • Loading branch information...
1 parent f3f05fd commit 31d5b38fba313aaef2893e99e2ff052f70080609 @ndbroadbent committed Nov 20, 2010
Showing with 124 additions and 10 deletions.
  1. +46 −0 chars/CD.chr
  2. +9 −0 chars/_blank.chr
  3. +9 −0 chars/guitar.chr
  4. +18 −0 chars/heart.chr
  5. +9 −0 chars/mic.chr
  6. +9 −0 chars/notes.chr
  7. +24 −10 rubyX2040.rb
View
46 chars/CD.chr
@@ -0,0 +1,46 @@
+.**..
+*..*.
+*...*
+*.*.*
+*.*.*
+*...*
+.*..*
+..**.
+-----
+.**..
+**.*.
+*.*.*
+*.*.*
+*.*.*
+*...*
+.*..*
+..**.
+-----
+.**..
+*..*.
+*.***
+*.*.*
+*.*.*
+*...*
+.*..*
+..**.
+-----
+.**..
+*..*.
+*...*
+*.***
+*.***
+*...*
+.*..*
+..**.
+-----
+.**..
+*..*.
+*...*
+*.*.*
+*.*.*
+*..**
+.*.**
+..**.
+-----
+
View
9 chars/_blank.chr
@@ -0,0 +1,9 @@
+.....
+.....
+.....
+.....
+.....
+.....
+.....
+.....
+
View
9 chars/guitar.chr
@@ -0,0 +1,9 @@
+..#..
+..#..
+..#..
+.###.
+.###.
+#####
+#####
+.###.
+
View
18 chars/heart.chr
@@ -0,0 +1,18 @@
+.....
+.*.*.
+*****
+*****
+.***.
+.***.
+..*..
+.....
+-----
+.....
+.*.*.
+*.*.*
+*...*
+.*.*.
+.*.*.
+..*..
+.....
+
View
9 chars/mic.chr
@@ -0,0 +1,9 @@
+.....
+.###.
+.###.
+.###.
+..#..
+..#..
+..#..
+.....
+
View
9 chars/notes.chr
@@ -0,0 +1,9 @@
+.....
+.####
+.#..#
+.#..#
+.#..#
+##.##
+##.##
+.....
+
View
34 rubyX2040.rb
@@ -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.
@@ -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
@@ -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)
@@ -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.