procon_bypass_man 0.1.8 → 0.1.9

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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +3 -2
  3. data/.github/workflows/ruby.yml +5 -4
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +7 -1
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +52 -2
  8. data/README.md +11 -0
  9. data/Steepfile +39 -0
  10. data/bin/report_receive_server.rb +11 -0
  11. data/docs/setup_raspi.mitamae.rb +12 -0
  12. data/lib/procon_bypass_man/analog_stick_position.rb +14 -0
  13. data/lib/procon_bypass_man/boot_message.rb +40 -0
  14. data/lib/procon_bypass_man/bypass.rb +20 -7
  15. data/lib/procon_bypass_man/configuration/layer.rb +33 -3
  16. data/lib/procon_bypass_man/configuration.rb +22 -8
  17. data/lib/procon_bypass_man/device_connector.rb +10 -27
  18. data/lib/procon_bypass_man/error_reporter.rb +44 -0
  19. data/lib/procon_bypass_man/io_monitor.rb +7 -4
  20. data/lib/procon_bypass_man/on_memory_cache.rb +34 -0
  21. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +88 -0
  22. data/lib/procon_bypass_man/procon/button_collection.rb +14 -6
  23. data/lib/procon_bypass_man/procon/debug_dumper.rb +17 -0
  24. data/lib/procon_bypass_man/procon/mode_registry.rb +2 -2
  25. data/lib/procon_bypass_man/procon/press_button_aware.rb +13 -0
  26. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +0 -10
  27. data/lib/procon_bypass_man/procon/user_operation.rb +10 -3
  28. data/lib/procon_bypass_man/procon.rb +15 -1
  29. data/lib/procon_bypass_man/reporter.rb +42 -0
  30. data/lib/procon_bypass_man/runner.rb +34 -46
  31. data/lib/procon_bypass_man/uptime.rb +1 -1
  32. data/lib/procon_bypass_man/version.rb +1 -1
  33. data/lib/procon_bypass_man.rb +43 -2
  34. data/project_template/app.rb +3 -1
  35. data/sig/README.rb +4 -0
  36. data/sig/main.rbs +467 -0
  37. metadata +15 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f5d2c0b9137168508351ca8a1492470cd1f03c31d7eb920010a32f08f92122e
4
- data.tar.gz: c7f42dd711cb3d8932a8fd6d99ee0735084618411e6cd723eeee8860ca96cd8c
3
+ metadata.gz: 5e4ad788ed57ca3bac1d4d17b1648285c8bc8d89d23a3c0a4ca4d5aaa58e4dfd
4
+ data.tar.gz: 512a1f754cf255c6692ab597c7997d6bad3f3004c2f1203a1ce6adaec603e655
5
5
  SHA512:
6
- metadata.gz: 71a45ddf739c64355197e1a0610d2441eb6445eb6d77eef8fd9cf711265d0a9fc23dfcf2d75075115bf1e546141fec7eab0e20c6469feff6b7dea238d4916951
7
- data.tar.gz: 1bb4bc56c9310d94d682454b33c3d28ebc0a45753ee292c98cdee47bc94b3400c50ddbbb9c1f08b17ade330829760b4dbc1eef85ea22faf1aa8f9271e1b53e0f
6
+ metadata.gz: 7a059a91051aee0fa59beb62aa7bd952b1c8db15a75d66c47a66fdbda96a60cd9285094524e1d3c619ec215fa47dc5f9ee44e4dd7524f6c2bd60a4d0dfcf25e3
7
+ data.tar.gz: 9748ad5293f1e3cc902d9b74bbb40997d0c9588e43e78ab4299eb4ddbb9bfd030a7f3bf717d58a3207ac51e348cc090b1a726d7f63780d705807e04db7d9201d
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:
@@ -16,7 +16,7 @@ jobs:
16
16
  runs-on: ubuntu-latest
17
17
  strategy:
18
18
  matrix:
19
- ruby-version: ['2.5', '2.7', '3.0']
19
+ ruby-version: ['2.7', '3.0.1']
20
20
 
21
21
  steps:
22
22
  - uses: actions/checkout@v2
@@ -24,10 +24,11 @@ jobs:
24
24
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
25
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
26
  # uses: ruby/setup-ruby@v1
27
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
27
+ uses: ruby/setup-ruby@v1
28
28
  with:
29
29
  ruby-version: ${{ matrix.ruby-version }}
30
30
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
31
31
  - name: Run tests
32
- run: bundle exec rubocop
33
- run: bundle exec rake
32
+ run: |-
33
+ bundle exec rake
34
+ bundle exec steep check
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.0.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
+ ## [0.1.9] - 2021-10-20
2
+ - 左スティックを傾けた時に設定した最大値内に丸めることができるようになりました
3
+ - 関連メソッド: set_neutral_position, left_analog_stick_cap
4
+ - 数時間に一度起きる、数秒間入力が通らなくなる問題の改善
5
+
1
6
  ## [0.1.8] - 2021-09-19
2
- - 使える場合、GC.auto_compactを有効にする
7
+ - 使える場合、GC.auto_compactを有効にしました
8
+ - 起動ログにuptimeからの経過時間を表示しました
3
9
 
4
10
  ## [0.1.7] - 2021-09-11
5
11
  - Support pbmenv
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.8)
4
+ procon_bypass_man (0.1.9)
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,8 +69,30 @@ 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
@@ -58,9 +104,13 @@ DEPENDENCIES
58
104
  procon_bypass_man!
59
105
  pry
60
106
  rake (~> 13.0)
107
+ rbs
61
108
  rspec
62
109
  rubocop
110
+ sinatra
111
+ steep
63
112
  timecop
113
+ webrick
64
114
 
65
115
  BUNDLED WITH
66
- 2.2.15
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
  * 特定のタイトルに特化した振る舞いにしたい時は各プラグインを使ってください
@@ -70,6 +72,15 @@ end
70
72
  sudo kill -USR2 `cat ./pbm_pid`
71
73
  ```
72
74
 
75
+ ### 起動ログをサーバに送信する
76
+ * `ProconBypassMan.api_server = "http://.."` を設定すると、 `POST /api/reports` に対して起動ログを送信するようになります
77
+
78
+ ### 開発環境でログの送信を確認する方法
79
+ * `bundle exec bin/report_receive_server.rb`
80
+ * `bin/console`
81
+ * `ProconBypassMan.api_server = "http://localhost:4567"`
82
+ * `message = ProconBypassMan::BootMessage.new; ProconBypassMan::Reporter.report(body: message.to_hash)"`
83
+
73
84
  ### リリース手順
74
85
  * project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
75
86
  * be rake release
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
@@ -41,6 +41,18 @@ execute "Initialize PBM" do
41
41
  SHELL
42
42
  end
43
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
+
44
56
  run_command 'sudo systemctl disable triggerhappy.socket'
45
57
  run_command 'sudo systemctl disable triggerhappy.service'
46
58
  run_command 'sudo systemctl disable bluetooth'
@@ -0,0 +1,14 @@
1
+ class AnalogStickPosition
2
+ def initialize(x: , y: )
3
+ @x = x
4
+ @y = y
5
+ end
6
+
7
+ def y
8
+ @y
9
+ end
10
+
11
+ def x
12
+ @x
13
+ end
14
+ 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::Configuration.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
@@ -1,5 +1,6 @@
1
1
  class ProconBypassMan::Bypass
2
2
  attr_accessor :gadget, :procon, :monitor
3
+
3
4
  def initialize(gadget: , procon: , monitor: )
4
5
  self.gadget = gadget
5
6
  self.procon = procon
@@ -11,12 +12,13 @@ class ProconBypassMan::Bypass
11
12
  monitor.record(:start_function)
12
13
  input = nil
13
14
  begin
14
- sleep($will_interval_1_6)
15
- input = self.gadget.read_nonblock(128)
15
+ return if $will_terminate_token
16
+ # TODO blocking readにしたい
17
+ input = self.gadget.read_nonblock(64)
16
18
  ProconBypassMan.logger.debug { ">>> #{input.unpack("H*")}" }
17
19
  rescue IO::EAGAINWaitReadable
18
20
  monitor.record(:eagain_wait_readable_on_read)
19
- return if $will_terminate_token
21
+ sleep(0.001)
20
22
  retry
21
23
  end
22
24
 
@@ -26,23 +28,34 @@ class ProconBypassMan::Bypass
26
28
  monitor.record(:eagain_wait_readable_on_write)
27
29
  return
28
30
  end
31
+
29
32
  monitor.record(:end_function)
30
33
  end
31
34
 
32
35
  def send_procon_to_gadget!
33
36
  monitor.record(:start_function)
34
37
  output = nil
38
+
35
39
  begin
36
- sleep($will_interval_0_0_0_5)
37
- output = self.procon.read_nonblock(128)
38
- ProconBypassMan.logger.debug { "<<< #{output.unpack("H*")}" }
40
+ return if $will_terminate_token
41
+ Timeout.timeout(1) do
42
+ output = self.procon.read(64)
43
+ ProconBypassMan.logger.debug { "<<< #{output.unpack("H*")}" }
44
+ 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
39
50
  rescue IO::EAGAINWaitReadable
51
+ ProconBypassMan.logger.debug { "EAGAINWaitReadable" }
40
52
  monitor.record(:eagain_wait_readable_on_read)
41
- return if $will_terminate_token
53
+ sleep(0.005)
42
54
  retry
43
55
  end
44
56
 
45
57
  begin
58
+ # ProconBypassMan::Procon::DebugDumper.new(binary: output).dump_analog_sticks
46
59
  self.gadget.write_nonblock(ProconBypassMan::Processor.new(output).process)
47
60
  rescue IO::EAGAINWaitReadable
48
61
  monitor.record(:eagain_wait_readable_on_write)
@@ -1,13 +1,14 @@
1
1
  module ProconBypassMan
2
2
  class Configuration
3
3
  class Layer
4
- attr_accessor :mode, :flips, :macros, :remaps
4
+ attr_accessor :mode, :flips, :macros, :remaps, :left_analog_stick_caps
5
5
 
6
- def initialize(mode: :manual, &block)
6
+ def initialize(mode: :manual)
7
7
  self.mode = mode
8
8
  self.flips = {}
9
9
  self.macros = {}
10
10
  self.remaps = {}
11
+ self.left_analog_stick_caps = {}
11
12
  instance_eval(&block) if block_given?
12
13
  end
13
14
 
@@ -50,7 +51,6 @@ module ProconBypassMan
50
51
  end
51
52
  end
52
53
 
53
- PRESET_MACROS = [:fast_return]
54
54
  def macro(name, if_pressed: )
55
55
  if name.respond_to?(:name)
56
56
  macro_name = name.name.to_sym
@@ -72,6 +72,36 @@ module ProconBypassMan
72
72
  end
73
73
  end
74
74
 
75
+ def left_analog_stick_cap(cap: , if_pressed: nil, force_neutral: nil)
76
+ hash = { cap: cap }
77
+
78
+ case if_pressed
79
+ when TrueClass
80
+ raise "not support class"
81
+ when Symbol, String
82
+ if_pressed = [if_pressed]
83
+ when Array, FalseClass
84
+ # sono mama
85
+ when NilClass
86
+ if_pressed = nil
87
+ else
88
+ raise "not support if_pressed"
89
+ end
90
+
91
+ if force_neutral
92
+ case force_neutral
93
+ when TrueClass, FalseClass
94
+ raise "ボタンを渡してください"
95
+ when Symbol, String
96
+ hash[:force_neutral] = [force_neutral]
97
+ when Array
98
+ hash[:force_neutral] = force_neutral
99
+ end
100
+ end
101
+
102
+ left_analog_stick_caps[if_pressed] = hash
103
+ end
104
+
75
105
  # @return [Array]
76
106
  def flip_buttons
77
107
  flips
@@ -4,13 +4,13 @@ require "procon_bypass_man/configuration/layer"
4
4
 
5
5
  module ProconBypassMan
6
6
  class Configuration
7
-
8
7
  attr_accessor :layers,
9
8
  :setting_path,
10
9
  :mode_plugins,
11
10
  :macro_plugins,
12
11
  :context,
13
- :current_context_key
12
+ :current_context_key,
13
+ :neutral_position
14
14
 
15
15
  def self.instance
16
16
  @@current_context_key ||= :main
@@ -35,13 +35,21 @@ module ProconBypassMan
35
35
  reset!
36
36
  end
37
37
 
38
- MODES = [:manual]
39
- def layer(direction, mode: :manual, &block)
40
- if mode.respond_to?(:name)
41
- mode_name = mode.name.to_sym
42
- else
43
- mode_name = mode
38
+ module ManualMode
39
+ def self.name
40
+ 'manual'
44
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
45
53
  unless (MODES + ProconBypassMan::Procon::ModeRegistry.plugins.keys).include?(mode_name)
46
54
  raise("#{mode_name} mode is unknown")
47
55
  end
@@ -67,6 +75,11 @@ module ProconBypassMan
67
75
  self
68
76
  end
69
77
 
78
+ def set_neutral_position(x, y)
79
+ self.neutral_position = AnalogStickPosition.new(x: x, y: y)
80
+ self
81
+ end
82
+
70
83
  def prefix_keys
71
84
  @prefix_keys_for_changing_layer
72
85
  end
@@ -81,6 +94,7 @@ module ProconBypassMan
81
94
  left: Layer.new,
82
95
  right: Layer.new,
83
96
  }
97
+ @neutral_position = AnalogStickPosition.new(x: 2124, y: 1808)
84
98
  end
85
99
  end
86
100
  end
@@ -12,23 +12,6 @@ class ProconBypassMan::DeviceConnector
12
12
  PROCON_PATH = "/dev/hidraw0"
13
13
  PROCON2_PATH = "/dev/hidraw1"
14
14
 
15
- # 画面で再接続ができたが状況は変わらない
16
- def self.reset_connection!
17
- s = new
18
- s.add([
19
- ["0000"],
20
- ["0000"],
21
- ["8005"],
22
- ["0000"],
23
- ["8001"],
24
- ], read_from: :switch)
25
- s.drain_all
26
- s.read_procon
27
- s.write_switch("213c910080005db7723d48720a800300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
28
- sleep(10) # いらないかも
29
- s
30
- end
31
-
32
15
  def self.connect
33
16
  s = new(throw_error_if_timeout: true, enable_at_exit: false)
34
17
  s.add([
@@ -75,7 +58,7 @@ class ProconBypassMan::DeviceConnector
75
58
  timer = ProconBypassMan::Timer.new
76
59
  begin
77
60
  timer.throw_if_timeout!
78
- data = from_device(item).read_nonblock(128)
61
+ data = from_device(item).read_nonblock(64)
79
62
  rescue IO::EAGAINWaitReadable
80
63
  retry
81
64
  end
@@ -128,7 +111,7 @@ class ProconBypassMan::DeviceConnector
128
111
  timer = ProconBypassMan::Timer.new
129
112
  begin
130
113
  timer.throw_if_timeout!
131
- data = switch.read_nonblock(128)
114
+ data = switch.read_nonblock(64)
132
115
  ProconBypassMan.logger.debug { " >>> #{data.unpack("H*")})" }
133
116
  rescue IO::EAGAINWaitReadable
134
117
  retry
@@ -163,7 +146,7 @@ class ProconBypassMan::DeviceConnector
163
146
  timer = ProconBypassMan::Timer.new
164
147
  begin
165
148
  timer.throw_if_timeout!
166
- data = procon.read_nonblock(128)
149
+ data = procon.read_nonblock(64)
167
150
  ProconBypassMan.logger.error " <<< #{data.unpack("H*")})"
168
151
  rescue IO::EAGAINWaitReadable
169
152
  retry
@@ -184,7 +167,7 @@ class ProconBypassMan::DeviceConnector
184
167
  timer = ProconBypassMan::Timer.new
185
168
  begin
186
169
  timer.throw_if_timeout!
187
- data = procon.read_nonblock(128)
170
+ data = procon.read_nonblock(64)
188
171
  ProconBypassMan.logger.debug { " <<< #{data.unpack("H*")})" }
189
172
  rescue IO::EAGAINWaitReadable
190
173
  retry
@@ -217,7 +200,7 @@ class ProconBypassMan::DeviceConnector
217
200
  timer = ProconBypassMan::Timer.new
218
201
  begin
219
202
  timer.throw_if_timeout!
220
- data = switch.read_nonblock(128)
203
+ data = switch.read_nonblock(64)
221
204
  ProconBypassMan.logger.debug { " >>> #{data.unpack("H*")})" }
222
205
  rescue IO::EAGAINWaitReadable
223
206
  retry
@@ -281,7 +264,7 @@ class ProconBypassMan::DeviceConnector
281
264
 
282
265
  file = File.open(path, "w+")
283
266
  begin
284
- file.read_nonblock(128)
267
+ file.read_nonblock(64)
285
268
  rescue EOFError
286
269
  file.close
287
270
  return false
@@ -303,12 +286,12 @@ class ProconBypassMan::DeviceConnector
303
286
  case
304
287
  when is_available_device?(PROCON_PATH)
305
288
  ProconBypassMan.logger.info "proconのデバイスファイルは#{PROCON_PATH}を使います"
306
- @procon = File.open(PROCON_PATH, "w+")
307
- @gadget = File.open('/dev/hidg0', "w+")
289
+ @procon = File.open(PROCON_PATH, "w+b")
290
+ @gadget = File.open('/dev/hidg0', "w+b")
308
291
  when is_available_device?(PROCON2_PATH)
309
292
  ProconBypassMan.logger.info "proconのデバイスファイルは#{PROCON2_PATH}を使います"
310
- @procon = File.open(PROCON2_PATH, "w+")
311
- @gadget = File.open('/dev/hidg0', "w+")
293
+ @procon = File.open(PROCON2_PATH, "w+b")
294
+ @gadget = File.open('/dev/hidg0', "w+b")
312
295
  else
313
296
  raise "/dev/hidraw0, /dev/hidraw1の両方見つかりませんでした"
314
297
  end
@@ -0,0 +1,44 @@
1
+ require "net/http"
2
+ require "json"
3
+
4
+ class ProconBypassMan::ErrorReporter
5
+ PATH = "/api/error_reports" # POST
6
+
7
+ class Client
8
+ def initialize
9
+ @server = ProconBypassMan.api_server
10
+ @hostname = `hostname`.chomp
11
+ end
12
+
13
+ def post(body: )
14
+ # TODO ここでvalidationする
15
+ if @server.nil?
16
+ ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
17
+ return
18
+ end
19
+
20
+ uri = URI.parse("#{@server}#{PATH}")
21
+ http = Net::HTTP.new(uri.host, uri.port)
22
+ http.use_ssl = uri.scheme === "https"
23
+ response = http.post(
24
+ uri.path,
25
+ { report: body.full_message.to_json, hostname: @hostname }.to_json,
26
+ { "Content-Type" => "application/json" },
27
+ )
28
+ unless response.code == /^20/
29
+ ProconBypassMan.logger.error(response.body)
30
+ end
31
+ rescue => e
32
+ puts e
33
+ ProconBypassMan.logger.error(e)
34
+ end
35
+ end
36
+
37
+ def self.report(body: )
38
+ ProconBypassMan.logger.error(body)
39
+ Client.new.post(body: body)
40
+ rescue => e
41
+ ProconBypassMan.logger.error(e)
42
+ end
43
+ end
44
+
@@ -62,10 +62,13 @@ module ProconBypassMan
62
62
  }.join(", ")
63
63
  max_output_length = line.length
64
64
  sleep 0.7
65
- print "\r"
66
- print " " * max_output_length
67
- print "\r"
68
- print line
65
+
66
+ if ENV["PBM_FOREGROUND"]
67
+ print "\r"
68
+ print " " * max_output_length
69
+ print "\r"
70
+ print line
71
+ end
69
72
  ProconBypassMan.logger.debug { line }
70
73
  break if $will_terminate_token
71
74
  end