Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Bielohlawek committed Jan 29, 2012
1 parent 90e4aca commit af82312
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
*.gem
.bundle
Gemfile.lock
pkg/*
.rvmrc
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in open_nabaztag.gemspec
gemspec
1 change: 1 addition & 0 deletions Rakefile
@@ -0,0 +1 @@
require "bundler/gem_tasks"
5 changes: 5 additions & 0 deletions config.ru
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'open_nabaztag/server'

run OpenNabaztag::Server.new
4 changes: 4 additions & 0 deletions lib/open_nabaztag.rb
@@ -0,0 +1,4 @@
require "open_nabaztag/version"

module OpenNabaztag
end
36 changes: 36 additions & 0 deletions lib/open_nabaztag/message.rb
@@ -0,0 +1,36 @@
module OpenNabaztag
module Message

def build(*commands)
commands = if commands.first.is_a?(Hash)
commands.first
elsif !commands.first.is_a?(Array)
[commands]
else
commands
end

pack full_message commands.map { |cmd, *data|
[cmd] + to_3b(data.flatten.size) + data.flatten
}
end
module_function(:build)

def to_3b(int)
[int >> 16, (int >> 8) & 0xFF, int & 0xFF]
end
module_function(:to_3b)

private
def full_message(*data)
[0x7F] + data.flatten + [0xFF, 0x0A]
end
module_function(:full_message)

def pack(message)
message.pack('c*')
end
module_function(:pack)
end

end
33 changes: 33 additions & 0 deletions lib/open_nabaztag/message/api.rb
@@ -0,0 +1,33 @@
module OpenNabaztag
module Message
module Api
OK = 2
INIT = 6
LOG = 7
ERROR = 8
REBOOT = 9

LED_0 = 20
LED_1 = 21
LED_2 = 22
LED_3 = 23
LED_4 = 24
LED_L0 = 25
LED_L1 = 26
LED_L2 = 27
LED_L3 = 28
LED_L4 = 29

EAR_L = 40
EAR_R = 41
EAR_LL = 42
EAR_LR = 43

F = 1
B = 2

def rgb(values)
end
end
end
end
25 changes: 25 additions & 0 deletions lib/open_nabaztag/message/helper.rb
@@ -0,0 +1,25 @@
module OpenNabaztag
module Message
module Helper
#blink
def bl(loops = 1, color_on = 0xFF, color_off = 0x00)
repeat(loops, [color_on, color_off])
end

#repeat
def rp(loops, pattern = 0)
Array.new(loops, pattern).flatten
end
alias_method :sl, :rp #sleep

#knight rider
def kr(color = 0xFF, led1 = LED_L1, led2 = LED_L2, led3 = LED_L3)
{
led1 => [color,0,0,0],
led2 => [0,color],
led3 => [0,0,color,0]
}
end
end
end
end
40 changes: 40 additions & 0 deletions lib/open_nabaztag/server.rb
@@ -0,0 +1,40 @@
module OpenNabaztag
class Server < Sinatra::Base

def send_nabaztag(*data)
OpenNabaztag::Message.build(*data)
end

def parse_log(logs)
logs.to_s.split("|").map do |line|
type, time, *values = line.split(",")
time = time.to_i
values = values.map &:to_i

if type == "moved"
values << (time - values[1]) << (values[1] - values[2]) << (time - values[2]) << (time - values[3])
end
"#{type}-#{time}: #{values.join("\t")}"
end
end

get '/vl/bc.jsp' do
#recompile
puts "bootcode #{@@reboot}"
send_file File.join('public', 'bootcode', 'bootcode.bin')
end

get '/vl/button.jsp' do
send_nabaztag EAR_L => [12,0,16,0,16,0,16,0]
end

get '/vl/log.jsp' do
@logs = parse_log params[:logs]
puts "#########################"
puts @logs.join("\n")
puts "#########################"
send_nabaztag OK
end
end

end
3 changes: 3 additions & 0 deletions lib/open_nabaztag/version.rb
@@ -0,0 +1,3 @@
module OpenNabaztag
VERSION = "0.0.1"
end
24 changes: 24 additions & 0 deletions open_nabaztag.gemspec
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "open_nabaztag/version"

Gem::Specification.new do |s|
s.name = "open_nabaztag"
s.version = OpenNabaztag::VERSION
s.authors = ["Tobias Bielohlawek"]
s.email = ["tobi@soundcloud.com"]
s.homepage = ""
s.summary = %q{Sinatra server to run custom Nabaztag bootcode}
s.description = %q{Sinatra server for Nabaztag v1/v2 to run your custom Nabaztag version. Sources + Compiler included (linux only)}

# s.rubyforge_project = "open_nabaztag"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

# specify any dependencies here; for example:
# s.add_development_dependency "rspec"
s.add_runtime_dependency "sinatra"
end

0 comments on commit af82312

Please sign in to comment.