Skip to content

Commit

Permalink
コントローラーアイコンのグリップカラーを変更する
Browse files Browse the repository at this point in the history
  • Loading branch information
jiikko committed Jan 5, 2024
1 parent 57ca8fb commit 91a57a3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
23 changes: 22 additions & 1 deletion lib/procon_bypass_man/device_connection/pre_bypass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,28 @@ def run_once
begin
raw_data = non_blocking_read_procon
output_report_watcher.mark_as_receive(raw_data)
ProconBypassMan.logger.info "[pre_bypass] <<< #{raw_data.unpack("H*").first}"
ProconBypassMan.logger.info "[pre_bypass] <<< #{raw_data.unpack1("H*")}"

if(first_data_part = raw_data[0].unpack1("H*"))
sub_command = raw_data[15..16].unpack1("H*")
if first_data_part == '21' && sub_command == "5060" # Controller Color
# new_color_bytes = ['bc 11 42, 75 a9 28, ff ff ff, ff ff ff'.gsub(/[,\s]/, "")].pack('H*') # new color
new_color_bytes = ['ff 00 00, ff ff ff, ff ff ff, 00 ff 00'.gsub(/[,\s]/, '')].pack('H*') # new color

# 216f81008000911870a547710490105060 00 00 0d, 32 32 32, ff ff ff, ff ff ff, ff ff f
# 216f81008000911870a547710490105060 00 00 0d, 32 32 32, ff ff ff, ff ff ff, ff ff f
# 210781008000f8d77a22c87b0c9010, 5060, 00,00,10,bc11,4275a928ffffffffffffff00000000000000000000000000000000000000000000000000000000000000
# 216f81008000911870a54771049010, 5060, 00,00,0d,3232,32ffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000
# 216f81008000911870a54771049010 5060, 00,00,0d,323232ffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000
# 216f81008000911870a54771049010506000000d323232ffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000

# 0103000000000000000010506000000d000000000000000000000000000000000000000000000000000000000000000000
# 216f81008000911870a54771049010506000000d,323232, ff ff ff, ff ff ff ff ffff0000000000000000000000000000000000000000000000000000000000000000
raw_data[20...(20+(3*4))] = new_color_bytes
# raw_data.unpack1("H*")
end
end

send_switch(raw_data)
rescue IO::EAGAINWaitReadable
# no-op
Expand Down
25 changes: 19 additions & 6 deletions spec/lib/procon_bypass_man/device_connection/pre_bypass_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@

subject { instance.run_once }

before do
allow(instance).to receive(:non_blocking_read_switch) { "01030000000000000000480000000000000000" }
allow(instance).to receive(:send_procon)
allow(instance).to receive(:non_blocking_read_procon) { "01030000000000000000480000000000000000" }
allow(instance).to receive(:send_switch)
context 'when provides "01030000000000000000480000000000000000"' do
before do
allow(instance).to receive(:non_blocking_read_switch) { "01030000000000000000480000000000000000" }
allow(instance).to receive(:send_procon)
allow(instance).to receive(:non_blocking_read_procon) { "01030000000000000000480000000000000000" }
allow(instance).to receive(:send_switch)
end

it { expect { subject }.not_to raise_error }
end

it { expect { subject }.not_to raise_error }
context 'when provides "216f81008000911870a54771049010506000000d323232ffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000"' do
before do
allow(instance).to receive(:non_blocking_read_switch) { "01030000000000000000480000000000000000" }
allow(instance).to receive(:send_procon)
allow(instance).to receive(:non_blocking_read_procon) { ["216f81008000911870a54771049010506000000d323232ffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000"].pack('H*') }
allow(instance).to receive(:send_switch)
end

it { expect { subject }.not_to raise_error }
end
end
end

0 comments on commit 91a57a3

Please sign in to comment.