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
Public: On close.
-
#on_message(data) ⇒ Object
Public: On message.
-
#on_open ⇒ Object
Public: On open.
-
#start_driver ⇒ Object
Public: Starts the driver.
Instance Method Details
#on_close(code, reason) ⇒ Object
Public: On close
code - params reason - params
Returns nil
64 65 66 |
# File 'lib/artoo/drivers/leapmotion.rb', line 64 def on_close(code, reason) publish(event_topic_name("close"), code, reason) end |
#on_message(data) ⇒ Object
Public: On message
data - params
Returns nil
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/artoo/drivers/leapmotion.rb', line 42 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
Public: On open
Returns nil
31 32 33 34 35 |
# File 'lib/artoo/drivers/leapmotion.rb', line 31 def on_open publish(event_topic_name("open")) data = JSON.dump("enableGestures" => true) connection.text(data) end |
#start_driver ⇒ Object
Public: Starts the driver
Returns nil
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/artoo/drivers/leapmotion.rb', line 15 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 |