procon_bypass_man 0.1.6 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +41 -16
  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 +57 -6
  10. data/README.md +18 -10
  11. data/Rakefile +10 -1
  12. data/Steepfile +39 -0
  13. data/bin/report_receive_server.rb +11 -0
  14. data/docs/setup_raspi.md +12 -7
  15. data/docs/setup_raspi.mitamae.rb +60 -0
  16. data/docs/setup_raspi_by_mitamae.md +14 -0
  17. data/lib/procon_bypass_man/analog_stick_position.rb +8 -0
  18. data/lib/procon_bypass_man/boot_message.rb +40 -0
  19. data/lib/procon_bypass_man/buttons_setting_configuration.rb +100 -0
  20. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +20 -0
  21. data/lib/procon_bypass_man/bypass.rb +61 -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 +68 -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 +40 -0
  31. data/lib/procon_bypass_man/outbound/error_reporter.rb +13 -0
  32. data/lib/procon_bypass_man/outbound/reporter.rb +12 -0
  33. data/lib/procon_bypass_man/outbound/usb_hid_data_reporter.rb +13 -0
  34. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +88 -0
  35. data/lib/procon_bypass_man/procon/button_collection.rb +14 -6
  36. data/lib/procon_bypass_man/procon/debug_dumper.rb +17 -0
  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 +0 -10
  42. data/lib/procon_bypass_man/procon/user_operation.rb +14 -3
  43. data/lib/procon_bypass_man/procon.rb +23 -5
  44. data/lib/procon_bypass_man/runner.rb +36 -48
  45. data/lib/procon_bypass_man/uptime.rb +15 -0
  46. data/lib/procon_bypass_man/version.rb +1 -1
  47. data/lib/procon_bypass_man.rb +26 -33
  48. data/project_template/README.md +17 -0
  49. data/project_template/app.rb +20 -0
  50. data/project_template/setting.yml +35 -0
  51. data/project_template/systemd_units/pbm.service +13 -0
  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 +30 -5
  57. data/examples/pbm.service +0 -27
  58. data/examples/simple.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21149148015d5d8194ba9b0dc35fc1699ba1fe4eff6aaf1dd0956e0b35856e14
4
- data.tar.gz: 6af893ef0a8ff0fdad56b53d9bd117f6cbd39ec7bdb5c216d44cf2d773b9974f
3
+ metadata.gz: 1a0674ff73c1ac25e311e304e7a3736e3feadb9f8d1221453202abbce8e00372
4
+ data.tar.gz: 29e63c8ee818a1ca3fe62de9152779cdbea38167db19824e0f402145dec36c04
5
5
  SHA512:
6
- metadata.gz: 7185d5bf2246b3c1e2ae00eb08e170db017e78b7ed43fecde3757f2fc99bf1132f01b4e541ba669b9fc2ef39ee17e035368eabe7d4b973728c8ae49fd2873a0a
7
- data.tar.gz: 6c3152904d3f4af9e3e3e4f519d4fbe3391cf7d727c3ee42966d9492672bb9ead227ce451e8b97088d8b5e27176e9427939009ff59873fac507cbdabeb7fa61a
6
+ metadata.gz: 2bbbce43d9ed8495f513b5cbd9688f0187f3fd64cdd932730c3938ba8d5e43d4c8e3b15118082742bb1692d95aa66537ccc501930cd778144d7639460d98c32e
7
+ data.tar.gz: 2a2276871754b37296e2dff2c4b0d3f1cc3822ecb4b5c55e61c2eba4996951072af69e990742463fa282cf57a5f956439a70304402cc4a208be8cd1a43309bb1
data/.circleci/config.yml CHANGED
@@ -2,22 +2,47 @@ version: 2.1
2
2
  orbs:
3
3
  ruby: circleci/ruby@0.1.2
4
4
 
5
- jobs:
6
- build:
5
+ executors:
6
+ ruby:
7
+ parameters:
8
+ tag:
9
+ type: string
10
+ default: "latest"
7
11
  docker:
8
- - image: circleci/ruby:3.0.1
9
- executor: ruby/default
12
+ - image: ruby:<< parameters.tag >>
13
+ environment:
14
+ BUNDLE_PATH: vendor/bundle
15
+ BUNDLE_JOBS: 4
16
+ working_directory: ~/app
17
+
18
+ jobs:
19
+ rspec:
20
+ parameters:
21
+ version:
22
+ type: string
23
+ executor:
24
+ name: ruby
25
+ tag: << parameters.version >>
10
26
  steps:
11
27
  - checkout
12
- - run:
13
- name: install bundler
14
- command: gem install bundler:2.2.20
15
- - run:
16
- name: bundle install
17
- command: bundle install --jobs 4
18
- - run:
19
- name: rubocop
20
- command: bundle exec rubocop
21
- - run:
22
- name: run test
23
- command: bundle exec rspec
28
+ - run: ruby --version
29
+ - run: bundle --version
30
+ - run: gem --version
31
+ - run: gem install bundler
32
+ - run: bundle install --jobs 4
33
+ - run: bundle exec rubocop
34
+ - run: bundle exec rspec
35
+ - run: bundle exec steep check
36
+
37
+ build_jobs: &build_jobs
38
+ - rspec:
39
+ matrix:
40
+ parameters:
41
+ version:
42
+ - "2.7"
43
+ - "3.0.1"
44
+ - "3.0.2"
45
+ workflows:
46
+ version: 2
47
+ build:
48
+ jobs: *build_jobs
@@ -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.10] - 202
2
+ - ボタンを無効化するdisableを設定できるようになりました
3
+ - pvmenvで生成する初期ファイルにprocon_bypass_man-webを同梱しました
4
+ - PBM自体の設定の構文を変更しました
5
+
6
+ ## [0.1.9] - 2021-10-20
7
+ - 左スティックを傾けた時に設定した最大値内に丸めることができるようになりました
8
+ - 関連メソッド: set_neutral_position, left_analog_stick_cap
9
+ - 数時間に一度起きる、数秒間入力が通らなくなる問題の改善
10
+
11
+ ## [0.1.8] - 2021-09-19
12
+ - 使える場合、GC.auto_compactを有効にしました
13
+ - 起動ログにuptimeからの経過時間を表示しました
14
+
15
+ ## [0.1.7] - 2021-09-11
16
+ - Support pbmenv
17
+
1
18
  ## [0.1.6] - 2021-08-19
2
19
  - 設定ファイルを読み込むと内容のmd5を `pbm_root_dir/.setting_yaml_digest` へ出力するようにしました
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.6)
4
+ procon_bypass_man (0.1.10)
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
- rake (13.0.3)
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)
@@ -33,33 +57,60 @@ GEM
33
57
  diff-lcs (>= 1.2.0, < 2.0)
34
58
  rspec-support (~> 3.10.0)
35
59
  rspec-support (3.10.2)
36
- rubocop (1.18.4)
60
+ rubocop (1.20.0)
37
61
  parallel (~> 1.10)
38
62
  parser (>= 3.0.0.0)
39
63
  rainbow (>= 2.2.2, < 4.0)
40
64
  regexp_parser (>= 1.8, < 3.0)
41
65
  rexml
42
- rubocop-ast (>= 1.8.0, < 2.0)
66
+ rubocop-ast (>= 1.9.1, < 2.0)
43
67
  ruby-progressbar (~> 1.7)
44
68
  unicode-display_width (>= 1.4.0, < 3.0)
45
- rubocop-ast (1.8.0)
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
54
100
  armv7l-linux
101
+ x86_64-linux
55
102
 
56
103
  DEPENDENCIES
57
104
  procon_bypass_man!
58
105
  pry
59
106
  rake (~> 13.0)
107
+ rbs
60
108
  rspec
61
109
  rubocop
110
+ sinatra
111
+ steep
62
112
  timecop
113
+ webrick
63
114
 
64
115
  BUNDLED WITH
65
- 2.2.20
116
+ 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
  * 特定のタイトルに特化した振る舞いにしたい時は各プラグインを使ってください
@@ -17,11 +19,11 @@ Switch <-- (PBM): ZR連打
17
19
  * Switch本体とドック
18
20
  * Raspberry Pi4 Model B/4GB(Raspberry Pi OS (32-bit))
19
21
  * 他のシリーズは未確認です
22
+ * zeroは非対応
20
23
  * データ通信が可能なUSBケーブル
21
24
 
22
25
  ## 使うソフトウェア
23
- * 必須
24
- * ruby-3.0.x
26
+ * ruby-3.0.x
25
27
 
26
28
  ## Usage
27
29
  * USBガジェットモードで起動するRaspberry Pi4を用意する
@@ -52,25 +54,31 @@ Switch <-- (PBM): ZR連打
52
54
  * 操作するdeviceファイルの所有者がrootだから
53
55
 
54
56
  ## TODO
55
- * ラズパイのプロビジョニングを楽にしたい
56
57
  * レコーディング機能(プロコンの入力をマクロとして登録ができる)
57
58
  * マクロにdelayを入れれるようにする
58
59
  * 設定ファイル マクロの引数に、ボタンを取れるようにする
59
60
 
60
61
  ## 開発系
61
- ```ruby
62
- ProconBypassMan.tap do |pbm|
63
- pbm.root = File.expand_path(__dir__)
64
- pbm.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
65
- pbm.logger.level = :debug
66
- end
67
- ```
62
+ * pbmenvで生成するapp.rbに開発用ブランチを参照してください
68
63
 
69
64
  ### プロコンとの接続を維持したまま、現在の設定ファイルをPBMに反映する
70
65
  ```shell
71
66
  sudo kill -USR2 `cat ./pbm_pid`
72
67
  ```
73
68
 
69
+ ### 起動ログをサーバに送信する
70
+ * `ProconBypassMan.api_server = "http://.."` を設定すると、 `POST /api/reports` に対して起動ログを送信するようになります
71
+
72
+ ### 開発環境でログの送信を確認する方法
73
+ * `bundle exec bin/report_receive_server.rb`
74
+ * `bin/console`
75
+ * `ProconBypassMan.api_server = "http://localhost:4567"`
76
+ * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::Reporter.report(body: message.to_hash)"`
77
+
78
+ ### リリース手順
79
+ * project_template/web.rb, project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
80
+ * be rake release
81
+
74
82
  ## License
75
83
 
76
84
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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
@@ -0,0 +1,11 @@
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
data/docs/setup_raspi.md CHANGED
@@ -13,7 +13,7 @@
13
13
  * /etc/dphys-swapfile を CONF_SWAPSIZE=1024 にする
14
14
  * sudo /etc/init.d/dphys-swapfile restart && swapon -s
15
15
  * tailscale をインストールする(optional)
16
- * sudo apt-get install vim rbenv
16
+ * sudo apt-get install vim rbenv git -y
17
17
  * rbenvでrubyを入れる
18
18
  * git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
19
19
  * rbenv install 3.0.1
@@ -22,20 +22,25 @@
22
22
  * sshkeyを作成する
23
23
  * github に鍵を登録する
24
24
  * ~/.ssh/authorized_keys に鍵を登録する
25
- * sudo pip3 install fluent-logger pytz
26
25
  * ガジェットモードで起動する
27
26
  * /boot/config.txtに、dtoverlay=dwc2を追記
28
-  * echo "dwc2" | sudo tee -a /etc/modules
29
-  * echo "libcomposite" | sudo tee -a /etc/modules
30
-  * sudo cat /etc/modules
27
+ * echo "dwc2" | sudo tee -a /etc/modules
28
+ * echo "libcomposite" | sudo tee -a /etc/modules
29
+ * sudo cat /etc/modules
31
30
  * cd ~ && wget https://gist.githubusercontent.com/jiikko/3f9fb3194c0cc7685e31fbfcb5b5f9ff/raw/23ddee29d94350be80b79d290ac3c8ce8400bd88/add_procon_gadget.sh
32
31
  * chmod 755 ~/add_procon_gadget.sh
33
32
  * sudo reboot
34
33
  * sudo sh ~/add_procon_gadget.sh の実行に成功させる
35
34
  * /etc/rc.local に sh /home/pi/add_procon_gadget.sh って書く
36
- * cd ~ && mkdir -p src && cd ~/src && git clone https://github.com/jiikko/procon_bypass_man_sample && cd procon_bypass_man && sudo bundle install
35
+ * cd ~ && mkdir -p src && cd ~/src && git clone https://github.com/jiikko/procon_bypass_man_sample && cd procon_bypass_man_sample
37
36
 
38
- おわり. 起動する時は都度sudo ruby app.rb を実行する
37
+ おわり. 起動する時は都度 sudo ruby app.rb を実行する
39
38
 
40
39
  ## 参考
41
40
  * https://mtosak-tech.hatenablog.jp/entry/2020/08/22/114622
41
+
42
+ # TIPS
43
+ * SDカードにイメージを焼くときは、ImagerのAdvanced Optionsを使うとセットアップが楽になる
44
+ * raspios_liteにした方が起動が早くなりそう
45
+ * https://qiita.com/Liesegang/items/dcdc669f80d1bf721c21
46
+ * http://ftp.jaist.ac.jp/pub/raspberrypi/raspios_lite_armhf
@@ -0,0 +1,60 @@
1
+ run_command "apt-get update"
2
+
3
+ package 'ruby' do
4
+ action :install
5
+ end
6
+
7
+ package 'vim' do
8
+ action :install
9
+ end
10
+
11
+ package 'git' do
12
+ action :install
13
+ end
14
+
15
+ gem_package 'bundler' do
16
+ action :install
17
+ end
18
+
19
+ # OTG
20
+ execute "append dtoverlay=dwc2 to /boot/config.txt" do
21
+ not_if "grep dtoverlay=dwc2 /boot/config.txt"
22
+ command "echo 'dtoverlay=dwc2' >> /boot/config.txt"
23
+ end
24
+
25
+ execute "append dwc2 to /etc/modules" do
26
+ not_if "grep dwc2 /etc/modules"
27
+ command "echo dwc2 >> /etc/modules"
28
+ end
29
+
30
+ execute "append libcomposite to /etc/modules" do
31
+ not_if "grep libcomposite /etc/modules"
32
+ command "echo libcomposite >> /etc/modules"
33
+ end
34
+
35
+ # PBM
36
+ execute "Initialize PBM" do
37
+ command <<~SHELL
38
+ sudo mkdir -p /usr/share/pbm/shared
39
+ wget https://gist.githubusercontent.com/jiikko/3f9fb3194c0cc7685e31fbfcb5b5f9ff/raw/23ddee29d94350be80b79d290ac3c8ce8400bd88/add_procon_gadget.sh -O /usr/share/pbm/shared/add_procon_gadget.sh
40
+ chmod +x /usr/share/pbm/shared/add_procon_gadget.sh
41
+ SHELL
42
+ end
43
+
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'
@@ -0,0 +1,14 @@
1
+ # Raspberry Pi4のセットアップ手順 With mitamae
2
+ * SDカードにRaspberry Pi OS lite (32-bit)を焼く
3
+ * sshをできる状態で焼いておく
4
+ * SDカードをRaspberry Pi4本体に挿して起動する
5
+ * sshする
6
+ * curl -L https://github.com/itamae-kitchen/mitamae/releases/latest/download/mitamae-armhf-linux.tar.gz | tar xvz
7
+ * wget https://raw.githubusercontent.com/splaplapla/procon_bypass_man/master/docs/setup_raspi.mitamae.rb -O setup_raspi.mitamae.rb
8
+ * sudo ./mitamae-armhf-linux local setup_raspi.mitamae.rb -l debug
9
+ * sudo reboot
10
+ * sudo sh /usr/share/pbm/shared/add_procon_gadget.sh の実行に成功させる
11
+ * /etc/rc.local に sh /usr/share/pbm/shared/add_procon_gadget.sh って書く
12
+ * PCとRaspberry Pi4を接続し、プロコンとして認識していることを確認する
13
+ * sudo gem i pbmenv
14
+ * sudo pbmenv install latest
@@ -0,0 +1,8 @@
1
+ class AnalogStickPosition
2
+ attr_accessor :x, :y
3
+
4
+ def initialize(x: , y: )
5
+ @x = x
6
+ @y = y
7
+ end
8
+ 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,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