apiotics_factory 1.0.12 → 1.0.13

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: 95734d4ab16fa4e71e6f4ee5703c3db3a04504db
4
- data.tar.gz: 257e8b067ae47c1820e2bdcfad41af83f4bd694d
3
+ metadata.gz: c59e4c2af33710657bcf828cac7f8fad3a31020d
4
+ data.tar.gz: b35cff21244a958ca0a4de7c03aa720eb53ac6a3
5
5
  SHA512:
6
- metadata.gz: 1ae45143b10d166ff4555bf9ec1c9bd7742ce2436b3fb657e12168096dd443f3fba73c59b9cda6689c61f1374c245ef7f373a431d3221c4f9da9b26eef0b0773
7
- data.tar.gz: 70c1d654675dfd1ebf7abf536786b8dc4c7e7c12909df268cd7e9f4f4dd18ecc2d94a130c6238209c18535db446342a8b2c325322afb1ff81a1ce05a8ab0e0f0
6
+ metadata.gz: 20530e3885b7bab8fb53a069745f0be79ec34d59d39ce0805011100548d09e10d60acfab728130ef91852907639af4f001eea66f6fb925409e6748fc1c277d31
7
+ data.tar.gz: 409a7a0181e5a6d84bac9910ae51ace88a5c9511e2f3c491106bd56c83e2c7ed43d90946001b7e3297d7c8cfe70a523d7fd6d2a91578ea4c424d82123adfa70f
@@ -1,3 +1,3 @@
1
1
  module ApioticsFactory
2
- VERSION = '1.0.12'
2
+ VERSION = '1.0.13'
3
3
  end
@@ -13,18 +13,24 @@ class <%= @driver_name %> < ApioticsDriver
13
13
  <% @interfaces["all"].each do |k, v|%>
14
14
  <% unless k == "port" || k == "delay" %>
15
15
  <% if v["accessor"] == "write only" || v["accessor"] == "read/write" %>
16
- def <%= "write_#{k}(#{v["type"]})"%>
16
+ def <%= "write_#{k}(#{v["type"]})"%>
17
+ # IF YOU ARE USING GROVE PI PERIPHERALS, UNCOMMENT THE GrovePi.get_lock AND GrovePi.release_lock LINES BELOW.
18
+ # GrovePi.get_lock
17
19
 
18
20
  # Your hardware specific logic to set the state of your <%= k %> hardware goes here based on the value of the <%= v['type'] %> variable.
19
21
 
22
+ # GrovePi.release_lock
20
23
  self.send_msg(<%= v["type"]%>) # This line sends a confirmation message back to the web application noting that the operation is complete.
21
24
  end
22
25
  <% end %>
23
26
  <% if v["accessor"] == "read only" || v["accessor"] == "read/write" %>
24
27
  def <%= "read_#{k}"%>
28
+ # IF YOU ARE USING GROVE PI PERIPHERALS, UNCOMMENT THE GrovePi.get_lock AND GrovePi.release_lock LINES BELOW.
29
+ # GrovePi.get_lock
25
30
 
26
31
  # Your hardware specific logic here should read a value from your <%= k %> hardware, and set the <%= v["type"] %> variable appropriately.
27
32
 
33
+ # GrovePi.release_lock
28
34
  self.send_msg(<%= v["type"]%>) # This line sends the value in the <%= v["type"] %> variable to the web application.
29
35
  end
30
36
  <% end %>
@@ -1,9 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module GrovePi
4
+ require 'json'
4
5
  require_relative 'i2c'
5
6
  require_relative 'i2c/driver/i2c-dev'
6
7
 
8
+ at_exit do
9
+ release_lock
10
+ end
11
+
7
12
  # Commands.
8
13
  CMD_READ_DIGITAL = 1
9
14
  CMD_WRITE_DIGITAL = 2
@@ -54,10 +59,18 @@ module GrovePi
54
59
  # LCD RGB display - I2C addresses
55
60
  DISPLAY_TEXT_ADDRESS = 0x3e #0x3e
56
61
  DISPLAY_RGB_ADDRESS = 0x62 #0x62
57
-
62
+
63
+
64
+ # Initialize the lock file path.
65
+ LOCK_FILE_PATH = "/tmp/grove"
58
66
 
59
67
  # The initialized I2C object.
60
68
  @_i2c_grove_pi = nil
69
+
70
+ # Initialize i2c file path
71
+ @_i2c_device_file = nil
72
+
73
+
61
74
 
62
75
  # Storage for I2C slave addresses present on ports I2C-1, I2C-2 or I2C-3.
63
76
  @_i2c_slave_addresses = Hash.new
@@ -114,13 +127,33 @@ module GrovePi
114
127
 
115
128
  return false, nil
116
129
  end
130
+
131
+ def self.get_lock
132
+ cycle = true
133
+ while cycle == true
134
+ begin
135
+ @_i2c_device_file = File.open(LOCK_FILE_PATH, File::WRONLY|File::CREAT|File::EXCL)
136
+ cycle = false
137
+ rescue
138
+ sleep 0.1
139
+ end
140
+ end
141
+ end
142
+
143
+ def self.release_lock
144
+ if @_i2c_device_file.is_a(File)
145
+ @_i2c_device_file.close
146
+ File.delete(LOCK_FILE_PATH)
147
+ @_i2c_device_file = nil
148
+ end
149
+ end
117
150
 
118
151
  def self._grove_pi_init()
119
- status, i2c_device_file = self._grove_pi_discover
152
+ status, @_i2c_device_file = self._grove_pi_discover
120
153
 
121
- if status && i2c_device_file != nil
154
+ if status && @_i2c_device_file != nil
122
155
  return I2CDevice.new address: GROVE_PI_I2C_SLAVE_ADDRESS,
123
- driver: I2CDevice::Driver::I2CDev.new(i2c_device_file)
156
+ driver: I2CDevice::Driver::I2CDev.new(_@i2c_device_file)
124
157
  else
125
158
  return nil
126
159
  end
@@ -133,6 +166,9 @@ module GrovePi
133
166
  if @_i2c_grove_pi == nil
134
167
  raise 'No GrovePi found.'
135
168
  end
169
+ unless @_i2c_device_file.is_a(File)
170
+ raise "Unable to secure lock on #{LOCK_FILE_PATH}."
171
+ end
136
172
  end
137
173
  end
138
174
 
@@ -40,16 +40,13 @@ class I2CDevice::Driver::I2CDev < I2CDevice::Driver::Base
40
40
  def i2cget(address, param, length)
41
41
  i2c = File.open(@path, "r+")
42
42
  begin
43
- i2c.flock(File::LOCK_EX)
44
43
  i2c.ioctl(@slave_command, address)
45
44
  i2c.syswrite(param.chr) unless param.nil?
46
45
  ret = i2c.sysread(length)
47
- i2c.flock(File::LOCK_UN)
48
46
  i2c.close
49
47
  ret
50
48
  rescue => e
51
49
  puts e.message
52
- i2c.flock(File::LOCK_UN)
53
50
  end
54
51
  rescue Errno::EIO => e
55
52
  raise I2CDevice::I2CIOError, e.message
@@ -59,14 +56,11 @@ class I2CDevice::Driver::I2CDev < I2CDevice::Driver::Base
59
56
  def i2cset(address, *data)
60
57
  i2c = File.open(@path, "r+")
61
58
  begin
62
- i2c.flock(File::LOCK_EX)
63
59
  i2c.ioctl(@slave_command, address)
64
60
  i2c.syswrite(data.pack("C*"))
65
- i2c.flock(File::LOCK_UN)
66
61
  i2c.close
67
62
  rescue => e
68
63
  puts e.message
69
- i2c.flock(File::LOCK_UN)
70
64
  end
71
65
  rescue Errno::EIO => e
72
66
  raise I2CDevice::I2CIOError, e.message
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.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apiotics