Sha256: 18311eb20eda1be7d92b022273db084ca1712de1f7c7ee1d6a6d66bf238581be

Contents?: true

Size: 1.8 KB

Versions: 10

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require "procon_bypass_man/bypass/bypass_command"

class ProconBypassMan::Bypass::SwitchToProcon
  include ProconBypassMan::Callbacks

  define_callbacks :run
  set_callback :run, :after, :log_after_run

  attr_accessor :gadget, :procon, :bypass_value

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

  # ゆっくりでいい
  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

  private

  def log_after_run
    return unless bypass_value.to_text

    if ProconBypassMan.config.verbose_bypass_log
      ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
    else
      # ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
      #   ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
      # end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.12 lib/procon_bypass_man/bypass/switch_to_procon.rb
procon_bypass_man-0.3.11 lib/procon_bypass_man/bypass/switch_to_procon.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/bypass/switch_to_procon.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/bypass/switch_to_procon.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/bypass/switch_to_procon.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/bypass/switch_to_procon.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/bypass/switch_to_procon.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/bypass/switch_to_procon.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/bypass/switch_to_procon.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/bypass/switch_to_procon.rb