procon_bypass_man 0.1.11 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +33 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +13 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +14 -12
  7. data/README.md +11 -7
  8. data/bin/dev_api_server.rb +1 -1
  9. data/lib/procon_bypass_man/background/job_performer.rb +16 -0
  10. data/lib/procon_bypass_man/background/{report_thread.rb → job_runner.rb} +13 -10
  11. data/lib/procon_bypass_man/background/jobs/base_job.rb +7 -0
  12. data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
  13. data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
  14. data/lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb +16 -0
  15. data/lib/procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job.rb +29 -0
  16. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +12 -0
  17. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +11 -0
  18. data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
  19. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +11 -0
  20. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +15 -0
  21. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +11 -0
  22. data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
  23. data/lib/procon_bypass_man/background.rb +14 -0
  24. data/lib/procon_bypass_man/boot_message.rb +16 -8
  25. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/layer.rb +34 -29
  26. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/loader.rb +5 -4
  27. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/validator.rb +0 -0
  28. data/lib/procon_bypass_man/buttons_setting_configuration.rb +6 -7
  29. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +18 -7
  30. data/lib/procon_bypass_man/bypass.rb +15 -14
  31. data/lib/procon_bypass_man/commands/bypass_command.rb +86 -0
  32. data/lib/procon_bypass_man/commands/connect_device_command.rb +16 -0
  33. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +9 -0
  34. data/lib/procon_bypass_man/commands/run_local_shell_command.rb +6 -0
  35. data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +21 -0
  36. data/lib/procon_bypass_man/commands/send_error_command.rb +19 -0
  37. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +11 -0
  38. data/lib/procon_bypass_man/commands/write_device_id_command.rb +12 -0
  39. data/lib/procon_bypass_man/commands/write_session_id_command.rb +7 -0
  40. data/lib/procon_bypass_man/commands.rb +8 -0
  41. data/lib/procon_bypass_man/configuration.rb +47 -6
  42. data/lib/procon_bypass_man/device_connector.rb +33 -26
  43. data/lib/procon_bypass_man/device_status.rb +44 -0
  44. data/lib/procon_bypass_man/io_monitor.rb +9 -4
  45. data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +17 -0
  46. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
  47. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
  48. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
  49. data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
  50. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
  51. data/lib/procon_bypass_man/plugin.rb +11 -0
  52. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +1 -1
  53. data/lib/procon_bypass_man/procon/{data.rb → consts.rb} +1 -1
  54. data/lib/procon_bypass_man/procon/layer_changer.rb +40 -0
  55. data/lib/procon_bypass_man/procon/user_operation.rb +11 -17
  56. data/lib/procon_bypass_man/procon.rb +6 -12
  57. data/lib/procon_bypass_man/{readonly_procon.rb → procon_reader.rb} +3 -4
  58. data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
  59. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +25 -0
  60. data/lib/procon_bypass_man/remote_pbm_action/lib/update_remote_pbm_action_status_command.rb +24 -0
  61. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +21 -0
  62. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
  63. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +21 -0
  64. data/lib/procon_bypass_man/remote_pbm_action.rb +32 -0
  65. data/lib/procon_bypass_man/runner.rb +14 -115
  66. data/lib/procon_bypass_man/scheduler.rb +92 -0
  67. data/lib/procon_bypass_man/{callbacks.rb → support/callbacks.rb} +0 -0
  68. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  69. data/lib/procon_bypass_man/support/http_client.rb +102 -0
  70. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  71. data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
  72. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  73. data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
  74. data/lib/procon_bypass_man/support/server_pool.rb +42 -0
  75. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  76. data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
  77. data/lib/procon_bypass_man/support/uptime.rb +25 -0
  78. data/lib/procon_bypass_man/value_objects/remote_pbm_action_object.rb +38 -0
  79. data/lib/procon_bypass_man/version.rb +1 -1
  80. data/lib/procon_bypass_man.rb +71 -36
  81. data/procon_bypass_man.gemspec +3 -3
  82. data/project_template/README.md +18 -11
  83. data/project_template/app.rb +2 -3
  84. data/project_template/setting.yml +8 -8
  85. data/sig/{README.rb → README.md} +0 -0
  86. data/sig/main.rbs +10 -11
  87. metadata +85 -26
  88. data/lib/procon_bypass_man/outbound/base.rb +0 -53
  89. data/lib/procon_bypass_man/outbound/error_reporter.rb +0 -13
  90. data/lib/procon_bypass_man/outbound/pressed_buttons_reporter.rb +0 -13
  91. data/lib/procon_bypass_man/outbound/reporter.rb +0 -12
  92. data/lib/procon_bypass_man/procon/layer_changeable.rb +0 -28
  93. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +0 -15
  94. data/lib/procon_bypass_man/uptime.rb +0 -15
@@ -1,5 +1,6 @@
1
1
  class ProconBypassMan::DeviceConnector
2
2
  class BytesMismatchError < StandardError; end
3
+ class NotFoundProconError < StandardError; end
3
4
 
4
5
  class Value
5
6
  attr_accessor :read_from, :values
@@ -48,6 +49,7 @@ class ProconBypassMan::DeviceConnector
48
49
  end
49
50
 
50
51
  def drain_all
52
+ debug_log_buffer = []
51
53
  unless @initialized_devices
52
54
  init_devices
53
55
  end
@@ -55,11 +57,13 @@ class ProconBypassMan::DeviceConnector
55
57
  while(item = @stack.shift)
56
58
  item.values.each do |value|
57
59
  data = nil
58
- timer = ProconBypassMan::Timer.new
60
+ timer = ProconBypassMan::SafeTimeout.new
59
61
  begin
60
62
  timer.throw_if_timeout!
61
63
  data = from_device(item).read_nonblock(64)
64
+ debug_log_buffer << "read_from(#{item.read_from}): #{data}"
62
65
  rescue IO::EAGAINWaitReadable
66
+ debug_log_buffer << "read_from(#{item.read_from}): IO::EAGAINWaitReadable"
63
67
  retry
64
68
  end
65
69
 
@@ -74,15 +78,19 @@ class ProconBypassMan::DeviceConnector
74
78
  end
75
79
  if result
76
80
  ProconBypassMan.logger.info "OK(expected: #{value}, got: #{data.unpack("H*")})"
81
+ debug_log_buffer << "OK(expected: #{value}, got: #{data.unpack("H*")})"
77
82
  else
78
83
  ProconBypassMan.logger.info "NG(expected: #{value}, got: #{data.unpack("H*")})"
84
+ debug_log_buffer << "NG(expected: #{value}, got: #{data.unpack("H*")})"
79
85
  raise BytesMismatchError if @throw_error_if_mismatch
80
86
  end
81
87
  to_device(item).write_nonblock(data)
82
88
  end
83
89
  end
84
- rescue ProconBypassMan::Timer::Timeout
90
+ rescue ProconBypassMan::SafeTimeout::Timeout
85
91
  ProconBypassMan.logger.error "timeoutになりました"
92
+ copressed_buffer_text = ProconBypassMan::CompressArray.new(debug_log_buffer).compress.join("\n")
93
+ ProconBypassMan::SendErrorCommand.execute(error: copressed_buffer_text)
86
94
  raise if @throw_error_if_timeout
87
95
  end
88
96
 
@@ -95,31 +103,31 @@ class ProconBypassMan::DeviceConnector
95
103
  init_devices
96
104
  end
97
105
 
98
- timer = ProconBypassMan::Timer.new
106
+ timer = ProconBypassMan::SafeTimeout.new
99
107
  data = nil
100
108
  begin
101
109
  timer.throw_if_timeout!
102
110
  switch.write_nonblock(data)
103
111
  rescue IO::EAGAINWaitReadable
104
112
  retry
105
- rescue ProconBypassMan::Timer::Timeout
113
+ rescue ProconBypassMan::SafeTimeout::Timeout
106
114
  ProconBypassMan.logger.error "writeでtimeoutになりました"
107
115
  raise
108
116
  end
109
117
  return(data.unpack("H*")) if only_write
110
118
 
111
- timer = ProconBypassMan::Timer.new
119
+ timer = ProconBypassMan::SafeTimeout.new
112
120
  begin
113
121
  timer.throw_if_timeout!
114
122
  data = switch.read_nonblock(64)
115
123
  ProconBypassMan.logger.debug { " >>> #{data.unpack("H*")})" }
116
124
  rescue IO::EAGAINWaitReadable
117
125
  retry
118
- rescue ProconBypassMan::Timer::Timeout
126
+ rescue ProconBypassMan::SafeTimeout::Timeout
119
127
  ProconBypassMan.logger.error "readでtimeoutになりました"
120
128
  raise
121
129
  end
122
- rescue ProconBypassMan::Timer::Timeout
130
+ rescue ProconBypassMan::SafeTimeout::Timeout
123
131
  raise if @throw_error_if_timeout
124
132
  end
125
133
 
@@ -131,30 +139,30 @@ class ProconBypassMan::DeviceConnector
131
139
  init_devices
132
140
  end
133
141
 
134
- timer = ProconBypassMan::Timer.new
142
+ timer = ProconBypassMan::SafeTimeout.new
135
143
  begin
136
144
  timer.throw_if_timeout!
137
145
  procon.write_nonblock(data)
138
146
  rescue IO::EAGAINWaitReadable
139
147
  retry
140
- rescue ProconBypassMan::Timer::Timeout
148
+ rescue ProconBypassMan::SafeTimeout::Timeout
141
149
  ProconBypassMan.logger.error "writeでtimeoutになりました"
142
150
  raise
143
151
  end
144
152
  return(data.unpack("H*")) if only_write
145
153
 
146
- timer = ProconBypassMan::Timer.new
154
+ timer = ProconBypassMan::SafeTimeout.new
147
155
  begin
148
156
  timer.throw_if_timeout!
149
157
  data = procon.read_nonblock(64)
150
158
  ProconBypassMan.logger.error " <<< #{data.unpack("H*")})"
151
159
  rescue IO::EAGAINWaitReadable
152
160
  retry
153
- rescue ProconBypassMan::Timer::Timeout
161
+ rescue ProconBypassMan::SafeTimeout::Timeout
154
162
  ProconBypassMan.logger.error "readでtimeoutになりました"
155
163
  raise
156
164
  end
157
- rescue ProconBypassMan::Timer::Timeout
165
+ rescue ProconBypassMan::SafeTimeout::Timeout
158
166
  raise if @throw_error_if_timeout
159
167
  end
160
168
 
@@ -164,30 +172,30 @@ class ProconBypassMan::DeviceConnector
164
172
  end
165
173
 
166
174
  data = nil
167
- timer = ProconBypassMan::Timer.new
175
+ timer = ProconBypassMan::SafeTimeout.new
168
176
  begin
169
177
  timer.throw_if_timeout!
170
178
  data = procon.read_nonblock(64)
171
179
  ProconBypassMan.logger.debug { " <<< #{data.unpack("H*")})" }
172
180
  rescue IO::EAGAINWaitReadable
173
181
  retry
174
- rescue ProconBypassMan::Timer::Timeout
182
+ rescue ProconBypassMan::SafeTimeout::Timeout
175
183
  ProconBypassMan.logger.error "readでtimeoutになりました"
176
184
  raise
177
185
  end
178
186
  return(data.unpack("H*")) if only_read
179
187
 
180
- timer = ProconBypassMan::Timer.new
188
+ timer = ProconBypassMan::SafeTimeout.new
181
189
  begin
182
190
  timer.throw_if_timeout!
183
191
  switch.write_nonblock(data)
184
192
  rescue IO::EAGAINWaitReadable
185
193
  retry
186
- rescue ProconBypassMan::Timer::Timeout
194
+ rescue ProconBypassMan::SafeTimeout::Timeout
187
195
  ProconBypassMan.logger.error "writeでtimeoutになりました"
188
196
  raise
189
197
  end
190
- rescue ProconBypassMan::Timer::Timeout
198
+ rescue ProconBypassMan::SafeTimeout::Timeout
191
199
  raise if @throw_error_if_timeout
192
200
  end
193
201
 
@@ -197,30 +205,30 @@ class ProconBypassMan::DeviceConnector
197
205
  end
198
206
 
199
207
  data = nil
200
- timer = ProconBypassMan::Timer.new
208
+ timer = ProconBypassMan::SafeTimeout.new
201
209
  begin
202
210
  timer.throw_if_timeout!
203
211
  data = switch.read_nonblock(64)
204
212
  ProconBypassMan.logger.debug { " >>> #{data.unpack("H*")})" }
205
213
  rescue IO::EAGAINWaitReadable
206
214
  retry
207
- rescue ProconBypassMan::Timer::Timeout
215
+ rescue ProconBypassMan::SafeTimeout::Timeout
208
216
  ProconBypassMan.logger.error "readでtimeoutになりました"
209
217
  raise
210
218
  end
211
219
  return(data.unpack("H*")) if only_read
212
220
 
213
- timer = ProconBypassMan::Timer.new
221
+ timer = ProconBypassMan::SafeTimeout.new
214
222
  begin
215
223
  timer.throw_if_timeout!
216
224
  procon.write_nonblock(data)
217
225
  rescue IO::EAGAINWaitReadable
218
226
  retry
219
- rescue ProconBypassMan::Timer::Timeout
227
+ rescue ProconBypassMan::SafeTimeout::Timeout
220
228
  ProconBypassMan.logger.error "writeでtimeoutになりました"
221
229
  raise
222
230
  end
223
- rescue ProconBypassMan::Timer::Timeout
231
+ rescue ProconBypassMan::SafeTimeout::Timeout
224
232
  raise if @throw_error_if_timeout
225
233
  end
226
234
 
@@ -293,7 +301,7 @@ class ProconBypassMan::DeviceConnector
293
301
  @procon = File.open(PROCON2_PATH, "w+b")
294
302
  @gadget = File.open('/dev/hidg0', "w+b")
295
303
  else
296
- raise "/dev/hidraw0, /dev/hidraw1の両方見つかりませんでした"
304
+ raise NotFoundProconError, "/dev/hidraw0, /dev/hidraw1の両方見つかりませんでした"
297
305
  end
298
306
  system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
299
307
  system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
@@ -309,11 +317,10 @@ class ProconBypassMan::DeviceConnector
309
317
  end
310
318
  rescue Errno::ENXIO => e
311
319
  # /dev/hidg0 をopenできないときがある
312
- ProconBypassMan.logger.error "Errno::ENXIO (No such device or address @ rb_sysopen - /dev/hidg0)が起きました。resetします"
313
- ProconBypassMan.logger.error e
320
+ ProconBypassMan::SendErrorCommand.execute(error: "Errno::ENXIO (No such device or address @ rb_sysopen - /dev/hidg0)が起きました。resetします. #{e.full_message}")
314
321
  system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
315
322
  system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
316
- sleep 2
323
+ sleep 0.5
317
324
  retry
318
325
  end
319
326
  end
@@ -0,0 +1,44 @@
1
+ class ProconBypassMan::DeviceStatus
2
+ INITIALIZED = :initialized
3
+ RUNNING = :running
4
+ CONNECTED_BUT_SLEEPING = :connected_but_sleeping # コードはつながっているが、switchがsleepしているとき
5
+ PROCON_NOT_FOUND_ERROR = :procon_not_found_error # 繋がっていないとか、デバイスが使えない時
6
+ CONNECTED_BUT_ERROR = :connected_but_error # 実行時エラーあたり
7
+ SETTING_SYNTAX_ERROR_AND_SHUTDOWN = :setting_syntax_error_and_shutdown
8
+
9
+ @@status = nil
10
+
11
+ def self.current
12
+ @@status || INITIALIZED
13
+ end
14
+
15
+ def self.change_to_running!
16
+ @@status = RUNNING
17
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
18
+ end
19
+
20
+ def self.change_to_connected_but_sleeping!
21
+ @@status = CONNECTED_BUT_SLEEPING
22
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
23
+ end
24
+
25
+ def self.change_to_procon_not_found_error!
26
+ @@status = PROCON_NOT_FOUND_ERROR
27
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
28
+ end
29
+
30
+ def self.change_to_device_error!
31
+ @@status = DEVICE_ERROR
32
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
33
+ end
34
+
35
+ def self.change_to_connected_but_error!
36
+ @@status = CONNECTED_BUT_ERROR
37
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
38
+ end
39
+
40
+ def self.change_to_setting_syntax_error_and_shutdown!
41
+ @@status = SETTING_SYNTAX_ERROR_AND_SHUTDOWN
42
+ ProconBypassMan::SyncDeviceStatsJob.perform_async(ProconBypassMan::DeviceStatus.current)
43
+ end
44
+ end
@@ -1,11 +1,12 @@
1
1
  module ProconBypassMan
2
2
  class Counter
3
- attr_accessor :label, :table, :previous_table
3
+ attr_accessor :label, :table, :previous_table, :active
4
4
 
5
5
  def initialize(label: )
6
6
  self.label = label
7
7
  self.table = {}
8
8
  self.previous_table = {}
9
+ self.active = true
9
10
  end
10
11
 
11
12
  # アクティブなバケットは1つだけ
@@ -24,7 +25,7 @@ module ProconBypassMan
24
25
  self
25
26
  end
26
27
 
27
- def formated_previous_table
28
+ def formatted_previous_table
28
29
  t = previous_table.dup
29
30
  start_function = t[:start_function] || 0
30
31
  end_function = t[:end_function] || 0
@@ -32,6 +33,10 @@ module ProconBypassMan
32
33
  eagain_wait_readable_on_write = t[:eagain_wait_readable_on_write] || 0
33
34
  "(#{(end_function / start_function.to_f * 100).floor(1)}%(#{end_function}/#{start_function}), loss: #{eagain_wait_readable_on_read}, #{eagain_wait_readable_on_write})"
34
35
  end
36
+
37
+ def shutdown
38
+ self.active = false
39
+ end
35
40
  end
36
41
 
37
42
  module IOMonitor
@@ -51,14 +56,14 @@ module ProconBypassMan
51
56
  Thread.start do
52
57
  max_output_length = 0
53
58
  loop do
54
- list = @@list.dup
59
+ list = @@list.select(&:active).dup
55
60
  unless list.all? { |x| x&.previous_table.is_a?(Hash) }
56
61
  sleep 0.5
57
62
  next
58
63
  end
59
64
 
60
65
  line = list.map { |counter|
61
- "#{counter.label}(#{counter.formated_previous_table})"
66
+ "#{counter.label}(#{counter.formatted_previous_table})"
62
67
  }.join(", ")
63
68
  max_output_length = line.length
64
69
  sleep 0.7
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module FastReturn
6
+ def self.name
7
+ :fast_return
8
+ end
9
+
10
+ def self.steps
11
+ [:x, :down, :a, :a].freeze
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module JumpToLeftKey
6
+ def self.name
7
+ :jump_to_left_key
8
+ end
9
+
10
+ def self.steps
11
+ [:x, :left, :a, :a].freeze
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module JumpToRightKey
6
+ def self.name
7
+ :jump_to_right_key
8
+ end
9
+
10
+ def self.steps
11
+ [:x, :right, :a, :a].freeze
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Macro
5
+ module JumpToUpKey
6
+ def self.name
7
+ :jump_to_up_key
8
+ end
9
+
10
+ def self.steps
11
+ [:x, :up, :a, :a].freeze
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+ module ProconBypassMan
2
+ module Plugin
3
+ module Splatoon2
4
+ module Mode
5
+ module Guruguru
6
+ def self.binaries
7
+ [ "309481408000362d684658750968f71cfe2c0e51000001480053f71ffedf0d4b000a013d00caf6ecfd4c0d480003011c00000000000000000000000000000000",
8
+ "30978140800037dd6748687509fdf6adfded0d6d0081005d00eef68dfdef0d6d00830059001bf791fd140e720090005400000000000000000000000000000000",
9
+ "309a8140800038cd67495875099af821fe120e40006400880042f8fcfdfd0d470067008900d4f7e0fdf20d4e006a008c00000000000000000000000000000000",
10
+ "309c8140800036ed67466875099bf878fe4a0e35005b004c00c1f875fe400e35005d004c00c4f856fe2d0e390063006c00000000000000000000000000000000",
11
+ "30a081408000371d6847587509b9f71bfee70d22002c002300e3f73afe150e2b003500280014f854fe300e2d0038002900000000000000000000000000000000",
12
+ "30a38140800039fd6743587509def70ffea10d1a0031001f00d1f70ffeb10d19002c002200c5f711feb80d18002c002500000000000000000000000000000000",
13
+ "30a58140800037dd6746687509d8f70bfe980d270035001200ddf70dfe980d240038001900dff70ffe9b0d1f0035001a00000000000000000000000000000000",
14
+ "30a98140800037ed67484875099cf7edfdb00d310020000d009ef7eefda30d310022000c00adf7f2fd980d300028000a00000000000000000000000000000000",
15
+ "30ac8140800036ed67484875099cf709fed40d3a002400160097f7fafdd30d39002200150096f7f0fdc80d380022001400000000000000000000000000000000",
16
+ "30ae8140800038fd674558750987f72efed40d360021001c0089f729fed50d39002400180092f715fed10d390022001800000000000000000000000000000000",
17
+ "30b18140800037dd6747487509b8f705fea90d19001d002000c5f70dfeb00d210019002200bff71efec20d280018002400000000000000000000000000000000",
18
+ "30b48140800038fd684868750980f7e9fdd40d0200080024007df7f1fdba0d060011001e0084f7f8fdaa0d12001a001a00000000000000000000000000000000",
19
+ "30b7814080003fdd694958750918f6a9fd510f0d00d1ff370024f7b0fda90e0100ecff30006cf7d1fd210efffff5ff2c00000000000000000000000000000000",
20
+ "30ba81408080482d744768750963f71ffe190f5e00d9fea100ccf62dfe650f510009ff980015f702fe580f4b002eff8400000000000000000000000000000000",
21
+ "30bd814080802f7d864758750974f70efe4c0f5e00c0fea000d1f726fe1c0f5d00c5fea30028f859fe0e0f5c00cafea800000000000000000000000000000000",
22
+ "30bf8140808057cc984758750961f73afe630f99009dfeae0050f738fe710f7500adfea40050f721fe720f6e00b2fea300000000000000000000000000000000",
23
+ "30c281408080f479bd483875092ef8b6feab0f0a0180feba00f1f798fe900f000181febd00c2f77dfe7c0fdb008efebd00000000000000000000000000000000",
24
+ "30c581408080ad87d846487509e1f80000a6107e0178fea2004ef88dff54106c0185fea70063f826ffe60f520182feae00000000000000000000000000000000",
25
+ "30c8810080800797d84868750995f8e1fe4b0f7a0161fe88000df96dffd00f700149fe990035f9cdff361088016afea000000000000000000000000000000000",
26
+ "30cb810080804586d848487509cef672fe8a0f6d0217ff42002df63cfe280f1d0219ff410059f61cfe070fed01f5fe4a00000000000000000000000000000000",
27
+ "30d08100808002c5d745687509d8f5aaff830f5e03e6fe3e01fbf55bffc30f3f03e4fe100158f600ff3e102903e5fee700000000000000000000000000000000",
28
+ "30d3810080807b94d14838750991f6cd00690f9903f0fff10147f6e200560f7e038fffc60101f6c900560f71033bffa901000000000000000000000000000000",
29
+ "30d681008080b743ca475875095af7f2009c0fca03a400320242f7ca00950fb503820028020af7b000820fa4034e001a02000000000000000000000000000000",
30
+ "30d9810080805be3c047587509e7f77a03c70f0e04bb00410258f79801940f0004b800410251f74401910fd803b3003602000000000000000000000000000000",
31
+ "30dc810080808a02b245587509c0fbd5086a10710475020a03b0fb8d085d106c042102e8027efb660876106a04bc01af02000000000000000000000000000000",
32
+ "30de8100808036d2a14568750970fbbf09ad103704af038003a9fb600989105c0459036103c2fb2a097210690412034603000000000000000000000000000000",
33
+ "30e281008000cbb18d4738750989f8b40b2812380341044c0429f99e0bef11510340043704f2f93c0b7911b0033704f003000000000000000000000000000000",
34
+ "30e581008000c9c18945587509a5f7ca0a2e13e400c6024c0547f7fd0a941264011703270578f74a0b6012e40168030205000000000000000000000000000000",
35
+ "30e781008000c6618948687509acf86909e813d0fe2801a1057cf8cf09ed130fff6301990516f8710aaa13ccff13028205000000000000000000000000000000",
36
+ "30ea81008000c77189475875093af93b0762136efbaeff19060cf90107b113a9fb99ff0906e1f85b07b113bafc9fffcd05000000000000000000000000000000",
37
+ "30ed81008000c791894568750950f9ce047c1432f900026007a5f9a6051f146ef9bb013707bff99206a813fef9ce00c606000000000000000000000000000000",
38
+ "30ef81008000c6d1894558750944f8ad0358143ef81c02f10780f8b403841484f84102d107ccf801049314bcf84202ad07000000000000000000000000000000",
39
+ "30f381008000c761884868750914f72105e4134cf6d001c00743f71a05f11391f6bf01e407a0f7c904fa13faf6b3011008000000000000000000000000000000",
40
+ "30f681008000c7718344587509eaf54a04c812a6f40002500627f66d041313f2f40d02940682f6a60468133ef51a02d806000000000000000000000000000000",
41
+ "30f881008000c4e1814668750b5cf5f803b51125f3b5000d0560f50f04e8118cf33c015d057df525042c1210f4b101cc05000000000000000000000000000000",
42
+ "30fb81008000c5e1814458750b19f65a02a410acf29effb804e2f5db02df10b7f2c0ffbf04a9f55c032011dcf22400d804000000000000000000000000000000",
43
+ "30fe8100800035e2814858750b81f65c00f80f8df231fe940471f6e6001f1088f2a6fe92044ef6b1015a1092f21fffa004000000000000000000000000000000",
44
+ "3001810080004b03814868750b69f6e6fdad0ffef20efdd40479f678feb40fd9f249fdc40484f6f4fec00fb0f29ffdad04000000000000000000000000000000",
45
+ "30048100800079e47d4858750b17f64cfb5f0f46f46afb430529f6c4fb710ff1f3d4fb300538f64bfc830fbbf315fc1d05000000000000000000000000000000",
46
+ "300781008000a7057e4668750bb1f5d3f9fb0e8ef5ccf96405cdf5fcf90c0f44f52dfa6505e1f52dfa210f29f550fa6305000000000000000000000000000000",
47
+ "30098100800041f67d4668750bcdf4b0f9ab0e21f602f955057ef5adf9d00ee1f559f95f05b1f5d3f9fb0e8ef5ccf96405000000000000000000000000000000",
48
+ "300d810080003d877c4838750b84f458f7dd0c89f6d0f8fc0436f4e2f7620d83f614f8430526f4c0f8a00e71f666f85c05000000000000000000000000000000",
49
+ "30108100800058e77a4668750bf7f2c3f57c0c9cf6abfa0a0470f30ef6790c89f65dfa420414f476f67e0c80f6d0f98a04000000000000000000000000000000",
50
+ "30128100800059f77a4658750b7ef249f5580cd9f69bfaa40389f269f56c0cd1f6a9fab503a3f286f5760cacf6c9faeb03000000000000000000000000000000",
51
+ "3016810080005b177b4868750ba9f298f4450b2cf774fa3102b8f2a5f47a0b24f765fa6e02b8f2b8f4b10b1df755faac02000000000000000000000000000000",
52
+ "30198100800057777a4558750b39f258f4480a80f73efaf40016f26af4940a5ef76bfa37014ef275f4d40a46f780fa8401000000000000000000000000000000",
53
+ ].map(&:freeze).freeze
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ProconBypassMan
4
+ module Plugin
5
+ module Splatoon2
6
+ VERSION = "0.1.2"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "plugin/splatoon2/version"
2
+ require_relative "plugin/splatoon2/macro/fast_return"
3
+ require_relative "plugin/splatoon2/macro/jump_to_right_key"
4
+ require_relative "plugin/splatoon2/macro/jump_to_up_key"
5
+ require_relative "plugin/splatoon2/macro/jump_to_left_key"
6
+ require_relative "plugin/splatoon2/mode/guruguru"
7
+
8
+ module ProconBypassMan
9
+ module Plugin
10
+ end
11
+ end
@@ -60,6 +60,6 @@ class ProconBypassMan::Procon::AnalogStickCap
60
60
  end
61
61
 
62
62
  def hypotenuse
63
- Math.sqrt(relative_x**2 + relative_y**2).floor(6)
63
+ Math.sqrt((relative_x**2) + (relative_y**2)).floor(6)
64
64
  end
65
65
  end
@@ -1,5 +1,5 @@
1
1
  class ProconBypassMan::Procon
2
- module Data
2
+ module Consts
3
3
  NO_ACTION = "30f28100800078c77448287509550274ff131029001b0022005a0271ff191028001e00210064027cff1410280020002100000000000000000000000000000000".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,40 @@
1
+ class ProconBypassMan::Procon::LayerChanger
2
+ def initialize(binary: )
3
+ @procon_reader = ProconBypassMan::ProconReader.new(binary: binary).freeze
4
+ end
5
+
6
+ # @return [Symbol]
7
+ def next_layer_key
8
+ case
9
+ when pressed?(button: :up)
10
+ :up
11
+ when pressed?(button: :right)
12
+ :right
13
+ when pressed?(button: :left)
14
+ :left
15
+ when pressed?(button: :down)
16
+ :down
17
+ else
18
+ ProconBypassMan.logger.warn("next_layer_key is unknown")
19
+ :up
20
+ end
21
+ end
22
+
23
+ # @return [Boolean]
24
+ def change_layer?
25
+ if ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.empty?
26
+ raise "prefix_keysが未設定です"
27
+ end
28
+ ProconBypassMan::ButtonsSettingConfiguration.instance.prefix_keys.map { |b| pressed?(button: b) }.all?
29
+ end
30
+
31
+ # @return [Boolean]
32
+ def pressed_next_layer?
33
+ change_layer? && (pressed?(button: :up) || pressed?(button: :right) || pressed?(button: :left) || pressed?(button: :down))
34
+ end
35
+
36
+ # @return [Boolean]
37
+ def pressed?(button: )
38
+ @procon_reader.pressed.include?(button)
39
+ end
40
+ end
@@ -1,12 +1,14 @@
1
1
  class ProconBypassMan::Procon
2
2
  class UserOperation
3
- include LayerChangeable
4
- extend PressedButtonHelper::Dynamic
5
-
6
3
  attr_reader :binary
7
4
 
5
+ ::ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP.each do |button, _value|
6
+ define_method "pressed_#{button}?" do
7
+ pressed_button?(button)
8
+ end
9
+ end
10
+
8
11
  def initialize(binary)
9
- self.class.compile_if_not_compile_yet!
10
12
  unless binary.encoding.name == ASCII_ENCODING
11
13
  raise "おかしいです"
12
14
  end
@@ -16,20 +18,16 @@ class ProconBypassMan::Procon
16
18
  ZERO_BIT = ["0"].pack("H*").freeze
17
19
  ASCII_ENCODING = "ASCII-8BIT"
18
20
 
19
- # @depilicate
20
- def binary=(binary)
21
- unless binary.encoding.name == ASCII_ENCODING
22
- raise "おかしいです"
23
- end
24
- @binary = binary
25
- end
26
-
27
21
  def set_no_action!
28
22
  binary[3] = ZERO_BIT
29
23
  binary[4] = ZERO_BIT
30
24
  binary[5] = ZERO_BIT
31
25
  end
32
26
 
27
+ def apply_left_analog_stick_cap(cap: )
28
+ binary[6..8] = ProconBypassMan::Procon::AnalogStickCap.new(binary).capped_position(cap_hypotenuse: cap).to_binary
29
+ end
30
+
33
31
  def unpress_button(button)
34
32
  return if not pressed_button?(button)
35
33
 
@@ -38,10 +36,6 @@ class ProconBypassMan::Procon
38
36
  binary[byte_position] = ["%02X" % value.to_s].pack("H*")
39
37
  end
40
38
 
41
- def apply_left_analog_stick_cap(cap: )
42
- binary[6..8] = ProconBypassMan::Procon::AnalogStickCap.new(binary).capped_position(cap_hypotenuse: cap).to_binary
43
- end
44
-
45
39
  def press_button(button)
46
40
  return if pressed_button?(button)
47
41
 
@@ -51,7 +45,7 @@ class ProconBypassMan::Procon
51
45
  end
52
46
 
53
47
  def press_button_only(button)
54
- [ProconBypassMan::Procon::Data::NO_ACTION.dup].pack("H*").tap do |no_action_binary|
48
+ [ProconBypassMan::Procon::Consts::NO_ACTION.dup].pack("H*").tap do |no_action_binary|
55
49
  ButtonCollection.load(button).byte_position
56
50
  byte_position = ButtonCollection.load(button).byte_position
57
51
  value = 2**ButtonCollection.load(button).bit_position
@@ -1,10 +1,9 @@
1
1
  class ProconBypassMan::Procon
2
- require "procon_bypass_man/procon/data"
2
+ require "procon_bypass_man/procon/consts"
3
3
  require "procon_bypass_man/procon/mode_registry"
4
4
  require "procon_bypass_man/procon/macro_registry"
5
- require "procon_bypass_man/procon/layer_changeable"
5
+ require "procon_bypass_man/procon/layer_changer"
6
6
  require "procon_bypass_man/procon/button_collection"
7
- require "procon_bypass_man/procon/pressed_button_helper"
8
7
  require "procon_bypass_man/procon/user_operation"
9
8
  require "procon_bypass_man/procon/flip_cache"
10
9
  require "procon_bypass_man/procon/press_button_aware"
@@ -35,8 +34,9 @@ class ProconBypassMan::Procon
35
34
  end
36
35
 
37
36
  def apply!
38
- if user_operation.change_layer?
39
- @@status[:current_layer_key] = user_operation.next_layer_key if user_operation.pressed_next_layer?
37
+ layer_changer = ProconBypassMan::Procon::LayerChanger.new(binary: user_operation.binary)
38
+ if layer_changer.change_layer?
39
+ @@status[:current_layer_key] = layer_changer.next_layer_key if layer_changer.pressed_next_layer?
40
40
  user_operation.set_no_action!
41
41
  return
42
42
  end
@@ -137,13 +137,7 @@ class ProconBypassMan::Procon
137
137
  end
138
138
  end
139
139
 
140
- b = user_operation.binary
141
- ProconBypassMan.cache.fetch key: 'user_operation.binary', expires_in: 60 do
142
- left_analog_stick = ProconBypassMan::ReadonlyProcon.new(binary: b).left_analog_stick
143
- ProconBypassMan.logger.debug "x: #{left_analog_stick[:x]}, val: #{left_analog_stick[:x].to_s(2)}"
144
- ProconBypassMan.logger.debug "y: #{left_analog_stick[:y]}, val: #{left_analog_stick[:y].to_s(2)}"
145
- end
146
- b
140
+ user_operation.binary
147
141
  end
148
142
 
149
143
  private
@@ -1,15 +1,14 @@
1
- # read
2
- class ProconBypassMan::ReadonlyProcon
1
+ class ProconBypassMan::ProconReader
3
2
  def initialize(binary: )
4
3
  @binary = binary
5
- @user_operation = ProconBypassMan::Procon::UserOperation.new(binary.dup)
6
4
  @analog_stick = ProconBypassMan::Procon::AnalogStick.new(binary: binary)
7
5
  end
8
6
 
9
7
  # @return [Array<Symbol>]
10
8
  def pressed
9
+ aware = ProconBypassMan::PpressButtonAware.new(@binary)
11
10
  pressed_table = ::ProconBypassMan::Procon::ButtonCollection::BUTTONS.reduce({}) do |acc, button|
12
- acc[button] = @user_operation.pressed_button?(button)
11
+ acc[button] = aware.pressed_button?(button)
13
12
  acc
14
13
  end
15
14
  pressed_table.select { |_key, value| value }.keys