Sha256: cb473af72bcd80266aacecd3265460535a7a3ef7fcded8be6ec5847936a2db9f
Contents?: true
Size: 872 Bytes
Versions: 1
Compression:
Stored size: 872 Bytes
Contents
# frozen_string_literal: true class ProconBypassMan::Procon::AnalogStick attr_accessor :neutral_position attr_writer :bin_x, :bin_y 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 def abs_x @bin_x.to_i(2) end def abs_y @bin_y.to_i(2) end def relative_x @bin_x.to_i(2) - neutral_position.x end def relative_y @bin_y.to_i(2) - neutral_position.y end # @return [Float] def relative_hypotenuse Math.sqrt((relative_x**2) + (relative_y**2)).floor(6) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
procon_bypass_man-0.3.12 | lib/procon_bypass_man/procon/value_objects/analog_stick.rb |