procon_bypass_man 0.1.18 → 0.1.20.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +85 -11
- data/CHANGELOG.md +19 -1
- data/Gemfile.lock +3 -3
- data/README.md +16 -22
- data/docs/getting_started.md +88 -0
- data/docs/setting/splatoon2_recommended_setting.md +127 -0
- data/docs/upgrade_pbm.md +25 -1
- data/lib/procon_bypass_man/background/jobs/report_error_reload_config_job.rb +11 -0
- data/lib/procon_bypass_man/background/jobs/report_start_reboot_job.rb +10 -0
- data/lib/procon_bypass_man/background.rb +2 -0
- data/lib/procon_bypass_man/buttons_setting_configuration/loader.rb +21 -2
- data/lib/procon_bypass_man/buttons_setting_configuration/validator.rb +12 -2
- data/lib/procon_bypass_man/buttons_setting_configuration.rb +9 -9
- data/lib/procon_bypass_man/bypass/bypass_mode.rb +21 -0
- data/lib/procon_bypass_man/bypass.rb +10 -8
- data/lib/procon_bypass_man/commands/bypass_command.rb +20 -8
- data/lib/procon_bypass_man/commands/connect_device_command.rb +23 -11
- data/lib/procon_bypass_man/configuration.rb +30 -1
- data/lib/procon_bypass_man/device_connector.rb +6 -33
- data/lib/procon_bypass_man/device_procon_finder.rb +65 -0
- data/lib/procon_bypass_man/never_exit_accidentally.rb +12 -0
- data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +1 -0
- data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +9 -2
- data/lib/procon_bypass_man/runner.rb +7 -7
- data/lib/procon_bypass_man/scheduler.rb +1 -1
- data/lib/procon_bypass_man/support/yaml_writer.rb +16 -0
- data/lib/procon_bypass_man/version.rb +1 -1
- data/lib/procon_bypass_man.rb +24 -11
- data/project_template/app.rb +5 -1
- data/project_template/setting.yml +6 -22
- data/sig/main.rbs +5 -0
- metadata +10 -2
@@ -10,8 +10,6 @@ module ProconBypassMan
|
|
10
10
|
:setting_path,
|
11
11
|
:mode_plugins,
|
12
12
|
:macro_plugins,
|
13
|
-
:context,
|
14
|
-
:current_context_key,
|
15
13
|
:neutral_position
|
16
14
|
|
17
15
|
def self.instance
|
@@ -27,22 +25,22 @@ module ProconBypassMan
|
|
27
25
|
@@context[current_context_key] = val
|
28
26
|
end
|
29
27
|
|
30
|
-
def self.switch_new_context(
|
31
|
-
@@context[
|
28
|
+
def self.switch_new_context(new_context_key)
|
29
|
+
@@context[new_context_key] = new
|
32
30
|
previous_key = current_context_key
|
33
31
|
if block_given?
|
34
|
-
@@current_context_key =
|
35
|
-
value = yield(@@context[
|
36
|
-
@@current_context_key = previous_key
|
32
|
+
@@current_context_key = new_context_key
|
33
|
+
value = yield(@@context[new_context_key])
|
37
34
|
return value
|
38
35
|
else
|
39
|
-
@@current_context_key =
|
36
|
+
@@current_context_key = new_context_key
|
40
37
|
end
|
38
|
+
ensure
|
39
|
+
@@current_context_key = previous_key
|
41
40
|
end
|
42
41
|
|
43
42
|
def initialize
|
44
43
|
reset!
|
45
|
-
self.class.instance = self
|
46
44
|
end
|
47
45
|
|
48
46
|
module ManualMode
|
@@ -103,6 +101,8 @@ module ProconBypassMan
|
|
103
101
|
def reset!
|
104
102
|
@prefix_keys_for_changing_layer = []
|
105
103
|
self.mode_plugins = {}
|
104
|
+
# プロセスを一度起動するとsetting_pathは変わらない、という想定なので適当に扱う. resetでは初期化しない
|
105
|
+
# self.setting_path = nil
|
106
106
|
self.macro_plugins = {}
|
107
107
|
self.layers = {
|
108
108
|
up: Layer.new,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ProconBypassMan::BypassMode
|
2
|
+
TYPE_NORMAL = :normal
|
3
|
+
TYPE_AGGRESSIVE = :aggressive
|
4
|
+
TYPES = [TYPE_NORMAL, TYPE_AGGRESSIVE]
|
5
|
+
|
6
|
+
DEFAULT_GADGET_TO_PROCON_INTERVAL = 0.5
|
7
|
+
|
8
|
+
attr_accessor :mode, :gadget_to_procon_interval
|
9
|
+
|
10
|
+
def self.default_value
|
11
|
+
new(
|
12
|
+
mode: TYPE_NORMAL,
|
13
|
+
gadget_to_procon_interval: DEFAULT_GADGET_TO_PROCON_INTERVAL,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(mode: , gadget_to_procon_interval: )
|
18
|
+
@mode = mode.to_sym
|
19
|
+
@gadget_to_procon_interval = gadget_to_procon_interval
|
20
|
+
end
|
21
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require "procon_bypass_man/bypass/usb_hid_logger"
|
2
|
+
require "procon_bypass_man/bypass/bypass_mode"
|
2
3
|
|
3
4
|
class ProconBypassMan::Bypass
|
4
5
|
include ProconBypassMan::Bypass::UsbHidLogger
|
5
6
|
|
6
7
|
class BypassValue < Struct.new(:binary, :sent)
|
7
8
|
def to_text
|
9
|
+
return unless binary
|
8
10
|
"#{binary.unpack.first} #{'x' unless sent}"
|
9
11
|
end
|
10
12
|
end
|
@@ -31,16 +33,16 @@ class ProconBypassMan::Bypass
|
|
31
33
|
self.bypass_value.binary = ProconBypassMan::Domains::InboundProconBinary.new(binary: input)
|
32
34
|
rescue IO::EAGAINWaitReadable
|
33
35
|
monitor.record(:eagain_wait_readable_on_read)
|
34
|
-
sleep(0.001)
|
35
|
-
retry
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
if input
|
39
|
+
begin
|
40
|
+
self.procon.write_nonblock(input)
|
41
|
+
self.bypass_value.sent = true
|
42
|
+
rescue IO::EAGAINWaitReadable
|
43
|
+
monitor.record(:eagain_wait_readable_on_write)
|
44
|
+
break
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
@@ -27,19 +27,31 @@ class ProconBypassMan::BypassCommand
|
|
27
27
|
monitor1 = ProconBypassMan::IOMonitor.new(label: "switch -> procon")
|
28
28
|
monitor2 = ProconBypassMan::IOMonitor.new(label: "procon -> switch")
|
29
29
|
ProconBypassMan.logger.info "Thread1を起動します"
|
30
|
+
|
31
|
+
@send_interval = 0.005
|
32
|
+
|
30
33
|
t1 = Thread.new do
|
31
34
|
timer = ProconBypassMan::SafeTimeout.new(timeout: Time.now + 10)
|
32
|
-
|
35
|
+
@did_first_step = false
|
33
36
|
loop do
|
37
|
+
bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor1)
|
34
38
|
break if $will_terminate_token
|
35
|
-
timer.throw_if_timeout!
|
39
|
+
!@did_first_step && timer.throw_if_timeout!
|
36
40
|
bypass.send_gadget_to_procon!
|
37
|
-
sleep(
|
41
|
+
sleep(@send_interval)
|
38
42
|
rescue ProconBypassMan::SafeTimeout::Timeout
|
39
|
-
ProconBypassMan.
|
40
|
-
|
41
|
-
|
42
|
-
|
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"
|
53
|
+
end
|
54
|
+
@did_first_step = true
|
43
55
|
rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError, Errno::ESHUTDOWN => e
|
44
56
|
ProconBypassMan::SendErrorCommand.execute(error: "Switchとの切断されました.終了処理を開始します. #{e.full_message}")
|
45
57
|
Process.kill "TERM", Process.ppid
|
@@ -80,7 +92,7 @@ class ProconBypassMan::BypassCommand
|
|
80
92
|
[t1, t2].each(&:join)
|
81
93
|
@gadget&.close
|
82
94
|
@procon&.close
|
83
|
-
exit 1
|
95
|
+
exit 1 # child processなのでexitしていい
|
84
96
|
end
|
85
97
|
end
|
86
98
|
end
|
@@ -1,16 +1,28 @@
|
|
1
1
|
class ProconBypassMan::ConnectDeviceCommand
|
2
|
+
class NotFoundProconError < StandardError; end
|
3
|
+
|
2
4
|
# @return [void]
|
3
5
|
def self.execute!
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
unless has_required_files?
|
7
|
+
raise ProconBypassMan::NotFoundRequiredFilesError, "there is not /sys/kernel/config/usb_gadget/procon"
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
gadget, procon = ProconBypassMan::DeviceConnector.connect
|
12
|
+
rescue ProconBypassMan::DeviceConnector::NotFoundProconError => e
|
13
|
+
ProconBypassMan.logger.error e
|
14
|
+
gadget&.close
|
15
|
+
procon&.close
|
16
|
+
raise ProconBypassMan::ConnectDeviceCommand::NotFoundProconError
|
17
|
+
rescue ProconBypassMan::SafeTimeout::Timeout
|
18
|
+
ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
|
19
|
+
gadget&.close
|
20
|
+
procon&.close
|
21
|
+
raise ProconBypassMan::EternalConnectionError
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.has_required_files?
|
26
|
+
Dir.exist?("/sys/kernel/config/usb_gadget/procon")
|
15
27
|
end
|
16
28
|
end
|
@@ -38,10 +38,19 @@ class ProconBypassMan::Configuration
|
|
38
38
|
def device_id
|
39
39
|
ENV["DEBUG_DEVICE_ID"] || ProconBypassMan::WriteDeviceIdCommand.execute
|
40
40
|
end
|
41
|
+
|
42
|
+
# @return [Boolean]
|
43
|
+
def never_exit_accidentally
|
44
|
+
config.never_exit_accidentally
|
45
|
+
end
|
46
|
+
|
47
|
+
def fallback_setting_path
|
48
|
+
"/tmp/procon_bypass_man_fallback_setting.yaml"
|
49
|
+
end
|
41
50
|
end
|
42
51
|
|
43
52
|
attr_accessor :enable_critical_error_logging
|
44
|
-
attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons
|
53
|
+
attr_writer :verbose_bypass_log, :raw_setting, :enable_reporting_pressed_buttons, :never_exit_accidentally
|
45
54
|
|
46
55
|
def root=(path)
|
47
56
|
@root = path
|
@@ -56,6 +65,17 @@ class ProconBypassMan::Configuration
|
|
56
65
|
end
|
57
66
|
end
|
58
67
|
|
68
|
+
def bypass_mode=(value)
|
69
|
+
@bypass_mode = ProconBypassMan::BypassMode.new(
|
70
|
+
mode: value[:mode],
|
71
|
+
gadget_to_procon_interval: value[:gadget_to_procon_interval],
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def bypass_mode
|
76
|
+
@bypass_mode || ProconBypassMan::BypassMode.default_value
|
77
|
+
end
|
78
|
+
|
59
79
|
def api_servers=(api_servers)
|
60
80
|
@api_servers = api_servers
|
61
81
|
return self
|
@@ -147,6 +167,10 @@ class ProconBypassMan::Configuration
|
|
147
167
|
end
|
148
168
|
end
|
149
169
|
|
170
|
+
def has_api_server?
|
171
|
+
not api_servers.length.zero?
|
172
|
+
end
|
173
|
+
|
150
174
|
def verbose_bypass_log
|
151
175
|
@verbose_bypass_log || !!ENV["VERBOSE_BYPASS_LOG"]
|
152
176
|
end
|
@@ -158,4 +182,9 @@ class ProconBypassMan::Configuration
|
|
158
182
|
def enable_reporting_pressed_buttons
|
159
183
|
@enable_reporting_pressed_buttons ||= false
|
160
184
|
end
|
185
|
+
|
186
|
+
# @return [Boolean]
|
187
|
+
def never_exit_accidentally
|
188
|
+
@never_exit_accidentally || false
|
189
|
+
end
|
161
190
|
end
|
@@ -263,46 +263,19 @@ class ProconBypassMan::DeviceConnector
|
|
263
263
|
@procon
|
264
264
|
end
|
265
265
|
|
266
|
-
def is_available_device?(path)
|
267
|
-
return false if !File.exist?(path)
|
268
|
-
|
269
|
-
system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
|
270
|
-
system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
|
271
|
-
sleep 0.5
|
272
|
-
|
273
|
-
file = File.open(path, "w+")
|
274
|
-
begin
|
275
|
-
file.read_nonblock(64)
|
276
|
-
rescue EOFError
|
277
|
-
file.close
|
278
|
-
return false
|
279
|
-
rescue IO::EAGAINWaitReadable
|
280
|
-
file.close
|
281
|
-
return true
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
def to_bin(string)
|
286
|
-
string.unpack "H*"
|
287
|
-
end
|
288
|
-
|
289
266
|
def init_devices
|
290
267
|
if @initialized_devices
|
291
268
|
return
|
292
269
|
end
|
293
270
|
|
294
|
-
|
295
|
-
|
296
|
-
ProconBypassMan.logger.info "proconのデバイスファイルは#{
|
297
|
-
@procon = File.open(PROCON_PATH, "w+b")
|
298
|
-
@gadget = File.open('/dev/hidg0', "w+b")
|
299
|
-
when is_available_device?(PROCON2_PATH)
|
300
|
-
ProconBypassMan.logger.info "proconのデバイスファイルは#{PROCON2_PATH}を使います"
|
301
|
-
@procon = File.open(PROCON2_PATH, "w+b")
|
302
|
-
@gadget = File.open('/dev/hidg0', "w+b")
|
271
|
+
if path = ProconBypassMan::DeviceProconFinder.find
|
272
|
+
@procon = File.open(path, "w+b")
|
273
|
+
ProconBypassMan.logger.info "proconのデバイスファイルは#{path}を使います"
|
303
274
|
else
|
304
|
-
raise
|
275
|
+
raise(ProconBypassMan::DeviceConnector::NotFoundProconError)
|
305
276
|
end
|
277
|
+
@gadget = File.open('/dev/hidg0', "w+b")
|
278
|
+
|
306
279
|
system('echo > /sys/kernel/config/usb_gadget/procon/UDC')
|
307
280
|
system('ls /sys/class/udc > /sys/kernel/config/usb_gadget/procon/UDC')
|
308
281
|
sleep 0.5
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class ProconBypassMan::DeviceProconFinder
|
2
|
+
HID_NAME = "Nintendo Co., Ltd. Pro Controller"
|
3
|
+
|
4
|
+
def self.find
|
5
|
+
new.find
|
6
|
+
end
|
7
|
+
|
8
|
+
# @return [String, NilClass]
|
9
|
+
def find
|
10
|
+
find_device_path
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# @return [String , NilClass]
|
16
|
+
def find_device_path
|
17
|
+
if(line = device_from_shell) && (hidraw_name = line.match(/(hidraw\d+)\s+/)[1])
|
18
|
+
"/dev/#{hidraw_name}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [String , NilClass]
|
23
|
+
def device_from_shell
|
24
|
+
shell_output.split("\n").detect { |o| o.include?(HID_NAME) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [String]
|
28
|
+
def shell_output
|
29
|
+
`bash -c '#{get_list_shell}'`
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_list_shell
|
33
|
+
<<~SHELL
|
34
|
+
#!/bin/bash
|
35
|
+
|
36
|
+
FILES=/dev/hidraw*
|
37
|
+
for f in $FILES
|
38
|
+
do
|
39
|
+
FILE=${f##*/}
|
40
|
+
DEVICE="$(cat /sys/class/hidraw/${FILE}/device/uevent | grep HID_NAME | cut -d '=' -f2)"
|
41
|
+
printf "%s %s\n" $FILE "$DEVICE"
|
42
|
+
done
|
43
|
+
SHELL
|
44
|
+
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
|
+
end
|
@@ -6,9 +6,16 @@ module ProconBypassMan
|
|
6
6
|
require "pbmenv"
|
7
7
|
ProconBypassMan.logger.info "execute RestorePbmSettingAction!"
|
8
8
|
setting = args.dig("setting") or raise(ProconBypassMan::RemotePbmAction::NeedPbmVersionError, "settingが必要です, #{args.inspect}")
|
9
|
-
|
9
|
+
|
10
|
+
# 復元に失敗したら戻せるように退避する
|
11
|
+
FileUtils.copy(
|
10
12
|
ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path,
|
11
|
-
|
13
|
+
ProconBypassMan.fallback_setting_path,
|
14
|
+
)
|
15
|
+
|
16
|
+
ProconBypassMan::YamlWriter.write(
|
17
|
+
path: ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path,
|
18
|
+
content: setting,
|
12
19
|
)
|
13
20
|
ProconBypassMan.hot_reload!
|
14
21
|
end
|
@@ -27,7 +27,7 @@ class ProconBypassMan::Runner
|
|
27
27
|
loop do
|
28
28
|
$will_terminate_token = false
|
29
29
|
# NOTE メインプロセスではThreadをいくつか起動しているので念のためパフォーマンスを優先するためにforkしていく
|
30
|
-
|
30
|
+
child_pid = Kernel.fork { ProconBypassMan::BypassCommand.new(gadget: @gadget, procon: @procon).execute }
|
31
31
|
|
32
32
|
begin
|
33
33
|
# TODO 小プロセスが消滅した時に、メインプロセスは生き続けてしまい、何もできなくなる問題がある
|
@@ -37,25 +37,25 @@ class ProconBypassMan::Runner
|
|
37
37
|
end
|
38
38
|
rescue InterruptForRestart
|
39
39
|
$will_terminate_token = true
|
40
|
-
Process.kill("TERM",
|
40
|
+
Process.kill("TERM", child_pid)
|
41
41
|
Process.wait
|
42
42
|
ProconBypassMan::PrintMessageCommand.execute(text: "Reloading config file")
|
43
43
|
begin
|
44
44
|
ProconBypassMan::ButtonsSettingConfiguration::Loader.reload_setting
|
45
45
|
ProconBypassMan::SendReloadConfigEventCommand.execute
|
46
|
-
rescue ProconBypassMan::CouldNotLoadConfigError
|
46
|
+
rescue ProconBypassMan::CouldNotLoadConfigError => error
|
47
47
|
ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。再読み込みができませんでした")
|
48
|
+
ProconBypassMan::ReportErrorReloadConfigJob.perform_async(error.message)
|
48
49
|
end
|
49
50
|
ProconBypassMan::PrintMessageCommand.execute(text: "バイパス処理を再開します")
|
50
51
|
rescue Interrupt
|
51
52
|
$will_terminate_token = true
|
52
|
-
Process.kill("TERM",
|
53
|
+
Process.kill("TERM", child_pid)
|
53
54
|
Process.wait
|
55
|
+
ProconBypassMan::PrintMessageCommand.execute(text: "処理を終了します")
|
54
56
|
@gadget&.close
|
55
57
|
@procon&.close
|
56
|
-
|
57
|
-
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
58
|
-
exit 1
|
58
|
+
break
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/lib/procon_bypass_man.rb
CHANGED
@@ -13,6 +13,7 @@ require_relative "procon_bypass_man/version"
|
|
13
13
|
require_relative "procon_bypass_man/remote_pbm_action"
|
14
14
|
require_relative "procon_bypass_man/support/signal_handler"
|
15
15
|
require_relative "procon_bypass_man/support/callbacks"
|
16
|
+
require_relative "procon_bypass_man/support/yaml_writer"
|
16
17
|
require_relative "procon_bypass_man/support/safe_timeout"
|
17
18
|
require_relative "procon_bypass_man/support/compress_array"
|
18
19
|
require_relative "procon_bypass_man/support/uptime"
|
@@ -26,7 +27,9 @@ require_relative "procon_bypass_man/background"
|
|
26
27
|
require_relative "procon_bypass_man/commands"
|
27
28
|
require_relative "procon_bypass_man/bypass"
|
28
29
|
require_relative "procon_bypass_man/domains"
|
30
|
+
require_relative "procon_bypass_man/never_exit_accidentally"
|
29
31
|
require_relative "procon_bypass_man/device_connector"
|
32
|
+
require_relative "procon_bypass_man/device_procon_finder"
|
30
33
|
require_relative "procon_bypass_man/device_status"
|
31
34
|
require_relative "procon_bypass_man/runner"
|
32
35
|
require_relative "procon_bypass_man/processor"
|
@@ -47,10 +50,11 @@ Thread.abort_on_exception = true
|
|
47
50
|
|
48
51
|
module ProconBypassMan
|
49
52
|
extend ProconBypassMan::Configuration::ClassMethods
|
53
|
+
extend ProconBypassMan::NeverExitAccidentally
|
50
54
|
|
51
55
|
class CouldNotLoadConfigError < StandardError; end
|
52
|
-
class NotFoundProconError < StandardError; end
|
53
56
|
class ConnectionError < StandardError; end
|
57
|
+
class NotFoundRequiredFilesError < StandardError; end
|
54
58
|
class FirstConnectionError < ConnectionError; end
|
55
59
|
class EternalConnectionError < ConnectionError; end
|
56
60
|
|
@@ -61,22 +65,31 @@ module ProconBypassMan
|
|
61
65
|
ProconBypassMan::Websocket::PbmJobClient.start!
|
62
66
|
|
63
67
|
ProconBypassMan::PrintMessageCommand.execute(text: "PBMを起動しています")
|
64
|
-
ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting_path)
|
65
68
|
initialize_pbm
|
69
|
+
ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting_path)
|
66
70
|
gadget, procon = ProconBypassMan::ConnectDeviceCommand.execute!
|
67
|
-
Runner.new(gadget: gadget, procon: procon).run
|
68
|
-
rescue ProconBypassMan::CouldNotLoadConfigError
|
69
|
-
ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。設定ファイルの読み込みに失敗しました")
|
70
|
-
ProconBypassMan::DeviceStatus.change_to_setting_syntax_error_and_shutdown!
|
71
|
+
Runner.new(gadget: gadget, procon: procon).run # ここでblockingする
|
71
72
|
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
72
73
|
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
73
|
-
|
74
|
-
|
75
|
-
ProconBypassMan::SendErrorCommand.execute(error: "プロコンが見つかりませんでした。終了します。")
|
76
|
-
ProconBypassMan::DeviceStatus.change_to_procon_not_found_error!
|
74
|
+
rescue ProconBypassMan::NotFoundRequiredFilesError
|
75
|
+
ProconBypassMan::SendErrorCommand.execute(error: "/sys/kernel/config/usb_gadget/proconディレクトリがありませんでした。処理を終了します。")
|
77
76
|
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
78
77
|
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
79
|
-
exit 1
|
78
|
+
exit 1 # 前提条件を満たしていないので絶対に落とす
|
79
|
+
rescue ProconBypassMan::CouldNotLoadConfigError
|
80
|
+
ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。設定ファイルの読み込みに失敗しました")
|
81
|
+
ProconBypassMan::DeviceStatus.change_to_setting_syntax_error_and_shutdown!
|
82
|
+
ProconBypassMan.exit_if_allow(1) do
|
83
|
+
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
84
|
+
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
85
|
+
end
|
86
|
+
rescue ProconBypassMan::ConnectDeviceCommand::NotFoundProconError
|
87
|
+
ProconBypassMan::SendErrorCommand.execute(error: "プロコンが見つかりませんでした。")
|
88
|
+
ProconBypassMan::DeviceStatus.change_to_procon_not_found_error!
|
89
|
+
ProconBypassMan.exit_if_allow(1) do
|
90
|
+
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
91
|
+
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
92
|
+
end
|
80
93
|
rescue ProconBypassMan::ConnectionError
|
81
94
|
begin
|
82
95
|
raise
|
data/project_template/app.rb
CHANGED
@@ -5,7 +5,7 @@ require 'bundler/inline'
|
|
5
5
|
gemfile do
|
6
6
|
source 'https://rubygems.org'
|
7
7
|
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
8
|
-
gem 'procon_bypass_man', '0.1.
|
8
|
+
gem 'procon_bypass_man', '0.1.20.1'
|
9
9
|
end
|
10
10
|
|
11
11
|
ProconBypassMan.configure do |config|
|
@@ -15,6 +15,10 @@ ProconBypassMan.configure do |config|
|
|
15
15
|
# webからProconBypassManを操作できるwebサービス
|
16
16
|
# config.api_servers = ['https://pbm-cloud.herokuapp.com']
|
17
17
|
config.enable_critical_error_logging = true
|
18
|
+
# pbm-cloudで使う場合はnever_exitにtrueをセットしてください. trueがセットされている場合、不慮の事故が発生してもプロセスが終了しなくなります
|
19
|
+
config.never_exit_accidentally = true
|
20
|
+
# 操作が高頻度で固まるときは、 gadget_to_procon_interval の数値は大きくしてください
|
21
|
+
config.bypass_mode = { mode: :normal, gadget_to_procon_interval: 0.5 }
|
18
22
|
end
|
19
23
|
|
20
24
|
ProconBypassMan.run(setting_path: "/usr/share/pbm/current/setting.yml")
|
@@ -1,35 +1,19 @@
|
|
1
1
|
version: 1.0
|
2
2
|
setting: |-
|
3
|
-
fast_return = ProconBypassMan::Plugin::Splatoon2::Macro::FastReturn
|
4
|
-
guruguru = ProconBypassMan::Plugin::Splatoon2::Mode::Guruguru
|
5
|
-
|
6
|
-
install_macro_plugin fast_return
|
7
|
-
install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::JumpToUpKey
|
8
|
-
install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::JumpToRightKey
|
9
|
-
install_macro_plugin ProconBypassMan::Plugin::Splatoon2::Macro::JumpToLeftKey
|
10
|
-
install_mode_plugin guruguru
|
11
|
-
|
12
3
|
prefix_keys_for_changing_layer [:zr, :zl, :l]
|
13
4
|
|
14
|
-
layer :up
|
15
|
-
# flip :zr, if_pressed: :zr, force_neutral: :zl
|
5
|
+
layer :up do
|
16
6
|
flip :zr, if_pressed: :zr, force_neutral: :zl
|
17
|
-
flip :zl, if_pressed: [:y, :b, :zl]
|
18
7
|
flip :a, if_pressed: [:a]
|
19
8
|
flip :down, if_pressed: :down
|
20
|
-
macro fast_return.name, if_pressed: [:y, :b, :down]
|
21
|
-
macro ProconBypassMan::Plugin::Splatoon2::Macro::JumpToUpKey, if_pressed: [:y, :b, :up]
|
22
|
-
macro ProconBypassMan::Plugin::Splatoon2::Macro::JumpToRightKey, if_pressed: [:y, :b, :right]
|
23
|
-
macro ProconBypassMan::Plugin::Splatoon2::Macro::JumpToLeftKey, if_pressed: [:y, :b, :left]
|
24
9
|
remap :l, to: :zr
|
25
10
|
end
|
26
|
-
|
11
|
+
|
12
|
+
layer :right do
|
13
|
+
end
|
14
|
+
|
27
15
|
layer :left do
|
28
|
-
# flip :zr, if_pressed: :zr, force_neutral: :zl
|
29
|
-
remap :l, to: :zr
|
30
16
|
end
|
17
|
+
|
31
18
|
layer :down do
|
32
|
-
# flip :zl
|
33
|
-
# flip :zr, if_pressed: :zr, force_neutral: :zl, flip_interval: "1F"
|
34
|
-
remap :l, to: :zr
|
35
19
|
end
|
data/sig/main.rbs
CHANGED
@@ -185,10 +185,13 @@ class ProconBypassMan::Configuration
|
|
185
185
|
def cache: () -> ProconBypassMan::OnMemoryCache
|
186
186
|
|
187
187
|
def config: () -> ProconBypassMan::Configuration
|
188
|
+
|
189
|
+
def never_exit_accidentally: () -> bool
|
188
190
|
end
|
189
191
|
|
190
192
|
attr_reader api_server: untyped
|
191
193
|
attr_reader api_servers: untyped
|
194
|
+
attr_writer never_exit_accidentally: bool
|
192
195
|
|
193
196
|
attr_accessor enable_critical_error_logging: bool
|
194
197
|
|
@@ -226,6 +229,8 @@ class ProconBypassMan::Configuration
|
|
226
229
|
def raw_setting: () -> untyped
|
227
230
|
|
228
231
|
def verbose_bypass_log: () -> bool
|
232
|
+
|
233
|
+
def never_exit_accidentally: () -> bool
|
229
234
|
end
|
230
235
|
|
231
236
|
|