Class: BubbleWrap::Motion::DeviceMotion

Inherits:
GenericMotionInterface show all
Defined in:
motion/motion/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)


406
407
408
# File 'motion/motion/motion.rb', line 406

def active?
  @manager.deviceMotionActive?
end

#available?Boolean

Returns:

  • (Boolean)


402
403
404
# File 'motion/motion/motion.rb', line 402

def available?
  @manager.deviceMotionAvailable?
end

#convert_reference_frame(reference_frame) ⇒ Object



387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'motion/motion/motion.rb', line 387

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



410
411
412
# File 'motion/motion/motion.rb', line 410

def data
  @manager.deviceMotion
end

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



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'motion/motion/motion.rb', line 287

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



414
415
416
# File 'motion/motion/motion.rb', line 414

def stop
  @manager.stopDeviceMotionUpdates
end