Skip to content

Commit

Permalink
Merge pull request #17 from splaplapla/edge
Browse files Browse the repository at this point in the history
0.1.13
  • Loading branch information
jiikko authored Nov 23, 2021
2 parents bf30a87 + a8911c2 commit 2e1f601
Show file tree
Hide file tree
Showing 49 changed files with 632 additions and 196 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.1.13] - 2021-11-24
- 起動を早くするために、procon_bypass_man-splatoon2を同梱しました

## [0.1.12] - 2021-11-18
- 起動ログなどを設定した外部サーバに送信できるようにしました

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
procon_bypass_man (0.1.12)
procon_bypass_man (0.1.13)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sudo kill -USR2 `cat ./pbm_pid`
### 開発環境でログの送信を確認する方法
* `bundle exec bin/dev_api_server.rb`
* `API_SERVER=http://localhost:4567 INTERNAL_API_SERVER=http://localhost:4567 bin/console`
* `message = ProconBypassMan::BootMessage.new; ProconBypassMan::ReportBootJob.report(body: message.to_hash)`
* `message = ProconBypassMan::BootMessage.new; ProconBypassMan::ReportBootJob.perform(body: message.to_hash)`

### リリース手順
* project_template/web.rb, project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
Expand Down
17 changes: 11 additions & 6 deletions lib/procon_bypass_man.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
require "securerandom"

require_relative "procon_bypass_man/version"
require_relative "procon_bypass_man/callbacks"
require_relative "procon_bypass_man/timer"
require_relative "procon_bypass_man/support/signal_handler"
require_relative "procon_bypass_man/support/callbacks"
require_relative "procon_bypass_man/support/safe_timeout"
require_relative "procon_bypass_man/support/compress_array"
require_relative "procon_bypass_man/support/uptime"
require_relative "procon_bypass_man/support/on_memory_cache"
require_relative "procon_bypass_man/background"
require_relative "procon_bypass_man/commands"
require_relative "procon_bypass_man/bypass"
require_relative "procon_bypass_man/device_connector"
require_relative "procon_bypass_man/runner"
require_relative "procon_bypass_man/processor"
require_relative "procon_bypass_man/configuration"
require_relative "procon_bypass_man/buttons_setting_configuration"
require_relative "procon_bypass_man/procon_reader"
require_relative "procon_bypass_man/procon"
require_relative "procon_bypass_man/procon_reader"
require_relative "procon_bypass_man/procon/analog_stick"
require_relative "procon_bypass_man/procon/analog_stick_cap"
require_relative "procon_bypass_man/background"
require_relative "procon_bypass_man/commands"
require_relative "procon_bypass_man/on_memory_cache"
require_relative "procon_bypass_man/splatoon2"

STDOUT.sync = true
Thread.abort_on_exception = true
Expand Down Expand Up @@ -52,6 +56,7 @@ def self.run(setting_path: nil, &block)
initialize_pbm
File.write(pid_path, $$)
ProconBypassMan::WriteSessionIdCommand.execute
ProconBypassMan::Background::JobRunner.start!
gadget, procon = ProconBypassMan::ConnectDeviceCommand.execute!
Runner.new(gadget: gadget, procon: procon).run
rescue CouldNotLoadConfigError
Expand Down
2 changes: 2 additions & 0 deletions lib/procon_bypass_man/background.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require "procon_bypass_man/background/job_runnable"
require "procon_bypass_man/background/job_runner"
require "procon_bypass_man/background/job_performer"
require "procon_bypass_man/background/has_server_pool"
require "procon_bypass_man/background/http_client"
require "procon_bypass_man/background/jobs/base_job"
require "procon_bypass_man/background/jobs/report_boot_job"
require "procon_bypass_man/background/jobs/report_reload_config_job"
require "procon_bypass_man/background/jobs/report_load_config_job"
require "procon_bypass_man/background/jobs/report_error_job"
require "procon_bypass_man/background/jobs/report_heartbeat_job"
require "procon_bypass_man/background/jobs/report_pressed_buttons_job"
13 changes: 5 additions & 8 deletions lib/procon_bypass_man/background/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ProconBypassMan
module Background
class HttpClient
class HttpRequest
def self.request!(uri: , hostname: , body: , device_id: , session_id: nil, event_type: )
def self.request!(uri: , hostname: , params: , device_id: , session_id: nil, event_type: )
@uri = uri
@http = Net::HTTP.new(uri.host, uri.port)
@http.use_ssl = uri.scheme === "https"
Expand All @@ -11,7 +11,7 @@ def self.request!(uri: , hostname: , body: , device_id: , session_id: nil, event
event_type: event_type,
session_id: session_id,
device_id: device_id,
}.merge(body)
}.merge(params)
@http.post(
@uri.path,
@params.to_json,
Expand All @@ -32,11 +32,8 @@ def post(body: , event_type: )
ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
return
end
if body.is_a?(Hash)
body = { body: body, event_type: event_type }
else
body = { body: { value: body, event_type: event_type } }
end

params = { body: body.to_json }
session_id = ProconBypassMan.session_id
device_id = ProconBypassMan.device_id

Expand All @@ -45,7 +42,7 @@ def post(body: , event_type: )
hostname: @hostname,
device_id: device_id,
session_id: session_id,
body: body,
params: params,
event_type: event_type,
)
case response.code
Expand Down
11 changes: 6 additions & 5 deletions lib/procon_bypass_man/background/job_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ def self.start!
end

# for test
def self.stop!
return unless defined?(@@thread)
@@thread.kill
def stop!
return unless defined?(@thread)
@thread.kill
end

def start!
return if defined?(@@thread)
@@thread = Thread.new do
return if defined?(@thread)
@thread = Thread.new do
while(item = self.class.queue.pop)
begin
JobPerformer.new(klass: item[:reporter_class], args: item[:args]).perform
Expand All @@ -25,6 +25,7 @@ def start!
end
end
end
self
end

def self.queue
Expand Down
10 changes: 10 additions & 0 deletions lib/procon_bypass_man/background/jobs/report_load_config_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ProconBypassMan::ReportLoadConfigJob < ProconBypassMan::BaseJob
# @param [String] body
def self.perform(body)
ProconBypassMan::Background::HttpClient.new(
path: path,
pool_server: pool_server,
retry_on_connection_error: false,
).post(body: body, event_type: :load_config)
end
end
4 changes: 3 additions & 1 deletion lib/procon_bypass_man/boot_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def initialize
@table[:pid_path] = ProconBypassMan.pid_path
@table[:setting_path] = ProconBypassMan::ButtonsSettingConfiguration.instance.setting_path
@table[:uptime_from_boot] = ProconBypassMan::Uptime.from_boot
@table[:use_pbmenv] = !(!!`which pbmenv`.empty?)

# 開発中のHEADを取りたかったけど、Gem::Specification経由から取得する必要がありそう
# build_version = `git rev-parse --short HEAD`.chomp
Expand All @@ -25,12 +26,13 @@ def to_s
booted_message = <<~EOF
----
RUBY_VERSION: #{@table[:ruby_version]}
ProconBypassMan: #{@table[:pbm_version]}
ProconBypassMan::VERSION: #{@table[:pbm_version]}
pid: #{@table[:pid]}
root: #{@table[:root_path]}
pid_path: #{@table[:pid_path]}
setting_path: #{@table[:setting_path]}
uptime from boot: #{@table[:uptime_from_boot]} sec
use_pbmenv: #{@table[:use_pbmenv]}
----
EOF
end
Expand Down
4 changes: 2 additions & 2 deletions lib/procon_bypass_man/buttons_setting_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def prefix_keys_for_changing_layer(buttons)
end

def set_neutral_position(x, y)
self.neutral_position = AnalogStickPosition.new(x, y)
self.neutral_position = AnalogStickPosition.new(x, y).freeze
self
end

Expand All @@ -95,7 +95,7 @@ def reset!
left: Layer.new,
right: Layer.new,
}
@neutral_position = AnalogStickPosition.new(2124, 1808)
@neutral_position = AnalogStickPosition.new(2124, 1808).freeze
end
end
end
63 changes: 34 additions & 29 deletions lib/procon_bypass_man/buttons_setting_configuration/layer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,26 @@ def flip(button, if_pressed: false, force_neutral: nil, flip_interval: nil)
if_pressed = [button]
when Symbol, String
if_pressed = [if_pressed]
when Array, FalseClass
# sono mama
when Array
# if_pressed = if_pressed
when FalseClass, NilClass
# no-op
else
raise "not support class"
end

hash = { if_pressed: if_pressed }
if force_neutral
case force_neutral
when TrueClass, FalseClass
raise "ボタンを渡してください"
when Symbol, String
hash[:force_neutral] = [force_neutral]
when Array
hash[:force_neutral] = force_neutral
end
case force_neutral
when TrueClass
raise "ボタンを渡してください"
when Symbol, String
hash[:force_neutral] = [force_neutral]
when Array
hash[:force_neutral] = force_neutral
when FalseClass, NilClass
# no-op
else
raise "not support value"
end

if flip_interval
Expand Down Expand Up @@ -63,7 +68,7 @@ def macro(name, if_pressed: )

def remap(button, to: )
case to
when TrueClass, FalseClass
when TrueClass, FalseClass, NilClass
raise "ボタンを渡してください"
when Symbol, String
self.remaps[button] = { to: [to] }
Expand All @@ -77,27 +82,27 @@ def left_analog_stick_cap(cap: , if_pressed: nil, force_neutral: nil)
hash = { cap: cap }

case if_pressed
when TrueClass
raise "not support class"
when TrueClass, FalseClass
raise "ボタンを渡してください"
when Symbol, String
if_pressed = [if_pressed]
when Array, FalseClass
# sono mama
when NilClass
if_pressed = nil
when Array, NilClass
# no-op
else
raise "not support if_pressed"
raise "not support value"
end

if force_neutral
case force_neutral
when TrueClass, FalseClass
raise "ボタンを渡してください"
when Symbol, String
hash[:force_neutral] = [force_neutral]
when Array
hash[:force_neutral] = force_neutral
end
case force_neutral
when TrueClass
raise "ボタンを渡してください"
when Symbol, String
hash[:force_neutral] = [force_neutral]
when Array
hash[:force_neutral] = force_neutral
when FalseClass, NilClass
# no-op
else
raise "not support value"
end

left_analog_stick_caps[if_pressed] = hash
Expand All @@ -114,7 +119,7 @@ def disable(button)
when Array
button.each { |b| disables << b }
else
raise "unknown"
raise "not support value"
end
end

Expand Down
8 changes: 7 additions & 1 deletion lib/procon_bypass_man/bypass/usb_hid_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ module UsbHidLogger
set_callback :send_procon_to_gadget, :after, :log_procon_to_gadget

def log_send_gadget_to_procon
ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
if ProconBypassMan.config.verbose_bypass_log
ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
else
ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
end
end
end

def log_procon_to_gadget
Expand Down
1 change: 1 addition & 0 deletions lib/procon_bypass_man/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
require "procon_bypass_man/commands/send_reload_config_event_command"
require "procon_bypass_man/commands/send_error_command"
require "procon_bypass_man/commands/connect_device_command"
require "procon_bypass_man/commands/bypass_command"
Loading

0 comments on commit 2e1f601

Please sign in to comment.