udooneorest 1.0.1 → 1.0.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
  SHA1:
3
- metadata.gz: 8423f087b238671a8fe5502d8fbf21576baa1d96
4
- data.tar.gz: 83933c1d73407f6061f1959a5d8d4a2a3372c872
3
+ metadata.gz: 34262ec7219cedb8d2adbe2f6572bc85051bddc1
4
+ data.tar.gz: 922373c8b181a581882583375c2eb718f518dfb9
5
5
  SHA512:
6
- metadata.gz: 9248abf15b708af872b9a35ae9b337a21af46bca99f6fc80a6bdfe3e6b6ad3d4adf8aa02265051caa83602c5e45afa5e14fdc685b21d0fb94726f0e9d81b602d
7
- data.tar.gz: ba619decc1c3d2d05510f5b09e4fa9575bef4d5c779a9df008471b56987274b93c246ebc5429e183d00e219091bd36a941249a3e86bb2fa4d49a08b57856a927
6
+ metadata.gz: 6f981131c2732cc2064c0b88804fb5a76f0c3e24d43be544a70152c1b4b8bdfbea4cc8496939e039cb42630d00b37a74ec0c5f9bc6400a5ee309a5d6b6a7730c
7
+ data.tar.gz: 6c6ee991662b996d85f89eacc8b6b513ff33abffa6354b4db381a1edb08af1419659516b297c5c131cb21d8d245fd68b85ecd162e69c82ed4f9b6f8d2a15d2fa
@@ -11,7 +11,7 @@ require_relative 'udooneorest/barometer'
11
11
  require_relative 'udooneorest/temperature'
12
12
 
13
13
 
14
- GPIOS = %w(106 107 180 181 172 173 182 124 25 22 14 15 16 17 18 19 20 21 203 202 177 176 175 174 119 124 127 116 7 6 5 4)
14
+ GPIOS = %w(178 179 104 143 142 141 140 149 105 148 146 147 100 102 NA NA 106 107 180 181 172 173 182 124 25 22 14 15 16 17 18 19 20 21 203 202 177 176 175 174 119 124 127 116 7 6 5 4)
15
15
  HELP_URL = 'http://github.com/marksull/udooneorest'
16
16
  BASE_PATH = '/sys/class/gpio/'
17
17
  VALUE_LOW = '0'
@@ -79,7 +79,11 @@ module UdooNeoRest
79
79
  # file : the file to cat
80
80
  #
81
81
  def self.cat(file)
82
- File.read(file).chomp
82
+ begin
83
+ return File.read(file).chomp
84
+ rescue Exception => e
85
+ return nil
86
+ end
83
87
  end
84
88
 
85
89
  #############################################################################
@@ -133,7 +137,12 @@ module UdooNeoRest
133
137
  # file : the file to cat
134
138
  #
135
139
  def self.cat_and_status(file)
136
- UdooNeoRest::Base.status_ok(UdooNeoRest::Base.cat file)
140
+ result = UdooNeoRest::Base.cat file
141
+ unless result.nil?
142
+ return UdooNeoRest::Base.status_ok result
143
+ end
144
+
145
+ return UdooNeoRest::Base.status_error 'GPIO/PIN could not be read. Have you already exported the GPIO/PIN?'
137
146
  end
138
147
 
139
148
  #############################################################################
@@ -64,7 +64,7 @@ module UdooNeoRest
64
64
  return gpio_.error_message unless gpio_.valid?
65
65
 
66
66
  # get the direction
67
- UdooNeoRest::Base.status_ok(UdooNeoRest::Base.cat "#{BASE_PATH}gpio#{gpio}/direction")
67
+ UdooNeoRest::Base.cat_and_status "#{BASE_PATH}gpio#{gpio}/direction"
68
68
  end
69
69
 
70
70
  #############################################################################
@@ -49,8 +49,8 @@ module UdooNeoRest
49
49
  class ValidateGpio < Validate
50
50
 
51
51
  def valid?
52
- unless GPIOS.include?(@value)
53
- @error_message = UdooNeoRest::Base.status_error("GPIO value of '#{@value}' is invalid. Should be one of #{GPIOS.sort.join(',')}.")
52
+ unless GPIOS.include?(@value) && (@value != 'NA')
53
+ @error_message = UdooNeoRest::Base.status_error("GPIO value of '#{@value}' is invalid. Should be one of #{(GPIOS - ['NA']).sort.join(',')}.")
54
54
  return false
55
55
  end
56
56
 
@@ -93,8 +93,8 @@ module UdooNeoRest
93
93
  end
94
94
 
95
95
  def valid?
96
- if (16 > @value || @value > 47)
97
- @error_message = UdooNeoRest::Base.status_error("Pin value of '#{@value}' is invalid. Should be between >=16 and <=47.")
96
+ if (@value > 47) || (GPIOS[@value] == 'NA')
97
+ @error_message = UdooNeoRest::Base.status_error("Pin value of #{@value} is invalid. Please refer to UDOO Neo documentation.")
98
98
  return false
99
99
  end
100
100
 
@@ -107,7 +107,7 @@ module UdooNeoRest
107
107
  #
108
108
  def to_gpio
109
109
  return nil unless valid?
110
- GPIOS[@value-16]
110
+ GPIOS[@value]
111
111
  end
112
112
 
113
113
  end
@@ -64,7 +64,7 @@ module UdooNeoRest
64
64
  return gpio_.error_message unless gpio_.valid?
65
65
 
66
66
  # Get the value
67
- UdooNeoRest::Base.status_ok(UdooNeoRest::Base.cat "#{BASE_PATH}gpio#{gpio}/value")
67
+ UdooNeoRest::Base.cat_and_status "#{BASE_PATH}gpio#{gpio}/value"
68
68
  end
69
69
 
70
70
  #############################################################################
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: udooneorest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Sullivan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-13 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  requirements: []
68
68
  rubyforge_project:
69
- rubygems_version: 2.2.1
69
+ rubygems_version: 2.2.2
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Rest API for interacting with UDOO Neo