apiotics_factory 1.0.9 → 1.0.10

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
  SHA1:
3
- metadata.gz: 9f26ab3e02dbf8d9e2ef12cb78aa6b18dcbdccce
4
- data.tar.gz: 00bcae0c277e65b2563cf50819657ca7052ecab8
3
+ metadata.gz: cb99cea55e392ce659821534aa4035d7b027a208
4
+ data.tar.gz: 5061c5353562c4e3058e5b377e468421df05f829
5
5
  SHA512:
6
- metadata.gz: 6bf0b67c00a2538631a3588f3a36cf9ad19cab3b71e357144e34eede89c761c42095d6ad03bed6c1d2e2b5bbcd7e0d27c3f61f58b1128bf3670d2ed3e7893403
7
- data.tar.gz: c19dd6553b9ae704e3469300910cbe4a08857a55526475bcc565bc57c804e8daa09231c7ae6c74a88ba553334369dcffe9e85f4ce41189c60fb5768e756d57df
6
+ metadata.gz: c640a055093018dd3f5f21e865c585773575a414695570ab49b6c5a9c44b6a57d726448ca8327cef0ea6735b611c0b370bb6095dff4b728bba42ee4d9345207b
7
+ data.tar.gz: 8c42c5c0f5f7a0087e1c836042aba5e703213aec34ee8b056bd10452f4111b6629684a55ba5fcea980c9569d4f6097a32c2a6d6b025721796bc3ae9df6b9c90b
@@ -1,3 +1,3 @@
1
1
  module ApioticsFactory
2
- VERSION = '1.0.9'
2
+ VERSION = '1.0.10'
3
3
  end
@@ -41,7 +41,7 @@ module GrovePi
41
41
  D7 = 7
42
42
  D8 = 8
43
43
 
44
- PINS_DIGITAL = [D2, D3, D4, D5, D6, D7, D8]
44
+ PINS_DIGITAL = [D2, D3, D4, D5, D6, D7, D8, A2] #added A2 to test using analog port as digital
45
45
 
46
46
  # Pin modes.
47
47
  PIN_MODE_IN = 0
@@ -209,7 +209,8 @@ module GrovePi
209
209
  begin
210
210
  self._set_pin_mode pin, PIN_MODE_IN
211
211
  return self._read_digital pin
212
- rescue Errno::EREMOTEIO
212
+ rescue => e
213
+ puts e.message
213
214
  next
214
215
  end
215
216
  end
@@ -310,26 +311,41 @@ module GrovePi
310
311
  # Temperature and Humidity Sensor
311
312
 
312
313
  # Read temperature and humidity values from sensor
313
- def self.read_temp_humidity(pin)
314
+ def self.read_temp_humidity(pin, sensor_version)
314
315
  self._ensure_init
316
+
317
+ # if sensor is white: module_type = 1, if sensor is blue: module_type = 0
318
+ if sensor_version == "white"
319
+ module_type = 1
320
+ else
321
+ module_type = 0
322
+ end
315
323
 
316
- module_type = 1 # if sensor is white: module_type = 1, if sensor is blue: module_type = 0
317
- @_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_READ_TEMP_HUM, pin, module_type, 0)
324
+ error = false
325
+ begin
326
+ @_i2c_grove_pi.i2cset(@_i2c_grove_pi.address, CMD_READ_TEMP_HUM, pin, module_type, 0)
327
+ rescue => e
328
+ puts e.message
329
+ error = true
330
+ end
318
331
 
319
- for i in 0..CONFIG_RETRIES - 1
320
- begin
321
- # read one byte
322
- @_i2c_grove_pi.i2cget(@_i2c_grove_pi.address, 1)
323
332
 
324
- # read 10 more bytes
325
- number = @_i2c_grove_pi.i2cget(@_i2c_grove_pi.address, 9)
326
-
327
- temp_value = number[1..4].unpack('f')[0].round(2) * 9/5 + 32 #convert to F
328
- humidity_value = number[5..8].unpack('f')[0].round(2)
333
+ if error == false
334
+ for i in 0..CONFIG_RETRIES - 1
335
+ begin
336
+ # read one byte
337
+ @_i2c_grove_pi.i2cget(@_i2c_grove_pi.address, 1)
329
338
 
330
- return temp_value, humidity_value
331
- rescue Errno::EREMOTEIO
332
- next
339
+ # read 10 more bytes
340
+ number = @_i2c_grove_pi.i2cget(@_i2c_grove_pi.address, 9)
341
+
342
+ temp_value = number[1..4].unpack('f')[0].round(2) * 9/5 + 32 #convert to F
343
+ humidity_value = number[5..8].unpack('f')[0].round(2)
344
+
345
+ return temp_value, humidity_value
346
+ rescue Errno::EREMOTEIO
347
+ next
348
+ end
333
349
  end
334
350
  end
335
351
  end
@@ -10,32 +10,62 @@ class I2CDevice::Driver::GPIO < I2CDevice::Driver::Base
10
10
 
11
11
  def self.export(pin) #:nodoc:
12
12
  File.open("/sys/class/gpio/export", "w") do |f|
13
- f.syswrite(pin)
13
+ begin
14
+ f.flock(FILE::LOCK_EX)
15
+ f.syswrite(pin)
16
+ f.flock(FILE::LOCK_UN)
17
+ rescue
18
+ f.flock(FILE::LOCK_UN)
19
+ end
14
20
  end
15
21
  end
16
22
 
17
23
  def self.unexport(pin) #:nodoc:
18
24
  File.open("/sys/class/gpio/unexport", "w") do |f|
19
- f.syswrite(pin)
25
+ begin
26
+ f.flock(FILE::LOCK_EX)
27
+ f.syswrite(pin)
28
+ f.flock(FILE::LOCK_UN)
29
+ rescue
30
+ f.flock(FILE::LOCK_UN)
31
+ end
20
32
  end
21
33
  end
22
34
 
23
35
  def self.direction(pin, direction) #:nodoc:
24
36
  # [:in, :out, :high, :low].include?(direction) or raise "direction must be :in, :out, :high or :low"
25
37
  File.open("/sys/class/gpio/gpio#{pin}/direction", "w") do |f|
26
- f.syswrite(direction)
38
+ begin
39
+ f.flock(FILE::LOCK_EX)
40
+ f.syswrite(direction)
41
+ f.flock(FILE::LOCK_UN)
42
+ rescue
43
+ f.flock(FILE::LOCK_UN)
44
+ end
27
45
  end
28
46
  end
29
47
 
30
48
  def self.read(pin) #:nodoc:
31
49
  File.open("/sys/class/gpio/gpio#{pin}/value", "r") do |f|
32
- f.sysread(1).to_i
50
+ begin
51
+ f.flock(FILE::LOCK_EX)
52
+ f.sysread(1).to_i
53
+ f.flock(FILE::LOCK_UN)
54
+ rescue
55
+ f.flock(FILE::LOCK_UN)
56
+ end
33
57
  end
34
58
  end
35
59
 
36
60
  def self.write(pin, val) #:nodoc:
37
61
  File.open("/sys/class/gpio/gpio#{pin}/value", "w") do |f|
38
- f.syswrite(val ? "1" : "0")
62
+ begin
63
+ f.flock(FILE::LOCK_EX)
64
+ f.syswrite(val ? "1" : "0")
65
+ f.flock(FILE::LOCK_UN)
66
+ rescue
67
+ f.flock(FILE::LOCK_UN)
68
+ end
39
69
  end
40
70
  end
41
71
 
@@ -39,11 +39,17 @@ class I2CDevice::Driver::I2CDev < I2CDevice::Driver::Base
39
39
  # Interface of I2CDevice::Driver
40
40
  def i2cget(address, param, length)
41
41
  i2c = File.open(@path, "r+")
42
- i2c.ioctl(@slave_command, address)
43
- i2c.syswrite(param.chr) unless param.nil?
44
- ret = i2c.sysread(length)
45
- i2c.close
46
- ret
42
+ begin
43
+ i2c.flock(FILE::LOCK_EX)
44
+ i2c.ioctl(@slave_command, address)
45
+ i2c.syswrite(param.chr) unless param.nil?
46
+ ret = i2c.sysread(length)
47
+ i2c.flock(FILE::LOCK_UN)
48
+ i2c.close
49
+ ret
50
+ rescue
51
+ f.flock(FILE::LOCK_UN)
52
+ end
47
53
  rescue Errno::EIO => e
48
54
  raise I2CDevice::I2CIOError, e.message
49
55
  end
@@ -51,9 +57,15 @@ class I2CDevice::Driver::I2CDev < I2CDevice::Driver::Base
51
57
  # Interface of I2CDevice::Driver
52
58
  def i2cset(address, *data)
53
59
  i2c = File.open(@path, "r+")
54
- i2c.ioctl(@slave_command, address)
55
- i2c.syswrite(data.pack("C*"))
56
- i2c.close
60
+ begin
61
+ i2c.flock(FILE::LOCK_EX)
62
+ i2c.ioctl(@slave_command, address)
63
+ i2c.syswrite(data.pack("C*"))
64
+ i2c.flock(FILE::LOCK_UN)
65
+ i2c.close
66
+ rescue
67
+ i2c.flock(FILE::LOCK_UN)
68
+ end
57
69
  rescue Errno::EIO => e
58
70
  raise I2CDevice::I2CIOError, e.message
59
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiotics_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apiotics
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.2.2
110
+ rubygems_version: 2.6.10
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: A Gem To Generate Apiotics Drivers