Class: LeapMotion::Device

Inherits:
Object
  • Object
show all
Includes:
EventEmitter
Defined in:
lib/leapmotion/main.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.options[: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

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/leapmotion/main.rb', line 15

def options
  @options
end

#versionObject

Returns the value of attribute version.



14
15
16
# File 'lib/leapmotion/main.rb', line 14

def version
  @version
end

Instance Method Details

#closeObject



47
48
49
# File 'lib/leapmotion/main.rb', line 47

def close
  @ws.close
end

#waitObject



51
52
53
54
55
# File 'lib/leapmotion/main.rb', line 51

def wait
  loop do
    sleep 1
  end
end