procon_bypass_man 0.1.3 → 0.1.4

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: f0ba281c9129f770b6cf905d9221bc39de1957f33d0091e2a5217c1fb4547be8
4
- data.tar.gz: ca0fbffd26fb3a7ad928803ea912a1fe6412a4b8d10a65acefbc21d0fe2f0b49
3
+ metadata.gz: 8326aa72e03d6b2b8ebe7342778c357ba7595019617683e075694c93d870960c
4
+ data.tar.gz: fc1df85f7d880ec11c8b5f7d47d46c1a21e726d862cc18000310571e8a072011
5
5
  SHA512:
6
- metadata.gz: 0425a0610a7ec5d583724a167f45eaf8f352d552f4158901d02138dbfe89a5b66972f7767c72eab7ed30c6b199af25db10a1c9ef1fb826c188fc30255e81ea98
7
- data.tar.gz: 271542b52dce9d7b0980fb5f97c4fbab80b8fa9f03fc726dbf5034899d8a4f7a7cbdc10456a6016bcc81c038d8f0f3463a732d4a4cf7f4940b2ab652d0125d58
6
+ metadata.gz: bc6aeb40ae12912216e0c40e4b538ab0337ef963c0bcc8e3ac46bafa858a56f44d140f8db694c2200eb1444bf53edf2e49ebc80e9ee63073af29287e556fcd7a
7
+ data.tar.gz: bdcb9405fe592e390073e70c2b7eb75d9336bf5f26a6ab08dc1db768e45217103abee62c06eb1dc847d80ff03a600135a0a8b3b41564d1ca68f5161b484df60a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.1.4] - 2021-0
2
+ - ProconBypassMan.rootの定義を、gem rootからproject rootへ変更した
3
+ - 連打の頻度を変更できるようにした
4
+ - シグナルで設定ファイルを読み直すとpid_pathが消滅する不具合を修正した
5
+
1
6
  ## [0.1.3] - 2021-07-03
2
7
  - 接続のしやすさ向上
3
8
 
data/Gemfile CHANGED
@@ -8,3 +8,4 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
  gem "rspec"
10
10
  gem "pry"
11
+ gem "timecop"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- procon_bypass_man (0.1.3)
4
+ procon_bypass_man (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -26,6 +26,7 @@ GEM
26
26
  diff-lcs (>= 1.2.0, < 2.0)
27
27
  rspec-support (~> 3.10.0)
28
28
  rspec-support (3.10.2)
29
+ timecop (0.9.4)
29
30
 
30
31
  PLATFORMS
31
32
  arm-linux
@@ -37,6 +38,7 @@ DEPENDENCIES
37
38
  pry
38
39
  rake (~> 13.0)
39
40
  rspec
41
+ timecop
40
42
 
41
43
  BUNDLED WITH
42
44
  2.2.20
data/README.md CHANGED
@@ -55,14 +55,14 @@ Switch <-- (PBM): ZR連打
55
55
  * 設定ファイルをwebから反映できる
56
56
  * ラズパイのプロビジョニングを楽にしたい
57
57
  * レコーディング機能(プロコンの入力をマクロとして登録ができる)
58
- * webページから設定ファイルを変更できるようにする(sshしたくない)
59
- * webサーバのデーモンとPBMはプロセスを分ける(NOTE)
58
+ * マクロにdelayを入れれるようにする
60
59
 
61
60
  ## 開発系
62
61
  ```ruby
63
62
  ProconBypassMan.tap do |pbm|
64
63
  pbm.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
65
64
  pbm.logger.level = :debug
65
+ pbm.root = File.expand_path(__dir__)
66
66
  end
67
67
  ```
68
68
 
@@ -15,6 +15,7 @@ end
15
15
  ProconBypassMan.tap do |pbm|
16
16
  pbm.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10) # 5世代まで残して, 10MBでローテーション
17
17
  pbm.logger.level = :debug
18
+ pbm.root = File.expand_path(__dir__)
18
19
  end
19
20
 
20
21
  ProconBypassMan.run(setting_path: "./setting.yml")
@@ -9,7 +9,7 @@ setting: |-
9
9
  prefix_keys_for_changing_layer [:zr, :r, :zl, :l]
10
10
 
11
11
  layer :up, mode: :manual do
12
- flip :zr, if_pressed: :zr, force_neutral: :zl
12
+ flip :zr, if_pressed: :zr, force_neutral: :zl, flip_interval: "8F"
13
13
  flip :zl, if_pressed: [:y, :b, :zl]
14
14
  flip :down, if_pressed: :down
15
15
  macro fast_return.name, if_pressed: [:y, :b, :down]
@@ -33,13 +33,13 @@ module ProconBypassMan
33
33
 
34
34
  def self.run(setting_path: nil, &block)
35
35
  configure(setting_path: setting_path, &block)
36
- at_exit { FileUtils.rm_rf(pid_path) }
37
36
  File.write(pid_path, $$)
38
37
  registry = ProconBypassMan::DeviceRegistry.new
39
38
  Runner.new(gadget: registry.gadget, procon: registry.procon).run
40
39
  rescue CouldNotLoadConfigError
41
40
  ProconBypassMan.logger.error "設定ファイルが不正です。設定ファイルの読み込みに失敗しました"
42
41
  puts "設定ファイルが不正です。設定ファイルの読み込みに失敗しました"
42
+ FileUtils.rm_rf(ProconBypassMan.pid_path)
43
43
  exit 1
44
44
  rescue FirstConnectionError
45
45
  puts "接続を確立できませんでした。やりなおします。"
@@ -58,9 +58,8 @@ module ProconBypassMan
58
58
  end
59
59
  end
60
60
 
61
- DEFAULT_PID_PATH = File.expand_path('../pbm_pid', __dir__).freeze
62
61
  def self.pid_path
63
- @@pid_path ||= DEFAULT_PID_PATH
62
+ @@pid_path ||= File.expand_path("#{root}/pbm_pid", __dir__).freeze
64
63
  end
65
64
 
66
65
  def self.reset!
@@ -72,6 +71,14 @@ module ProconBypassMan
72
71
  end
73
72
 
74
73
  def self.root
75
- File.expand_path('..', __dir__).freeze
74
+ if defined?(@@root)
75
+ @@root
76
+ else
77
+ File.expand_path('..', __dir__).freeze
78
+ end
79
+ end
80
+
81
+ def self.root=(path)
82
+ @@root = path
76
83
  end
77
84
  end
@@ -12,7 +12,7 @@ module ProconBypassMan
12
12
  end
13
13
 
14
14
  # @param [Symbol] button
15
- def flip(button, if_pressed: false, channel: nil, force_neutral: nil)
15
+ def flip(button, if_pressed: false, force_neutral: nil, flip_interval: nil)
16
16
  case if_pressed
17
17
  when TrueClass
18
18
  if_pressed = [button]
@@ -24,12 +24,17 @@ module ProconBypassMan
24
24
  raise "not support class"
25
25
  end
26
26
  hash = { if_pressed: if_pressed }
27
- if channel
28
- hash[:channel] = channel
29
- end
30
27
  if force_neutral
31
28
  hash[:force_neutral] = force_neutral
32
29
  end
30
+ if flip_interval
31
+ if /\A(\d+)F\z/i =~ flip_interval
32
+ interval = ((frame = $1.to_i) / 60.0).floor(2)
33
+ else
34
+ raise "8F みたいなフォーマットで入力してください"
35
+ end
36
+ hash[:flip_interval] = interval
37
+ end
33
38
  self.flips[button] = hash
34
39
  end
35
40
 
@@ -5,6 +5,7 @@ class ProconBypassMan::Procon
5
5
  require "procon_bypass_man/procon/button_collection"
6
6
  require "procon_bypass_man/procon/pressed_button_helper"
7
7
  require "procon_bypass_man/procon/user_operation"
8
+ require "procon_bypass_man/procon/flip_cache"
8
9
 
9
10
  attr_accessor :user_operation
10
11
 
@@ -51,15 +52,21 @@ class ProconBypassMan::Procon
51
52
  when :manual
52
53
  @@status[:ongoing_mode] = ModeRegistry.load(:manual)
53
54
  current_layer.flip_buttons.each do |button, options|
54
- unless options[:if_pressed]
55
- status[button] = !status[button]
55
+ if !options[:if_pressed]
56
+ FlipCache.fetch(key: button, expires_in: options[:flip_interval]) do
57
+ status[button] = !status[button]
58
+ end
56
59
  next
57
60
  end
58
61
 
59
62
  if options[:if_pressed] && options[:if_pressed].all? { |b| user_operation.pressed_button?(b) }
60
- status[button] = !status[button]
63
+ FlipCache.fetch(key: button, expires_in: options[:flip_interval]) do
64
+ status[button] = !status[button]
65
+ end
61
66
  else
62
- status[button] = false
67
+ FlipCache.fetch(key: button, expires_in: options[:flip_interval]) do
68
+ status[button] = false
69
+ end
63
70
  end
64
71
  end
65
72
  else
@@ -0,0 +1,22 @@
1
+ class ProconBypassMan::Procon
2
+ class FlipCache
3
+ def self.fetch(key: , expires_in: , &block)
4
+ if expires_in.nil?
5
+ block.call
6
+ else
7
+ @@previous_flips_at_table[key] ||= Time.now
8
+ if @@previous_flips_at_table[key] < Time.now
9
+ @@previous_flips_at_table[key] = Time.now + expires_in
10
+ block.call
11
+ end
12
+ end
13
+ end
14
+
15
+ # for testing
16
+ def self.reset!
17
+ @@previous_flips_at_table = {}
18
+ end
19
+
20
+ reset!
21
+ end
22
+ end
@@ -22,7 +22,7 @@ class ProconBypassMan::Runner
22
22
  self_write.puts(sig)
23
23
  end
24
24
  rescue ArgumentError
25
- ProconBypassMan.logger.info("Signal #{sig} not supported")
25
+ ProconBypassMan.logger.error("Signal #{sig} not supported")
26
26
  end
27
27
  end
28
28
 
@@ -53,6 +53,7 @@ class ProconBypassMan::Runner
53
53
  Process.wait
54
54
  @gadget&.close
55
55
  @procon&.close
56
+ FileUtils.rm_rf(ProconBypassMan.pid_path)
56
57
  exit 1
57
58
  end
58
59
  end
@@ -179,10 +180,14 @@ class ProconBypassMan::Runner
179
180
  # @return [void]
180
181
  def print_booted_message
181
182
  booted_message = <<~EOF
183
+ ----
184
+ RUBY_VERSION: #{RUBY_VERSION}
182
185
  ProconBypassMan: #{ProconBypassMan::VERSION}
183
- pid_path: #{ProconBypassMan.pid_path}
184
186
  pid: #{$$}
185
- project_path: #{ProconBypassMan.root}
187
+ root: #{ProconBypassMan.root}
188
+ pid_path: #{ProconBypassMan.pid_path}
189
+ setting_path: #{ProconBypassMan::Configuration.instance.setting_path}
190
+ ----
186
191
  EOF
187
192
  ProconBypassMan.logger.info(booted_message)
188
193
  puts booted_message
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProconBypassMan
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
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.3
4
+ version: 0.1.4
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-03 00:00:00.000000000 Z
11
+ date: 2021-07-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: extension for Nintendo Switch Pro Controller
14
14
  email:
@@ -47,6 +47,7 @@ files:
47
47
  - lib/procon_bypass_man/procon.rb
48
48
  - lib/procon_bypass_man/procon/button_collection.rb
49
49
  - lib/procon_bypass_man/procon/data.rb
50
+ - lib/procon_bypass_man/procon/flip_cache.rb
50
51
  - lib/procon_bypass_man/procon/layer_changeable.rb
51
52
  - lib/procon_bypass_man/procon/macro_registry.rb
52
53
  - lib/procon_bypass_man/procon/mode_registry.rb