procon_bypass_man 0.1.12 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +33 -0
  3. data/CHANGELOG.md +13 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +35 -15
  6. data/README.md +19 -8
  7. data/lib/ext/em_pure_ruby.rb +25 -0
  8. data/lib/procon_bypass_man/background/job_runner.rb +6 -5
  9. data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -6
  10. data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
  11. data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
  12. data/lib/procon_bypass_man/background/{job_runnable.rb → jobs/concerns/job_runnable.rb} +0 -0
  13. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +5 -3
  14. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +6 -5
  15. data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
  16. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +11 -0
  17. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +7 -10
  18. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +5 -4
  19. data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
  20. data/lib/procon_bypass_man/background.rb +7 -4
  21. data/lib/procon_bypass_man/buttons_setting_configuration/layer.rb +36 -35
  22. data/lib/procon_bypass_man/buttons_setting_configuration.rb +2 -2
  23. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +8 -6
  24. data/lib/procon_bypass_man/bypass.rb +13 -6
  25. data/lib/procon_bypass_man/commands/bypass_command.rb +86 -0
  26. data/lib/procon_bypass_man/commands/connect_device_command.rb +7 -2
  27. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +51 -2
  28. data/lib/procon_bypass_man/commands/print_message_command.rb +8 -0
  29. data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +21 -0
  30. data/lib/procon_bypass_man/commands/send_error_command.rb +2 -1
  31. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +2 -2
  32. data/lib/procon_bypass_man/commands/write_device_id_command.rb +1 -0
  33. data/lib/procon_bypass_man/commands/write_session_id_command.rb +1 -7
  34. data/lib/procon_bypass_man/commands.rb +3 -0
  35. data/lib/procon_bypass_man/configuration.rb +51 -5
  36. data/lib/procon_bypass_man/device_connector.rb +32 -24
  37. data/lib/procon_bypass_man/device_status.rb +44 -0
  38. data/lib/procon_bypass_man/domains/binary/base.rb +11 -0
  39. data/lib/procon_bypass_man/domains/binary/has_immutable_binary.rb +5 -0
  40. data/lib/procon_bypass_man/domains/binary/has_mutable_binary.rb +5 -0
  41. data/lib/procon_bypass_man/domains/binary/inbound_procon_binary.rb +23 -0
  42. data/lib/procon_bypass_man/domains/binary/processing_procon_binary.rb +80 -0
  43. data/lib/procon_bypass_man/domains.rb +11 -0
  44. data/lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb +17 -0
  45. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_left_key.rb +17 -0
  46. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_right_key.rb +17 -0
  47. data/lib/procon_bypass_man/plugin/splatoon2/macro/jump_to_up_key.rb +17 -0
  48. data/lib/procon_bypass_man/plugin/splatoon2/mode/guruguru.rb +59 -0
  49. data/lib/procon_bypass_man/plugin/splatoon2/version.rb +9 -0
  50. data/lib/procon_bypass_man/plugins.rb +11 -0
  51. data/lib/procon_bypass_man/processor.rb +4 -5
  52. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +1 -1
  53. data/lib/procon_bypass_man/procon/button.rb +11 -0
  54. data/lib/procon_bypass_man/procon/button_collection.rb +2 -12
  55. data/lib/procon_bypass_man/procon/layer_changer.rb +3 -2
  56. data/lib/procon_bypass_man/procon/press_button_aware.rb +5 -4
  57. data/lib/procon_bypass_man/procon/user_operation.rb +46 -63
  58. data/lib/procon_bypass_man/procon/{analog_stick.rb → value_objects/analog_stick.rb} +3 -4
  59. data/lib/procon_bypass_man/procon/value_objects/procon_reader.rb +34 -0
  60. data/lib/procon_bypass_man/procon.rb +16 -14
  61. data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
  62. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +25 -0
  63. data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb +24 -0
  64. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +21 -0
  65. data/lib/procon_bypass_man/remote_pbm_action/restore_pbm_setting.rb +28 -0
  66. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +21 -0
  67. data/lib/procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object.rb +38 -0
  68. data/lib/procon_bypass_man/remote_pbm_action.rb +32 -0
  69. data/lib/procon_bypass_man/runner.rb +8 -97
  70. data/lib/procon_bypass_man/scheduler.rb +85 -0
  71. data/lib/procon_bypass_man/{callbacks.rb → support/callbacks.rb} +0 -0
  72. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  73. data/lib/procon_bypass_man/support/http_client.rb +102 -0
  74. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  75. data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
  76. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  77. data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
  78. data/lib/procon_bypass_man/{background/has_server_pool.rb → support/server_pool.rb} +3 -15
  79. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  80. data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
  81. data/lib/procon_bypass_man/{uptime.rb → support/uptime.rb} +0 -0
  82. data/lib/procon_bypass_man/version.rb +1 -1
  83. data/lib/procon_bypass_man/websocket/pbm_job_client.rb +79 -0
  84. data/lib/procon_bypass_man.rb +68 -34
  85. data/procon_bypass_man.gemspec +5 -3
  86. data/project_template/README.md +18 -11
  87. data/project_template/app.rb +1 -2
  88. data/project_template/setting.yml +8 -8
  89. data/sig/{README.rb → README.md} +0 -0
  90. data/sig/main.rbs +16 -1
  91. metadata +102 -21
  92. data/lib/procon_bypass_man/background/http_client.rb +0 -70
  93. data/lib/procon_bypass_man/background/jobs/report_heartbeat_job.rb +0 -10
  94. data/lib/procon_bypass_man/boot_message.rb +0 -42
  95. data/lib/procon_bypass_man/procon_reader.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42551d494786247ae06f81c416f522360001fb0a78ffdd67311520aafb56587a
4
- data.tar.gz: 92da20f533512ec4e1fdebe93f2c064f5ae1513fd6f26d3c4f34f2a0d488dffd
3
+ metadata.gz: ece30577af00d56afa2e2e0be7e09d8328c9d7f8cc96c2e49d207a2bb423b867
4
+ data.tar.gz: faf86731651a110fd63ce977f65b76f46c31fe6215a2512d4c3a1ba545fd4f81
5
5
  SHA512:
6
- metadata.gz: b52fde78831c29dc1b56b56217a604e421b6c0cdf5859b997732b36d94b9b7dc9d02f3906835d41df5f7168a2b694c2c457d3f96fd235903fc4827f42e74422b
7
- data.tar.gz: 50defecca29919fca30680469deddc5adc5c41d0c4f02f084c0a73f9633aa8e11101a5f07e863ea4e0b6481178d4f11e0d466a4bf2d9954f08cb5407d3cb10dd
6
+ metadata.gz: 313d36b543a7c539effaabb6fca121a5112b4076a196ad52386924f3e043ad25e52c5c880a710c1d8aafc66d4a647b3387cebe0b82391eb4ccffa10dd1f4af65
7
+ data.tar.gz: 55e7a87c35f972e8537654b86a1f5e1815ed22144a4097e1993ad986666f1111972ce8ce1a744e56196c16957a56c328ba510b6b19af4ff8961ac989d216af20
@@ -0,0 +1,33 @@
1
+ name: Publish to RubyGems
2
+
3
+ on:
4
+ [workflow_dispatch]
5
+
6
+ jobs:
7
+ release:
8
+ runs-on: ubuntu-latest
9
+ permissions:
10
+ contents: write
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ with:
15
+ token: ${{ secrets.GITHUB_TOKEN }}
16
+ - name: Set up Ruby 2.6
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6
20
+ bundler-cache: true
21
+ - name: Publish to RubyGems
22
+ run: |
23
+ git config --local user.email "action@github.com"
24
+ git config --local user.name "GitHub Action"
25
+
26
+ mkdir -p $HOME/.gem
27
+ touch $HOME/.gem/credentials
28
+ chmod 0600 $HOME/.gem/credentials
29
+ printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_TOKEN}\n" > $HOME/.gem/credentials
30
+ bundle exec rake release
31
+ env:
32
+ RUBYGEMS_API_TOKEN: "${{secrets.RUBYGEMS_API_TOKEN}}"
33
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [0.1.16] - 202
2
+ - websocket経由で外部サーバからの命令を受け取れるようになりました
3
+
4
+ ## [0.1.15] - 2021-12-08
5
+ - 外部サーバから設定ファイルのリストアができるようになりました
6
+ - splatoon2 pluginのネームスペースを変更しました
7
+
8
+ ## [0.1.14] - 2021-12-02
9
+ - 外部サーバからOSの再起動やprocon_bypass_manのバージョンアップができるようになりました
10
+
11
+ ## [0.1.13] - 2021-11-24
12
+ - 起動を早くするために、procon_bypass_man-splatoon2を同梱しました
13
+
1
14
  ## [0.1.12] - 2021-11-18
2
15
  - 起動ログなどを設定した外部サーバに送信できるようにしました
3
16
 
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in procon_bypass_man.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "rake"
9
9
  gem "rspec"
10
10
  gem "pry"
11
11
  gem "timecop"
data/Gemfile.lock CHANGED
@@ -1,11 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.12)
4
+ procon_bypass_man (0.1.16)
5
+ action_cable_client
6
+ pbmenv
7
+ sorted_set
5
8
 
6
9
  GEM
7
10
  remote: https://rubygems.org/
8
11
  specs:
12
+ action_cable_client (3.1.0)
13
+ websocket-eventmachine-client (>= 1.2.0)
9
14
  activesupport (6.1.4.1)
10
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
11
16
  i18n (>= 1.6, < 2)
@@ -16,8 +21,9 @@ GEM
16
21
  coderay (1.1.3)
17
22
  concurrent-ruby (1.1.9)
18
23
  diff-lcs (1.4.4)
24
+ eventmachine (1.2.7)
19
25
  ffi (1.15.4)
20
- i18n (1.8.10)
26
+ i18n (1.8.11)
21
27
  concurrent-ruby (~> 1.0)
22
28
  language_server-protocol (3.16.0.3)
23
29
  listen (3.7.0)
@@ -27,9 +33,10 @@ GEM
27
33
  minitest (5.14.4)
28
34
  mustermann (1.1.1)
29
35
  ruby2_keywords (~> 0.0.1)
30
- parallel (1.20.1)
31
- parser (3.0.2.0)
36
+ parallel (1.21.0)
37
+ parser (3.0.3.2)
32
38
  ast (~> 2.4.1)
39
+ pbmenv (0.1.6)
33
40
  pry (0.14.1)
34
41
  coderay (~> 1.1)
35
42
  method_source (~> 1.0)
@@ -41,8 +48,9 @@ GEM
41
48
  rb-fsevent (0.11.0)
42
49
  rb-inotify (0.10.1)
43
50
  ffi (~> 1.0)
44
- rbs (1.6.2)
45
- regexp_parser (2.1.1)
51
+ rbs (1.7.1)
52
+ rbtree (0.4.4)
53
+ regexp_parser (2.2.0)
46
54
  rexml (3.2.5)
47
55
  rspec (3.10.0)
48
56
  rspec-core (~> 3.10.0)
@@ -56,33 +64,37 @@ GEM
56
64
  rspec-mocks (3.10.2)
57
65
  diff-lcs (>= 1.2.0, < 2.0)
58
66
  rspec-support (~> 3.10.0)
59
- rspec-support (3.10.2)
60
- rubocop (1.20.0)
67
+ rspec-support (3.10.3)
68
+ rubocop (1.23.0)
61
69
  parallel (~> 1.10)
62
70
  parser (>= 3.0.0.0)
63
71
  rainbow (>= 2.2.2, < 4.0)
64
72
  regexp_parser (>= 1.8, < 3.0)
65
73
  rexml
66
- rubocop-ast (>= 1.9.1, < 2.0)
74
+ rubocop-ast (>= 1.12.0, < 2.0)
67
75
  ruby-progressbar (~> 1.7)
68
76
  unicode-display_width (>= 1.4.0, < 3.0)
69
- rubocop-ast (1.11.0)
77
+ rubocop-ast (1.14.0)
70
78
  parser (>= 3.0.1.1)
71
79
  ruby-progressbar (1.11.0)
72
80
  ruby2_keywords (0.0.5)
81
+ set (1.0.2)
73
82
  sinatra (2.1.0)
74
83
  mustermann (~> 1.0)
75
84
  rack (~> 2.2)
76
85
  rack-protection (= 2.1.0)
77
86
  tilt (~> 2.0)
78
- steep (0.46.0)
87
+ sorted_set (1.0.3)
88
+ rbtree
89
+ set (~> 1.0)
90
+ steep (0.47.0)
79
91
  activesupport (>= 5.1)
80
92
  language_server-protocol (>= 3.15, < 4.0)
81
93
  listen (~> 3.0)
82
94
  parallel (>= 1.0.0)
83
95
  parser (>= 3.0)
84
96
  rainbow (>= 2.2.2, < 4.0)
85
- rbs (>= 1.2.0)
97
+ rbs (~> 1.7.0)
86
98
  terminal-table (>= 2, < 4)
87
99
  terminal-table (3.0.2)
88
100
  unicode-display_width (>= 1.1.1, < 3)
@@ -90,9 +102,17 @@ GEM
90
102
  timecop (0.9.4)
91
103
  tzinfo (2.0.4)
92
104
  concurrent-ruby (~> 1.0)
93
- unicode-display_width (2.0.0)
105
+ unicode-display_width (2.1.0)
94
106
  webrick (1.7.0)
95
- zeitwerk (2.4.2)
107
+ websocket (1.2.9)
108
+ websocket-eventmachine-base (1.2.0)
109
+ eventmachine (~> 1.0)
110
+ websocket (~> 1.0)
111
+ websocket-native (~> 1.0)
112
+ websocket-eventmachine-client (1.3.0)
113
+ websocket-eventmachine-base (~> 1.0)
114
+ websocket-native (1.0.0)
115
+ zeitwerk (2.5.1)
96
116
 
97
117
  PLATFORMS
98
118
  arm-linux
@@ -104,7 +124,7 @@ PLATFORMS
104
124
  DEPENDENCIES
105
125
  procon_bypass_man!
106
126
  pry
107
- rake (~> 13.0)
127
+ rake
108
128
  rbs
109
129
  rspec
110
130
  rubocop
data/README.md CHANGED
@@ -28,12 +28,20 @@ Switch <-- (PBM): ZR連打
28
28
  ## Usage
29
29
  * USBガジェットモードで起動するRaspberry Pi4を用意する
30
30
  * https://github.com/splaplapla/procon_bypass_man/blob/master/docs/setup_raspi.md
31
- * Raspberry Pi4で https://github.com/jiikko/procon_bypass_man_sample をclone して実行ファイルを動かす
32
- * 実行ファイルと設定ファイルについては https://github.com/splaplapla/procon_bypass_man/wiki に詳細を書いていますが、まず動かすためにはcloneしたほうが早いです
31
+ * Raspberry Pi4 sudo pbmenv install latest && cd /usr/share/pbm/current && sudo ruby app.rb
32
+ * 動いたのを確認したらserviceとして登録にするなどしてください
33
33
 
34
34
  ## Plugins
35
35
  * https://github.com/splaplapla/procon_bypass_man-splatoon2
36
36
 
37
+ ## 関連ソフトウェア
38
+ * サーバソフトウェア(WIP)
39
+ * https://github.com/splaplapla/procon_bypass_man_cloud
40
+ * このサーバからOS自体の再起動、設定ファイルの変更、PBMのバージョンアップができます
41
+ * 自分でホストティングしてください
42
+ * pbmenv
43
+ * バージョンマネージャー
44
+
37
45
  ## FAQ
38
46
  * どうやって動かすの?
39
47
  * このツールはRaspberry Pi4をUSBガジェットモードで起動して有線でプロコンとSwitchに接続して使います
@@ -52,6 +60,8 @@ Switch <-- (PBM): ZR連打
52
60
  * 連射中には特定のキーの入力を無視したり、複数のキーをトリガーに連射することができます
53
61
  * どうしてsudoが必要なの?
54
62
  * 操作するdeviceファイルの所有者がrootだから
63
+ * 市販されているサードパーティ製連射機との違いは?
64
+ * サードパーティ製のコントローラーは、設定方法や形状が特殊で買い換えるたびに学習・設定コストが発生します。本ツールを使えば、設定内容はテキストで管理することができ、使い慣れたプロコンで同等のことができます。
55
65
 
56
66
  ## TODO
57
67
  * レコーディング機能(プロコンの入力をマクロとして登録ができる)
@@ -59,21 +69,18 @@ Switch <-- (PBM): ZR連打
59
69
  * 設定ファイル マクロの引数に、ボタンを取れるようにする
60
70
 
61
71
  ## 開発系
62
- * pbmenvで生成するapp.rbに開発用ブランチを参照してください
63
-
64
72
  ### プロコンとの接続を維持したまま、現在の設定ファイルをPBMに反映する
65
73
  ```shell
66
74
  sudo kill -USR2 `cat ./pbm_pid`
67
75
  ```
68
76
 
69
77
  ### 起動ログをサーバに送信する
70
- * `ProconBypassMan.api_server = "http://.."` を設定すると、 `POST /api/events` に対して起動ログなどを送信するようになります
78
+ * `ProconBypassMan.api_servers = "http://.."` を設定すると、 `POST /api/events` に対して起動ログなどを送信するようになります
71
79
 
72
80
  ### 開発環境でログの送信を確認する方法
73
81
  * `bundle exec bin/dev_api_server.rb`
74
- * `INTERNAL_API_SERVER=http://localhost:4567 bin/console`
75
- * `API_SERVER=http://localhost:4567 bin/console`
76
- * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::ReportBootJob.report(body: message.to_hash)`
82
+ * `API_SERVER=http://localhost:4567 INTERNAL_API_SERVER=http://localhost:4567 bin/console`
83
+ * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::ReportBootJob.perform(body: message.to_hash)`
77
84
 
78
85
  ### リリース手順
79
86
  * project_template/web.rb, project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
@@ -83,3 +90,7 @@ sudo kill -USR2 `cat ./pbm_pid`
83
90
  ## License
84
91
 
85
92
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
93
+
94
+
95
+ ## Links
96
+ * https://discord.gg/bEcRNKf4ep
@@ -0,0 +1,25 @@
1
+ # https://github.com/eventmachine/eventmachine/pull/929 is not released yet.
2
+ # i will delete this patch if released.
3
+ module EventMachine
4
+ # @private
5
+ class Reactor
6
+ def run_timers
7
+ timers_to_delete = []
8
+ @timers.each {|t|
9
+ if t.first <= @current_loop_time
10
+ #@timers.delete t
11
+ timers_to_delete << t
12
+ EventMachine::event_callback "", TimerFired, t.last
13
+ else
14
+ break
15
+ end
16
+ }
17
+ timers_to_delete.map{|c| @timers.delete c}
18
+ timers_to_delete = nil
19
+ #while @timers.length > 0 and @timers.first.first <= now
20
+ # t = @timers.shift
21
+ # EventMachine::event_callback "", TimerFired, t.last
22
+ #end
23
+ end
24
+ end
25
+ end
@@ -8,14 +8,14 @@ module ProconBypassMan
8
8
  end
9
9
 
10
10
  # for test
11
- def self.stop!
12
- return unless defined?(@@thread)
13
- @@thread.kill
11
+ def stop!
12
+ return unless defined?(@thread)
13
+ @thread.kill
14
14
  end
15
15
 
16
16
  def start!
17
- return if defined?(@@thread)
18
- @@thread = Thread.new do
17
+ return if defined?(@thread)
18
+ @thread = Thread.new do
19
19
  while(item = self.class.queue.pop)
20
20
  begin
21
21
  JobPerformer.new(klass: item[:reporter_class], args: item[:args]).perform
@@ -25,6 +25,7 @@ module ProconBypassMan
25
25
  end
26
26
  end
27
27
  end
28
+ self
28
29
  end
29
30
 
30
31
  def self.queue
@@ -1,12 +1,7 @@
1
1
  class ProconBypassMan::BaseJob
2
- extend ProconBypassMan::Background::HasServerPool
3
2
  extend ProconBypassMan::Background::JobRunnable
4
3
 
5
4
  def self.servers
6
- ProconBypassMan.config.api_servers
7
- end
8
-
9
- def self.path
10
- "/api/events"
5
+ raise NotImplementedError
11
6
  end
12
7
  end
@@ -0,0 +1,5 @@
1
+ module ProconBypassMan::HasExternalApiSetting
2
+ def server_pool
3
+ ProconBypassMan.config.server_pool
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module ProconBypassMan::HasInternalApiSetting
2
+ def server_pool
3
+ ProconBypassMan.config.internal_server_pool
4
+ end
5
+ end
@@ -1,9 +1,11 @@
1
- class ProconBypassMan::ReportBootJob < ProconBypassMan::BaseJob
1
+ class ProconBypassMan::ReportBootJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
2
4
  # @param [String] body
3
5
  def self.perform(body)
4
- ProconBypassMan::Background::HttpClient.new(
6
+ ProconBypassMan::ReportHttpClient.new(
5
7
  path: path,
6
- pool_server: pool_server,
8
+ server_pool: server_pool,
7
9
  retry_on_connection_error: true,
8
10
  ).post(body: body, event_type: :boot)
9
11
  end
@@ -1,10 +1,11 @@
1
- class ProconBypassMan::ReportErrorJob < ProconBypassMan::BaseJob
1
+ class ProconBypassMan::ReportErrorJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
2
4
  # @param [String] body
3
5
  def self.perform(body)
4
- ProconBypassMan::Background::HttpClient.new(
6
+ ProconBypassMan::ReportHttpClient.new(
5
7
  path: path,
6
- pool_server: pool_server,
7
- retry_on_connection_error: false,
8
- ).post(body: body, event_type: :error,)
8
+ server_pool: server_pool,
9
+ ).post(body: body, event_type: :error)
9
10
  end
10
11
  end
@@ -0,0 +1,5 @@
1
+ class ProconBypassMan::ReportEventBaseJob < ProconBypassMan::BaseJob
2
+ def self.path
3
+ "/api/events".freeze
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class ProconBypassMan::ReportLoadConfigJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
4
+ # @param [String] body
5
+ def self.perform(body)
6
+ ProconBypassMan::ReportHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
9
+ ).post(body: body, event_type: :load_config)
10
+ end
11
+ end
@@ -1,18 +1,15 @@
1
- class ProconBypassMan::ReportPressedButtonsJob
2
- extend ProconBypassMan::Background::HasServerPool
3
- extend ProconBypassMan::Background::JobRunnable
4
-
5
- PATH = "/api/pressed_buttons"
1
+ class ProconBypassMan::ReportPressedButtonsJob < ProconBypassMan::BaseJob
2
+ extend ProconBypassMan::HasInternalApiSetting
6
3
 
7
4
  # @param [String] body
8
5
  def self.perform(body)
9
- ProconBypassMan::Background::HttpClient.new(
10
- path: PATH,
11
- pool_server: pool_server,
6
+ ProconBypassMan::ReportHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
12
9
  ).post(body: body, event_type: :internal)
13
10
  end
14
11
 
15
- def self.servers
16
- ProconBypassMan.config.internal_api_servers
12
+ def self.path
13
+ "/api/pressed_buttons"
17
14
  end
18
15
  end
@@ -1,10 +1,11 @@
1
- class ProconBypassMan::ReportReloadConfigJob < ProconBypassMan::BaseJob
1
+ class ProconBypassMan::ReportReloadConfigJob < ProconBypassMan::ReportEventBaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
2
4
  # @param [String] body
3
5
  def self.perform(body)
4
- ProconBypassMan::Background::HttpClient.new(
6
+ ProconBypassMan::ReportHttpClient.new(
5
7
  path: path,
6
- pool_server: pool_server,
7
- retry_on_connection_error: false,
8
+ server_pool: server_pool,
8
9
  ).post(body: body, event_type: :reload_config)
9
10
  end
10
11
  end
@@ -0,0 +1,16 @@
1
+ class ProconBypassMan::SyncDeviceStatsJob < ProconBypassMan::BaseJob
2
+ extend ProconBypassMan::HasExternalApiSetting
3
+
4
+ # @param [Symbol] status
5
+ def self.perform(status)
6
+ ProconBypassMan::SendDeviceStatsHttpClient.new(
7
+ path: path,
8
+ server_pool: server_pool,
9
+ ).post(status: status, pbm_session_id: ProconBypassMan.session_id)
10
+ end
11
+
12
+ def self.path
13
+ device_id = ProconBypassMan.device_id
14
+ "/api/devices/#{ProconBypassMan.device_id}/device_statuses"
15
+ end
16
+ end
@@ -1,10 +1,13 @@
1
- require "procon_bypass_man/background/job_runnable"
1
+ require "procon_bypass_man/background/jobs/concerns/has_internal_api_setting"
2
+ require "procon_bypass_man/background/jobs/concerns/has_external_api_setting"
3
+ require "procon_bypass_man/background/jobs/concerns/job_runnable"
4
+ require "procon_bypass_man/background/job_runner"
2
5
  require "procon_bypass_man/background/job_performer"
3
- require "procon_bypass_man/background/has_server_pool"
4
- require "procon_bypass_man/background/http_client"
5
6
  require "procon_bypass_man/background/jobs/base_job"
7
+ require "procon_bypass_man/background/jobs/report_event_base_job"
6
8
  require "procon_bypass_man/background/jobs/report_boot_job"
7
9
  require "procon_bypass_man/background/jobs/report_reload_config_job"
10
+ require "procon_bypass_man/background/jobs/report_load_config_job"
8
11
  require "procon_bypass_man/background/jobs/report_error_job"
9
- require "procon_bypass_man/background/jobs/report_heartbeat_job"
10
12
  require "procon_bypass_man/background/jobs/report_pressed_buttons_job"
13
+ require "procon_bypass_man/background/jobs/sync_device_stats_job"
@@ -10,7 +10,6 @@ module ProconBypassMan
10
10
  self.remaps = {}
11
11
  self.left_analog_stick_caps = {}
12
12
  self.disables = []
13
- instance_eval(&block) if block_given?
14
13
  end
15
14
 
16
15
  # @param [Symbol] button
@@ -20,21 +19,26 @@ module ProconBypassMan
20
19
  if_pressed = [button]
21
20
  when Symbol, String
22
21
  if_pressed = [if_pressed]
23
- when Array, FalseClass
24
- # sono mama
22
+ when Array
23
+ # if_pressed = if_pressed
24
+ when FalseClass, NilClass
25
+ # no-op
25
26
  else
26
27
  raise "not support class"
27
28
  end
29
+
28
30
  hash = { if_pressed: if_pressed }
29
- if force_neutral
30
- case force_neutral
31
- when TrueClass, FalseClass
32
- raise "ボタンを渡してください"
33
- when Symbol, String
34
- hash[:force_neutral] = [force_neutral]
35
- when Array
36
- hash[:force_neutral] = force_neutral
37
- end
31
+ case force_neutral
32
+ when TrueClass
33
+ raise "ボタンを渡してください"
34
+ when Symbol, String
35
+ hash[:force_neutral] = [force_neutral]
36
+ when Array
37
+ hash[:force_neutral] = force_neutral
38
+ when FalseClass, NilClass
39
+ # no-op
40
+ else
41
+ raise "not support value"
38
42
  end
39
43
 
40
44
  if flip_interval
@@ -45,11 +49,8 @@ module ProconBypassMan
45
49
  end
46
50
  hash[:flip_interval] = interval
47
51
  end
48
- if self.flips[button]
49
- raise "#{button}への設定をすでに割り当て済みです"
50
- else
51
- self.flips[button] = hash
52
- end
52
+
53
+ self.flips[button] = hash
53
54
  end
54
55
 
55
56
  def macro(name, if_pressed: )
@@ -63,7 +64,7 @@ module ProconBypassMan
63
64
 
64
65
  def remap(button, to: )
65
66
  case to
66
- when TrueClass, FalseClass
67
+ when TrueClass, FalseClass, NilClass
67
68
  raise "ボタンを渡してください"
68
69
  when Symbol, String
69
70
  self.remaps[button] = { to: [to] }
@@ -77,27 +78,27 @@ module ProconBypassMan
77
78
  hash = { cap: cap }
78
79
 
79
80
  case if_pressed
80
- when TrueClass
81
- raise "not support class"
81
+ when TrueClass, FalseClass
82
+ raise "ボタンを渡してください"
82
83
  when Symbol, String
83
84
  if_pressed = [if_pressed]
84
- when Array, FalseClass
85
- # sono mama
86
- when NilClass
87
- if_pressed = nil
85
+ when Array, NilClass
86
+ # no-op
88
87
  else
89
- raise "not support if_pressed"
88
+ raise "not support value"
90
89
  end
91
90
 
92
- if force_neutral
93
- case force_neutral
94
- when TrueClass, FalseClass
95
- raise "ボタンを渡してください"
96
- when Symbol, String
97
- hash[:force_neutral] = [force_neutral]
98
- when Array
99
- hash[:force_neutral] = force_neutral
100
- end
91
+ case force_neutral
92
+ when TrueClass
93
+ raise "ボタンを渡してください"
94
+ when Symbol, String
95
+ hash[:force_neutral] = [force_neutral]
96
+ when Array
97
+ hash[:force_neutral] = force_neutral
98
+ when FalseClass, NilClass
99
+ # no-op
100
+ else
101
+ raise "not support value"
101
102
  end
102
103
 
103
104
  left_analog_stick_caps[if_pressed] = hash
@@ -114,7 +115,7 @@ module ProconBypassMan
114
115
  when Array
115
116
  button.each { |b| disables << b }
116
117
  else
117
- raise "unknown"
118
+ raise "not support value"
118
119
  end
119
120
  end
120
121
 
@@ -77,7 +77,7 @@ module ProconBypassMan
77
77
  end
78
78
 
79
79
  def set_neutral_position(x, y)
80
- self.neutral_position = AnalogStickPosition.new(x, y)
80
+ self.neutral_position = AnalogStickPosition.new(x, y).freeze
81
81
  self
82
82
  end
83
83
 
@@ -95,7 +95,7 @@ module ProconBypassMan
95
95
  left: Layer.new,
96
96
  right: Layer.new,
97
97
  }
98
- @neutral_position = AnalogStickPosition.new(2124, 1808)
98
+ @neutral_position = AnalogStickPosition.new(2124, 1808).freeze
99
99
  end
100
100
  end
101
101
  end
@@ -10,7 +10,13 @@ class ProconBypassMan::Bypass
10
10
  set_callback :send_procon_to_gadget, :after, :log_procon_to_gadget
11
11
 
12
12
  def log_send_gadget_to_procon
13
- ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
13
+ if ProconBypassMan.config.verbose_bypass_log
14
+ ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
15
+ else
16
+ ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
17
+ ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
18
+ end
19
+ end
14
20
  end
15
21
 
16
22
  def log_procon_to_gadget
@@ -24,13 +30,9 @@ class ProconBypassMan::Bypass
24
30
 
25
31
  ProconBypassMan.cache.fetch key: 'pressed_buttons_reporter', expires_in: 5 do
26
32
  ProconBypassMan::ReportPressedButtonsJob.perform_async(
27
- ProconBypassMan::ProconReader.new(binary: bypass_value.binary).to_hash
33
+ bypass_value.binary.to_procon_reader.to_hash
28
34
  )
29
35
  end
30
-
31
- ProconBypassMan.cache.fetch key: 'heartbeat_reporter', expires_in: 60 do
32
- ProconBypassMan::ReportHeartbeatJob.perform_async(ProconBypassMan::BootMessage.new.to_hash)
33
- end
34
36
  end
35
37
  end
36
38
  end