procon_bypass_man 0.1.21 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +9 -0
  3. data/.github/workflows/gitleacks.yml +11 -0
  4. data/.gitignore +1 -0
  5. data/CHANGELOG.md +24 -0
  6. data/Gemfile.lock +4 -4
  7. data/README.md +4 -1
  8. data/docs/getting_started.md +70 -5
  9. data/docs/setting/left-analogstick-cap.md +1 -1
  10. data/docs/setting/splatoon2_macro_dasei_cancel.md +4 -0
  11. data/docs/setting/splatoon2_macro_sokuwari_bubble.md +4 -0
  12. data/docs/setting/splatoon2_shake_tansan.md +47 -0
  13. data/docs/setup_raspi.md +0 -1
  14. data/lib/procon_bypass_man/background/jobs/post_completed_remote_macro_job.rb +17 -0
  15. data/lib/procon_bypass_man/background.rb +1 -0
  16. data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +142 -80
  17. data/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +3 -1
  18. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/button.rb +28 -0
  19. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/button_list.rb +31 -0
  20. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/disable_macro_if_pressed.rb +28 -0
  21. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/flip_if_pressed.rb +31 -0
  22. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/force_neutral.rb +28 -0
  23. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/if_pressed.rb +26 -0
  24. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/if_pressed_allows_nil.rb +28 -0
  25. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/open_macro_steps.rb +26 -0
  26. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer.rb +17 -0
  27. data/lib/procon_bypass_man/buttons_setting_configuration.rb +5 -4
  28. data/lib/procon_bypass_man/{commands → bypass}/bypass_command.rb +36 -24
  29. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +4 -0
  30. data/lib/procon_bypass_man/bypass.rb +43 -23
  31. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +2 -3
  32. data/lib/procon_bypass_man/commands/send_error_command.rb +2 -2
  33. data/lib/procon_bypass_man/commands.rb +0 -3
  34. data/lib/procon_bypass_man/configuration.rb +29 -3
  35. data/lib/procon_bypass_man/device_connection/command.rb +28 -0
  36. data/lib/procon_bypass_man/device_connection/executor.rb +190 -0
  37. data/lib/procon_bypass_man/device_connection/output_report_generator.rb +42 -0
  38. data/lib/procon_bypass_man/device_connection/output_report_markerable.rb +28 -0
  39. data/lib/procon_bypass_man/device_connection/output_report_sub_command_table.rb +133 -0
  40. data/lib/procon_bypass_man/device_connection/output_report_watcher.rb +41 -0
  41. data/lib/procon_bypass_man/device_connection/pre_bypass.rb +67 -0
  42. data/lib/procon_bypass_man/device_connection/procon_setting_overrider.rb +78 -0
  43. data/lib/procon_bypass_man/device_connection/spoofing_output_report_watcher.rb +39 -0
  44. data/lib/procon_bypass_man/device_connection.rb +16 -0
  45. data/lib/procon_bypass_man/device_model.rb +17 -0
  46. data/lib/procon_bypass_man/io_monitor.rb +20 -1
  47. data/lib/procon_bypass_man/plugin/splatoon2/macro/charge_tansan_bomb.rb +21 -0
  48. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +1 -1
  49. data/lib/procon_bypass_man/plugins.rb +1 -0
  50. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +4 -23
  51. data/lib/procon_bypass_man/procon/analog_stick_manipulator.rb +36 -0
  52. data/lib/procon_bypass_man/procon/layer_changer.rb +4 -1
  53. data/lib/procon_bypass_man/procon/macro.rb +5 -2
  54. data/lib/procon_bypass_man/procon/macro_builder.rb +20 -20
  55. data/lib/procon_bypass_man/procon/macro_plugin_map.rb +23 -0
  56. data/lib/procon_bypass_man/procon/macro_registry.rb +21 -10
  57. data/lib/procon_bypass_man/procon/suppress_rumble.rb +13 -0
  58. data/lib/procon_bypass_man/procon/user_operation.rb +29 -15
  59. data/lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb +18 -0
  60. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/base.rb +0 -0
  61. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/has_immutable_binary.rb +0 -0
  62. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/has_mutable_binary.rb +0 -0
  63. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/inbound_procon_binary.rb +5 -0
  64. data/lib/procon_bypass_man/{domains → procon/value_objects}/binary/processing_procon_binary.rb +6 -1
  65. data/lib/procon_bypass_man/procon/value_objects/binary.rb +11 -0
  66. data/lib/procon_bypass_man/{domains → procon/value_objects}/bypass_mode.rb +0 -0
  67. data/lib/procon_bypass_man/procon/value_objects/rumble_binary.rb +18 -0
  68. data/lib/procon_bypass_man/procon.rb +27 -5
  69. data/lib/procon_bypass_man/remote_macro/queue_over_process.rb +62 -0
  70. data/lib/procon_bypass_man/remote_macro/remote_macro_object.rb +30 -0
  71. data/lib/procon_bypass_man/remote_macro/remote_macro_receiver.rb +37 -0
  72. data/lib/procon_bypass_man/remote_macro/remote_macro_sender.rb +8 -0
  73. data/lib/procon_bypass_man/remote_macro/task.rb +6 -0
  74. data/lib/procon_bypass_man/remote_macro/task_queue.rb +13 -0
  75. data/lib/procon_bypass_man/remote_macro.rb +14 -0
  76. data/lib/procon_bypass_man/{commands → remote_pbm_action/commands}/run_remote_pbm_action_dispatch_command.rb +0 -0
  77. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +7 -1
  78. data/lib/procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object.rb +1 -1
  79. data/lib/procon_bypass_man/remote_pbm_action.rb +2 -0
  80. data/lib/procon_bypass_man/runner.rb +13 -13
  81. data/lib/procon_bypass_man/support/cycle_sleep.rb +22 -0
  82. data/lib/procon_bypass_man/support/device_mouse_finder.rb +60 -0
  83. data/lib/procon_bypass_man/{device_procon_finder.rb → support/device_procon_finder.rb} +0 -2
  84. data/lib/procon_bypass_man/support/never_exit_accidentally.rb +3 -3
  85. data/lib/procon_bypass_man/support/remote_macro_http_client.rb +9 -0
  86. data/lib/procon_bypass_man/support/safe_timeout.rb +7 -1
  87. data/lib/procon_bypass_man/{usb_device_controller.rb → support/usb_device_controller.rb} +9 -6
  88. data/lib/procon_bypass_man/support/yaml_loader.rb +12 -0
  89. data/lib/procon_bypass_man/version.rb +1 -1
  90. data/lib/procon_bypass_man/websocket/{pbm_job_client.rb → client.rb} +32 -10
  91. data/lib/procon_bypass_man.rb +69 -46
  92. data/procon_bypass_man.gemspec +1 -1
  93. data/project_template/app.rb +19 -4
  94. data/sig/main.rbs +4 -16
  95. metadata +55 -17
  96. data/lib/procon_bypass_man/commands/connect_device_command.rb +0 -18
  97. data/lib/procon_bypass_man/device_connector.rb +0 -296
  98. data/lib/procon_bypass_man/domains.rb +0 -12
@@ -0,0 +1,28 @@
1
+ module ProconBypassMan
2
+ class ButtonsSettingConfiguration
3
+ module ParamNormalizer
4
+ class Button
5
+ attr_reader :button
6
+
7
+ def initialize(button)
8
+ @button = button
9
+ end
10
+
11
+ def to_value!
12
+ case button
13
+ when TrueClass, FalseClass, NilClass, Array, Integer
14
+ raise UnSupportValueError
15
+ when Symbol, String
16
+ unless !!ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP[button.to_sym]
17
+ raise UnexpectedValueError
18
+ end
19
+
20
+ return button.to_sym
21
+ else
22
+ raise UnexpectedValueError
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ module ProconBypassMan
2
+ class ButtonsSettingConfiguration
3
+ module ParamNormalizer
4
+ class ButtonList
5
+ attr_reader :button
6
+
7
+ def initialize(button)
8
+ @button = button
9
+ end
10
+
11
+ # @return [Array]
12
+ # @raise [UnSupportValueError]
13
+ # @raise [UnexpectedValueError]
14
+ def to_value!
15
+ case button
16
+ when Integer, TrueClass, FalseClass, NilClass
17
+ raise UnSupportValueError
18
+ when Symbol
19
+ return [button]
20
+ when String
21
+ return [button.to_sym]
22
+ when Array
23
+ return button.map(&:to_sym).uniq
24
+ else
25
+ raise UnexpectedValueError
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ module ProconBypassMan
2
+ class ButtonsSettingConfiguration
3
+ module ParamNormalizer
4
+ class DisableMacroIfPressed
5
+ attr_reader :value
6
+
7
+ def initialize(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_value!
12
+ case value
13
+ when FalseClass, Integer, TrueClass
14
+ raise UnSupportValueError
15
+ when Symbol, String
16
+ return [value.to_sym]
17
+ when Array
18
+ return value.map(&:to_sym).uniq
19
+ when NilClass # 常に対象のmacroをdisableにする
20
+ return [true]
21
+ else
22
+ raise UnexpectedValueError
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ module ProconBypassMan
2
+ class ButtonsSettingConfiguration
3
+ module ParamNormalizer
4
+ class FlipIfPressed
5
+ attr_reader :value
6
+
7
+ def initialize(value, button: )
8
+ @value = value
9
+ @button = button
10
+ end
11
+
12
+ def to_value!
13
+ case value
14
+ when Integer
15
+ raise UnSupportValueError
16
+ when TrueClass
17
+ return [@button]
18
+ when Symbol, String
19
+ return [value.to_sym]
20
+ when Array
21
+ return value.map(&:to_sym).uniq
22
+ when FalseClass, NilClass
23
+ return false
24
+ else
25
+ raise UnexpectedValueError
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ module ProconBypassMan
2
+ class ButtonsSettingConfiguration
3
+ module ParamNormalizer
4
+ class ForceNeutral
5
+ attr_reader :force_neutral
6
+
7
+ def initialize(force_neutral)
8
+ @force_neutral = force_neutral
9
+ end
10
+
11
+ def to_value!
12
+ case force_neutral
13
+ when Integer, TrueClass
14
+ raise UnSupportValueError
15
+ when Symbol, String
16
+ return [force_neutral.to_sym]
17
+ when Array
18
+ return force_neutral.map(&:to_sym).uniq
19
+ when FalseClass, NilClass
20
+ return nil
21
+ else
22
+ raise UnexpectedValueError
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module ProconBypassMan
2
+ class ButtonsSettingConfiguration
3
+ module ParamNormalizer
4
+ class IfPressed
5
+ attr_reader :value
6
+
7
+ def initialize(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_value!
12
+ case value
13
+ when Integer, TrueClass, FalseClass, NilClass
14
+ raise UnSupportValueError
15
+ when Symbol, String
16
+ return [value.to_sym]
17
+ when Array
18
+ return value.map(&:to_sym).uniq
19
+ else
20
+ raise UnexpectedValueError
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ module ProconBypassMan
2
+ class ButtonsSettingConfiguration
3
+ module ParamNormalizer
4
+ class IfPressedAllowsFalsy
5
+ attr_reader :value
6
+
7
+ def initialize(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_value!
12
+ case value
13
+ when Integer, TrueClass
14
+ raise UnSupportValueError
15
+ when Symbol, String
16
+ return [value.to_sym]
17
+ when Array
18
+ return value.map(&:to_sym).uniq
19
+ when FalseClass, NilClass
20
+ # OK
21
+ else
22
+ raise UnexpectedValueError
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module ProconBypassMan
2
+ class ButtonsSettingConfiguration
3
+ module ParamNormalizer
4
+ class OpenMacroSteps
5
+ attr_reader :steps
6
+
7
+ def initialize(steps)
8
+ @steps = steps
9
+ end
10
+
11
+ def to_value!
12
+ case steps
13
+ when Integer, TrueClass, FalseClass, NilClass
14
+ raise UnSupportValueError
15
+ when String, Symbol
16
+ return [steps.to_sym]
17
+ when Array
18
+ return steps.map(&:to_sym)
19
+ else
20
+ raise UnexpectedValueError
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ require "procon_bypass_man/buttons_setting_configuration/param_normalizer/button_list"
2
+ require "procon_bypass_man/buttons_setting_configuration/param_normalizer/button"
3
+ require "procon_bypass_man/buttons_setting_configuration/param_normalizer/force_neutral"
4
+ require "procon_bypass_man/buttons_setting_configuration/param_normalizer/if_pressed_allows_nil"
5
+ require "procon_bypass_man/buttons_setting_configuration/param_normalizer/flip_if_pressed"
6
+ require "procon_bypass_man/buttons_setting_configuration/param_normalizer/disable_macro_if_pressed"
7
+ require "procon_bypass_man/buttons_setting_configuration/param_normalizer/if_pressed"
8
+ require "procon_bypass_man/buttons_setting_configuration/param_normalizer/open_macro_steps"
9
+
10
+ module ProconBypassMan
11
+ class ButtonsSettingConfiguration
12
+ module ParamNormalizer
13
+ class UnSupportValueError < StandardError; end
14
+ class UnexpectedValueError < UnSupportValueError; end
15
+ end
16
+ end
17
+ end
@@ -3,7 +3,7 @@ require "procon_bypass_man/buttons_setting_configuration/loader"
3
3
  require "procon_bypass_man/buttons_setting_configuration/layer"
4
4
 
5
5
  module ProconBypassMan
6
- class AnalogStickPosition < Struct.new(:x, :y); end
6
+ class Position < Struct.new(:x, :y); end
7
7
 
8
8
  class ButtonsSettingConfiguration
9
9
  attr_accessor :layers,
@@ -90,7 +90,7 @@ module ProconBypassMan
90
90
  end
91
91
 
92
92
  def set_neutral_position(x, y)
93
- self.neutral_position = AnalogStickPosition.new(x, y).freeze
93
+ self.neutral_position = Position.new(x, y).freeze
94
94
  self
95
95
  end
96
96
 
@@ -103,14 +103,15 @@ module ProconBypassMan
103
103
  self.mode_plugins = {}
104
104
  # プロセスを一度起動するとsetting_pathは変わらない、という想定なので適当に扱う. resetでは初期化しない
105
105
  # self.setting_path = nil
106
- self.macro_plugins = {}
106
+ # どこかで初期化している気がするのでコメントアウト
107
+ self.macro_plugins = ProconBypassMan::Procon::MacroPluginMap.new # ProconBypassMan::Procon::MacroRegistry.reset!と重複している
107
108
  self.layers = {
108
109
  up: Layer.new,
109
110
  down: Layer.new,
110
111
  left: Layer.new,
111
112
  right: Layer.new,
112
113
  }
113
- @neutral_position = AnalogStickPosition.new(2124, 1808).freeze
114
+ @neutral_position = Position.new(2124, 1808).freeze
114
115
  end
115
116
  end
116
117
  end
@@ -1,18 +1,23 @@
1
1
  class ProconBypassMan::BypassCommand
2
2
  include ProconBypassMan::SignalHandler
3
3
 
4
+ module WILL_TERMINATE_TOKEN
5
+ TERMINATE = :terminate
6
+ RESTART = :restart
7
+ end
8
+
4
9
  def initialize(gadget:, procon:)
5
10
  @gadget = gadget
6
11
  @procon = procon
7
12
 
8
- ProconBypassMan::IOMonitor.start!
13
+ ProconBypassMan::IOMonitor.start! if ProconBypassMan.io_monitor_logging
9
14
  ProconBypassMan::Background::JobRunner.queue.clear # forkしたときに残留物も移ってしまうため
10
15
  ProconBypassMan::Background::JobRunner.start!
11
16
  end
12
17
 
13
18
  def execute
14
19
  self_read, self_write = IO.pipe
15
- %w(TERM INT).each do |sig|
20
+ %w(TERM INT USR2).each do |sig|
16
21
  begin
17
22
  trap sig do
18
23
  self_write.puts(sig)
@@ -28,30 +33,22 @@ class ProconBypassMan::BypassCommand
28
33
  monitor2 = ProconBypassMan::IOMonitor.new(label: "procon -> switch")
29
34
  ProconBypassMan.logger.info "Thread1を起動します"
30
35
 
31
- @send_interval = 0.005
36
+ cycle_sleep = ProconBypassMan::CycleSleep.new(cycle_interval: 1, execution_cycle: ProconBypassMan.config.bypass_mode.gadget_to_procon_interval)
32
37
 
33
38
  t1 = Thread.new do
34
- timer = ProconBypassMan::SafeTimeout.new(timeout: Time.now + 10)
35
- @did_first_step = false
39
+ if ProconBypassMan.config.bypass_mode.mode == ProconBypassMan::BypassMode::TYPE_AGGRESSIVE
40
+ ProconBypassMan.logger.info "TYPE_AGGRESSIVEなのでThread1を終了します"
41
+ monitor1.shutdown
42
+ next
43
+ end
44
+
36
45
  loop do
37
- bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor1)
38
46
  break if $will_terminate_token
39
- !@did_first_step && timer.throw_if_timeout!
40
- bypass.send_gadget_to_procon!
41
- sleep(@send_interval)
42
- rescue ProconBypassMan::SafeTimeout::Timeout
43
- case ProconBypassMan.config.bypass_mode.mode
44
- when ProconBypassMan::BypassMode::TYPE_AGGRESSIVE
45
- ProconBypassMan.logger.info "10秒経過したのでThread1を終了します"
46
- monitor1.shutdown
47
- break
48
- when ProconBypassMan::BypassMode::TYPE_NORMAL
49
- ProconBypassMan.logger.info "10秒経過したのでsend_intervalを長くします"
50
- @send_interval = ProconBypassMan.config.bypass_mode.gadget_to_procon_interval
51
- else
52
- raise "unknown type"
47
+
48
+ cycle_sleep.sleep_or_execute do
49
+ bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor1)
50
+ bypass.send_gadget_to_procon!
53
51
  end
54
- @did_first_step = true
55
52
  rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError, Errno::ESHUTDOWN => e
56
53
  ProconBypassMan::SendErrorCommand.execute(error: "Switchとの切断されました.終了処理を開始します. #{e.full_message}")
57
54
  Process.kill "TERM", Process.ppid
@@ -60,6 +57,7 @@ class ProconBypassMan::BypassCommand
60
57
  ProconBypassMan::SendErrorCommand.execute(error: "Switchと意図せず切断されました.終了処理を開始します. #{e.full_message}")
61
58
  Process.kill "TERM", Process.ppid
62
59
  end
60
+
63
61
  ProconBypassMan.logger.info "Thread1を終了します"
64
62
  end
65
63
 
@@ -69,14 +67,22 @@ class ProconBypassMan::BypassCommand
69
67
  t2 = Thread.new do
70
68
  bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor2)
71
69
  loop do
72
- break if $will_terminate_token
70
+ if $will_terminate_token
71
+ if $will_terminate_token == WILL_TERMINATE_TOKEN::TERMINATE
72
+ bypass.direct_connect_switch_via_bluetooth
73
+ end
74
+ break
75
+ end
76
+
73
77
  bypass.send_procon_to_gadget!
74
78
  rescue EOFError => e
75
79
  ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します. #{e.full_message}")
76
80
  Process.kill "TERM", Process.ppid
81
+ break
77
82
  rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError, Errno::ESHUTDOWN => e
78
83
  ProconBypassMan::SendErrorCommand.execute(error: "Proconが切断されました。終了処理を開始します2. #{e.full_message}")
79
84
  Process.kill "TERM", Process.ppid
85
+ break
80
86
  end
81
87
  ProconBypassMan.logger.info "Thread2を終了します"
82
88
  end
@@ -87,12 +93,18 @@ class ProconBypassMan::BypassCommand
87
93
  signal = readable_io.first[0].gets.strip
88
94
  handle_signal(signal)
89
95
  end
96
+ rescue ProconBypassMan::Runner::InterruptForRestart
97
+ $will_terminate_token = WILL_TERMINATE_TOKEN::RESTART
98
+ [t1, t2].each(&:join)
99
+ @gadget&.close
100
+ @procon&.close
101
+ exit! 1 # child processなのでexitしていい
90
102
  rescue Interrupt
91
- $will_terminate_token = true
103
+ $will_terminate_token = WILL_TERMINATE_TOKEN::TERMINATE
92
104
  [t1, t2].each(&:join)
93
105
  @gadget&.close
94
106
  @procon&.close
95
- exit 1 # child processなのでexitしていい
107
+ exit! 1 # child processなのでexitしていい
96
108
  end
97
109
  end
98
110
  end
@@ -10,6 +10,8 @@ class ProconBypassMan::Bypass
10
10
  set_callback :send_procon_to_gadget, :after, :log_procon_to_gadget
11
11
 
12
12
  def log_send_gadget_to_procon
13
+ return unless bypass_value.to_text
14
+
13
15
  if ProconBypassMan.config.verbose_bypass_log
14
16
  ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
15
17
  else
@@ -20,6 +22,8 @@ class ProconBypassMan::Bypass
20
22
  end
21
23
 
22
24
  def log_procon_to_gadget
25
+ return unless bypass_value.to_text
26
+
23
27
  if ProconBypassMan.config.verbose_bypass_log
24
28
  ProconBypassMan.logger.debug { "<<< #{bypass_value.to_text}" }
25
29
  else
@@ -1,12 +1,13 @@
1
1
  require "procon_bypass_man/bypass/usb_hid_logger"
2
+ require "procon_bypass_man/bypass/bypass_command"
2
3
 
3
4
  class ProconBypassMan::Bypass
4
5
  include ProconBypassMan::Bypass::UsbHidLogger
5
6
 
6
- class BypassValue < Struct.new(:binary, :sent)
7
+ class BypassValue < Struct.new(:binary)
7
8
  def to_text
8
9
  return unless binary
9
- "#{binary.unpack.first} #{'x' unless sent}"
10
+ binary.unpack.first
10
11
  end
11
12
  end
12
13
 
@@ -21,23 +22,31 @@ class ProconBypassMan::Bypass
21
22
  # ゆっくりでいい
22
23
  def send_gadget_to_procon!
23
24
  monitor.record(:start_function)
24
- input = nil
25
- self.bypass_value = BypassValue.new(nil, sent = false)
25
+ self.bypass_value = BypassValue.new(nil)
26
26
 
27
27
  run_callbacks(:send_gadget_to_procon) do
28
+ break if $will_terminate_token
29
+
30
+ raw_input = nil
28
31
  begin
29
- break if $will_terminate_token
30
- # TODO blocking readにしたいが、接続時のフェーズによって長さが違うので厳しい
31
- input = self.gadget.read_nonblock(64)
32
- self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: input)
32
+ raw_input = self.gadget.read_nonblock(64)
33
+ self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: raw_input)
33
34
  rescue IO::EAGAINWaitReadable
34
35
  monitor.record(:eagain_wait_readable_on_read)
35
36
  end
36
37
 
37
- if input
38
+ if self.bypass_value.binary
38
39
  begin
39
- self.procon.write_nonblock(input)
40
- self.bypass_value.sent = true
40
+ raw_data =
41
+ case
42
+ when self.bypass_value.binary.rumble_data?
43
+ binary = ProconBypassMan::RumbleBinary.new(binary: self.bypass_value.binary.raw)
44
+ binary.noop!
45
+ binary.raw
46
+ else
47
+ self.bypass_value.binary.raw
48
+ end
49
+ self.procon.write_nonblock(raw_data)
41
50
  rescue IO::EAGAINWaitReadable
42
51
  monitor.record(:eagain_wait_readable_on_write)
43
52
  break
@@ -50,15 +59,15 @@ class ProconBypassMan::Bypass
50
59
 
51
60
  def send_procon_to_gadget!
52
61
  monitor.record(:start_function)
53
- output = nil
54
- self.bypass_value = BypassValue.new(nil, sent = false)
62
+ self.bypass_value = BypassValue.new(nil)
55
63
 
56
64
  run_callbacks(:send_procon_to_gadget) do
65
+ break if $will_terminate_token
66
+
57
67
  begin
58
- break if $will_terminate_token
59
68
  Timeout.timeout(1) do
60
- output = self.procon.read(64)
61
- self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: output)
69
+ raw_output = self.procon.read(64)
70
+ self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: raw_output)
62
71
  end
63
72
  rescue Timeout::Error
64
73
  ProconBypassMan.logger.debug { "read timeout! do sleep. by send_procon_to_gadget!" }
@@ -73,16 +82,10 @@ class ProconBypassMan::Bypass
73
82
  retry
74
83
  end
75
84
 
76
- # blocking readをしているのでnilが入ることはないが、雑なテストでnilが通るので分岐を入れる。できれば消したい
77
- break if output.nil?
78
-
79
85
  begin
80
86
  self.gadget.write_nonblock(
81
- ProconBypassMan::Processor.new(
82
- ProconBypassMan::Domains::InboundProconBinary.new(binary: output)
83
- ).process
87
+ ProconBypassMan::Processor.new(bypass_value.binary).process
84
88
  )
85
- self.bypass_value.sent = true
86
89
  rescue IO::EAGAINWaitReadable
87
90
  monitor.record(:eagain_wait_readable_on_write)
88
91
  break
@@ -90,4 +93,21 @@ class ProconBypassMan::Bypass
90
93
  end
91
94
  monitor.record(:end_function)
92
95
  end
96
+
97
+ # @return [void]
98
+ def direct_connect_switch_via_bluetooth
99
+ ProconBypassMan.logger.debug { "direct_connect_switch_via_bluetooth!" }
100
+ self.procon.write_nonblock(["010500000000000000003800"].pack("H*")) # home led off
101
+ self.procon.write_nonblock(["010600000000000000003800"].pack("H*")) # home led off
102
+ self.procon.write_nonblock(["010700000000000000003800"].pack("H*")) # home led off
103
+ self.procon.write_nonblock(["010800000000000000003800"].pack("H*")) # home led off
104
+ self.procon.write_nonblock(["8005"].pack("H*"))
105
+ self.procon.write_nonblock(["8005"].pack("H*"))
106
+ self.procon.write_nonblock(["8005"].pack("H*"))
107
+ end
108
+
109
+ # @return [void] 入力してから取り出さないと接続しっぱなしになるっぽいのでこれが必要っぽい
110
+ def be_empty_procon
111
+ # タイムアウトまでブロッキングされるので、プロセスに逃す
112
+ end
93
113
  end
@@ -32,8 +32,8 @@ class ProconBypassMan::PrintBootMessageCommand
32
32
  def to_s
33
33
  booted_message = <<~EOF
34
34
  ----
35
- RUBY_VERSION: #{@table[:ruby_version]}
36
35
  ProconBypassMan::VERSION: #{@table[:pbm_version]}
36
+ RUBY_VERSION: #{@table[:ruby_version]}
37
37
  Pbmenv::VERSION: #{@table[:pbmenv_version]}
38
38
  pid: #{@table[:pid]}
39
39
  root: #{@table[:root_path]}
@@ -42,7 +42,7 @@ class ProconBypassMan::PrintBootMessageCommand
42
42
  uptime from boot: #{@table[:uptime_from_boot]} sec
43
43
  use_pbmenv: #{@table[:use_pbmenv]}
44
44
  session_id: #{ProconBypassMan.session_id}
45
- device_id: #{ProconBypassMan.device_id}
45
+ device_id: #{ProconBypassMan.device_id.gsub(/.{25}$/, "*"*25)}
46
46
  bypass_mode: #{ProconBypassMan.config.bypass_mode}
47
47
  ----
48
48
  EOF
@@ -58,7 +58,6 @@ class ProconBypassMan::PrintBootMessageCommand
58
58
  def self.execute
59
59
  message = BootMessage.new
60
60
  ProconBypassMan::ReportBootJob.perform_async(message.to_hash)
61
- ProconBypassMan::ReportLoadConfigJob.perform_async(ProconBypassMan.config.raw_setting)
62
61
  puts message.to_s
63
62
  end
64
63
  end
@@ -1,7 +1,7 @@
1
1
  class ProconBypassMan::SendErrorCommand
2
2
  # @param [String, Hash, Exception] error
3
3
  # @return [void]
4
- def self.execute(error: )
4
+ def self.execute(error: , stdout: true)
5
5
  body =
6
6
  case error
7
7
  when String, Hash
@@ -12,7 +12,7 @@ class ProconBypassMan::SendErrorCommand
12
12
 
13
13
  ProconBypassMan.logger.error body
14
14
  ProconBypassMan.error_logger.error body
15
- puts body
15
+ puts body if stdout
16
16
 
17
17
  ProconBypassMan::ReportErrorJob.perform(error)
18
18
  end
@@ -4,6 +4,3 @@ require "procon_bypass_man/commands/write_session_id_command"
4
4
  require "procon_bypass_man/commands/write_device_id_command"
5
5
  require "procon_bypass_man/commands/send_reload_config_event_command"
6
6
  require "procon_bypass_man/commands/send_error_command"
7
- require "procon_bypass_man/commands/connect_device_command"
8
- require "procon_bypass_man/commands/bypass_command"
9
- require "procon_bypass_man/commands/run_remote_pbm_action_dispatch_command"
@@ -47,10 +47,14 @@ class ProconBypassMan::Configuration
47
47
  def fallback_setting_path
48
48
  "/tmp/procon_bypass_man_fallback_setting.yaml"
49
49
  end
50
+
51
+ def io_monitor_logging
52
+ config.io_monitor_logging
53
+ end
50
54
  end
51
55
 
52
56
  attr_accessor :enable_critical_error_logging
53
- attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons, :never_exit_accidentally
57
+ attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons, :never_exit_accidentally, :io_monitor_logging, :enable_home_led_on_connect
54
58
 
55
59
  def root=(path)
56
60
  @root = path
@@ -156,7 +160,14 @@ class ProconBypassMan::Configuration
156
160
  end
157
161
 
158
162
  # @return [Boolean]
159
- def enable_ws?; !!current_server; end
163
+ def enable_ws?
164
+ !!current_server
165
+ end
166
+
167
+ # @return [Boolean]
168
+ def enable_remote_macro?
169
+ enable_ws?
170
+ end
160
171
 
161
172
  # @return [Array<String>]
162
173
  def api_servers
@@ -179,12 +190,27 @@ class ProconBypassMan::Configuration
179
190
  @raw_setting ||= {}
180
191
  end
181
192
 
193
+ # @return [Boolean] default false
182
194
  def enable_reporting_pressed_buttons
183
195
  @enable_reporting_pressed_buttons ||= false
184
196
  end
185
197
 
186
- # @return [Boolean]
198
+ # @return [Boolean] default false
187
199
  def never_exit_accidentally
188
200
  @never_exit_accidentally || false
189
201
  end
202
+
203
+ # @return [Boolean] default false
204
+ def io_monitor_logging
205
+ @io_monitor_logging ||= false
206
+ end
207
+
208
+ # @return [Boolean] default true
209
+ def enable_home_led_on_connect
210
+ if defined?(@enable_home_led_on_connect)
211
+ return @enable_home_led_on_connect
212
+ else
213
+ true
214
+ end
215
+ end
190
216
  end