lib/myo/band.rb in myo-ruby-wrapper-0.0.1 vs lib/myo/band.rb in myo-ruby-wrapper-0.0.2

- old
+ new

@@ -1,11 +1,20 @@ class Myo::Band + # messg ["event", {"myo"=>0, "timestamp"=>"52593461767", "type"=>"paired", "version"=>[1, 1, 5, 2]}] + # messg ["event", {"myo"=>0, "timestamp"=>"56817670098", "type"=>"connected", "version"=>[1, 1, 5, 2]}] + # messg ["event", {"arm"=>"left", "myo"=>0, "timestamp"=>"56908739636", "type"=>"arm_synced", "x_direction"=>"toward_wrist"}] + def initialize(socket) - @socket = socket + @socket = socket + @events = {} + @callbacks = {} end + def on_connect(event, &block) + end + def run EM.run do conn = EventMachine::WebSocketClient.connect(@socket) conn.callback do conn.send_msg "Hello!" @@ -15,12 +24,21 @@ conn.errback do |e| puts "Got error: #{e}" end conn.stream do |msg| - puts "<#{msg}>" - if msg.data == "done" - conn.close_connection + conn.close_connection if msg.data == "done" + + message = JSON.parse(msg.data)[1] + case message['type'] + when 'paired' + puts "MYO PAIRED" + puts "msg: #{msg.inspect}" + when 'connected' + puts 'MYO CONNECTED' + puts "msg: #{msg.inspect}" + when 'orientation' + puts "msg: #{msg.inspect}" end end conn.disconnect do puts "gone"