Class: ProconBypassMan::Procon::AnalogStickManipulator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binary, method:) ⇒ AnalogStickManipulator

Returns a new instance of AnalogStickManipulator.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/procon_bypass_man/procon/analog_stick_manipulator.rb', line 6

def initialize(binary, method: )
  analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)

  if method =~ /tilt_left_stick_(completely)_to_(left|right)/
    power_level = $1
    direction = $2

    case direction
    when 'left'
      self.manipulated_abs_x = 400
      # yを引き継ぐとタンサンボムの溜まりが悪くなったので固定値を入れる
      self.manipulated_abs_y = analog_stick.abs_y
      # self.manipulated_abs_y = 1808
    when 'right'
      self.manipulated_abs_x = 3400
      self.manipulated_abs_y = 1808
    end

    return
  end

  if method =~ /tilt_left_stick_(completely)_to_(\d+)deg/
    power_level = $1
    arc_degree = $2.to_i
    syahen = 1800 # 最大まで傾けた状態
    neutral_position = ProconBypassMan.buttons_setting_configuration.neutral_position
    self.manipulated_abs_x = (syahen * Math.cos(arc_degree * Math::PI / 180)).to_i - neutral_position.x
    self.manipulated_abs_y = (syahen * Math.sin(arc_degree * Math::PI / 180)).to_i - neutral_position.y
    return
  end

  warn "error stick manipulator"
  self.manipulated_abs_x = analog_stick.abs_x
  self.manipulated_abs_y = analog_stick.abs_y
end

Instance Attribute Details

#manipulated_abs_xObject

Returns the value of attribute manipulated_abs_x.



4
5
6
# File 'lib/procon_bypass_man/procon/analog_stick_manipulator.rb', line 4

def manipulated_abs_x
  @manipulated_abs_x
end

#manipulated_abs_yObject

Returns the value of attribute manipulated_abs_y.



4
5
6
# File 'lib/procon_bypass_man/procon/analog_stick_manipulator.rb', line 4

def manipulated_abs_y
  @manipulated_abs_y
end

Instance Method Details

#to_binaryString

Returns:

  • (String)


44
45
46
47
48
49
# File 'lib/procon_bypass_man/procon/analog_stick_manipulator.rb', line 44

def to_binary
  ProconBypassMan::AnalogStickPosition.new(
    x: self.manipulated_abs_x,
    y: self.manipulated_abs_y,
  ).to_binary
end