Skip to content

Commit e7bccdd

Browse files
committed
カウンターが1バイトをこえないようにする
1 parent 9621fa7 commit e7bccdd

File tree

6 files changed

+37
-31
lines changed

6 files changed

+37
-31
lines changed

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ source "https://rubygems.org"
55
# Specify your gem's dependencies in switch_connection_manager.gemspec
66
gemspec
77

8-
gem "rake", "~> 13.0"
8+
gem "rake"
99
gem "rspec"
10+
gem "pry"

Gemfile.lock

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ PATH
66
GEM
77
remote: https://rubygems.org/
88
specs:
9+
coderay (1.1.3)
910
diff-lcs (1.5.0)
11+
method_source (1.0.0)
12+
pry (0.14.1)
13+
coderay (~> 1.1)
14+
method_source (~> 1.0)
1015
rake (13.0.6)
1116
rspec (3.11.0)
1217
rspec-core (~> 3.11.0)
@@ -26,7 +31,8 @@ PLATFORMS
2631
arm64-darwin-20
2732

2833
DEPENDENCIES
29-
rake (~> 13.0)
34+
pry
35+
rake
3036
rspec
3137
switch_connection_manager!
3238

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ TODO: Write usage instructions here
2525
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
2626

2727
## TODO:
28-
* procon_simulatorを起動するとバッテリーが動きまくるのを直す
2928
* PBMとプロコンをbluetoothで接続する
3029
* usb gadgetをresetしてからすぐにavailableになる時と、数秒開けないとavailableにならない時がある.
3130
* readとかすれば状態を認知できて適切なインターバルがわかるかも

lib/switch_connection_manager/procon_simulator.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ def response(data)
124124
end
125125

126126
def response_counter
127+
@response_counter = @response_counter + 1
127128
if @response_counter >= 256
128-
@response_counter = 0
129+
@response_counter = "0"
129130
else
130-
@response_counter = @response_counter + 1
131+
@response_counter.to_s
131132
end
132-
@response_counter.to_s.rjust(2, "0")
133133
end
134134

135135
def write(data)

spec/procon_simulator_spec.rb

+24-25
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
let(:simulator) { described_class.new }
77

88
describe '#response_counter' do
9-
it '256の次は0になること' do
10-
255.times do
9+
it '255の次は0になること' do
10+
254.times do
1111
simulator.send(:response_counter)
1212
end
13-
14-
expect(simulator.send(:response_counter)).to eq("256")
15-
expect(simulator.send(:response_counter)).to eq("00")
13+
expect(simulator.send(:response_counter)).to eq("255")
14+
expect(simulator.send(:response_counter)).to eq("0")
1615
end
1716
end
1817

@@ -72,26 +71,26 @@
7271
expect(simulator.read_once).to eq("0000")
7372
expect(simulator.read_once).to match("8101000300005e00535e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
7473
expect(simulator.read_once).to match("81020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
75-
expect(simulator.read_once).to match(/^21..#{initial_input}800300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-03
76-
expect(simulator.read_once).to match(nil)
77-
expect(simulator.read_once).to match(/^21..#{initial_input}804800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-48
78-
expect(simulator.read_once).to match(/^21..#{initial_input}820203480302#{procon_mac_addr.reverse}030100000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-02
79-
expect(simulator.read_once).to match(/^21..#{initial_input}800800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-08
80-
expect(simulator.read_once).to match(/^21..#{initial_input}90100060000010ffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000/) # 01-10-0060, Serial number
81-
expect(simulator.read_once).to match(/^21..#{initial_input}90105060000010bc114275a928ffffffffffffff00000000000000000000000000000000000000000000000000000000000000/) # Controller Color
82-
expect(simulator.read_once).to match(/^21..#{initial_input}810103000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-01, Bluetooth manual pairing
83-
expect(simulator.read_once).to match(/^21..#{initial_input}83040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-04, Trigger buttons elapsed time
84-
expect(simulator.read_once).to match(/^21..#{initial_input}9010806000001050fd0000c60f0f30619630f3d41454411554c7799c333663000000000000000000000000000000000000000/) # 01-10-8060, Factory Sensor and Stick device parameters
85-
expect(simulator.read_once).to match(/^21..#{initial_input}901098600000100f30619630f3d41454411554c7799c333663000000000000000000000000000000000000000000000000000/) # 01-10-9860, Factory Stick device parameters 2
86-
expect(simulator.read_once).to match(/^21..#{initial_input}90101080000010ffffffffffffffffffffffffffffffffffffffffffffb2a1000000000000000000000000000000000000000/) # 01-10-1080, User Analog sticks calibration
87-
expect(simulator.read_once).to be_nil # unkown
88-
expect(simulator.read_once).to match(/^21..#{initial_input}90103d60000010ba156211b87f29065bffe77e0e36569e8560ff323232ffffff0000000000000000000000000000000000000/) # 01-10-3d60, Factory configuration & calibration 2
89-
expect(simulator.read_once).to match(/^21..#{initial_input}90102880000010beff3e00f001004000400040fefffeff0800e73be73be73b000000000000000000000000000000000000000/) # 01-10-2880, User 6-Axis Motion Sensor calibration
90-
expect(simulator.read_once).to match(/^21..#{initial_input}80400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-40
91-
expect(simulator.read_once).to be_nil # unkown
92-
expect(simulator.read_once).to match(/^21..#{initial_input}80480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-40
93-
expect(simulator.read_once).to match(/^21..#{initial_input}80480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-40
94-
expect(simulator.read_once).to match(/^21..#{initial_input}80300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-40
74+
expect(simulator.read_once).to match(/^21.#{initial_input}8003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-03
75+
expect(simulator.read_once).to match(nil)
76+
expect(simulator.read_once).to match(/^21.#{initial_input}804800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-48
77+
expect(simulator.read_once).to match(/^21.#{initial_input}820203480302#{procon_mac_addr.reverse}0301000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-02
78+
expect(simulator.read_once).to match(/^21.#{initial_input}8008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-08
79+
expect(simulator.read_once).to match(/^21.#{initial_input}90100060000010ffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000/) # 01-10-0060, Serial number
80+
expect(simulator.read_once).to match(/^21.#{initial_input}90105060000010bc114275a928ffffffffffffff000000000000000000000000000000000000000000000000000000000000000/) # Controller Color
81+
expect(simulator.read_once).to match(/^21.#{initial_input}8101030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-01, Bluetooth manual pairing
82+
expect(simulator.read_once).to match(/^21.#{initial_input}830400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-04, Trigger buttons elapsed time
83+
expect(simulator.read_once).to match(/^21.#{initial_input}9010806000001050fd0000c60f0f30619630f3d41454411554c7799c3336630000000000000000000000000000000000000000/) # 01-10-8060, Factory Sensor and Stick device parameters
84+
expect(simulator.read_once).to match(/^21..?#{initial_input}901098600000100f30619630f3d41454411554c7799c3336630000000000000000000000000000000000000000000000000000/) # 01-10-9860, Factory Stick device parameters 2
85+
expect(simulator.read_once).to match(/^21..?#{initial_input}90101080000010ffffffffffffffffffffffffffffffffffffffffffffb2a10000000000000000000000000000000000000000/) # 01-10-1080, User Analog sticks calibration
86+
expect(simulator.read_once).to be_nil # unkown
87+
expect(simulator.read_once).to match(/^21..?#{initial_input}90103d60000010ba156211b87f29065bffe77e0e36569e8560ff323232ffffff00000000000000000000000000000000000000/) # 01-10-3d60, Factory configuration & calibration 2
88+
expect(simulator.read_once).to match(/^21..?#{initial_input}90102880000010beff3e00f001004000400040fefffeff0800e73be73be73b0000000000000000000000000000000000000000/) # 01-10-2880, User 6-Axis Motion Sensor calibration
89+
expect(simulator.read_once).to match(/^21..?#{initial_input}804000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-40
90+
expect(simulator.read_once).to be_nil # unkown
91+
expect(simulator.read_once).to match(/^21..?#{initial_input}804800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-40
92+
expect(simulator.read_once).to match(/^21..?#{initial_input}804800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-40
93+
expect(simulator.read_once).to match(/^21..?#{initial_input}803000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/) # 01-40
9594
end
9695
end
9796
end

spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require "pry"
12
require "switch_connection_manager"
23

34
# This file was generated by the `rspec --init` command. Conventionally, all

0 commit comments

Comments
 (0)