rpi-dht 0.1.1 → 0.1.2

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: 623ee424958f626dcb1cf34d07cc8486334c7175ab0dd606eb452c43e5cdb6cb
4
- data.tar.gz: c430f89fc5e112381f951f94b95badb8afd3566ed8ba68439d9af5d11a95b39a
3
+ metadata.gz: e0a69dfa6fd94bf7b56d6f66f5973b05b61abbe62cbf0661f18b5d2f59ca59c4
4
+ data.tar.gz: ab93cdc389917a0324393ef7b31d8a77e0eaea99fc18e06728c19257aeab85b9
5
5
  SHA512:
6
- metadata.gz: 384ffcfc2dc165368551403e6cfedc5a427b143f55b0e736d2d0adbcb1f56b3cacc115996990811d95a582c167d9c07e38714f07a3ec1be2ad3c601a96938e66
7
- data.tar.gz: c16747e3cab7587fe1559c702fb38d852c2b79d7042d192d4a80ca56103ad139232ca6e18554aa2cc3c4b8daaf1ba34682a04a0eca52ceb108f8dd905600015c
6
+ metadata.gz: 27dfb4cbe157a5225a271af035ed60a22b20d6302cd2a391a0047e232198ccaeb257d88c79d9bb5baf166408803969b5e5d9e949d54e61af0d99db2b3d63bede
7
+ data.tar.gz: 13fece35fa376964d948a4869dfb8e6bae18a01e20213493f18d984da4acf59c323aacfbef8f8331098fbcf3e7083406276d59d01ee1883ac8a0eae869456915
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rpi-dht (0.1.0)
4
+ rpi-dht (0.1.2)
5
5
  rpi_gpio
6
6
 
7
7
  GEM
@@ -25,6 +25,7 @@ module RPi
25
25
  tries.to_i.times do
26
26
  value = ignore_exception { read!(pin) }
27
27
  return value if value.is_a?(Hash)
28
+ sleep 0.1
28
29
  end
29
30
 
30
31
  nil
@@ -100,38 +101,39 @@ module RPi
100
101
  # ...
101
102
  # ...
102
103
 
103
- # end_part (useless)
104
+ # end_part (useless), but it's an indicator that 40 pairs before this is the data
104
105
  # after data, it ends with short period of falses then eternal trues
105
106
  # [false, false, false, ...]
106
107
  # [true, true, true, true, true, true, true, true, true, ...]
107
- end_part, *low_high_pairs = break_by_high_or_low.reverse.each_slice(2).to_a
108
+
109
+ # take last 82 elements and make pairs
110
+ pair = 2
111
+ end_part_pair = pair
112
+ *low_high_pairs, end_part =
113
+ break_by_high_or_low.last(VALID_BYTE_SIZE * BITS_IN_BYTE * pair + end_part_pair)
114
+ .each_slice(2).to_a
108
115
 
109
116
  # https://i.gyazo.com/baba7ce475e945c732491a6afc9e4b9a.png
110
117
  # low_high_pairs = [
111
118
  # ture / false array pair = 1bit
112
119
  # 8elements of them = 1byte worth of data
113
120
  # [
114
- # [[true, true ...], [false, false ...]], 1
115
- # [[true, true ...], [false, false ...]], 2
116
- # [[true, true ...], [false, false ...]], 3
117
- # [[true, true ...], [false, false ...]], 4
118
- # [[true, true ...], [false, false ...]], 5
119
- # [[true, true ...], [false, false ...]], 6
120
- # [[true, true ...], [false, false ...]], 7
121
- # [[true, true ...], [false, false ...]], 8
121
+ # [[false, false ...], [true, true ...]], 1
122
+ # [[false, false ...], [true, true ...]], 2
123
+ # [[false, false ...], [true, true ...]], 3
124
+ # [[false, false ...], [true, true ...]], 4
125
+ # [[false, false ...], [true, true ...]], 5
126
+ # [[false, false ...], [true, true ...]], 6
127
+ # [[false, false ...], [true, true ...]], 7
128
+ # [[false, false ...], [true, true ...]], 8
122
129
  # ]
123
130
 
124
131
  # ...
125
132
  # total of 5 bytes
126
133
  # ]
127
134
 
128
- response_signal_part_chopped_off =
129
- low_high_pairs.each_slice(8).collect(&:reverse).to_a.reverse.last(
130
- VALID_BYTE_SIZE
131
- )
132
-
133
135
  valid_bytes =
134
- response_signal_part_chopped_off.select do |pair|
136
+ low_high_pairs.each_slice(8).to_a.select do |pair|
135
137
  pair.all? { |x| x.is_a?(Array) }
136
138
  end
137
139
 
@@ -157,13 +159,13 @@ module RPi
157
159
  # [false, false, false, ...],
158
160
  # ...
159
161
  # ]
160
- all_falses = valid_bytes.collect { |byte| byte.collect(&:last) }.flatten(1)
162
+ all_falses = valid_bytes.collect { |byte| byte.collect(&:first) }.flatten(1)
161
163
  average_50us_false_size = all_falses.sum(&:size) / all_falses.size.to_f
162
164
 
163
165
  # https://i.gyazo.com/085693e497f9105bc66392d05112e0d3.png
164
166
  @byte_strings =
165
167
  valid_bytes.collect do |byte|
166
- byte.collect { |trues, _| average_50us_false_size <= trues.size ? 1 : 0 }.join
168
+ byte.collect { |_, trues| average_50us_false_size <= trues.size ? 1 : 0 }.join
167
169
  end
168
170
  end
169
171
 
@@ -1,5 +1,5 @@
1
1
  module RPi
2
2
  module Dht
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpi-dht
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - github0013