Browse files

cleaning up repo

git-svn-id: svn+ssh://rubyforge.org/var/svn/betabrite/trunk@15 32089d7b-f314-0410-b504-a527b3b390a0
  • Loading branch information...
1 parent 6a3e536 commit 5feed8e97d5e7631d1cfda4d5df23ed5fd71e013 aaronp committed Feb 10, 2008
View
6 CHANGELOG → History.txt
@@ -1,10 +1,8 @@
-= BetaBrite Changelog
-
-== 0.0.2
+=== 0.0.2
* Added new syntax to BetaBrite::String and BetaBrite::TextFile
-== 0.0.1
+=== 0.0.1
* First release
View
8 README → README.txt
@@ -1,8 +1,12 @@
= BetaBrite Library
-== Synopsis
+* http://rubyforge.org/projects/betabrite/
+* http://betabrite.rubyforge.org/
+* mailto:aaron@tenderlovemaking.com
-This library is used for controlling BetaBrite LED signs via Ruby.
+== DESCRIPTION
+
+Provides a Ruby interface to BetaBrite LED signs
== More Information
View
90 Rakefile
@@ -1,85 +1,11 @@
-require 'rubygems'
-require 'rake'
-require 'rake/testtask'
-require 'rake/gempackagetask'
-require 'rake/rdoctask'
-require 'rake/contrib/sshpublisher'
+require 'hoe'
-def announce(msg='')
- STDERR.puts msg
-end
-
-PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
-PKG_NAME = 'betabrite'
-PKG_VERSION = '0.0.2' + PKG_BUILD
-PKG_FILES = FileList["{doc,lib,test}/**/*"].exclude("rdoc").to_a
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "lib")
+require 'betabrite'
-spec = Gem::Specification.new do |s|
- s.name = PKG_NAME
- s.version = PKG_VERSION
- s.author = "Aaron Patterson"
- s.email = "aaronp@rubyforge.org"
- s.homepage = "#{PKG_NAME}.rubyforge.org"
- s.platform = Gem::Platform::RUBY
- s.summary = "Provides a Ruby interface to BetaBrite LED signs"
- s.files = Dir.glob("{bin,test,lib,doc}/**/*").delete_if {|item| item.include?(".svn") }
- s.require_path = "lib"
- s.has_rdoc = true
- s.extra_rdoc_files = ["README", "EXAMPLES", "CHANGELOG", "LICENSE", "NOTES"]
- s.rdoc_options << "--main" << 'README' << "--title" << "'BetaBrite RDoc'"
- s.rubyforge_project = PKG_NAME
+Hoe.new('betabrite', BetaBrite::VERSION) do |p|
+ p.rubyforge_name = 'betabrite'
+ p.author = 'Aaron Patterson'
+ p.email = 'aaronp@rubyforge.org'
+ p.summary = "Provides a Ruby interface to BetaBrite LED signs"
end
-
-Rake::GemPackageTask.new(spec) do |p|
- p.gem_spec = spec
- p.need_tar = true
- p.need_zip = true
-end
-
-Rake::RDocTask.new do |p|
- p.main = "README"
- p.rdoc_dir = "doc"
- p.rdoc_files.include("README", "CHANGELOG", "LICENSE", "EXAMPLES", "NOTES", "lib/**/*.rb")
- p.options << "--main" << 'README' << "--title" << "BetaBrite RDoc"
-end
-
-desc "Publish the API documentation"
-task :pubrdoc => [ :rdoc ] do
- Rake::SshDirPublisher.new(
- "#{ENV['USER']}@rubyforge.org",
- "/var/www/gforge-projects/#{PKG_NAME}/",
- "doc" ).upload
-end
-
-task :update_version do
- announce "Updating BetaBrite Version to #{PKG_VERSION}"
- File.open("lib/bb_version.rb", "w") do |f|
- f.puts "class BetaBrite"
- f.puts " Version = '#{PKG_VERSION}'"
- f.puts "end"
- end
- sh 'svn commit -m"updating version" lib/bb_version.rb'
-end
-
-desc "Create a new release"
-task :release => [ :clobber, :update_version, :package, :tag ] do
- announce
- announce "**************************************************************"
- announce "* Release #{PKG_VERSION} Complete."
- announce "* Packages ready to upload."
- announce "**************************************************************"
- announce
-end
-
-desc "Tag code"
-Rake::Task.define_task("tag") do |p|
- baseurl = "svn+ssh://#{ENV['USER']}@rubyforge.org//var/svn/#{PKG_NAME}"
- sh "svn cp -m 'tagged #{ PKG_VERSION }' . #{ baseurl }/tags/REL-#{ PKG_VERSION }"
-end
-
-desc "Branch code"
-Rake::Task.define_task("branch") do |p|
- baseurl = "svn+ssh://#{ENV['USER']}@rubyforge.org/var/svn/#{PKG_NAME}"
- sh "svn cp -m 'branched #{ PKG_VERSION }' #{baseurl}/trunk #{ baseurl }/branches/RB-#{ PKG_VERSION }"
-end
-
View
16 lib/betabrite.rb
@@ -22,7 +22,9 @@ class BetaBrite
# Beta Brite sign
SIGN_TYPE = 0x5a.chr
- attr_reader :sleep_time
+ VERSION = '0.1.0'
+
+ attr_accessor :sleep_time
attr_reader :string_files, :text_files, :dots_files
def initialize
@@ -78,32 +80,32 @@ def add_memory(packet)
# This method is used to write on the sign
def write(&block)
if @text_files.length > 0 || @string_files.length > 0
- write_header &block
+ write_header(&block)
@text_files.each { |packet| yield packet.to_s }
@string_files.each { |packet| block.call(packet.to_s) }
- write_end &block
+ write_end(&block)
end
end
def write_dots(&block)
if @dots_files.length > 0
- write_header &block
+ write_header(&block)
@dots_files.each { |packet|
yield packet.to_s
sleep sleep_time
}
- write_end &block
+ write_end(&block)
end
end
# This method is used to allocate memory on the sign
def allocate(&block)
if @memory.length > 0
- write_header &block
+ write_header(&block)
yield STX
yield MEMORY_CODE
@memory.each { |packet| yield packet.to_s }
- write_end &block
+ write_end(&block)
end
end
View
65 script/stock_alloc.rb
@@ -1,11 +1,68 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
require 'betabrite'
-require 'serialport'
+require 'usb'
-sp = SerialPort.new(0, 9600, 8, 1, SerialPort::NONE)
+class UsbBetabrite
+ # USB Device Codes
+ PRODUCT_ID = 0x1234
+ VENDOR_ID = 0x8765
+ INTERFACE = 0x00
+ RECV_LENGTH = 0x40 # Max Packet Size of 64
+ SEND_LENGTH = 0x40 # Max Packet Size of 64
+ WRITE_ENDPOINT = 0x02
+ READ_ENDPOINT = 0x82
+ WRITE_TIMEOUT = 5000
+ READ_TIMEOUT = 5000
+
+ # Creates a new interface between ruby and the Betabrite
+ def initialize
+ @device = get_usb_device()
+ @handle = get_usb_interface(@device)
+ end
+
+ def write(bytes)
+ # write twice to force past the 'data toggle bit' check
+ #@handle.usb_bulk_write(WRITE_ENDPOINT, bytes.pack('C*'), WRITE_TIMEOUT)
+ @handle.usb_bulk_write(WRITE_ENDPOINT, bytes, WRITE_TIMEOUT)
+ end
+
+ private
+
+ def get_usb_device
+ device = USB.devices.find {|d| d.idProduct == PRODUCT_ID and d.idVendor == VENDOR_ID }
+ raise "Unable to locate the BETABrite." if device.nil?
+ return device
+ end
+
+ def get_usb_interface(device)
+ handle = device.open
+ raise "Unable to obtain a handle to the device." if handle.nil?
+
+ retries = 0
+ begin
+ error_code = handle.usb_claim_interface(INTERFACE)
+ raise unless error_code.nil?
+ rescue
+ handle.usb_detach_kernel_driver_np(INTERFACE);
+ if retries.zero?
+ retries += 1
+ retry
+ else
+ raise "Unable to claim the device interface."
+ end
+ end
+
+ raise "Unable to set alternative interface." unless handle.set_altinterface(0).nil?
+
+ handle
+ end
+end
+
+betabrite = UsbBetabrite.new
sign = BetaBrite.new
+sign.sleep_time = 0
0.upto(9) { |i|
string = BetaBrite::Memory::String.new(i.to_s, 64)
@@ -16,7 +73,9 @@
sign.add text
+write_text = ''
sign.allocate { |text|
- sp.write text
+ write_text << text
}
+betabrite.write write_text
View
5 test/bb_override.rb
@@ -1,5 +0,0 @@
-class BetaBrite
- def sleep_time
- 0
- end
-end
View
4 test/tc_many_mem.rb → test/test_many_mem.rb
@@ -3,11 +3,11 @@
require 'test/unit'
require 'betabrite'
-require 'bb_override'
-class MemoryAllocTest < Test::Unit::TestCase
+class ManyMemoryAllocTest < Test::Unit::TestCase
def setup
@sign = BetaBrite.new
+ @sign.sleep_time = 0
end
def test_text_and_string
View
2 test/tc_memory.rb → test/test_memory.rb
@@ -3,11 +3,11 @@
require 'test/unit'
require 'betabrite'
-require 'bb_override'
class MemoryAllocTest < Test::Unit::TestCase
def setup
@sign = BetaBrite.new
+ @sign.sleep_time = 0
end
def test_text_file
View
2 test/tc_set_string.rb → test/test_set_string.rb
@@ -3,11 +3,11 @@
require 'test/unit'
require 'betabrite'
-require 'bb_override'
class MemoryAllocTest < Test::Unit::TestCase
def setup
@sign = BetaBrite.new
+ @sign.sleep_time = 0
end
def test_many_mem
View
1 test/tc_string.rb → test/test_string.rb
@@ -3,7 +3,6 @@
require 'test/unit'
require 'betabrite'
-require 'bb_override'
class StringTest < Test::Unit::TestCase
def test_const_dsl
View
1 test/tc_text_file.rb → test/test_text_file.rb
@@ -3,7 +3,6 @@
require 'test/unit'
require 'betabrite'
-require 'bb_override'
class TextFileTest < Test::Unit::TestCase
def test_const_dsl
View
7 test/ts_bb.rb
@@ -1,7 +0,0 @@
-require 'test/unit'
-
-require 'tc_many_mem'
-require 'tc_memory'
-require 'tc_set_string'
-require 'tc_text_file'
-require 'tc_string'

0 comments on commit 5feed8e

Please sign in to comment.