procon_bypass_man 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5780c7567981a37aef9f32801868f1e59db9d70e47f5cb65dc302cc16a22252e
4
- data.tar.gz: e1f6d212b9076c0e081e720f3f3c75217183d3bdb4cbab660ab14abc61a35671
3
+ metadata.gz: 21149148015d5d8194ba9b0dc35fc1699ba1fe4eff6aaf1dd0956e0b35856e14
4
+ data.tar.gz: 6af893ef0a8ff0fdad56b53d9bd117f6cbd39ec7bdb5c216d44cf2d773b9974f
5
5
  SHA512:
6
- metadata.gz: 4ea7163f5d33b68c1cfe9e65c15bbe40414435ecf6c5c3fdadc9c70e29eb77f8fa4bbd8897cc8306f2d9cb8b42d231cce240973828f30e8e24771a66235c7304
7
- data.tar.gz: d829cdf3cd7d3428247a55eb2e5140344d79d6c0b48321a4a7bdcbc3f3e122c66066fa31839bc260016643375b104847f9c8435dfe151f9afa027990b98df630
6
+ metadata.gz: 7185d5bf2246b3c1e2ae00eb08e170db017e78b7ed43fecde3757f2fc99bf1132f01b4e541ba669b9fc2ef39ee17e035368eabe7d4b973728c8ae49fd2873a0a
7
+ data.tar.gz: 6c3152904d3f4af9e3e3e4f519d4fbe3391cf7d727c3ee42966d9492672bb9ead227ce451e8b97088d8b5e27176e9427939009ff59873fac507cbdabeb7fa61a
data/.circleci/config.yml CHANGED
@@ -15,6 +15,9 @@ jobs:
15
15
  - run:
16
16
  name: bundle install
17
17
  command: bundle install --jobs 4
18
+ - run:
19
+ name: rubocop
20
+ command: bundle exec rubocop
18
21
  - run:
19
22
  name: run test
20
23
  command: bundle exec rspec
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ Include:
5
+ - 'lib/**/*.rb'
6
+ - 'spec/**/*.rb'
7
+ Style:
8
+ Enabled: false
9
+
10
+ Metrics:
11
+ Enabled: false
12
+
13
+ Layout:
14
+ Enabled: false
15
+
16
+ Naming:
17
+ Enabled: false
18
+
19
+ Lint/ConstantDefinitionInBlock:
20
+ Enabled: false
21
+ Lint/UselessAssignment:
22
+ Enabled: false
23
+ Lint/EmptyBlock:
24
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## [0.1.6] - 2021-08-19
2
+ - 設定ファイルを読み込むと内容のmd5を `pbm_root_dir/.setting_yaml_digest` へ出力するようにしました
3
+
1
4
  ## [0.1.5] - 2021-07-29
2
5
  - siwtch, proコンが電源OFF時にCPU使いまくるのを修正した
3
6
  - 連打中に無視するボタンを複数登録できるようにした
data/Gemfile CHANGED
@@ -9,3 +9,4 @@ gem "rake", "~> 13.0"
9
9
  gem "rspec"
10
10
  gem "pry"
11
11
  gem "timecop"
12
+ gem "rubocop", require: false
data/Gemfile.lock CHANGED
@@ -1,18 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.5)
4
+ procon_bypass_man (0.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.2)
9
10
  coderay (1.1.3)
10
11
  diff-lcs (1.4.4)
11
12
  method_source (1.0.0)
13
+ parallel (1.20.1)
14
+ parser (3.0.2.0)
15
+ ast (~> 2.4.1)
12
16
  pry (0.14.1)
13
17
  coderay (~> 1.1)
14
18
  method_source (~> 1.0)
19
+ rainbow (3.0.0)
15
20
  rake (13.0.3)
21
+ regexp_parser (2.1.1)
22
+ rexml (3.2.5)
16
23
  rspec (3.10.0)
17
24
  rspec-core (~> 3.10.0)
18
25
  rspec-expectations (~> 3.10.0)
@@ -26,7 +33,20 @@ GEM
26
33
  diff-lcs (>= 1.2.0, < 2.0)
27
34
  rspec-support (~> 3.10.0)
28
35
  rspec-support (3.10.2)
36
+ rubocop (1.18.4)
37
+ parallel (~> 1.10)
38
+ parser (>= 3.0.0.0)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8, < 3.0)
41
+ rexml
42
+ rubocop-ast (>= 1.8.0, < 2.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 3.0)
45
+ rubocop-ast (1.8.0)
46
+ parser (>= 3.0.1.1)
47
+ ruby-progressbar (1.11.0)
29
48
  timecop (0.9.4)
49
+ unicode-display_width (2.0.0)
30
50
 
31
51
  PLATFORMS
32
52
  arm-linux
@@ -38,6 +58,7 @@ DEPENDENCIES
38
58
  pry
39
59
  rake (~> 13.0)
40
60
  rspec
61
+ rubocop
41
62
  timecop
42
63
 
43
64
  BUNDLED WITH
data/README.md CHANGED
@@ -25,12 +25,12 @@ Switch <-- (PBM): ZR連打
25
25
 
26
26
  ## Usage
27
27
  * USBガジェットモードで起動するRaspberry Pi4を用意する
28
- * https://github.com/splaspla-hacker/procon_bypass_man/blob/master/docs/setup_raspi.md
28
+ * https://github.com/splaplapla/procon_bypass_man/blob/master/docs/setup_raspi.md
29
29
  * Raspberry Pi4で https://github.com/jiikko/procon_bypass_man_sample をclone して実行ファイルを動かす
30
- * 実行ファイルと設定ファイルについては https://github.com/splaspla-hacker/procon_bypass_man/wiki に詳細を書いていますが、まず動かすためにはcloneしたほうが早いです
30
+ * 実行ファイルと設定ファイルについては https://github.com/splaplapla/procon_bypass_man/wiki に詳細を書いていますが、まず動かすためにはcloneしたほうが早いです
31
31
 
32
32
  ## Plugins
33
- * https://github.com/splaspla-hacker/procon_bypass_man-splatoon2
33
+ * https://github.com/splaplapla/procon_bypass_man-splatoon2
34
34
 
35
35
  ## FAQ
36
36
  * どうやって動かすの?
@@ -38,7 +38,7 @@ Switch <-- (PBM): ZR連打
38
38
  * どうやって使うの?
39
39
  * ケーブルでそれらを接続した状態で、Raspberry Pi4にsshして本プログラムを起動することで使用します
40
40
  * ラズベリーパイ4のセットアップ方法は?
41
- * https://github.com/splaspla-hacker/procon_bypass_man/tree/master/docs/setup_raspi.md
41
+ * https://github.com/splaplapla/procon_bypass_man/tree/master/docs/setup_raspi.md
42
42
  * モード, マクロの違いは?
43
43
  * modeはProconの入力をそのまま再現するため機能。レイヤーを切り替えるまで繰り返し続ける
44
44
  * マクロは特定のキーを順番に入れていく機能。キーの入力が終わったらマクロは終了する
@@ -52,10 +52,10 @@ Switch <-- (PBM): ZR連打
52
52
  * 操作するdeviceファイルの所有者がrootだから
53
53
 
54
54
  ## TODO
55
- * 設定ファイルをwebから反映できる
56
55
  * ラズパイのプロビジョニングを楽にしたい
57
56
  * レコーディング機能(プロコンの入力をマクロとして登録ができる)
58
57
  * マクロにdelayを入れれるようにする
58
+ * 設定ファイル マクロの引数に、ボタンを取れるようにする
59
59
 
60
60
  ## 開発系
61
61
  ```ruby
@@ -8,8 +8,8 @@ require 'bundler/inline'
8
8
 
9
9
  gemfile do
10
10
  source 'https://rubygems.org'
11
- gem 'procon_bypass_man', github: 'splaspla-hacker/procon_bypass_man', branch: "edge"
12
- gem 'procon_bypass_man-splatoon2', github: 'splaspla-hacker/procon_bypass_man-splatoon2', branch: "0.1.0"
11
+ gem 'procon_bypass_man', github: 'splaplapla/procon_bypass_man', branch: "edge"
12
+ gem 'procon_bypass_man-splatoon2', github: 'splaplapla/procon_bypass_man-splatoon2', branch: "0.1.0"
13
13
  end
14
14
 
15
15
  ProconBypassMan.tap do |pbm|
@@ -40,12 +40,13 @@ module ProconBypassMan
40
40
  ProconBypassMan.logger.error "設定ファイルが不正です。設定ファイルの読み込みに失敗しました"
41
41
  puts "設定ファイルが不正です。設定ファイルの読み込みに失敗しました"
42
42
  FileUtils.rm_rf(ProconBypassMan.pid_path)
43
+ FileUtils.rm_rf(ProconBypassMan.digest_path)
43
44
  exit 1
44
45
  rescue EternalConnectionError
45
46
  ProconBypassMan.logger.error "接続の見込みがないのでsleepしまくります"
46
47
  puts "接続の見込みがないのでsleepしまくります"
47
48
  FileUtils.rm_rf(ProconBypassMan.pid_path)
48
- sleep(999999999999999999)
49
+ sleep(999999999)
49
50
  rescue FirstConnectionError
50
51
  puts "接続を確立できませんでした。やりなおします。"
51
52
  retry
@@ -86,4 +87,8 @@ module ProconBypassMan
86
87
  def self.root=(path)
87
88
  @@root = path
88
89
  end
90
+
91
+ def self.digest_path
92
+ "#{root}/.setting_yaml_digest"
93
+ end
89
94
  end
@@ -4,7 +4,6 @@ require "procon_bypass_man/configuration/layer"
4
4
 
5
5
  module ProconBypassMan
6
6
  class Configuration
7
- include Validator
8
7
 
9
8
  attr_accessor :layers,
10
9
  :setting_path,
@@ -19,13 +18,12 @@ module ProconBypassMan
19
18
  @@context[@@current_context_key] ||= new
20
19
  end
21
20
 
22
- def self.switch_context(key)
23
- @@context[key] ||= new
21
+ def self.switch_new_context(key)
22
+ @@context[key] = new
24
23
  previous_key = @@current_context_key
25
24
  if block_given?
26
25
  @@current_context_key = key
27
26
  value = yield(@@context[key])
28
- @@context[key].reset!
29
27
  @@current_context_key = previous_key
30
28
  return value
31
29
  else
@@ -1,24 +1,22 @@
1
1
  module ProconBypassMan
2
2
  class Configuration
3
3
  module Loader
4
+ require 'digest/md5'
5
+
4
6
  def self.load(setting_path: )
5
- validation_instance = ProconBypassMan::Configuration.switch_context(:validation) do |instance|
6
- begin
7
- yaml = YAML.load_file(setting_path) or raise "読み込みに失敗しました"
8
- instance.instance_eval(yaml["setting"])
9
- rescue SyntaxError
10
- instance.errors[:base] << "Rubyのシンタックスエラーです"
11
- next(instance)
12
- rescue Psych::SyntaxError
13
- instance.errors[:base] << "yamlのシンタックスエラーです"
14
- next(instance)
7
+ ProconBypassMan::Configuration.switch_new_context(:validation) do |validation_instance|
8
+ yaml = YAML.load_file(setting_path) or raise "読み込みに失敗しました"
9
+ validation_instance.instance_eval(yaml["setting"])
10
+ validator = Validator.new(validation_instance)
11
+ if validator.valid?
12
+ next
13
+ else
14
+ raise ProconBypassMan::CouldNotLoadConfigError, validator.errors
15
15
  end
16
- instance.valid?
17
- next(instance)
18
- end
19
-
20
- if !validation_instance.errors.empty?
21
- raise ProconBypassMan::CouldNotLoadConfigError, validation_instance.errors
16
+ rescue SyntaxError
17
+ raise ProconBypassMan::CouldNotLoadConfigError, "Rubyのシンタックスエラーです"
18
+ rescue Psych::SyntaxError
19
+ raise ProconBypassMan::CouldNotLoadConfigError, "yamlのシンタックスエラーです"
22
20
  end
23
21
 
24
22
  yaml = YAML.load_file(setting_path)
@@ -33,6 +31,9 @@ module ProconBypassMan
33
31
  ProconBypassMan.logger.warn "不明なバージョンです。failoverします"
34
32
  ProconBypassMan::Configuration.instance.instance_eval(yaml["setting"])
35
33
  end
34
+
35
+ File.write(ProconBypassMan.digest_path, Digest::MD5.hexdigest(yaml["setting"]))
36
+
36
37
  ProconBypassMan::Configuration.instance
37
38
  end
38
39
 
@@ -1,6 +1,11 @@
1
1
  module ProconBypassMan
2
2
  class Configuration
3
- module Validator
3
+ class Validator
4
+ def initialize(config)
5
+ @layers = config.layers
6
+ @prefix_keys = config.prefix_keys
7
+ end
8
+
4
9
  # @return [Boolean]
5
10
  def valid?
6
11
  @errors = Hash.new {|h,k| h[k] = [] }
@@ -38,7 +43,7 @@ module ProconBypassMan
38
43
  end
39
44
 
40
45
  def validate_require_prefix_keys
41
- if prefix_keys.empty?
46
+ if @prefix_keys.empty?
42
47
  @errors[:prefix_keys] ||= []
43
48
  @errors[:prefix_keys] << "prefix_keys_for_changing_layerに値が入っていません。"
44
49
  end
@@ -48,24 +53,20 @@ module ProconBypassMan
48
53
  @layers.each do |layer_key, value|
49
54
  unverified_buttons = []
50
55
  # teplevel target button
51
- value.instance_eval { @flips.keys }.map(&:to_sym).each { |b| unverified_buttons << b }
52
- value.instance_eval { @remaps.keys }.map(&:to_sym).each { |b| unverified_buttons << b }
56
+ value.flips.keys.map(&:to_sym).each { |b| unverified_buttons << b }
57
+ value.remaps.keys.map(&:to_sym).each { |b| unverified_buttons << b }
53
58
  # internal target button
54
- value.instance_eval {
55
- @flips.flat_map { |flip_button, flip_option|
56
- flip_option.flat_map { |flip_option_key, flip_option_target_button|
57
- next if flip_option_key == :flip_interval
58
- next if flip_option_target_button.is_a?(FalseClass) || flip_option_target_button.is_a?(TrueClass)
59
- flip_option_target_button
60
- }
59
+ value.flips.flat_map { |_flip_button, flip_option|
60
+ flip_option.flat_map { |flip_option_key, flip_option_target_button|
61
+ next if flip_option_key == :flip_interval
62
+ next if flip_option_target_button.is_a?(FalseClass) || flip_option_target_button.is_a?(TrueClass)
63
+ flip_option_target_button
61
64
  }
62
65
  }.compact.each { |b| unverified_buttons << b }
63
- value.instance_eval {
64
- @remaps.flat_map { |button, option|
65
- option.flat_map { |flip_option_key, flip_option_target_button|
66
- next if flip_option_target_button.is_a?(FalseClass) || flip_option_target_button.is_a?(TrueClass)
67
- flip_option_target_button
68
- }
66
+ value.remaps.flat_map { |_button, option|
67
+ option.flat_map { |_flip_option_key, flip_option_target_button|
68
+ next if flip_option_target_button.is_a?(FalseClass) || flip_option_target_button.is_a?(TrueClass)
69
+ flip_option_target_button
69
70
  }
70
71
  }.compact.each { |b| unverified_buttons << b }
71
72
  unless(nunsupport_buttons = (unverified_buttons - ProconBypassMan::Procon::ButtonCollection::BUTTONS)).length.zero?
@@ -78,8 +79,8 @@ module ProconBypassMan
78
79
  @layers.each do |layer_key, value|
79
80
  flip_buttons = []
80
81
  remap_buttons = []
81
- value.instance_eval { @flips.keys }.map(&:to_sym).each { |b| flip_buttons << b }
82
- value.instance_eval { @remaps.keys }.map(&:to_sym).each { |b| remap_buttons << b }
82
+ value.flips.keys.map(&:to_sym).each { |b| flip_buttons << b }
83
+ value.remaps.keys.map(&:to_sym).each { |b| remap_buttons << b }
83
84
  if(duplicated_buttons = flip_buttons & remap_buttons).length > 0
84
85
  @errors[:layers] << "レイヤー#{layer_key}で、連打とリマップの定義が重複しているボタン#{duplicated_buttons.join(", ")}があります"
85
86
  end
@@ -29,7 +29,7 @@ class ProconBypassMan::DeviceConnector
29
29
  s
30
30
  end
31
31
 
32
- def self.connect(throw_error_if_timeout: true, enable_at_exit: false)
32
+ def self.connect
33
33
  s = new(throw_error_if_timeout: true, enable_at_exit: false)
34
34
  s.add([
35
35
  ["0000"],
@@ -13,7 +13,7 @@ module ProconBypassMan::Procon::PushedButtonHelper
13
13
  @@compiled = false
14
14
  def compile_if_not_compile_yet!
15
15
  unless @@compiled
16
- ::ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP.each do |button, value|
16
+ ::ProconBypassMan::Procon::ButtonCollection::BUTTONS_MAP.each do |button, _value|
17
17
  define_method "pressed_#{button}?" do
18
18
  pressed_button?(button)
19
19
  end
@@ -28,7 +28,7 @@ class ProconBypassMan::Runner
28
28
  main_loop_pid = fork { main_loop }
29
29
 
30
30
  begin
31
- while readable_io = IO.select([self_read])
31
+ while(readable_io = IO.select([self_read]))
32
32
  signal = readable_io.first[0].gets.strip
33
33
  handle_signal(signal)
34
34
  end
@@ -51,6 +51,7 @@ class ProconBypassMan::Runner
51
51
  @gadget&.close
52
52
  @procon&.close
53
53
  FileUtils.rm_rf(ProconBypassMan.pid_path)
54
+ FileUtils.rm_rf(ProconBypassMan.digest_path)
54
55
  exit 1
55
56
  end
56
57
  end
@@ -119,7 +120,7 @@ class ProconBypassMan::Runner
119
120
 
120
121
  ProconBypassMan.logger.info "子プロセスでgraceful shutdownの準備ができました"
121
122
  begin
122
- while readable_io = IO.select([self_read])
123
+ while(readable_io = IO.select([self_read]))
123
124
  signal = readable_io.first[0].gets.strip
124
125
  handle_signal(signal)
125
126
  end
@@ -135,7 +136,7 @@ class ProconBypassMan::Runner
135
136
  def first_negotiation
136
137
  return if $will_terminate_token
137
138
 
138
- @gadget, @procon = ProconBypassMan::DeviceConnector.connect(throw_error_if_timeout: true, enable_at_exit: false)
139
+ @gadget, @procon = ProconBypassMan::DeviceConnector.connect
139
140
  rescue ProconBypassMan::Timer::Timeout
140
141
  ::ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
141
142
  @gadget&.close
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProconBypassMan
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "extension for Nintendo Switch Pro Controller"
12
12
  spec.description = spec.summary
13
- spec.homepage = "https://github.com/splaspla-hacker/procon_bypass_man"
13
+ spec.homepage = "https://github.com/splaplapla/procon_bypass_man"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procon_bypass_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiikko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-29 00:00:00.000000000 Z
11
+ date: 2021-08-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: extension for Nintendo Switch Pro Controller
14
14
  email:
@@ -20,6 +20,7 @@ files:
20
20
  - ".circleci/config.yml"
21
21
  - ".gitignore"
22
22
  - ".rspec"
23
+ - ".rubocop.yml"
23
24
  - ".ruby-version"
24
25
  - CHANGELOG.md
25
26
  - Gemfile
@@ -57,12 +58,12 @@ files:
57
58
  - lib/procon_bypass_man/timer.rb
58
59
  - lib/procon_bypass_man/version.rb
59
60
  - procon_bypass_man.gemspec
60
- homepage: https://github.com/splaspla-hacker/procon_bypass_man
61
+ homepage: https://github.com/splaplapla/procon_bypass_man
61
62
  licenses:
62
63
  - MIT
63
64
  metadata:
64
- homepage_uri: https://github.com/splaspla-hacker/procon_bypass_man
65
- source_code_uri: https://github.com/splaspla-hacker/procon_bypass_man
65
+ homepage_uri: https://github.com/splaplapla/procon_bypass_man
66
+ source_code_uri: https://github.com/splaplapla/procon_bypass_man
66
67
  post_install_message:
67
68
  rdoc_options: []
68
69
  require_paths: