Class: ProconBypassMan::Procon::AnalogStick

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/procon/value_objects/analog_stick.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.buttons_setting_configuration.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

Parameters:

  • value

    the value to set the attribute bin_x to.



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

Parameters:

  • value

    the value to set the attribute bin_y to.



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_positionObject

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_xObject



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_yObject



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_hypotenuseFloat

Returns:

  • (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_xObject



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_yObject



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