Class: ProconBypassMan::AnalogStickPosition
- Inherits:
-
Object
- Object
- ProconBypassMan::AnalogStickPosition
- Defined in:
- lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(x:, y:) ⇒ AnalogStickPosition
constructor
A new instance of AnalogStickPosition.
- #to_binary ⇒ Object
Constructor Details
#initialize(x:, y:) ⇒ AnalogStickPosition
Returns a new instance of AnalogStickPosition.
4 5 6 7 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb', line 4 def initialize(x:, y:) @x = x.to_i @y = y.to_i end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
2 3 4 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb', line 2 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
2 3 4 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb', line 2 def y @y end |
Instance Method Details
#to_binary ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb', line 9 def to_binary analog_stick_data = [ (@x & "0xff".to_i(16)), ((@y << 4) & "0xf0".to_i(16)) | ((@x >> 8) & "0x0f".to_i(16)), (@y >> 4) & "0xff".to_i(16), ] hex = analog_stick_data.map{ |x| x.to_s(16).rjust(2, "0") }.join [hex].pack("H*") end |