Class: Artoo::Drivers::Leapmotion
- Inherits:
-
Driver
- Object
- Driver
- Artoo::Drivers::Leapmotion
- Defined in:
- lib/artoo/drivers/leapmotion.rb,
lib/artoo/drivers/leapmotion/hand.rb,
lib/artoo/drivers/leapmotion/frame.rb,
lib/artoo/drivers/leapmotion/gesture.rb,
lib/artoo/drivers/leapmotion/pointable.rb
Overview
The leapmotion driver behaviors
Defined Under Namespace
Classes: Frame, Gesture, Hand, Pointable
Instance Method Summary collapse
- #on_close(code, reason) ⇒ Object
- #on_message(data) ⇒ Object
- #on_open ⇒ Object
-
#start_driver ⇒ Object
Start driver and any required connections.
Instance Method Details
#on_close(code, reason) ⇒ Object
46 47 48 |
# File 'lib/artoo/drivers/leapmotion.rb', line 46 def on_close(code, reason) publish(event_topic_name("close"), code, reason) end |
#on_message(data) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/artoo/drivers/leapmotion.rb', line 30 def (data) = JSON.parse(data) if .key?("id") and .key?("timestamp") frame = Artoo::Drivers::Leapmotion::Frame.new() publish(event_topic_name("frame"), frame) frame.hands.each {|h| publish(event_topic_name("hand"), h)} if frame.hands frame.gestures.each {|g| publish(event_topic_name("gesture"), g)} if frame.gestures frame.pointables.each {|p| publish(event_topic_name("pointable"), p)} if frame.pointables else publish(event_topic_name("error"), data) end rescue Exception => e publish(event_topic_name("error"), data) end |
#on_open ⇒ Object
24 25 26 27 28 |
# File 'lib/artoo/drivers/leapmotion.rb', line 24 def on_open publish(event_topic_name("open")) data = JSON.dump("enableGestures" => true) connection.text(data) end |
#start_driver ⇒ Object
Start driver and any required connections
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/artoo/drivers/leapmotion.rb', line 11 def start_driver begin connection.handler = current_actor connection.start super rescue Exception => e Logger.error "Error starting Leapmotion driver!" Logger.error e. Logger.error e.backtrace.inspect end end |