Class: LeapMotion::Device
- Inherits:
-
Object
- Object
- LeapMotion::Device
- Includes:
- EventEmitter
- Defined in:
- lib/leapmotion/main.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(opts) ⇒ Device
constructor
A new instance of Device.
- #wait ⇒ Object
Constructor Details
#initialize(opts) ⇒ Device
Returns a new instance of Device.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/leapmotion/main.rb', line 17 def initialize(opts) @ws = WebSocket::Client::Simple.connect opts[:websocket] @options = opts @version = nil this = self @ws.on :message do |msg| data = Data.new JSON.parse msg.data rescue this.emit :error, "JSON parse error" if data.has_key? "gestures" and !data.gestures.empty? this.emit :gestures, data.gestures end if data.has_key? "currentFrameRate" this.emit :data, data elsif data.has_key? "version" this.version = data.version end end @ws.on :open do if this.[:gestures] data = {:enableGestures => true}.to_json send data end this.emit :connect end @ws.on :close do this.emit :disconnect end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/leapmotion/main.rb', line 15 def @options end |
#version ⇒ Object
Returns the value of attribute version.
14 15 16 |
# File 'lib/leapmotion/main.rb', line 14 def version @version end |
Instance Method Details
#close ⇒ Object
47 48 49 |
# File 'lib/leapmotion/main.rb', line 47 def close @ws.close end |
#wait ⇒ Object
51 52 53 54 55 |
# File 'lib/leapmotion/main.rb', line 51 def wait loop do sleep 1 end end |