procon_bypass_man 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +1 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +18 -0
  6. data/CODE_OF_CONDUCT.md +84 -0
  7. data/Gemfile +10 -0
  8. data/Gemfile.lock +42 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +157 -0
  11. data/Rakefile +4 -0
  12. data/bin/console +15 -0
  13. data/bin/setup +8 -0
  14. data/docs/how_to_connect_procon.md +23 -0
  15. data/docs/setup_raspi.md +38 -0
  16. data/examples/practical/app.rb +16 -0
  17. data/examples/practical/setting.yml +24 -0
  18. data/examples/simple.rb +13 -0
  19. data/lib/procon_bypass_man.rb +66 -0
  20. data/lib/procon_bypass_man/bypass.rb +53 -0
  21. data/lib/procon_bypass_man/configuration.rb +83 -0
  22. data/lib/procon_bypass_man/configuration/layer.rb +52 -0
  23. data/lib/procon_bypass_man/configuration/loader.rb +44 -0
  24. data/lib/procon_bypass_man/configuration/validator.rb +26 -0
  25. data/lib/procon_bypass_man/device_registry.rb +41 -0
  26. data/lib/procon_bypass_man/io_monitor.rb +89 -0
  27. data/lib/procon_bypass_man/processor.rb +17 -0
  28. data/lib/procon_bypass_man/procon.rb +129 -0
  29. data/lib/procon_bypass_man/procon/button_collection.rb +40 -0
  30. data/lib/procon_bypass_man/procon/data.rb +5 -0
  31. data/lib/procon_bypass_man/procon/layer_changeable.rb +28 -0
  32. data/lib/procon_bypass_man/procon/macro_registry.rb +48 -0
  33. data/lib/procon_bypass_man/procon/mode_registry.rb +46 -0
  34. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +25 -0
  35. data/lib/procon_bypass_man/procon/user_operation.rb +72 -0
  36. data/lib/procon_bypass_man/runner.rb +171 -0
  37. data/lib/procon_bypass_man/version.rb +5 -0
  38. data/procon_bypass_man.gemspec +35 -0
  39. metadata +82 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b4e92960c4a8756b58054f9ed64d27ac2a59917371781b4299a88e9a26502075
4
+ data.tar.gz: 34e839eb78c1c1d0674291112c2c7c4a5d9be5ae026df60e3ac66395d52927a1
5
+ SHA512:
6
+ metadata.gz: 6c16bde4afb251d833d7bf411c8521566027d4109fcd654992b004c336735b1c8f4c6f97441cf99f728d06808cdd9b6d43f73bc527081b9c8d9059fd89893fa3
7
+ data.tar.gz: bd1ef2643d015a4e80d233a2493d1dcc80c871a958b9551b3691b31cdddefbbfef64e5a61b2fff3737186e064ce39cfe0cce310085c4cbb96c51fcf85be7b761
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ vendor
10
+ todo.local.md
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ ## [0.1.2]
2
+ - features
3
+ - 設定ファイルのライブリロードができるようになった
4
+ - 設定ファイルのバリデーションエラーとシンタックスエラーを投げるようになった
5
+ - key remap
6
+ - breking changes
7
+ - 設定情報をyamlで書くようになった
8
+
9
+ ## [0.1.1]
10
+ - プロコンの出力をLoggerに書き出す
11
+ - コマンドの標準出力にstatsを出す
12
+ - graceful shutdown
13
+ - たまに数秒ハングアップする問題の修正
14
+ - 内蔵していたマクロとモードをプラグインに切り出した
15
+
16
+ ## [0.1] - 2021-06-17
17
+
18
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at n905i.1214@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in procon_bypass_man.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec"
10
+ gem "pry"
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ procon_bypass_man (0.1.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.3)
10
+ diff-lcs (1.4.4)
11
+ method_source (1.0.0)
12
+ pry (0.14.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rake (13.0.3)
16
+ rspec (3.10.0)
17
+ rspec-core (~> 3.10.0)
18
+ rspec-expectations (~> 3.10.0)
19
+ rspec-mocks (~> 3.10.0)
20
+ rspec-core (3.10.1)
21
+ rspec-support (~> 3.10.0)
22
+ rspec-expectations (3.10.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-mocks (3.10.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-support (3.10.2)
29
+
30
+ PLATFORMS
31
+ arm-linux
32
+ arm64-darwin-20
33
+ armv7l-linux
34
+
35
+ DEPENDENCIES
36
+ procon_bypass_man!
37
+ pry
38
+ rake (~> 13.0)
39
+ rspec
40
+
41
+ BUNDLED WITH
42
+ 2.2.20
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 jiikko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # ProconBypassMan
2
+ * プロコンを連射機にしたり、マクロを実行できるツールです
3
+ * 設定ファイルはrubyスクリプトで記述します
4
+ * 特定のタイトルに特化した振る舞いにしたい時は各プラグインを使ってください
5
+
6
+ ## 使うハードウェア
7
+ * プロコン
8
+ * Switch本体とドック
9
+ * Raspberry Pi4
10
+ * 他のシリーズは未確認です
11
+ * データ通信が可能なUSBケーブル
12
+
13
+ ## 使うソフトウェア
14
+ * 必須
15
+ * ruby-3.0.x
16
+
17
+ ## Usage
18
+ * 以下のファイルを用意して`sudo`をつけて実行してください
19
+ * ex) `sudo bin/run.rb`
20
+
21
+ ```ruby
22
+ # bundler inline
23
+ require 'bundler/inline'
24
+
25
+ gemfile do
26
+ gem 'procon_bypass_man', github: 'splaspla-hacker/procon_bypass_man', branch: "0.1.1"
27
+ end
28
+
29
+ ProconBypassMan.run(setting_path: "./setting.yml")
30
+ ```
31
+
32
+ setting.yml
33
+
34
+ ```yml
35
+ version: 1.0
36
+ setting: |-
37
+ prefix_keys_for_changing_layer [:zr, :r, :zl, :l]
38
+ layer :up do
39
+ flip :zr, if_pressed: :zr
40
+ flip :zl, if_pressed: [:y, :b, :zl]
41
+ flip :down, if_pressed: true
42
+ end
43
+ layer :right do
44
+ end
45
+ layer :left
46
+ layer :down do
47
+ flip :zl, if_pressed: true
48
+ remap :l, to: :zr
49
+ end
50
+ ```
51
+
52
+ ### プラグインを使った設定例
53
+ ```ruby
54
+ #!/usr/bin/env ruby
55
+
56
+ require 'bundler/inline'
57
+
58
+ gemfile do
59
+ gem 'procon_bypass_man', github: 'splaspla-hacker/procon_bypass_man', branch: "0.1.1"
60
+ gem 'procon_bypass_man-splatoon2', github: 'splaspla-hacker/procon_bypass_man-splatoon2', branch: "0.1.0"
61
+ end
62
+
63
+ ProconBypassMan.run(setting_path: "./setting.yml")
64
+ ```
65
+ setting.yml
66
+
67
+ ```yml
68
+ version: 1.0
69
+ setting: |-
70
+ fast_return = ProconBypassMan::Splatoon2::Macro::FastReturn
71
+ guruguru = ProconBypassMan::Splatoon2::Mode::Guruguru
72
+
73
+ install_macro_plugin fast_return
74
+ install_mode_plugin guruguru
75
+
76
+ prefix_keys_for_changing_layer [:zr, :r, :zl, :l]
77
+
78
+ layer :up, mode: :manual do
79
+ flip :zr, if_pressed: :zr, force_neutral: :zl
80
+ flip :zl, if_pressed: [:y, :b, :zl]
81
+ flip :down, if_pressed: :down
82
+ macro fast_return.name, if_pressed: [:y, :b, :down]
83
+ end
84
+ layer :right, mode: guruguru.name
85
+ layer :left do
86
+ # no-op
87
+ end
88
+ layer :down do
89
+ flip :zl
90
+ end
91
+ ```
92
+
93
+ * 設定ファイルの例
94
+ * https://github.com/jiikko/procon_bypass_man_sample
95
+
96
+ ## Plugins
97
+ * https://github.com/splaspla-hacker/procon_bypass_man-splatoon2
98
+
99
+ ## プラグインの作り方
100
+ https://github.com/splaspla-hacker/procon_bypass_man-splatoon2 を見てみてください
101
+
102
+ ### モード
103
+ * name, binariesの持つオブジェクトを定義してください
104
+ * binariesには、Proconが出力するバイナリに対して16進数化した文字列を配列で定義してください
105
+
106
+ ### マクロ
107
+ * name, stepsの持つメソッドをオブジェクトを定義してください
108
+ * stepsには、プロコンで入力ができるキーを配列で定義してください
109
+ * 現在はintervalは設定できません
110
+
111
+ ## FAQ
112
+ ### ソフトウェアについて
113
+ * どうやって動かすの?
114
+ * このツールはRaspberry Pi4をUSBガジェットモードで起動して有線でプロコンとSwitchに接続して使います
115
+ * どうやって使うの?
116
+ * ケーブルでそれらを接続した状態で、Raspberry Pi4にsshして本プログラムを起動することで使用します
117
+ * ラズベリーパイ4のセットアップ方法は?
118
+ * https://github.com/splaspla-hacker/procon_bypass_man/tree/master/docs/setup_raspi.md
119
+ * モード, マクロの違いは?
120
+ * modeはProconの入力をそのまま再現するため機能。レイヤーを切り替えるまで繰り返し続ける
121
+ * マクロは特定のキーを順番に入れていく機能。キーの入力が終わったらマクロは終了する
122
+ * レイヤーとは?
123
+ * 自作キーボードみたいな感じでレイヤー毎に設定内容を記述して切り替えれる
124
+
125
+ ## TODO
126
+ * ログをfluentdへ送信
127
+ * 設定ファイルをwebから反映できる
128
+ * ケーブルの抜き差しなし再接続(厳しい)
129
+ * 接続確立後、プロセスを強制停止し、接続したままプロセスを再起動すると、USBの経由での接続ができなくなる
130
+ * ケーブルを抜いてからリトライすると改善する
131
+ * ケーブルで繋がっているけどswitchとプロコンがBluetoothで繋がっている状態かつ非充電状態だとバイパスができない、ということがわかった
132
+ * ラズパイとプロコン間でBluetooth接続できれば解決するかもしれない
133
+ * ジャイロの入力を取る方法がまだ発見できていないらしく厳しいことがわかった
134
+ * https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/issues/7
135
+ * それとSwitchOS 12からペアリングの仕様に変更があって類似ツールが動かなくっている
136
+ * ラズパイのプロビジョニングを楽にしたい
137
+ * レコーディング機能(プロコンの入力をマクロとして登録ができる)
138
+ * swtichとの接続完了はIOを見て判断する
139
+ * webページから設定ファイルを変更できるようにする(sshしたくない)
140
+ * webサーバのデーモンとPBMはプロセスを分ける(NOTE)
141
+ * プロセスを停止するときにtmp/pidを削除する
142
+
143
+ ## Contributing
144
+
145
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/procon_bypass_man. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/procon_bypass_man/blob/master/CODE_OF_CONDUCT.md).
146
+
147
+ ### ロギング
148
+ ```
149
+ ProconBypassMan.tap do |pbm|
150
+ pbm.logger = STDOUT
151
+ pbm.logger.level = :debug
152
+ end
153
+ ```
154
+
155
+ ## License
156
+
157
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "procon_bypass_man"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # Raspberry Pi4とプロコンの接続方法
2
+ ## USB経由
3
+ * ケーブルに接続するだけ
4
+
5
+ ## Bluetooth経由
6
+ * Switch本体の電源を落とす
7
+ * $ bluetoothctl
8
+ * -> scan on
9
+ * プロコンのリセットボタンを長押しする
10
+ * `[NEW] Device 98:B6:E9:XX:XX:XX Pro Controller` という出力が出る
11
+ * 長押ししながら、pair, trust, connect を入力していく
12
+ * Connection successfulが出力されて、プロコンのLEDランプが点滅し続ければ成功
13
+
14
+ ```
15
+ [bluetooth]# pair 98:B6:E9:XX:XX:XX
16
+ Attempting to pair with 98:B6:E9:XX:XX:XX
17
+ [bluetooth]# trust 98:B6:E9:XX:XX:XX
18
+ [bluetooth]# connect 98:B6:E9:XX:XX:XX
19
+ Attempting to connect to 98:B6:E9:XX:XX:XX
20
+ Changing 98:B6:E9:XX:XX:XX trust succeeded
21
+ Pairing successful
22
+ Connection successful
23
+ ```
@@ -0,0 +1,38 @@
1
+ # Raspberry Pi4のセットアップ手順
2
+ * SDカードに焼く
3
+ * SDカードをRaspberry Pi4本体に挿して起動する
4
+ * ラズパイGUI
5
+ * 無線LANに接続する
6
+ * sshdを許可する
7
+ * macからsshする
8
+ * sudo apt-get dist-upgrade
9
+ * hostnameを変える
10
+ * sudo hostnamectl set-hostname raspizero
11
+ * /etc/hosts に追記する
12
+ * 仮想メモリを増やす(optional)
13
+ * /etc/dphys-swapfile を CONF_SWAPSIZE=1024 にする
14
+ * sudo /etc/init.d/dphys-swapfile restart && swapon -s
15
+ * tailscale をインストールする(optional)
16
+ * sudo apt-get install vim rbenv
17
+ * rbenvでrubyを入れる
18
+ * git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
19
+ * rbenv install 3.0.1
20
+ * rbenv local 3.0.1
21
+ * gem i bundler
22
+ * sshkeyを作成する
23
+ * github に鍵を登録する
24
+ * ~/.ssh/authorized_keys に鍵を登録する
25
+ * sudo pip3 install fluent-logger pytz
26
+ * ガジェットモードで起動する
27
+ * /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
31
+ * cd ~ && wget https://gist.githubusercontent.com/jiikko/3f9fb3194c0cc7685e31fbfcb5b5f9ff/raw/23ddee29d94350be80b79d290ac3c8ce8400bd88/add_procon_gadget.sh
32
+ * chmod 755 ~/add_procon_gadget.sh
33
+ * sudo reboot
34
+ * sudo sh ~/add_procon_gadget.sh の実行に成功させる
35
+ * /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
37
+
38
+ おわり. 起動する時は都度sudo ruby app.rb を実行する