Class: Led

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_wiimote.rb

Constant Summary collapse

HIGH =
1
LOW =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Led

Returns a new instance of Led.



15
16
17
18
# File 'lib/simple_wiimote.rb', line 15

def initialize(parent)
  @state, @status = LOW, :off
  @parent = parent
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



13
14
15
# File 'lib/simple_wiimote.rb', line 13

def state
  @state
end

Instance Method Details



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/simple_wiimote.rb', line 33

def blink(seconds=0.5, duration: nil)

  @status = :blink
  t2 = Time.now + duration if duration

  Thread.new do
    while @status == :blink do
      @state = 1
      (set_pin HIGH; sleep seconds; set_pin LOW; sleep seconds) 
      self.off if duration and Time.now >= t2
    end
    
  end
end

#offObject Also known as: stop



26
27
28
29
30
31
# File 'lib/simple_wiimote.rb', line 26

def off()
  
  return if self.off?
  @state, @status = LOW, :off
  @parent.on_ledchange
end

#off?Boolean

Returns:

  • (Boolean)


51
# File 'lib/simple_wiimote.rb', line 51

def off?() @status == :off end

#on(duration = nil) ⇒ Object



20
21
22
23
24
# File 'lib/simple_wiimote.rb', line 20

def on(duration=nil)
  @state, @status = HIGH, :on
  @parent.on_ledchange
  (sleep duration; self.off) if duration
end

#on?Boolean

Returns:

  • (Boolean)


50
# File 'lib/simple_wiimote.rb', line 50

def on?()  @status == :on  end