hcitools_wrapper 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d603be0aa030331923e1af810fcc67eacec6ed8c
4
- data.tar.gz: cb86854699886e27cb9a76383aad2fa3a3dbe889
3
+ metadata.gz: 4226dd2bf64738ccdefdefc96c7a145d70d892a3
4
+ data.tar.gz: 0129f4c5a91819e35d99fb3084dd247f5a66357d
5
5
  SHA512:
6
- metadata.gz: 96463bfe68d72bb6fa5edb1d0e48e2d9d60bf20a3d97095dfbfad2085d4e11e5acea563e2120847be9083c404264681863bc24e5e460fa5614f81495ba867ab8
7
- data.tar.gz: 485757bb6a2fa78aa047271c095ccc8d05c613310ca9710f5c5497f8d244593babb0d3988f46df5f829b6b423d256f51efe5cf9a8b07cb00be5113fb8bbf75aa
6
+ metadata.gz: 79b4edc9248b0dadce8fa70c2436378b843dba037a55ff1950e8a68d9f1964c268f3186d32d80064fb69ddd3cdfaa6d03673ac55172873af070b5c315c4d0281
7
+ data.tar.gz: 2984d116ff14eed0470e3d152bc803d1ddb250dfd7ea023ace7da991d3b331e22d6adb119a646691d174186d63e1ab1a5cefdddd554b64ed89e41ca248c47002
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1 @@
1
- uq�G�����΅ך��Ab��W��J�ń��S�ݞ爤J��Y�\��z�����B�⌱�\lu��_bhn��� � �H��������OՇ0�|���g��t����f�ƺ��2������ ��@����IGN�i��|��:pOT��������b?�M׆����t��Ӷ@��T���
2
- ��gΉ��9�'���&�x���Ӛ�$)
1
+ ��&�ڴx� 3E����[��l�w��Y#{��6jyp(PN�l Qgb�ӹ�
data.tar.gz.sig CHANGED
Binary file
@@ -31,10 +31,10 @@ module HcitoolsWrapper
31
31
 
32
32
  class Detect
33
33
 
34
- def initialize(bd_address: '', interval: 0, verbose: false)
34
+ def initialize(bd_address: '', refreshinterval: 60, verbose: false)
35
35
 
36
36
  @bd_address = bd_address
37
- @interval = interval
37
+ @refreshinterval = refreshinterval
38
38
  @verbose = verbose
39
39
 
40
40
  end
@@ -45,44 +45,38 @@ module HcitoolsWrapper
45
45
  found, last_found = false, Time.now - 60
46
46
  a = []
47
47
 
48
- t3 = Time.now + @interval
49
48
 
50
49
  IO.popen('sudo hcidump --raw').each_line do |x|
51
50
 
52
51
  found = if found then
53
52
 
54
53
  rssi = (x.split.last.hex - 256)
55
- a << rssi.to_i unless a.include? rssi.to_i
56
- h = {bdaddress: @bd_address, rssi: rssi.inspect}
54
+ a << rssi unless a.include? rssi
55
+ h = {bdaddress: @bd_address, rssi: rssi}
57
56
 
58
- if t3 <= Time.now then
57
+ avg = a.max + (a.min - a.max) / 2
59
58
 
60
- avg = a.max + (a.min - a.max) / 2
59
+ if @verbose then
60
+ puts Time.now.inspect + ': ' + h.inspect
61
+ puts "max: %s, min: %s, average: %s, a: %s" % \
62
+ [a.max, a.min, avg, a.sort.inspect]
61
63
 
62
- if @verbose then
63
- puts Time.now.inspect + ': ' + h.inspect
64
- puts "max: %s, min: %s, average: %s, a: %s" % \
65
- [a.max, a.min, avg, a.sort.inspect]
66
-
67
- end
68
-
69
- recent_movement = Time.now - last_found >= 60
70
-
71
- # the RSSI will vary by up to 10 when the device is stationary
72
- if recent_movement or a.length > 10 or rssi > (a.max + 10) or rssi < (a.min - 10) then
64
+ end
65
+
66
+ recent_movement = Time.now - last_found >= @refreshinterval
73
67
 
74
- puts 'movement!' if @verbose
75
-
76
- if block_given? then
77
- yield a, avg
78
- end
68
+ # the RSSI will vary by up to 10 when the device is stationary
69
+ if recent_movement or a.length > 10 then
79
70
 
80
- a = []
71
+ puts 'movement!' if @verbose
72
+
73
+ if block_given? then
74
+ yield( a, rssi == a.min ? rssi : avg)
81
75
  end
82
76
 
83
- t3 = Time.now + @interval
77
+ a = []
84
78
  end
85
-
79
+
86
80
  last_found = Time.now
87
81
 
88
82
  false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hcitools_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file