Class: BubbleWrap::Motion::DeviceMotion

Inherits:
GenericMotionInterface show all
Defined in:
motion/motion/device_motion.rb

Instance Method Summary collapse

Methods inherited from GenericMotionInterface

#every, #initialize, #once, #repeat

Constructor Details

This class inherits a constructor from BubbleWrap::Motion::GenericMotionInterface

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'motion/motion/device_motion.rb', line 124

def active?
  @manager.deviceMotionActive?
end

#available?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'motion/motion/device_motion.rb', line 120

def available?
  @manager.deviceMotionAvailable?
end

#convert_reference_frame(reference_frame) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'motion/motion/device_motion.rb', line 105

def convert_reference_frame(reference_frame)
  case reference_frame
  when :arbitrary_z
    CMAttitudeReferenceFrameXArbitraryZVertical
  when :corrected_z
    CMAttitudeReferenceFrameXArbitraryCorrectedZVertical
  when :magnetic_north
    CMAttitudeReferenceFrameXMagneticNorthZVertical
  when :true_north
    CMAttitudeReferenceFrameXTrueNorthZVertical
  else
    reference_frame
  end
end

#dataObject



128
129
130
# File 'motion/motion/device_motion.rb', line 128

def data
  @manager.deviceMotion
end

#start(options = {}, &handler) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'motion/motion/device_motion.rb', line 5

def start(options={}, &handler)
  if options.key?(:interval)
    @manager.deviceMotionUpdateInterval = options[:interval]
  end

  if options.key?(:reference)
    reference_frame = convert_reference_frame(options[:reference])
  else
    reference_frame = nil
  end

  if handler
    queue = convert_queue(options[:queue])

    if reference_frame
        @manager.startDeviceMotionUpdatesUsingReferenceFrame(reference_frame, toQueue: queue, withHandler: internal_handler(handler))
    else
        @manager.startDeviceMotionUpdatesToQueue(queue, withHandler: internal_handler(handler))
    end
  else
    if reference_frame
      @manager.startDeviceMotionUpdatesUsingReferenceFrame(reference_frame)
    else
      @manager.startDeviceMotionUpdates
    end
  end

  return self
end

#stopObject



132
133
134
# File 'motion/motion/device_motion.rb', line 132

def stop
  @manager.stopDeviceMotionUpdates
end