lib/myo/client.rb in myo-ruby-0.1.0 vs lib/myo/client.rb in myo-ruby-0.2.0

- old
+ new

@@ -14,28 +14,32 @@ def start EM.run do conn = EventMachine::WebSocketClient.connect(@socket_url) conn.callback do - @callbacks_[:connected].call(self) + return unless @callbacks_[:connected] + instance_eval(&@callbacks_[:connected]) end conn.errback do |e| - @callbacks_[:error].call(self) + return unless @callbacks_[:error] + instance_eval(e, &@callbacks_[:error]) end conn.stream do |msg| conn.close_connection if msg.data == "done" event = JSON.parse(msg.data)[1] case event['type'] when 'pose' + break unless @callbacks_[:pose] pose = event['pose'] - @callbacks_[:pose].call(self, @pool_[:prev_pose], :off) if @pool_[:prev_pose] - @callbacks_[:pose].call(self, pose, :on) + instance_eval(@pool_[:prev_pose], :off, &@callbacks_[:pose]) if @pool_[:prev_pose] + instance_eval(pose, :on, &@callbacks_[:pose]) @pool_[:prev_pose] = pose when 'orientation' + break unless @callbacks_[:periodic] e = OpenStruct.new({ :accel => OpenStruct.new({ :x => event['accelerometer'][0], :y => event['accelerometer'][1], :z => event['accelerometer'][2] @@ -46,10 +50,10 @@ :z => event['gyroscope'][2] }), :orientation => OpenStruct.new(event['orientation']) }) @pool_[:latest_orientation] = e - @callbacks_[:periodic].call(self, e) + instance_eval(e, &@callbacks_[:periodic]) end end conn.disconnect do EM::stop_event_loop