Class: ProconBypassMan::Procon::AnalogStick
- Inherits:
-
Object
- Object
- ProconBypassMan::Procon::AnalogStick
- Defined in:
- lib/procon_bypass_man/procon/value_objects/analog_stick.rb
Instance Attribute Summary collapse
-
#bin_x ⇒ Object
writeonly
Sets the attribute bin_x.
-
#bin_y ⇒ Object
writeonly
Sets the attribute bin_y.
-
#neutral_position ⇒ Object
Returns the value of attribute neutral_position.
Instance Method Summary collapse
- #abs_x ⇒ Object
- #abs_y ⇒ Object
-
#initialize(binary:) ⇒ AnalogStick
constructor
A new instance of AnalogStick.
- #relative_hypotenuse ⇒ Float
- #relative_x ⇒ Object
- #relative_y ⇒ Object
Constructor Details
#initialize(binary:) ⇒ AnalogStick
Returns a new instance of AnalogStick.
7 8 9 10 11 12 13 14 15 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick.rb', line 7 def initialize(binary: ) @neutral_position = ProconBypassMan..neutral_position bytes = binary[ProconBypassMan::Procon::ButtonCollection::LEFT_ANALOG_STICK.fetch(:byte_position)] byte6, byte7, byte8 = bytes.each_char.map { |x| x.unpack("C").first.to_s(2).rjust(8, "0") } self.bin_x = "#{byte7[4..7]}#{byte6}" self.bin_y = "#{byte8}#{byte7[0..3]}" freeze end |
Instance Attribute Details
#bin_x=(value) ⇒ Object (writeonly)
Sets the attribute bin_x
5 6 7 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick.rb', line 5 def bin_x=(value) @bin_x = value end |
#bin_y=(value) ⇒ Object (writeonly)
Sets the attribute bin_y
5 6 7 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick.rb', line 5 def bin_y=(value) @bin_y = value end |
#neutral_position ⇒ Object
Returns the value of attribute neutral_position.
4 5 6 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick.rb', line 4 def neutral_position @neutral_position end |
Instance Method Details
#abs_x ⇒ Object
17 18 19 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick.rb', line 17 def abs_x @bin_x.to_i(2) end |
#abs_y ⇒ Object
21 22 23 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick.rb', line 21 def abs_y @bin_y.to_i(2) end |
#relative_hypotenuse ⇒ Float
34 35 36 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick.rb', line 34 def relative_hypotenuse Math.sqrt((relative_x**2) + (relative_y**2)).floor(6) end |
#relative_x ⇒ Object
25 26 27 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick.rb', line 25 def relative_x @bin_x.to_i(2) - neutral_position.x end |
#relative_y ⇒ Object
29 30 31 |
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick.rb', line 29 def relative_y @bin_y.to_i(2) - neutral_position.y end |