Class: ProconBypassMan::DeviceConnection::PreBypass

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/device_connection/pre_bypass.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gadget:, procon:) ⇒ PreBypass

Returns a new instance of PreBypass.



4
5
6
7
8
# File 'lib/procon_bypass_man/device_connection/pre_bypass.rb', line 4

def initialize(gadget: , procon: )
  self.gadget = ProconBypassMan::DeviceModel.new(gadget)
  self.procon = ProconBypassMan::DeviceModel.new(procon)
  self.output_report_watcher = ProconBypassMan::DeviceConnection::OutputReportWatcher.new
end

Instance Attribute Details

#gadgetObject

Returns the value of attribute gadget.



2
3
4
# File 'lib/procon_bypass_man/device_connection/pre_bypass.rb', line 2

def gadget
  @gadget
end

#output_report_watcherObject

Returns the value of attribute output_report_watcher.



2
3
4
# File 'lib/procon_bypass_man/device_connection/pre_bypass.rb', line 2

def output_report_watcher
  @output_report_watcher
end

#proconObject

Returns the value of attribute procon.



2
3
4
# File 'lib/procon_bypass_man/device_connection/pre_bypass.rb', line 2

def procon
  @procon
end

Instance Method Details

#execute!void

This method returns an undefined value.



11
12
13
14
15
16
17
18
19
# File 'lib/procon_bypass_man/device_connection/pre_bypass.rb', line 11

def execute!
  loop do
    run_once

    if output_report_watcher.timeout_or_completed?
      break
    end
  end
end

#run_oncevoid

This method returns an undefined value.



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/device_connection/pre_bypass.rb', line 22

def run_once
  begin
    raw_data = non_blocking_read_switch
    output_report_watcher.mark_as_send(raw_data)
    ProconBypassMan.logger.info "[pre_bypass] >>> #{raw_data.unpack("H*").first}"
    send_procon(raw_data)
  rescue IO::EAGAINWaitReadable
    # no-op
  end

  3.times do
    begin
      raw_data = non_blocking_read_procon
      output_report_watcher.mark_as_receive(raw_data)
      ProconBypassMan.logger.info "[pre_bypass] <<< #{raw_data.unpack1("H*")}"

      if(recognized_procon_color = ProconBypassMan.ephemeral_config.recognized_procon_color)
        first_data_part = raw_data[0].unpack1("H*")
        sub_command = raw_data[15..16].unpack1("H*")
        if first_data_part == '21' && sub_command == "5060"
          raw_data[recognized_procon_color.byte_position] = recognized_procon_color.to_bytes
        end
      end

      send_switch(raw_data)
    rescue IO::EAGAINWaitReadable
      # no-op
    end
  end
end