procon_bypass_man 0.1.7 → 0.1.11

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +3 -2
  3. data/.github/workflows/ruby.yml +34 -0
  4. data/.gitignore +4 -0
  5. data/.rubocop.yml +2 -0
  6. data/.ruby-version +1 -1
  7. data/CHANGELOG.md +17 -0
  8. data/Gemfile +4 -0
  9. data/Gemfile.lock +54 -2
  10. data/README.md +13 -8
  11. data/Rakefile +10 -1
  12. data/Steepfile +39 -0
  13. data/bin/console +4 -0
  14. data/bin/dev_api_server.rb +18 -0
  15. data/docs/setup_raspi.mitamae.rb +17 -2
  16. data/docs/setup_raspi_by_mitamae.md +2 -1
  17. data/lib/procon_bypass_man/background/report_thread.rb +42 -0
  18. data/lib/procon_bypass_man/boot_message.rb +40 -0
  19. data/lib/procon_bypass_man/buttons_setting_configuration.rb +102 -0
  20. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +27 -0
  21. data/lib/procon_bypass_man/bypass.rb +60 -29
  22. data/lib/procon_bypass_man/callbacks.rb +70 -0
  23. data/lib/procon_bypass_man/configuration/layer.rb +50 -4
  24. data/lib/procon_bypass_man/configuration/loader.rb +8 -8
  25. data/lib/procon_bypass_man/configuration/validator.rb +1 -1
  26. data/lib/procon_bypass_man/configuration.rb +67 -64
  27. data/lib/procon_bypass_man/device_connector.rb +13 -30
  28. data/lib/procon_bypass_man/io_monitor.rb +7 -4
  29. data/lib/procon_bypass_man/on_memory_cache.rb +34 -0
  30. data/lib/procon_bypass_man/outbound/base.rb +53 -0
  31. data/lib/procon_bypass_man/outbound/error_reporter.rb +13 -0
  32. data/lib/procon_bypass_man/outbound/pressed_buttons_reporter.rb +13 -0
  33. data/lib/procon_bypass_man/outbound/reporter.rb +12 -0
  34. data/lib/procon_bypass_man/procon/analog_stick.rb +31 -0
  35. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +65 -0
  36. data/lib/procon_bypass_man/procon/button_collection.rb +15 -6
  37. data/lib/procon_bypass_man/procon/layer_changeable.rb +2 -2
  38. data/lib/procon_bypass_man/procon/macro_registry.rb +2 -2
  39. data/lib/procon_bypass_man/procon/mode_registry.rb +4 -4
  40. data/lib/procon_bypass_man/procon/press_button_aware.rb +13 -0
  41. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +1 -11
  42. data/lib/procon_bypass_man/procon/user_operation.rb +15 -4
  43. data/lib/procon_bypass_man/procon.rb +25 -5
  44. data/lib/procon_bypass_man/readonly_procon.rb +32 -0
  45. data/lib/procon_bypass_man/runner.rb +39 -48
  46. data/lib/procon_bypass_man/uptime.rb +15 -0
  47. data/lib/procon_bypass_man/version.rb +1 -1
  48. data/lib/procon_bypass_man.rb +26 -33
  49. data/project_template/README.md +3 -2
  50. data/project_template/app.rb +8 -6
  51. data/project_template/systemd_units/pbm.service +1 -1
  52. data/project_template/systemd_units/pbm_web.service +11 -0
  53. data/project_template/web.rb +16 -0
  54. data/sig/README.rb +4 -0
  55. data/sig/main.rbs +507 -0
  56. metadata +25 -5
  57. data/examples/practical/app.rb +0 -21
  58. data/examples/practical/setting.yml +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59fe04b1f616674f3f4a500fbc0abf1dce166482b2e7c880e94d0247a7162877
4
- data.tar.gz: 55217706d204a06777fb9c9bfe87a64113dc2bdcfd0efa1079e79afc266690ce
3
+ metadata.gz: ead44cd36352dba5f4bd97af9c99936657a1a896fb9793a6735ce730a045b6f1
4
+ data.tar.gz: b8d115ef493d0b58a064fc7a0a7348a66e9e331e8173edd7543d96e9e213daba
5
5
  SHA512:
6
- metadata.gz: 1c57e7ca180ec142258a4725197e928cf073358743c8e98a78cbd87c4419b05f47859d97428f86dabcaee68f7856596a697a9f211b1f928efd3bb88b9a840c2a
7
- data.tar.gz: fa60bd01934dc80f811bd8871ba256c2cc70fb6cc6cbaa33fd180922fdde5bc70476234d00ce28303acb37229cace8137de540e29483af9d7dce926cd7e75fc6
6
+ metadata.gz: 3229e5e9f0fef53072b4869af2c6469b55703804d12bd8a9d077fe7c413d2198f747d482b30134daa4da55a0c5309eeda45d9928e46cd7778391ed865720ca00
7
+ data.tar.gz: 2de07a44334162b54ca8ba2464286c12a7a21d6ef74cb36b39a97bd5e22a833a5a6a5af2dac5ba6382da99a8635cdd9bd196a98d7f63dac311a4e61c2387ecad
data/.circleci/config.yml CHANGED
@@ -32,15 +32,16 @@ jobs:
32
32
  - run: bundle install --jobs 4
33
33
  - run: bundle exec rubocop
34
34
  - run: bundle exec rspec
35
+ - run: bundle exec steep check
35
36
 
36
37
  build_jobs: &build_jobs
37
38
  - rspec:
38
39
  matrix:
39
40
  parameters:
40
41
  version:
41
- - "2.5"
42
42
  - "2.7"
43
- - "3.0"
43
+ - "3.0.1"
44
+ - "3.0.2"
44
45
  workflows:
45
46
  version: 2
46
47
  build:
@@ -0,0 +1,34 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ [push]
12
+
13
+ jobs:
14
+ test:
15
+
16
+ runs-on: ubuntu-latest
17
+ strategy:
18
+ matrix:
19
+ ruby-version: ['2.7', '3.0.1']
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
+ # uses: ruby/setup-ruby@v1
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby-version }}
30
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
31
+ - name: Run tests
32
+ run: |-
33
+ bundle exec rake
34
+ bundle exec steep check
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/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.0.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## [0.1.11] - 2021-11-05
2
+ - PBM-WEB(>= 0.1.3)でボタンの入力を見るためのスレッドが動くようになりました
3
+
4
+ ## [0.1.10] - 2021-10-28
5
+ - ボタンを無効化するdisableを設定できるようになりました
6
+ - pvmenvで生成する初期ファイルにprocon_bypass_man-webを同梱しました
7
+ - PBM自体の設定の構文を変更しました
8
+
9
+ ## [0.1.9] - 2021-10-20
10
+ - 左スティックを傾けた時に設定した最大値内に丸めることができるようになりました
11
+ - 関連メソッド: set_neutral_position, left_analog_stick_cap
12
+ - 数時間に一度起きる、数秒間入力が通らなくなる問題の改善
13
+
14
+ ## [0.1.8] - 2021-09-19
15
+ - 使える場合、GC.auto_compactを有効にしました
16
+ - 起動ログにuptimeからの経過時間を表示しました
17
+
1
18
  ## [0.1.7] - 2021-09-11
2
19
  - Support pbmenv
3
20
 
data/Gemfile CHANGED
@@ -10,3 +10,7 @@ gem "rspec"
10
10
  gem "pry"
11
11
  gem "timecop"
12
12
  gem "rubocop", require: false
13
+ gem "steep", require: false
14
+ gem 'rbs', require: false
15
+ gem "sinatra", require: false
16
+ gem "webrick", require: false
data/Gemfile.lock CHANGED
@@ -1,23 +1,47 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.7)
4
+ procon_bypass_man (0.1.11)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ activesupport (6.1.4.1)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
14
+ zeitwerk (~> 2.3)
9
15
  ast (2.4.2)
10
16
  coderay (1.1.3)
17
+ concurrent-ruby (1.1.9)
11
18
  diff-lcs (1.4.4)
19
+ ffi (1.15.4)
20
+ i18n (1.8.10)
21
+ concurrent-ruby (~> 1.0)
22
+ language_server-protocol (3.16.0.3)
23
+ listen (3.7.0)
24
+ rb-fsevent (~> 0.10, >= 0.10.3)
25
+ rb-inotify (~> 0.9, >= 0.9.10)
12
26
  method_source (1.0.0)
27
+ minitest (5.14.4)
28
+ mustermann (1.1.1)
29
+ ruby2_keywords (~> 0.0.1)
13
30
  parallel (1.20.1)
14
31
  parser (3.0.2.0)
15
32
  ast (~> 2.4.1)
16
33
  pry (0.14.1)
17
34
  coderay (~> 1.1)
18
35
  method_source (~> 1.0)
36
+ rack (2.2.3)
37
+ rack-protection (2.1.0)
38
+ rack
19
39
  rainbow (3.0.0)
20
40
  rake (13.0.6)
41
+ rb-fsevent (0.11.0)
42
+ rb-inotify (0.10.1)
43
+ ffi (~> 1.0)
44
+ rbs (1.6.2)
21
45
  regexp_parser (2.1.1)
22
46
  rexml (3.2.5)
23
47
  rspec (3.10.0)
@@ -45,21 +69,49 @@ GEM
45
69
  rubocop-ast (1.11.0)
46
70
  parser (>= 3.0.1.1)
47
71
  ruby-progressbar (1.11.0)
72
+ ruby2_keywords (0.0.5)
73
+ sinatra (2.1.0)
74
+ mustermann (~> 1.0)
75
+ rack (~> 2.2)
76
+ rack-protection (= 2.1.0)
77
+ tilt (~> 2.0)
78
+ steep (0.46.0)
79
+ activesupport (>= 5.1)
80
+ language_server-protocol (>= 3.15, < 4.0)
81
+ listen (~> 3.0)
82
+ parallel (>= 1.0.0)
83
+ parser (>= 3.0)
84
+ rainbow (>= 2.2.2, < 4.0)
85
+ rbs (>= 1.2.0)
86
+ terminal-table (>= 2, < 4)
87
+ terminal-table (3.0.2)
88
+ unicode-display_width (>= 1.1.1, < 3)
89
+ tilt (2.0.10)
48
90
  timecop (0.9.4)
91
+ tzinfo (2.0.4)
92
+ concurrent-ruby (~> 1.0)
49
93
  unicode-display_width (2.0.0)
94
+ webrick (1.7.0)
95
+ zeitwerk (2.4.2)
50
96
 
51
97
  PLATFORMS
52
98
  arm-linux
53
99
  arm64-darwin-20
100
+ arm64-darwin-21
54
101
  armv7l-linux
102
+ x86_64-linux
55
103
 
56
104
  DEPENDENCIES
57
105
  procon_bypass_man!
58
106
  pry
59
107
  rake (~> 13.0)
108
+ rbs
60
109
  rspec
61
110
  rubocop
111
+ sinatra
112
+ steep
62
113
  timecop
114
+ webrick
63
115
 
64
116
  BUNDLED WITH
65
- 2.2.15
117
+ 2.2.22
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # ProconBypassMan
2
+ [![Ruby](https://github.com/splaplapla/procon_bypass_man/actions/workflows/ruby.yml/badge.svg?branch=master)](https://github.com/splaplapla/procon_bypass_man/actions/workflows/ruby.yml)
3
+
2
4
  * Switchに繋いだプロコンを連射機にしたり、キーのリマップをしたり、マクロを実行できるツールです
3
5
  * 設定ファイルはrubyスクリプトで記述します
4
6
  * 特定のタイトルに特化した振る舞いにしたい時は各プラグインを使ってください
@@ -57,21 +59,24 @@ Switch <-- (PBM): ZR連打
57
59
  * 設定ファイル マクロの引数に、ボタンを取れるようにする
58
60
 
59
61
  ## 開発系
60
- ```ruby
61
- ProconBypassMan.tap do |pbm|
62
- pbm.root = File.expand_path(__dir__)
63
- pbm.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
64
- pbm.logger.level = :debug
65
- end
66
- ```
62
+ * pbmenvで生成するapp.rbに開発用ブランチを参照してください
67
63
 
68
64
  ### プロコンとの接続を維持したまま、現在の設定ファイルをPBMに反映する
69
65
  ```shell
70
66
  sudo kill -USR2 `cat ./pbm_pid`
71
67
  ```
72
68
 
69
+ ### 起動ログをサーバに送信する
70
+ * `ProconBypassMan.api_server = "http://.."` を設定すると、 `POST /api/reports` に対して起動ログを送信するようになります
71
+
72
+ ### 開発環境でログの送信を確認する方法
73
+ * `bundle exec bin/dev_api_server.rb`
74
+ * `INTERNAL_API_SERVER=http://localhost:4567 bin/console`
75
+ * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::Reporter.report(body: message.to_hash)"`
76
+
73
77
  ### リリース手順
74
- * project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
78
+ * project_template/web.rb, project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
79
+ * CHANGELOG.md に日付を書く
75
80
  * be rake release
76
81
 
77
82
  ## License
data/Rakefile CHANGED
@@ -1,4 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- task default: %i[]
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: :spec
11
+ rescue LoadError
12
+ # no rspec available
13
+ end
data/Steepfile ADDED
@@ -0,0 +1,39 @@
1
+ # D = Steep::Diagnostic
2
+ #
3
+ # target :lib do
4
+ # signature "sig"
5
+ #
6
+ # check "lib" # Directory name
7
+ # check "Gemfile" # File name
8
+ # check "app/models/**/*.rb" # Glob
9
+ # # ignore "lib/templates/*.rb"
10
+ #
11
+ # # library "pathname", "set" # Standard libraries
12
+ # # library "strong_json" # Gems
13
+ #
14
+ # # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
15
+ # # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
16
+ # # configure_code_diagnostics do |hash| # You can setup everything yourself
17
+ # # hash[D::Ruby::NoMethod] = :information
18
+ # # end
19
+ # end
20
+
21
+ # target :test do
22
+ # signature "sig", "sig-private"
23
+ #
24
+ # check "test"
25
+ #
26
+ # # library "pathname", "set" # Standard libraries
27
+ # end
28
+
29
+ target :lib do
30
+ check "lib/procon_bypass_man/timer.rb"
31
+ check "lib/procon_bypass_man/uptime.rb"
32
+ check "lib/procon_bypass_man/configuration.rb"
33
+
34
+ signature "sig"
35
+
36
+ library "time"
37
+ library "logger"
38
+ library "monitor"
39
+ end
data/bin/console CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  require "bundler/setup"
5
5
  require "procon_bypass_man"
6
+ require "pry"
6
7
 
7
8
  # You can add fixtures and/or initialization code here to make experimenting
8
9
  # with your gem easier. You can also use a different console, if you like.
@@ -12,4 +13,7 @@ require "procon_bypass_man"
12
13
  # Pry.start
13
14
 
14
15
  require "irb"
16
+
17
+ ProconBypassMan.config.logger = Logger.new($stdout)
18
+
15
19
  IRB.start(__FILE__)
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "sinatra"
4
+ require "webrick"
5
+ require "pry"
6
+
7
+ post '/api/reports' do
8
+ puts JSON.parse(request.body.read)
9
+ status 200
10
+ body ''
11
+ end
12
+
13
+ post '/api/pressed_buttons' do
14
+ r = JSON.parse(request.body.read)
15
+ puts r
16
+ status 200
17
+ body ''
18
+ end
@@ -41,5 +41,20 @@ execute "Initialize PBM" do
41
41
  SHELL
42
42
  end
43
43
 
44
- run_command 'systemctl disable triggerhappy'
45
- run_command 'systemctl disable bluetooth'
44
+ # rbenv
45
+ execute "Install rbenv" do
46
+ not_if "which rbenv"
47
+ command "git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build"
48
+ end
49
+
50
+ # ruby
51
+ execute "Install ruby" do
52
+ not_if "rbenv versions | grep 3.0.1"
53
+ command "rbenv install 3.0.1"
54
+ end
55
+
56
+ run_command 'sudo systemctl disable triggerhappy.socket'
57
+ run_command 'sudo systemctl disable triggerhappy.service'
58
+ run_command 'sudo systemctl disable bluetooth'
59
+ run_command 'sudo systemctl disable apt-daily-upgrade.timer'
60
+ run_command 'sudo systemctl disable apt-daily.timer'
@@ -10,4 +10,5 @@
10
10
  * sudo sh /usr/share/pbm/shared/add_procon_gadget.sh の実行に成功させる
11
11
  * /etc/rc.local に sh /usr/share/pbm/shared/add_procon_gadget.sh って書く
12
12
  * PCとRaspberry Pi4を接続し、プロコンとして認識していることを確認する
13
- * TOOD install pbmenv
13
+ * sudo gem i pbmenv
14
+ * sudo pbmenv install latest
@@ -0,0 +1,42 @@
1
+ module ProconBypassMan
2
+ module Background
3
+ class Reporter
4
+ MAX_QUEUE_SIZE = 100
5
+
6
+ def self.start!
7
+ new.start!
8
+ end
9
+
10
+ def start!
11
+ return if defined?(@@thread)
12
+ @@latest_request_result = { stats: true, timestamp: Time.now }
13
+ @@queue = Queue.new
14
+ @@thread = Thread.new do
15
+ while(item = @@queue.pop)
16
+ begin
17
+ result = item[:reporter_class].report(body: item[:data])
18
+ @@latest_request_result = { stats: result.stats, timestamp: Time.now }
19
+ sleep(1)
20
+ rescue => e
21
+ ProconBypassMan.logger.error(e)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.queue
28
+ raise "Do not start this thread yet" unless defined?(@@queue)
29
+ @@queue
30
+ end
31
+
32
+ def self.push(hash)
33
+ if queue.size > MAX_QUEUE_SIZE
34
+ ProconBypassMan.logger.error('Over queue size cap!!')
35
+ return
36
+ end
37
+
38
+ queue.push(hash)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ class ProconBypassMan::BootMessage
2
+ def initialize
3
+ @table = {}
4
+ @table[:ruby_version] = RUBY_VERSION
5
+ @table[:pbm_version] = ProconBypassMan::VERSION
6
+ @table[:pid] = $$
7
+ @table[:root_path] = ProconBypassMan.root
8
+ @table[:pid_path] = ProconBypassMan.pid_path
9
+ @table[:setting_path] = ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path
10
+ @table[:uptime_from_boot] = ProconBypassMan::Uptime.from_boot
11
+
12
+ build_version = `git rev-parse --short HEAD`.chomp
13
+ if build_version.empty?
14
+ @table[:build_version] = 'release version'
15
+ else
16
+ @table[:build_version] = build_version
17
+ end
18
+ end
19
+
20
+ # @return [String]
21
+ def to_s
22
+ booted_message = <<~EOF
23
+ ----
24
+ RUBY_VERSION: #{@table[:ruby_version]}
25
+ ProconBypassMan: #{@table[:pbm_version]}
26
+ pid: #{@table[:pid]}
27
+ root: #{@table[:root_path]}
28
+ pid_path: #{@table[:pid_path]}
29
+ setting_path: #{@table[:setting_path]}
30
+ uptime from boot: #{@table[:uptime_from_boot]} sec
31
+ build version: #{@table[:build_version]}
32
+ ----
33
+ EOF
34
+ end
35
+
36
+ # @return [Hash]
37
+ def to_hash
38
+ @table
39
+ end
40
+ end
@@ -0,0 +1,102 @@
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 AnalogStickPosition < Struct.new(:x, :y); end
7
+
8
+ class ButtonsSettingConfiguration
9
+ attr_accessor :layers,
10
+ :setting_path,
11
+ :mode_plugins,
12
+ :macro_plugins,
13
+ :context,
14
+ :current_context_key,
15
+ :neutral_position
16
+
17
+ def self.instance
18
+ @@current_context_key ||= :main
19
+ @@context ||= {}
20
+ @@context[@@current_context_key] ||= new
21
+ end
22
+
23
+ def self.switch_new_context(key)
24
+ @@context[key] = new
25
+ previous_key = @@current_context_key
26
+ if block_given?
27
+ @@current_context_key = key
28
+ value = yield(@@context[key])
29
+ @@current_context_key = previous_key
30
+ return value
31
+ else
32
+ @@current_context_key = key
33
+ end
34
+ end
35
+
36
+ def initialize
37
+ reset!
38
+ end
39
+
40
+ module ManualMode
41
+ def self.name
42
+ 'manual'
43
+ end
44
+ end
45
+ MODES = [:manual]
46
+ def layer(direction, mode: ManualMode, &block)
47
+ mode_name = case mode
48
+ when String
49
+ mode.to_sym
50
+ when Symbol
51
+ mode
52
+ else
53
+ mode.name.to_sym
54
+ end
55
+ unless (MODES + ProconBypassMan::Procon::ModeRegistry.plugins.keys).include?(mode_name)
56
+ raise("#{mode_name} mode is unknown")
57
+ end
58
+
59
+ layer = Layer.new(mode: mode_name)
60
+ layer.instance_eval(&block) if block_given?
61
+ self.layers[direction] = layer
62
+ self
63
+ end
64
+
65
+ def install_mode_plugin(klass)
66
+ ProconBypassMan::Procon::ModeRegistry.install_plugin(klass)
67
+ self
68
+ end
69
+
70
+ def install_macro_plugin(klass)
71
+ ProconBypassMan::Procon::MacroRegistry.install_plugin(klass)
72
+ self
73
+ end
74
+
75
+ def prefix_keys_for_changing_layer(buttons)
76
+ @prefix_keys_for_changing_layer = buttons
77
+ self
78
+ end
79
+
80
+ def set_neutral_position(x, y)
81
+ self.neutral_position = AnalogStickPosition.new(x, y)
82
+ self
83
+ end
84
+
85
+ def prefix_keys
86
+ @prefix_keys_for_changing_layer
87
+ end
88
+
89
+ def reset!
90
+ @prefix_keys_for_changing_layer = []
91
+ self.mode_plugins = {}
92
+ self.macro_plugins = {}
93
+ self.layers = {
94
+ up: Layer.new,
95
+ down: Layer.new,
96
+ left: Layer.new,
97
+ right: Layer.new,
98
+ }
99
+ @neutral_position = AnalogStickPosition.new(2124, 1808)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,27 @@
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
+
19
+ ProconBypassMan.cache.fetch key: 'reporter', expires_in: 5 do
20
+ ProconBypassMan::Background::Reporter.push({
21
+ data: ProconBypassMan::ReadonlyProcon.new(binary: bypass_status.binary).to_hash,
22
+ reporter_class: ProconBypassMan::PressedButtonsReporter
23
+ })
24
+ end
25
+ end
26
+ end
27
+ end