Class: Powermate::Event
- Inherits:
-
Object
- Object
- Powermate::Event
- Defined in:
- lib/powermate/event.rb
Instance Attribute Summary collapse
-
#clockwise ⇒ Object
readonly
Returns the value of attribute clockwise.
-
#counter_clockwise ⇒ Object
readonly
Returns the value of attribute counter_clockwise.
-
#pressed ⇒ Object
readonly
Returns the value of attribute pressed.
Instance Method Summary collapse
-
#initialize(raw_event, old_pressed) ⇒ Event
constructor
A new instance of Event.
- #to_hash ⇒ Object
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
#clockwise ⇒ Object (readonly)
Returns the value of attribute clockwise.
5 6 7 |
# File 'lib/powermate/event.rb', line 5 def clockwise @clockwise end |
#counter_clockwise ⇒ Object (readonly)
Returns the value of attribute counter_clockwise.
5 6 7 |
# File 'lib/powermate/event.rb', line 5 def counter_clockwise @counter_clockwise end |
#pressed ⇒ Object (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_hash ⇒ Object
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 |