Class: BubbleWrap::Motion::GenericMotionInterface

Inherits:
Object
  • Object
show all
Defined in:
motion/motion/motion.rb

Direct Known Subclasses

Accelerometer, DeviceMotion, Gyroscope, Magnetometer

Instance Method Summary collapse

Constructor Details

#initialize(manager) ⇒ GenericMotionInterface


61
62
63
# File 'motion/motion/motion.rb', line 61

def initialize(manager)
  @manager = manager
end

Instance Method Details

#every(time = nil, options = {}, &blk) ⇒ Object


73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'motion/motion/motion.rb', line 73

def every(time=nil, options={}, &blk)
  raise "A block is required" unless blk
  blk.weak! if BubbleWrap.use_weak_callbacks?

  if time.is_a?(NSDictionary)
    options = time
  elsif time
    options = options.merge(interval: time)
  end

  self.start(options, &blk)
  return self
end

#once(options = {}, &blk) ⇒ Object


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'motion/motion/motion.rb', line 87

def once(options={}, &blk)
  raise "A block is required" unless blk
  blk.weak! if BubbleWrap.use_weak_callbacks?

  @called_once = false
  every(options) do |result, error|
    unless @called_once
      @called_once = true
      blk.call(result, error)
    end
    self.stop
  end

  return self
end

#repeat(options = {}, &blk) ⇒ Object


65
66
67
68
69
70
71
# File 'motion/motion/motion.rb', line 65

def repeat(options={}, &blk)
  raise "A block is required" unless blk
  blk.weak! if BubbleWrap.use_weak_callbacks?

  self.start(options, &blk)
  return self
end