procon_bypass_man 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +2 -0
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile.lock +1 -1
  6. data/README.md +2 -8
  7. data/lib/procon_bypass_man/analog_stick_position.rb +2 -8
  8. data/lib/procon_bypass_man/boot_message.rb +1 -1
  9. data/lib/procon_bypass_man/buttons_setting_configuration.rb +100 -0
  10. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +20 -0
  11. data/lib/procon_bypass_man/bypass.rb +57 -38
  12. data/lib/procon_bypass_man/callbacks.rb +70 -0
  13. data/lib/procon_bypass_man/configuration/layer.rb +18 -2
  14. data/lib/procon_bypass_man/configuration/loader.rb +8 -8
  15. data/lib/procon_bypass_man/configuration/validator.rb +1 -1
  16. data/lib/procon_bypass_man/configuration.rb +67 -77
  17. data/lib/procon_bypass_man/outbound/base.rb +40 -0
  18. data/lib/procon_bypass_man/outbound/error_reporter.rb +13 -0
  19. data/lib/procon_bypass_man/outbound/reporter.rb +12 -0
  20. data/lib/procon_bypass_man/outbound/usb_hid_data_reporter.rb +13 -0
  21. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +1 -1
  22. data/lib/procon_bypass_man/procon/layer_changeable.rb +2 -2
  23. data/lib/procon_bypass_man/procon/macro_registry.rb +2 -2
  24. data/lib/procon_bypass_man/procon/mode_registry.rb +2 -2
  25. data/lib/procon_bypass_man/procon/user_operation.rb +4 -0
  26. data/lib/procon_bypass_man/procon.rb +9 -5
  27. data/lib/procon_bypass_man/runner.rb +1 -1
  28. data/lib/procon_bypass_man/uptime.rb +3 -1
  29. data/lib/procon_bypass_man/version.rb +1 -1
  30. data/lib/procon_bypass_man.rb +20 -73
  31. data/project_template/README.md +1 -1
  32. data/project_template/app.rb +5 -5
  33. data/project_template/systemd_units/pbm_web.service +11 -0
  34. data/project_template/web.rb +16 -0
  35. data/sig/main.rbs +44 -4
  36. metadata +11 -4
  37. data/lib/procon_bypass_man/error_reporter.rb +0 -44
  38. data/lib/procon_bypass_man/reporter.rb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e4ad788ed57ca3bac1d4d17b1648285c8bc8d89d23a3c0a4ca4d5aaa58e4dfd
4
- data.tar.gz: 512a1f754cf255c6692ab597c7997d6bad3f3004c2f1203a1ce6adaec603e655
3
+ metadata.gz: 1a0674ff73c1ac25e311e304e7a3736e3feadb9f8d1221453202abbce8e00372
4
+ data.tar.gz: 29e63c8ee818a1ca3fe62de9152779cdbea38167db19824e0f402145dec36c04
5
5
  SHA512:
6
- metadata.gz: 7a059a91051aee0fa59beb62aa7bd952b1c8db15a75d66c47a66fdbda96a60cd9285094524e1d3c619ec215fa47dc5f9ee44e4dd7524f6c2bd60a4d0dfcf25e3
7
- data.tar.gz: 9748ad5293f1e3cc902d9b74bbb40997d0c9588e43e78ab4299eb4ddbb9bfd030a7f3bf717d58a3207ac51e348cc090b1a726d7f63780d705807e04db7d9201d
6
+ metadata.gz: 2bbbce43d9ed8495f513b5cbd9688f0187f3fd64cdd932730c3938ba8d5e43d4c8e3b15118082742bb1692d95aa66537ccc501930cd778144d7639460d98c32e
7
+ data.tar.gz: 2a2276871754b37296e2dff2c4b0d3f1cc3822ecb4b5c55e61c2eba4996951072af69e990742463fa282cf57a5f956439a70304402cc4a208be8cd1a43309bb1
data/.gitignore CHANGED
@@ -8,3 +8,7 @@
8
8
  /tmp/
9
9
  vendor
10
10
  todo.local.md
11
+ *.log
12
+ .setting_yaml_digest
13
+ pbm_pid
14
+ setting.yml
data/.rubocop.yml CHANGED
@@ -22,3 +22,5 @@ Lint/UselessAssignment:
22
22
  Enabled: false
23
23
  Lint/EmptyBlock:
24
24
  Enabled: false
25
+ Lint/ReturnInVoidContext:
26
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.1.10] - 202
2
+ - ボタンを無効化するdisableを設定できるようになりました
3
+ - pvmenvで生成する初期ファイルにprocon_bypass_man-webを同梱しました
4
+ - PBM自体の設定の構文を変更しました
5
+
1
6
  ## [0.1.9] - 2021-10-20
2
7
  - 左スティックを傾けた時に設定した最大値内に丸めることができるようになりました
3
8
  - 関連メソッド: set_neutral_position, left_analog_stick_cap
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.9)
4
+ procon_bypass_man (0.1.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -59,13 +59,7 @@ Switch <-- (PBM): ZR連打
59
59
  * 設定ファイル マクロの引数に、ボタンを取れるようにする
60
60
 
61
61
  ## 開発系
62
- ```ruby
63
- ProconBypassMan.tap do |pbm|
64
- pbm.root = File.expand_path(__dir__)
65
- pbm.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
66
- pbm.logger.level = :debug
67
- end
68
- ```
62
+ * pbmenvで生成するapp.rbに開発用ブランチを参照してください
69
63
 
70
64
  ### プロコンとの接続を維持したまま、現在の設定ファイルをPBMに反映する
71
65
  ```shell
@@ -82,7 +76,7 @@ sudo kill -USR2 `cat ./pbm_pid`
82
76
  * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::Reporter.report(body: message.to_hash)"`
83
77
 
84
78
  ### リリース手順
85
- * project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
79
+ * project_template/web.rb, project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
86
80
  * be rake release
87
81
 
88
82
  ## License
@@ -1,14 +1,8 @@
1
1
  class AnalogStickPosition
2
+ attr_accessor :x, :y
3
+
2
4
  def initialize(x: , y: )
3
5
  @x = x
4
6
  @y = y
5
7
  end
6
-
7
- def y
8
- @y
9
- end
10
-
11
- def x
12
- @x
13
- end
14
8
  end
@@ -6,7 +6,7 @@ class ProconBypassMan::BootMessage
6
6
  @table[:pid] = $$
7
7
  @table[:root_path] = ProconBypassMan.root
8
8
  @table[:pid_path] = ProconBypassMan.pid_path
9
- @table[:setting_path] = ProconBypassMan::Configuration.instance.setting_path
9
+ @table[:setting_path] = ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path
10
10
  @table[:uptime_from_boot] = ProconBypassMan::Uptime.from_boot
11
11
 
12
12
  build_version = `git rev-parse --short HEAD`.chomp
@@ -0,0 +1,100 @@
1
+ require "procon_bypass_man/configuration/validator"
2
+ require "procon_bypass_man/configuration/loader"
3
+ require "procon_bypass_man/configuration/layer"
4
+
5
+ module ProconBypassMan
6
+ class ButtonsSettingConfiguration
7
+ attr_accessor :layers,
8
+ :setting_path,
9
+ :mode_plugins,
10
+ :macro_plugins,
11
+ :context,
12
+ :current_context_key,
13
+ :neutral_position
14
+
15
+ def self.instance
16
+ @@current_context_key ||= :main
17
+ @@context ||= {}
18
+ @@context[@@current_context_key] ||= new
19
+ end
20
+
21
+ def self.switch_new_context(key)
22
+ @@context[key] = new
23
+ previous_key = @@current_context_key
24
+ if block_given?
25
+ @@current_context_key = key
26
+ value = yield(@@context[key])
27
+ @@current_context_key = previous_key
28
+ return value
29
+ else
30
+ @@current_context_key = key
31
+ end
32
+ end
33
+
34
+ def initialize
35
+ reset!
36
+ end
37
+
38
+ module ManualMode
39
+ def self.name
40
+ 'manual'
41
+ end
42
+ end
43
+ MODES = [:manual]
44
+ def layer(direction, mode: ManualMode, &block)
45
+ mode_name = case mode
46
+ when String
47
+ mode.to_sym
48
+ when Symbol
49
+ mode
50
+ else
51
+ mode.name.to_sym
52
+ end
53
+ unless (MODES + ProconBypassMan::Procon::ModeRegistry.plugins.keys).include?(mode_name)
54
+ raise("#{mode_name} mode is unknown")
55
+ end
56
+
57
+ layer = Layer.new(mode: mode_name)
58
+ layer.instance_eval(&block) if block_given?
59
+ self.layers[direction] = layer
60
+ self
61
+ end
62
+
63
+ def install_mode_plugin(klass)
64
+ ProconBypassMan::Procon::ModeRegistry.install_plugin(klass)
65
+ self
66
+ end
67
+
68
+ def install_macro_plugin(klass)
69
+ ProconBypassMan::Procon::MacroRegistry.install_plugin(klass)
70
+ self
71
+ end
72
+
73
+ def prefix_keys_for_changing_layer(buttons)
74
+ @prefix_keys_for_changing_layer = buttons
75
+ self
76
+ end
77
+
78
+ def set_neutral_position(x, y)
79
+ self.neutral_position = AnalogStickPosition.new(x: x, y: y)
80
+ self
81
+ end
82
+
83
+ def prefix_keys
84
+ @prefix_keys_for_changing_layer
85
+ end
86
+
87
+ def reset!
88
+ @prefix_keys_for_changing_layer = []
89
+ self.mode_plugins = {}
90
+ self.macro_plugins = {}
91
+ self.layers = {
92
+ up: Layer.new,
93
+ down: Layer.new,
94
+ left: Layer.new,
95
+ right: Layer.new,
96
+ }
97
+ @neutral_position = AnalogStickPosition.new(x: 2124, y: 1808)
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,20 @@
1
+ class ProconBypassMan::Bypass
2
+ module UsbHidLogger
3
+ extend ProconBypassMan::Callbacks::ClassMethods
4
+ include ProconBypassMan::Callbacks
5
+
6
+ define_callbacks :send_gadget_to_procon
7
+ define_callbacks :send_procon_to_gadget
8
+
9
+ set_callback :send_gadget_to_procon, :after, :log_send_gadget_to_procon
10
+ set_callback :send_procon_to_gadget, :after, :log_procon_to_gadget
11
+
12
+ def log_send_gadget_to_procon
13
+ ProconBypassMan.logger.debug { ">>> #{bypass_status.to_text}" }
14
+ end
15
+
16
+ def log_procon_to_gadget
17
+ ProconBypassMan.logger.debug { "<<< #{bypass_status.to_text}" }
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,15 @@
1
+ require "procon_bypass_man/bypass/usb_hid_logger"
2
+
1
3
  class ProconBypassMan::Bypass
2
- attr_accessor :gadget, :procon, :monitor
4
+ include ProconBypassMan::Bypass::UsbHidLogger
5
+
6
+ class BypassStatus < Struct.new(:binary, :sent)
7
+ def to_text
8
+ "#{binary.unpack("H*").first} #{'x' unless sent}"
9
+ end
10
+ end
11
+
12
+ attr_accessor :gadget, :procon, :monitor, :bypass_status
3
13
 
4
14
  def initialize(gadget: , procon: , monitor: )
5
15
  self.gadget = gadget
@@ -11,22 +21,27 @@ class ProconBypassMan::Bypass
11
21
  def send_gadget_to_procon!
12
22
  monitor.record(:start_function)
13
23
  input = nil
14
- begin
15
- return if $will_terminate_token
16
- # TODO blocking readにしたい
17
- input = self.gadget.read_nonblock(64)
18
- ProconBypassMan.logger.debug { ">>> #{input.unpack("H*")}" }
19
- rescue IO::EAGAINWaitReadable
20
- monitor.record(:eagain_wait_readable_on_read)
21
- sleep(0.001)
22
- retry
23
- end
24
+ self.bypass_status = BypassStatus.new(input, sent = false)
24
25
 
25
- begin
26
- self.procon.write_nonblock(input)
27
- rescue IO::EAGAINWaitReadable
28
- monitor.record(:eagain_wait_readable_on_write)
29
- return
26
+ run_callbacks :send_gadget_to_procon do
27
+ begin
28
+ return if $will_terminate_token
29
+ # TODO blocking readにしたいが、接続時のフェーズによって長さが違宇野で厳しい
30
+ input = self.gadget.read_nonblock(64)
31
+ self.bypass_status.binary = input
32
+ rescue IO::EAGAINWaitReadable
33
+ monitor.record(:eagain_wait_readable_on_read)
34
+ sleep(0.001)
35
+ retry
36
+ end
37
+
38
+ begin
39
+ self.procon.write_nonblock(input)
40
+ self.bypass_status.sent = true
41
+ rescue IO::EAGAINWaitReadable
42
+ monitor.record(:eagain_wait_readable_on_write)
43
+ return
44
+ end
30
45
  end
31
46
 
32
47
  monitor.record(:end_function)
@@ -35,31 +50,35 @@ class ProconBypassMan::Bypass
35
50
  def send_procon_to_gadget!
36
51
  monitor.record(:start_function)
37
52
  output = nil
53
+ self.bypass_status = BypassStatus.new(output, sent = false)
38
54
 
39
- begin
40
- return if $will_terminate_token
41
- Timeout.timeout(1) do
42
- output = self.procon.read(64)
43
- ProconBypassMan.logger.debug { "<<< #{output.unpack("H*")}" }
55
+ run_callbacks(:send_procon_to_gadget) do
56
+ begin
57
+ return if $will_terminate_token
58
+ Timeout.timeout(1) do
59
+ output = self.procon.read(64)
60
+ self.bypass_status.binary = output
61
+ end
62
+ rescue Timeout::Error
63
+ ProconBypassMan.logger.debug { "read timeout! do sleep. by send_procon_to_gadget!" }
64
+ ProconBypassMan.error_logger.error { "read timeout! do sleep. by send_procon_to_gadget!" }
65
+ monitor.record(:eagain_wait_readable_on_read)
66
+ retry
67
+ rescue IO::EAGAINWaitReadable
68
+ ProconBypassMan.logger.debug { "EAGAINWaitReadable" }
69
+ monitor.record(:eagain_wait_readable_on_read)
70
+ sleep(0.005)
71
+ retry
44
72
  end
45
- rescue Timeout::Error
46
- ProconBypassMan.logger.debug { "read timeout! do sleep. by send_procon_to_gadget!" }
47
- ProconBypassMan.error_logger.error { "read timeout! do sleep. by send_procon_to_gadget!" }
48
- monitor.record(:eagain_wait_readable_on_read)
49
- retry
50
- rescue IO::EAGAINWaitReadable
51
- ProconBypassMan.logger.debug { "EAGAINWaitReadable" }
52
- monitor.record(:eagain_wait_readable_on_read)
53
- sleep(0.005)
54
- retry
55
- end
56
73
 
57
- begin
58
- # ProconBypassMan::Procon::DebugDumper.new(binary: output).dump_analog_sticks
59
- self.gadget.write_nonblock(ProconBypassMan::Processor.new(output).process)
60
- rescue IO::EAGAINWaitReadable
61
- monitor.record(:eagain_wait_readable_on_write)
62
- return
74
+ begin
75
+ # ProconBypassMan::Procon::DebugDumper.new(binary: output).dump_analog_sticks
76
+ self.gadget.write_nonblock(ProconBypassMan::Processor.new(output).process)
77
+ self.bypass_status.sent = true
78
+ rescue IO::EAGAINWaitReadable
79
+ monitor.record(:eagain_wait_readable_on_write)
80
+ return
81
+ end
63
82
  end
64
83
  monitor.record(:end_function)
65
84
  end
@@ -0,0 +1,70 @@
1
+ module ProconBypassMan
2
+ module Callbacks
3
+ class CallbacksChain
4
+ attr_accessor :filter, :chain_method
5
+ def initialize(filter: , chain_method: , block: )
6
+ @filter = filter
7
+ @chain_method = chain_method
8
+ @block = block
9
+ end
10
+ end
11
+
12
+ # TODO __callbacksをincludeしたクラス側で保持する. 今はnemespaceがない
13
+ module M
14
+ class << self
15
+ attr_accessor :__callbacks
16
+ end
17
+ end
18
+
19
+ module ClassMethods
20
+ def define_callbacks(name)
21
+ self.singleton_class.attr_accessor "_#{name}_callbacks"
22
+ send "_#{name}_callbacks=", [name] # CallbacksChain
23
+
24
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
25
+ def _run_#{name}_callbacks(&block)
26
+ __run_callbacks__(_#{name}_callbacks, &block)
27
+ end
28
+ RUBY
29
+ end
30
+
31
+ def set_callback(kind, filter, chain_method, &block)
32
+ ProconBypassMan::Callbacks::M.__callbacks ||= {}
33
+ ProconBypassMan::Callbacks::M.__callbacks[kind] = CallbacksChain.new(
34
+ filter: filter,
35
+ chain_method: chain_method,
36
+ block: block,
37
+ )
38
+ end
39
+ end
40
+
41
+ # TODO haltしたらcallbackを止める
42
+ # TODO 複数をチェインできるようにする
43
+ def run_callbacks(kind, &block)
44
+ chain = get_callbacks(kind) or raise("unknown callback")
45
+ case chain.filter
46
+ when :before
47
+ send chain.chain_method
48
+ block.call
49
+ when :after
50
+ block.call
51
+ send chain.chain_method
52
+ else
53
+ raise("unknown filter")
54
+ end
55
+ end
56
+
57
+ # def __run_callbacks__(name, &block)
58
+ # puts "called"
59
+ # end
60
+
61
+ def get_callbacks(kind) # :nodoc:
62
+ ProconBypassMan::Callbacks::M.__callbacks[kind.to_sym]
63
+ end
64
+
65
+ def set_callbacks(name, callbacks) # :nodoc:
66
+ send "_#{name}_callbacks=", callbacks
67
+ ProconBypassMan::Callbacks::M.__callbacks[kind.to_sym] = callbacks
68
+ end
69
+ end
70
+ end
@@ -1,7 +1,7 @@
1
1
  module ProconBypassMan
2
- class Configuration
2
+ class ButtonsSettingConfiguration
3
3
  class Layer
4
- attr_accessor :mode, :flips, :macros, :remaps, :left_analog_stick_caps
4
+ attr_accessor :mode, :flips, :macros, :remaps, :left_analog_stick_caps, :disables
5
5
 
6
6
  def initialize(mode: :manual)
7
7
  self.mode = mode
@@ -9,6 +9,7 @@ module ProconBypassMan
9
9
  self.macros = {}
10
10
  self.remaps = {}
11
11
  self.left_analog_stick_caps = {}
12
+ self.disables = []
12
13
  instance_eval(&block) if block_given?
13
14
  end
14
15
 
@@ -102,6 +103,21 @@ module ProconBypassMan
102
103
  left_analog_stick_caps[if_pressed] = hash
103
104
  end
104
105
 
106
+ def disable(button)
107
+ case button
108
+ when TrueClass, FalseClass, NilClass
109
+ raise "not support class"
110
+ when Symbol
111
+ disables << button
112
+ when String
113
+ disables << button.to_sym
114
+ when Array
115
+ button.each { |b| disables << b }
116
+ else
117
+ raise "unknown"
118
+ end
119
+ end
120
+
105
121
  # @return [Array]
106
122
  def flip_buttons
107
123
  flips
@@ -1,10 +1,10 @@
1
1
  module ProconBypassMan
2
- class Configuration
2
+ class ButtonsSettingConfiguration
3
3
  module Loader
4
4
  require 'digest/md5'
5
5
 
6
6
  def self.load(setting_path: )
7
- ProconBypassMan::Configuration.switch_new_context(:validation) do |validation_instance|
7
+ ProconBypassMan::ButtonsSettingConfiguration.switch_new_context(:validation) do |validation_instance|
8
8
  yaml = YAML.load_file(setting_path) or raise "読み込みに失敗しました"
9
9
  validation_instance.instance_eval(yaml["setting"])
10
10
  validator = Validator.new(validation_instance)
@@ -20,25 +20,25 @@ module ProconBypassMan
20
20
  end
21
21
 
22
22
  yaml = YAML.load_file(setting_path)
23
- ProconBypassMan::Configuration.instance.setting_path = setting_path
24
- ProconBypassMan::Configuration.instance.reset!
23
+ ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path = setting_path
24
+ ProconBypassMan::ButtonsSettingConfiguration.instance.reset!
25
25
  ProconBypassMan.reset!
26
26
 
27
27
  case yaml["version"]
28
28
  when 1.0, nil
29
- ProconBypassMan::Configuration.instance.instance_eval(yaml["setting"])
29
+ ProconBypassMan::ButtonsSettingConfiguration.instance.instance_eval(yaml["setting"])
30
30
  else
31
31
  ProconBypassMan.logger.warn "不明なバージョンです。failoverします"
32
- ProconBypassMan::Configuration.instance.instance_eval(yaml["setting"])
32
+ ProconBypassMan::ButtonsSettingConfiguration.instance.instance_eval(yaml["setting"])
33
33
  end
34
34
 
35
35
  File.write(ProconBypassMan.digest_path, Digest::MD5.hexdigest(yaml["setting"]))
36
36
 
37
- ProconBypassMan::Configuration.instance
37
+ ProconBypassMan::ButtonsSettingConfiguration.instance
38
38
  end
39
39
 
40
40
  def self.reload_setting
41
- self.load(setting_path: ProconBypassMan::Configuration.instance.setting_path)
41
+ self.load(setting_path: ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path)
42
42
  end
43
43
  end
44
44
  end
@@ -1,5 +1,5 @@
1
1
  module ProconBypassMan
2
- class Configuration
2
+ class ButtonsSettingConfiguration
3
3
  class Validator
4
4
  def initialize(config)
5
5
  @layers = config.layers
@@ -1,100 +1,90 @@
1
- require "procon_bypass_man/configuration/validator"
2
- require "procon_bypass_man/configuration/loader"
3
- require "procon_bypass_man/configuration/layer"
4
-
5
- module ProconBypassMan
6
- class Configuration
7
- attr_accessor :layers,
8
- :setting_path,
9
- :mode_plugins,
10
- :macro_plugins,
11
- :context,
12
- :current_context_key,
13
- :neutral_position
14
-
15
- def self.instance
16
- @@current_context_key ||= :main
17
- @@context ||= {}
18
- @@context[@@current_context_key] ||= new
1
+ class ProconBypassMan::Configuration
2
+ module ClassAttributes
3
+ def root
4
+ config.root
19
5
  end
20
6
 
21
- def self.switch_new_context(key)
22
- @@context[key] = new
23
- previous_key = @@current_context_key
24
- if block_given?
25
- @@current_context_key = key
26
- value = yield(@@context[key])
27
- @@current_context_key = previous_key
28
- return value
29
- else
30
- @@current_context_key = key
31
- end
7
+ def logger
8
+ config.logger
32
9
  end
33
10
 
34
- def initialize
35
- reset!
11
+ def error_logger
12
+ config.error_logger
36
13
  end
37
14
 
38
- module ManualMode
39
- def self.name
40
- 'manual'
41
- end
15
+ def pid_path
16
+ @@pid_path ||= File.expand_path("#{root}/pbm_pid", __dir__).freeze
42
17
  end
43
- MODES = [:manual]
44
- def layer(direction, mode: ManualMode, &block)
45
- mode_name = case mode
46
- when String
47
- mode.to_sym
48
- when Symbol
49
- mode
50
- else
51
- mode.name.to_sym
52
- end
53
- unless (MODES + ProconBypassMan::Procon::ModeRegistry.plugins.keys).include?(mode_name)
54
- raise("#{mode_name} mode is unknown")
55
- end
56
18
 
57
- layer = Layer.new(mode: mode_name)
58
- layer.instance_eval(&block) if block_given?
59
- self.layers[direction] = layer
60
- self
19
+ def digest_path
20
+ config.digest_path
61
21
  end
62
22
 
63
- def install_mode_plugin(klass)
64
- ProconBypassMan::Procon::ModeRegistry.install_plugin(klass)
65
- self
23
+ def cache
24
+ @@cache_table ||= ProconBypassMan::OnMemoryCache.new
66
25
  end
26
+ end
27
+
28
+ attr_reader :api_server
29
+ attr_accessor :enable_critical_error_logging
67
30
 
68
- def install_macro_plugin(klass)
69
- ProconBypassMan::Procon::MacroRegistry.install_plugin(klass)
70
- self
31
+ def root=(path)
32
+ @root = path
33
+ return self
34
+ end
35
+
36
+ def root
37
+ if defined?(@root)
38
+ @root
39
+ else
40
+ File.expand_path('..', __dir__ || ".").freeze
71
41
  end
42
+ end
72
43
 
73
- def prefix_keys_for_changing_layer(buttons)
74
- @prefix_keys_for_changing_layer = buttons
75
- self
44
+ def api_server=(api_server)
45
+ @api_server = api_server
46
+ return self
47
+ end
48
+
49
+ def logger=(logger)
50
+ @logger = logger
51
+ return self
52
+ end
53
+
54
+ def logger
55
+ if ENV["PBM_ENV"] == 'test'
56
+ return Logger.new($stdout)
76
57
  end
77
58
 
78
- def set_neutral_position(x, y)
79
- self.neutral_position = AnalogStickPosition.new(x: x, y: y)
80
- self
59
+ if defined?(@logger) && @logger.is_a?(Logger)
60
+ @logger
61
+ else
62
+ Logger.new(File.open("/dev/null"))
81
63
  end
64
+ end
82
65
 
83
- def prefix_keys
84
- @prefix_keys_for_changing_layer
66
+ def error_logger
67
+ if enable_critical_error_logging
68
+ @@error_logger ||= Logger.new("#{ProconBypassMan.root}/error.log", 5, 1024 * 1024 * 10)
69
+ else
70
+ Logger.new(File.open("/dev/null"))
85
71
  end
72
+ self
73
+ end
74
+
75
+ def digest_path
76
+ "#{root}/.setting_yaml_digest"
77
+ end
86
78
 
87
- def reset!
88
- @prefix_keys_for_changing_layer = []
89
- self.mode_plugins = {}
90
- self.macro_plugins = {}
91
- self.layers = {
92
- up: Layer.new,
93
- down: Layer.new,
94
- left: Layer.new,
95
- right: Layer.new,
96
- }
97
- @neutral_position = AnalogStickPosition.new(x: 2124, y: 1808)
79
+ # @return [String] pbm-webの接続先
80
+ def internal_api_servers
81
+ if !!ENV["INTERNAL_API_SERVER"]
82
+ [ENV["INTERNAL_API_SERVER"]]
83
+ else
84
+ [ ENV["INTERNAL_API_SERVER"],
85
+ 'http://localhost:9090',
86
+ 'http://localhost:8080',
87
+ ].compact
98
88
  end
99
89
  end
100
90
  end