Class: Powermate::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_event, old_pressed) ⇒ Event

Returns a new instance of Event.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/powermate/event.rb', line 7

def initialize raw_event, old_pressed
  @clockwise = false
  @counter_clockwise = false
  @pressed = old_pressed

  type = raw_event[16] == 1 ? :push : :rotate
  value = raw_event[20] == 1

  if type == :push
    @pressed = value
  elsif type == :rotate
    @clockwise = value
    @counter_clockwise = !value
  end

end

Instance Attribute Details

#clockwiseObject (readonly)

Returns the value of attribute clockwise.



5
6
7
# File 'lib/powermate/event.rb', line 5

def clockwise
  @clockwise
end

#counter_clockwiseObject (readonly)

Returns the value of attribute counter_clockwise.



5
6
7
# File 'lib/powermate/event.rb', line 5

def counter_clockwise
  @counter_clockwise
end

#pressedObject (readonly)

Returns the value of attribute pressed.



5
6
7
# File 'lib/powermate/event.rb', line 5

def pressed
  @pressed
end

Instance Method Details

#to_hashObject



24
25
26
27
28
29
30
# File 'lib/powermate/event.rb', line 24

def to_hash
  {
    clockwise: @clockwise,
    counter_clockwise: @counter_clockwise,
    pressed: @pressed
  }
end