Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added character maps, custom character support

  • Loading branch information...
commit 31d5b38fba313aaef2893e99e2ff052f70080609 1 parent f3f05fd
Nathan Broadbent authored
46 chars/CD.chr
View
@@ -0,0 +1,46 @@
+.**..
+*..*.
+*...*
+*.*.*
+*.*.*
+*...*
+.*..*
+..**.
+-----
+.**..
+**.*.
+*.*.*
+*.*.*
+*.*.*
+*...*
+.*..*
+..**.
+-----
+.**..
+*..*.
+*.***
+*.*.*
+*.*.*
+*...*
+.*..*
+..**.
+-----
+.**..
+*..*.
+*...*
+*.***
+*.***
+*...*
+.*..*
+..**.
+-----
+.**..
+*..*.
+*...*
+*.*.*
+*.*.*
+*..**
+.*.**
+..**.
+-----
+
9 chars/_blank.chr
View
@@ -0,0 +1,9 @@
+.....
+.....
+.....
+.....
+.....
+.....
+.....
+.....
+
9 chars/guitar.chr
View
@@ -0,0 +1,9 @@
+..#..
+..#..
+..#..
+.###.
+.###.
+#####
+#####
+.###.
+
18 chars/heart.chr
View
@@ -0,0 +1,18 @@
+.....
+.*.*.
+*****
+*****
+.***.
+.***.
+..*..
+.....
+-----
+.....
+.*.*.
+*.*.*
+*...*
+.*.*.
+.*.*.
+..*..
+.....
+
9 chars/mic.chr
View
@@ -0,0 +1,9 @@
+.....
+.###.
+.###.
+.###.
+..#..
+..#..
+..#..
+.....
+
9 chars/notes.chr
View
@@ -0,0 +1,9 @@
+.....
+.####
+.#..#
+.#..#
+.#..#
+##.##
+##.##
+.....
+
34 rubyX2040.rb
View
@@ -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,13 +36,13 @@ 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
@@ -50,7 +50,7 @@ def send_bytes(str, delay=WRITE_DELAY)
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
Please sign in to comment.
Something went wrong with that request. Please try again.