Class: ProconBypassMan::Bypass::SwitchToProcon

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/procon_bypass_man/bypass/switch_to_procon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

#get_callbacks, included, #run_callbacks

Constructor Details

#initialize(gadget:, procon:) ⇒ SwitchToProcon

Returns a new instance of SwitchToProcon.



13
14
15
16
# File 'lib/procon_bypass_man/bypass/switch_to_procon.rb', line 13

def initialize(gadget: , procon: )
  self.gadget = gadget
  self.procon = procon
end

Instance Attribute Details

#bypass_valueObject

Returns the value of attribute bypass_value.



11
12
13
# File 'lib/procon_bypass_man/bypass/switch_to_procon.rb', line 11

def bypass_value
  @bypass_value
end

#gadgetObject

Returns the value of attribute gadget.



11
12
13
# File 'lib/procon_bypass_man/bypass/switch_to_procon.rb', line 11

def gadget
  @gadget
end

#proconObject

Returns the value of attribute procon.



11
12
13
# File 'lib/procon_bypass_man/bypass/switch_to_procon.rb', line 11

def procon
  @procon
end

Instance Method Details

#runObject

ゆっくりでいい



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/procon_bypass_man/bypass/switch_to_procon.rb', line 19

def run
  self.bypass_value = ProconBypassMan::Bypass::BypassValue.new(nil)

  run_callbacks(:run) do
    next if $will_terminate_token

    raw_input = nil
    begin
      raw_input = self.gadget.read_nonblock(64)
      self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: raw_input)
    rescue IO::EAGAINWaitReadable
      next
    end

    if self.bypass_value.binary
      begin
        raw_data =
          case
          when self.bypass_value.binary.rumble_data? # TODO そもそも無効になっているので消していい
            binary = ProconBypassMan::RumbleBinary.new(binary: self.bypass_value.binary.raw)
            binary.noop!
            binary.raw
          else
            self.bypass_value.binary.raw
          end
        # バイブレーションを無効にしているのでおそらく書き込む必要はない
        # self.procon.write_nonblock(raw_data)
      rescue IO::EAGAINWaitReadable
        next
      end
    end
  end
end