Sha256: d35956b30bc837199ec8e35632797d5984bf0f5e67c5ca476a1a8981be89f8b2

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

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
    @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!"
        conn.send_msg "done"
      end

      conn.errback do |e|
        puts "Got error: #{e}"
      end

      conn.stream do |msg|
        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"
        EM::stop_event_loop
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
myo-ruby-wrapper-0.0.2 lib/myo/band.rb