Class: ProconBypassMan::DeviceConnection::OutputReportSubCommandTable

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

Defined Under Namespace

Classes: HIDSubCommandResponse

Constant Summary collapse

IGNORE_SUB_COMMANDS =
{
  "48-01" => true,
  "04-00" => true,
  "10-28" => true, # 返ってこないことがあった
}
SPECIAL_SUB_COMMANDS =

レスポンスに引数が含まれない

[
  "01",
  "02",
  "03",
  "30",
  "38", # home led
  "40",
  "48",
]
EXPECTED_SUB_COMMANDS =
[
  "01-04",
  "02-",
  "04-00",
  "08-00",
  "10-00",
  "10-50",
  "10-80",
  "10-98",
  "10-10",
  "30-",
  "40-",
  "48-", # Enable vibration
]

Instance Method Summary collapse

Constructor Details

#initializeOutputReportSubCommandTable

Returns a new instance of OutputReportSubCommandTable.



55
56
57
# File 'lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb', line 55

def initialize
  @table = {}
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


127
128
129
130
131
132
# File 'lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb', line 127

def completed?
  EXPECTED_SUB_COMMANDS.all? do |key|
    sub_command, sub_command_arg = key.split("-")
    has_value?(sub_command: sub_command, sub_command_arg: sub_command_arg)
  end
end

#has_key?(sub_command:, sub_command_arg:) ⇒ Boolean

Parameters:

  • sub_command (String)
  • sub_command_arg (String)

Returns:

  • (Boolean)


85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb', line 85

def has_key?(sub_command: , sub_command_arg: )
  if IGNORE_SUB_COMMANDS["#{sub_command}-#{sub_command_arg}"]
    return true
  end

  case sub_command
  when *SPECIAL_SUB_COMMANDS
    @table.key?(sub_command)
  else
    response = HIDSubCommandResponse.new(sub_command: sub_command, sub_command_arg: sub_command_arg)
    @table.key?(response.sub_command_with_arg)
  end
end

#has_unreceived_command?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb', line 112

def has_unreceived_command?
  !@table.values.all?(&:itself)
end

#has_value?(sub_command:, sub_command_arg:) ⇒ Boolean

Parameters:

  • sub_command (String)
  • sub_command_arg (String)

Returns:

  • (Boolean)


102
103
104
105
106
107
108
109
# File 'lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb', line 102

def has_value?(sub_command: , sub_command_arg: )
  if IGNORE_SUB_COMMANDS["#{sub_command}-#{sub_command_arg}"]
    return true
  end

  response = HIDSubCommandResponse.new(sub_command: sub_command, sub_command_arg: sub_command_arg)
  !!@table[response.sub_command_with_arg]
end

#mark_as_receive(sub_command:, sub_command_arg:) ⇒ void

This method returns an undefined value.

Parameters:

  • sub_command (String)
  • sub_command_arg (String)


75
76
77
78
79
80
# File 'lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb', line 75

def mark_as_receive(sub_command: , sub_command_arg: )
  response = HIDSubCommandResponse.new(sub_command: sub_command, sub_command_arg: sub_command_arg)
  if @table.key?(response.sub_command_with_arg)
    @table[response.sub_command_with_arg] = true
  end
end

#mask_as_send(sub_command:, sub_command_arg:) ⇒ void

This method returns an undefined value.

Parameters:

  • sub_command (String)
  • sub_command_arg (String)


62
63
64
65
66
67
68
69
70
# File 'lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb', line 62

def mask_as_send(sub_command: , sub_command_arg: )
  case sub_command
  when *SPECIAL_SUB_COMMANDS
    @table[sub_command] = false
  else
    response = HIDSubCommandResponse.new(sub_command: sub_command, sub_command_arg: sub_command_arg)
    @table[response.sub_command_with_arg] = false
  end
end

#unreceived_sub_command_with_argString, NilClass

Returns:

  • (String, NilClass)


117
118
119
120
121
122
123
124
# File 'lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb', line 117

def unreceived_sub_command_with_arg
  sub_command = @table.detect { |_key, value| !value }&.first
  if(arg = ProconBypassMan::DeviceConnection::ProconSettingOverrider::SPECIAL_SUB_COMMAND_ARGS[sub_command])
    "#{sub_command}#{arg}"
  else
    sub_command
  end
end