procon_bypass_man 0.1.20.1 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +33 -8
  3. data/.github/workflows/ruby.yml +1 -1
  4. data/.gitignore +1 -0
  5. data/.rspec +1 -0
  6. data/CHANGELOG.md +29 -2
  7. data/Gemfile.lock +3 -3
  8. data/README.md +4 -1
  9. data/docs/getting_started.md +104 -7
  10. data/docs/setting/left-analogstick-cap.md +1 -1
  11. data/docs/setting/splatoon2_macro_dasei_cancel.md +77 -0
  12. data/docs/setting/splatoon2_macro_sokuwari_bubble.md +4 -0
  13. data/docs/setting/splatoon2_shake_tansan.md +47 -0
  14. data/lib/procon_bypass_man/background/jobs/post_completed_remote_macro_job.rb +17 -0
  15. data/lib/procon_bypass_man/background/jobs/report_completed_upgrade_pbm_job.rb +10 -0
  16. data/lib/procon_bypass_man/background.rb +2 -0
  17. data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +155 -70
  18. data/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +2 -0
  19. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/button.rb +28 -0
  20. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/button_list.rb +31 -0
  21. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/disable_macro_if_pressed.rb +28 -0
  22. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/flip_if_pressed.rb +31 -0
  23. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/force_neutral.rb +28 -0
  24. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/if_pressed.rb +26 -0
  25. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/if_pressed_allows_nil.rb +28 -0
  26. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer/open_macro_steps.rb +26 -0
  27. data/lib/procon_bypass_man/buttons_setting_configuration/param_normalizer.rb +17 -0
  28. data/lib/procon_bypass_man/buttons_setting_configuration.rb +6 -5
  29. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +4 -0
  30. data/lib/procon_bypass_man/bypass.rb +0 -1
  31. data/lib/procon_bypass_man/commands/connect_device_command.rb +11 -21
  32. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +6 -0
  33. data/lib/procon_bypass_man/configuration.rb +8 -1
  34. data/lib/procon_bypass_man/device_connector.rb +7 -13
  35. data/lib/procon_bypass_man/device_procon_finder.rb +0 -22
  36. data/lib/procon_bypass_man/domains/analog_stick_position.rb +18 -0
  37. data/lib/procon_bypass_man/domains/binary/processing_procon_binary.rb +7 -2
  38. data/lib/procon_bypass_man/{bypass → domains}/bypass_mode.rb +8 -0
  39. data/lib/procon_bypass_man/domains.rb +2 -0
  40. data/lib/procon_bypass_man/plugin/splatoon2/macro/charge_tansan_bomb.rb +21 -0
  41. data/lib/procon_bypass_man/plugin/splatoon2/macro/dasei_cancel.rb +21 -0
  42. data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +4 -0
  43. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +4 -0
  44. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +4 -0
  45. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +4 -0
  46. data/lib/procon_bypass_man/plugin/splatoon2/macro/sokuwari_for_splash_bomb.rb +4 -0
  47. data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +4 -0
  48. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +1 -1
  49. data/lib/procon_bypass_man/plugins.rb +2 -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/button_collection.rb +0 -8
  53. data/lib/procon_bypass_man/procon/layer_changer.rb +4 -1
  54. data/lib/procon_bypass_man/procon/macro.rb +53 -25
  55. data/lib/procon_bypass_man/procon/macro_builder.rb +43 -35
  56. data/lib/procon_bypass_man/procon/macro_plugin_map.rb +23 -0
  57. data/lib/procon_bypass_man/procon/macro_registry.rb +26 -10
  58. data/lib/procon_bypass_man/procon/user_operation.rb +30 -16
  59. data/lib/procon_bypass_man/procon/value_objects/analog_stick.rb +9 -5
  60. data/lib/procon_bypass_man/procon.rb +51 -17
  61. data/lib/procon_bypass_man/remote_macro/queue_over_process.rb +62 -0
  62. data/lib/procon_bypass_man/remote_macro/remote_macro_object.rb +30 -0
  63. data/lib/procon_bypass_man/remote_macro/remote_macro_receiver.rb +37 -0
  64. data/lib/procon_bypass_man/remote_macro/remote_macro_sender.rb +8 -0
  65. data/lib/procon_bypass_man/remote_macro/task.rb +6 -0
  66. data/lib/procon_bypass_man/remote_macro/task_queue.rb +13 -0
  67. data/lib/procon_bypass_man/remote_macro.rb +14 -0
  68. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +4 -1
  69. data/lib/procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object.rb +1 -1
  70. data/lib/procon_bypass_man/remote_pbm_action.rb +1 -0
  71. data/lib/procon_bypass_man/runner.rb +5 -1
  72. data/lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb +59 -0
  73. data/lib/procon_bypass_man/{never_exit_accidentally.rb → support/never_exit_accidentally.rb} +0 -0
  74. data/lib/procon_bypass_man/support/remote_macro_http_client.rb +9 -0
  75. data/lib/procon_bypass_man/usb_device_controller.rb +51 -0
  76. data/lib/procon_bypass_man/version.rb +1 -1
  77. data/lib/procon_bypass_man/websocket/{pbm_job_client.rb → client.rb} +44 -12
  78. data/lib/procon_bypass_man/websocket/forever.rb +47 -0
  79. data/lib/procon_bypass_man/websocket/watchdog.rb +19 -0
  80. data/lib/procon_bypass_man.rb +19 -9
  81. data/procon_bypass_man.gemspec +2 -2
  82. data/project_template/app.rb +10 -2
  83. data/project_template/systemd_units/pbm.service +1 -1
  84. data/sig/main.rbs +20 -0
  85. metadata +38 -8
@@ -4,6 +4,7 @@ class ProconBypassMan::PrintBootMessageCommand
4
4
  @table = {}
5
5
  @table[:ruby_version] = RUBY_VERSION
6
6
  @table[:pbm_version] = ProconBypassMan::VERSION
7
+ @table[:pbmenv_version] = Pbmenv::VERSION
7
8
  @table[:pid] = $$
8
9
  @table[:root_path] = ProconBypassMan.root
9
10
  @table[:pid_path] = ProconBypassMan.pid_path
@@ -12,6 +13,9 @@ class ProconBypassMan::PrintBootMessageCommand
12
13
  @table[:use_pbmenv] = !(!!`which pbmenv`.empty?)
13
14
  @table[:session_id] = ProconBypassMan.session_id
14
15
  @table[:device_id] = ProconBypassMan.device_id
16
+ @table[:bypass_mode] = ProconBypassMan.config.bypass_mode.to_s
17
+ @table[:never_exit_accidentally] = ProconBypassMan.config.never_exit_accidentally
18
+ @table[:uname] = `uname -a`.chomp
15
19
 
16
20
  # 開発中のHEADを取りたかったけど、Gem::Specification経由から取得する必要がありそう
17
21
  # build_version = `git rev-parse --short HEAD`.chomp
@@ -30,6 +34,7 @@ class ProconBypassMan::PrintBootMessageCommand
30
34
  ----
31
35
  RUBY_VERSION: #{@table[:ruby_version]}
32
36
  ProconBypassMan::VERSION: #{@table[:pbm_version]}
37
+ Pbmenv::VERSION: #{@table[:pbmenv_version]}
33
38
  pid: #{@table[:pid]}
34
39
  root: #{@table[:root_path]}
35
40
  pid_path: #{@table[:pid_path]}
@@ -38,6 +43,7 @@ class ProconBypassMan::PrintBootMessageCommand
38
43
  use_pbmenv: #{@table[:use_pbmenv]}
39
44
  session_id: #{ProconBypassMan.session_id}
40
45
  device_id: #{ProconBypassMan.device_id}
46
+ bypass_mode: #{ProconBypassMan.config.bypass_mode}
41
47
  ----
42
48
  EOF
43
49
  end
@@ -156,7 +156,14 @@ class ProconBypassMan::Configuration
156
156
  end
157
157
 
158
158
  # @return [Boolean]
159
- def enable_ws?; !!current_server; end
159
+ def enable_ws?
160
+ !!current_server
161
+ end
162
+
163
+ # @return [Boolean]
164
+ def enable_remote_macro?
165
+ enable_ws?
166
+ end
160
167
 
161
168
  # @return [Array<String>]
162
169
  def api_servers
@@ -10,16 +10,13 @@ class ProconBypassMan::DeviceConnector
10
10
  end
11
11
  end
12
12
 
13
- PROCON_PATH = "/dev/hidraw0"
14
- PROCON2_PATH = "/dev/hidraw1"
15
-
16
13
  def self.connect
17
14
  s = new(throw_error_if_timeout: true, enable_at_exit: false)
18
15
  s.add([
19
16
  ["0000"],
20
17
  ["0000"],
21
18
  ["8005"],
22
- ["0010"],
19
+ ["0000"],
23
20
  ], read_from: :switch)
24
21
  # 1. Sends current connection status, and if the Joy-Con are connected,
25
22
  s.add([["8001"]], read_from: :switch)
@@ -61,9 +58,9 @@ class ProconBypassMan::DeviceConnector
61
58
  begin
62
59
  timer.throw_if_timeout!
63
60
  data = from_device(item).read_nonblock(64)
64
- debug_log_buffer << "read_from(#{item.read_from}): #{data}"
61
+ debug_log_buffer << "read_from(#{item.read_from}): #{data.unpack("H*")}"
65
62
  rescue IO::EAGAINWaitReadable
66
- debug_log_buffer << "read_from(#{item.read_from}): IO::EAGAINWaitReadable"
63
+ # debug_log_buffer << "read_from(#{item.read_from}): IO::EAGAINWaitReadable"
67
64
  retry
68
65
  end
69
66
 
@@ -267,6 +264,7 @@ class ProconBypassMan::DeviceConnector
267
264
  if @initialized_devices
268
265
  return
269
266
  end
267
+ ProconBypassMan::UsbDeviceController.init
270
268
 
271
269
  if path = ProconBypassMan::DeviceProconFinder.find
272
270
  @procon = File.open(path, "w+b")
@@ -276,9 +274,7 @@ class ProconBypassMan::DeviceConnector
276
274
  end
277
275
  @gadget = File.open('/dev/hidg0', "w+b")
278
276
 
279
- system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
280
- system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
281
- sleep 0.5
277
+ ProconBypassMan::UsbDeviceController.reset
282
278
 
283
279
  @initialized_devices = true
284
280
 
@@ -290,10 +286,8 @@ class ProconBypassMan::DeviceConnector
290
286
  end
291
287
  rescue Errno::ENXIO => e
292
288
  # /dev/hidg0 をopenできないときがある
293
- ProconBypassMan::SendErrorCommand.execute(error: "Errno::ENXIO (No such device or address @ rb_sysopen - /dev/hidg0)が起きました。resetします. #{e.full_message}")
294
- system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
295
- system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
296
- sleep 0.5
289
+ ProconBypassMan::SendErrorCommand.execute(error: "Errno::ENXIO (No such device or address @ rb_sysopen - /dev/hidg0)が起きました。resetします.\n #{e.full_message}")
290
+ ProconBypassMan::UsbDeviceController.reset
297
291
  retry
298
292
  end
299
293
  end
@@ -31,8 +31,6 @@ class ProconBypassMan::DeviceProconFinder
31
31
 
32
32
  def get_list_shell
33
33
  <<~SHELL
34
- #!/bin/bash
35
-
36
34
  FILES=/dev/hidraw*
37
35
  for f in $FILES
38
36
  do
@@ -42,24 +40,4 @@ class ProconBypassMan::DeviceProconFinder
42
40
  done
43
41
  SHELL
44
42
  end
45
-
46
- # これいる?
47
- def is_available_device?(path)
48
- return false if !File.exist?(path)
49
-
50
- system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
51
- system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
52
- sleep 0.5
53
-
54
- file = File.open(path, "w+")
55
- begin
56
- file.read_nonblock(64)
57
- rescue EOFError
58
- file.close
59
- return false
60
- rescue IO::EAGAINWaitReadable
61
- file.close
62
- return true
63
- end
64
- end
65
43
  end
@@ -0,0 +1,18 @@
1
+ class ProconBypassMan::AnalogStickPosition
2
+ attr_accessor :x, :y
3
+
4
+ def initialize(x:, y:)
5
+ @x = x.to_i
6
+ @y = y.to_i
7
+ end
8
+
9
+ def to_binary
10
+ analog_stick_data = [
11
+ (@x & "0xff".to_i(16)),
12
+ ((@y << 4) & "0xf0".to_i(16)) | ((@x >> 8) & "0x0f".to_i(16)),
13
+ (@y >> 4) & "0xff".to_i(16),
14
+ ]
15
+ hex = analog_stick_data.map{ |x| x.to_s(16).rjust(2, "0") }.join
16
+ [hex].pack("H*")
17
+ end
18
+ end
@@ -36,16 +36,21 @@ class ProconBypassMan::Domains::ProcessingProconBinary < ProconBypassMan::Domain
36
36
 
37
37
  # @param [Symbol] button
38
38
  def write_as_press_button(button)
39
- raise "already pressing button(#{button})" if ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)
39
+ return if ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)
40
40
 
41
41
  button_obj = ProconBypassMan::Procon::Button.new(button)
42
42
  value = binary[button_obj.byte_position].unpack("C").first + (2**button_obj.bit_position)
43
43
  binary[button_obj.byte_position] = ["%02X" % value.to_s].pack("H*")
44
44
  end
45
45
 
46
+ # @param [Symbol] stick method
47
+ def write_as_tilt_left_stick(step)
48
+ binary[6..8] = ProconBypassMan::Procon::AnalogStickManipulator.new(binary, method: step).to_binary
49
+ end
50
+
46
51
  # @param [Symbol] button
47
52
  def write_as_unpress_button(button)
48
- raise "not press button(#{button}) yet" if not ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)
53
+ raise "do not press button(#{button}) yet" if not ProconBypassMan::PressButtonAware.new(binary).pressing_button?(button)
49
54
 
50
55
  button_obj = ProconBypassMan::Procon::Button.new(button)
51
56
  value = binary[button_obj.byte_position].unpack("C").first - (2**button_obj.bit_position)
@@ -18,4 +18,12 @@ class ProconBypassMan::BypassMode
18
18
  @mode = mode.to_sym
19
19
  @gadget_to_procon_interval = gadget_to_procon_interval
20
20
  end
21
+
22
+ def to_s
23
+ if mode == TYPE_NORMAL
24
+ "#{mode}(#{gadget_to_procon_interval})"
25
+ else
26
+ mode.to_s
27
+ end
28
+ end
21
29
  end
@@ -4,6 +4,8 @@ module ProconBypassMan
4
4
  end
5
5
  end
6
6
 
7
+ require_relative "domains/bypass_mode"
8
+ require_relative "domains/analog_stick_position"
7
9
  require_relative "domains/binary/base"
8
10
  require_relative "domains/binary/has_mutable_binary"
9
11
  require_relative "domains/binary/has_immutable_binary"
@@ -0,0 +1,21 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module ChargeTansanBomb
6
+ def self.display_name
7
+ :charge_tansan_bomb
8
+ end
9
+
10
+ def self.steps
11
+ [:shake_left_stick_and_toggle_b_for_0_1sec].freeze
12
+ end
13
+
14
+ def self.description
15
+ 'タンサンボムのチャージ'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module DaseiCancel
6
+ def self.display_name
7
+ :dasei_cancel
8
+ end
9
+
10
+ def self.steps
11
+ [:pressing_r_for_0_03sec, :pressing_r_and_pressing_zl_for_0_2sec].freeze
12
+ end
13
+
14
+ def self.description
15
+ '惰性キャンセル'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -10,6 +10,10 @@ module ProconBypassMan
10
10
  def self.steps
11
11
  [:x, :down, :a, :a].freeze
12
12
  end
13
+
14
+ def self.description
15
+ '試合中にリスポーンにスーパージャンプ'
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -10,6 +10,10 @@ module ProconBypassMan
10
10
  def self.steps
11
11
  [:x, :left, :a, :a].freeze
12
12
  end
13
+
14
+ def self.description
15
+ '試合中に左キーに割り当てられている味方へのスーパージャンプ'
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -10,6 +10,10 @@ module ProconBypassMan
10
10
  def self.steps
11
11
  [:x, :right, :a, :a].freeze
12
12
  end
13
+
14
+ def self.description
15
+ '試合中に右キーに割り当てられている味方へのスーパージャンプ'
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -10,6 +10,10 @@ module ProconBypassMan
10
10
  def self.steps
11
11
  [:x, :up, :a, :a].freeze
12
12
  end
13
+
14
+ def self.description
15
+ '試合中に上キーに割り当てられている味方へのスーパージャンプ'
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -15,6 +15,10 @@ module ProconBypassMan
15
15
  :toggle_r_for_1sec,
16
16
  ].freeze
17
17
  end
18
+
19
+ def self.description
20
+ 'バブル即割'
21
+ end
18
22
  end
19
23
  end
20
24
  end
@@ -3,6 +3,10 @@ module ProconBypassMan
3
3
  module Splatoon2
4
4
  module Mode
5
5
  module Guruguru
6
+ def self.description
7
+ '適当に動きます'
8
+ end
9
+
6
10
  def self.binaries
7
11
  [ "309481408000362d684658750968f71cfe2c0e51000001480053f71ffedf0d4b000a013d00caf6ecfd4c0d480003011c00000000000000000000000000000000",
8
12
  "30978140800037dd6748687509fdf6adfded0d6d0081005d00eef68dfdef0d6d00830059001bf791fd140e720090005400000000000000000000000000000000",
@@ -3,7 +3,7 @@
3
3
  module ProconBypassMan
4
4
  module Plugin
5
5
  module Splatoon2
6
- VERSION = "0.1.3"
6
+ VERSION = "0.1.5"
7
7
  end
8
8
  end
9
9
  end
@@ -4,6 +4,8 @@ require_relative "plugin/splatoon2/macro/jump_to_right_key"
4
4
  require_relative "plugin/splatoon2/macro/jump_to_up_key"
5
5
  require_relative "plugin/splatoon2/macro/jump_to_left_key"
6
6
  require_relative "plugin/splatoon2/macro/sokuwari_for_splash_bomb"
7
+ require_relative "plugin/splatoon2/macro/dasei_cancel"
8
+ require_relative "plugin/splatoon2/macro/charge_tansan_bomb"
7
9
  require_relative "plugin/splatoon2/mode/guruguru"
8
10
 
9
11
  module ProconBypassMan
@@ -1,36 +1,17 @@
1
1
  class ProconBypassMan::Procon::AnalogStickCap
2
- class Position
3
- attr_accessor :x, :y
4
-
5
- def initialize(x:, y:)
6
- @x = x.to_i
7
- @y = y.to_i
8
- end
9
-
10
- def to_binary
11
- analog_stick_data = [
12
- (@x & "0xff".to_i(16)),
13
- ((@y << 4) & "0xf0".to_i(16)) | ((@x >> 8) & "0x0f".to_i(16)),
14
- (@y >> 4) & "0xff".to_i(16),
15
- ]
16
- hex = analog_stick_data.map{ |x| x.to_s(16).rjust(2, "0") }.join
17
- [hex].pack("H*")
18
- end
19
- end
20
-
21
2
  def initialize(binary)
22
3
  @binary = binary
23
4
  @analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
24
5
  end
25
6
 
26
- # @return [ProconBypassMan::Procon::AnalogStickCap::Position]
7
+ # @return [ProconBypassMan::AnalogStickPosition]
27
8
  def capped_position(cap_hypotenuse: )
28
9
  if hypotenuse > cap_hypotenuse
29
10
  relative_capped_x = cap_hypotenuse * Math.cos(rad * Math::PI / 180).abs
30
11
  relative_capped_y = cap_hypotenuse * Math.sin(rad * Math::PI / 180).abs
31
12
  relative_capped_x = -(relative_capped_x.abs) if relative_x.negative?
32
13
  relative_capped_y = -(relative_capped_y.abs) if relative_y.negative?
33
- return Position.new(
14
+ return ProconBypassMan::AnalogStickPosition.new(
34
15
  x: relative_capped_x + @analog_stick.neutral_position.x,
35
16
  y: relative_capped_y + @analog_stick.neutral_position.y,
36
17
  )
@@ -39,9 +20,9 @@ class ProconBypassMan::Procon::AnalogStickCap
39
20
  end
40
21
  end
41
22
 
42
- # @return [ProconBypassMan::Procon::AnalogStickCap::Position]
23
+ # @return [ProconBypassMan::AnalogStickPosition]
43
24
  def position
44
- Position.new(x: abs_x, y: abs_y)
25
+ ProconBypassMan::AnalogStickPosition.new(x: abs_x, y: abs_y)
45
26
  end
46
27
 
47
28
  def abs_x; @analog_stick.abs_x; end # 0, 0からのx
@@ -0,0 +1,36 @@
1
+ class ProconBypassMan::Procon::AnalogStickManipulator
2
+ attr_accessor :manipulated_abs_x, :manipulated_abs_y
3
+
4
+ def initialize(binary, method: )
5
+ analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
6
+
7
+ if method =~ /tilt_left_stick_(completely)_to_(left|right)/
8
+ power_level = $1
9
+ direction = $2
10
+
11
+ case direction
12
+ when 'left'
13
+ self.manipulated_abs_x = 400
14
+ # yを引き継ぐとタンサンボムの溜まりが悪くなったので固定値を入れる
15
+ self.manipulated_abs_y = analog_stick.abs_y
16
+ # self.manipulated_abs_y = 1808
17
+ when 'right'
18
+ self.manipulated_abs_x = 3400
19
+ self.manipulated_abs_y = 1808
20
+ end
21
+ else
22
+ warn "error stick manipulator"
23
+ self.manipulated_abs_x = analog_stick.abs_x
24
+ self.manipulated_abs_y = analog_stick.abs_y
25
+ end
26
+ end
27
+
28
+
29
+ # @return [String]
30
+ def to_binary
31
+ ProconBypassMan::AnalogStickPosition.new(
32
+ x: self.manipulated_abs_x,
33
+ y: self.manipulated_abs_y,
34
+ ).to_binary
35
+ end
36
+ end
@@ -37,12 +37,4 @@ class ProconBypassMan::Procon::ButtonCollection
37
37
  BUTTONS = ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP.keys.freeze
38
38
 
39
39
  LEFT_ANALOG_STICK = { byte_position: 6..8 }
40
-
41
- # @param [Array<Symbol>] buttons
42
- # @return [Array<Symbol>]
43
- def self.normalize(buttons)
44
- buttons.select { |x|
45
- !!ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP[x]
46
- }
47
- end
48
40
  end
@@ -24,7 +24,10 @@ class ProconBypassMan::Procon::LayerChanger
24
24
  # @return [Boolean]
25
25
  def change_layer?
26
26
  if ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.empty?
27
- raise "prefix_keysが未設定です"
27
+ ProconBypassMan.cache.fetch key: 'unknown prefix_keys', expires_in: 60 do
28
+ warn "prefix_keysが未設定です"
29
+ end
30
+ return false
28
31
  end
29
32
  ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.map { |b| pressed?(button: b) }.all?
30
33
  end
@@ -1,13 +1,51 @@
1
1
  class ProconBypassMan::Procon::Macro
2
- class NestedStep
2
+ class BaseNestedStep
3
3
  def initialize(value)
4
4
  @hash = value
5
+ end
6
+
7
+ private
8
+
9
+ def incr_step_index!
10
+ if step_index
11
+ @hash[:step_index] += 1
12
+ else
13
+ @hash[:step_index] = 0
14
+ end
15
+ end
16
+
17
+ def current_step
18
+ @hash[:steps][step_index]
19
+ end
20
+ end
21
+
22
+ class OnetimeNestedStep < BaseNestedStep
23
+ def over?
24
+ current_step.nil?
25
+ end
26
+
27
+ def next_step
28
+ step = current_step
29
+ incr_step_index!
30
+ step
31
+ end
32
+
33
+ private
34
+
35
+ def step_index
36
+ @hash[:step_index] ||= 0
37
+ end
38
+ end
39
+
40
+ class NestedStep < BaseNestedStep
41
+ def initialize(value)
42
+ super
5
43
  unless @hash[:end_at]
6
44
  @hash[:end_at] = (Time.now + @hash[:continue_for]).round(4)
7
45
  end
8
46
  end
9
47
 
10
- def over_end_at?
48
+ def over?
11
49
  (@hash[:end_at] < Time.now).tap do |result|
12
50
  if result
13
51
  ProconBypassMan.logger.debug { "[Macro] nested step is finished(#{@hash})" }
@@ -17,8 +55,6 @@ class ProconBypassMan::Procon::Macro
17
55
 
18
56
  def next_step
19
57
  incr_step_index!
20
-
21
- debug_incr_called_count!
22
58
  if step = current_step
23
59
  return step
24
60
  else
@@ -29,37 +65,22 @@ class ProconBypassMan::Procon::Macro
29
65
 
30
66
  private
31
67
 
32
- def current_step
33
- @hash[:steps][step_index]
34
- end
35
-
36
68
  def step_index
37
69
  @hash[:step_index]
38
70
  end
39
71
 
40
- def incr_step_index!
41
- if step_index
42
- @hash[:step_index] += 1
43
- else
44
- @hash[:step_index] = 0
45
- end
46
- end
47
-
48
72
  def reset_step_index!
49
73
  @hash[:step_index] = 0
50
74
  end
51
-
52
- def debug_incr_called_count!
53
- @hash[:debug_called_count] ||= 0
54
- @hash[:debug_called_count] += 1
55
- end
56
75
  end
57
76
 
58
- attr_accessor :name, :steps
77
+ attr_accessor :name, :steps, :after_callback_block, :force_neutral_buttons
59
78
 
60
- def initialize(name: , steps: )
79
+ def initialize(name: , steps: , force_neutral_buttons: [], &after_callback_block)
61
80
  self.name = name
62
81
  self.steps = steps
82
+ self.after_callback_block = after_callback_block
83
+ self.force_neutral_buttons = force_neutral_buttons # 外部から呼ばれるだけ
63
84
  end
64
85
 
65
86
  def next_step
@@ -69,9 +90,16 @@ class ProconBypassMan::Procon::Macro
69
90
  end
70
91
 
71
92
  if step.is_a?(Hash)
72
- nested_step = NestedStep.new(step)
73
- if nested_step.over_end_at?
93
+ nested_step =
94
+ if step[:continue_for]
95
+ NestedStep.new(step)
96
+ else
97
+ OnetimeNestedStep.new(step)
98
+ end
99
+
100
+ if nested_step.over?
74
101
  steps.shift # NestedStepを破棄する
102
+ self.after_callback_block.call if self.after_callback_block
75
103
  return next_step
76
104
  else
77
105
  return nested_step.next_step