udooneorest 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c05a465947a23bb721af3753d43b51e74349e64
4
+ data.tar.gz: 279e4c8a58466597bfc76e5eae1929353959d790
5
+ SHA512:
6
+ metadata.gz: 8c7ad84f98bfec09920e7e7b0099666972f77767b90296350b273a777b44604502f6ae0ad429dec6ec5764b275bd8f158d0ea4d62fd1b021b39ddcd24102379c
7
+ data.tar.gz: b447bdc805ca0875b01aa90f8adf376bebff1e1ab78e105f34f9e83cebd59314e8b92c4f09817111381100f89499e574545963cd0a753a158a8b2ff71b9cfb9c
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "sinatra"
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require 'udooneorest'
@@ -0,0 +1,183 @@
1
+ require 'sinatra/base'
2
+
3
+ require_relative 'udooneorest/validators'
4
+ require_relative 'udooneorest/export'
5
+ require_relative 'udooneorest/value'
6
+ require_relative 'udooneorest/direction'
7
+ require_relative 'udooneorest/gyroscope'
8
+ require_relative 'udooneorest/accelerometer'
9
+ require_relative 'udooneorest/magnetometer'
10
+ require_relative 'udooneorest/barometer'
11
+ require_relative 'udooneorest/temperature'
12
+
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)
15
+ HELP_URL = 'http://github.com/marksull/udooneorest'
16
+ BASE_PATH = '/sys/class/gpio/'
17
+ VALUE_LOW = '0'
18
+ VALUE_HIGH = '1'
19
+ DIRECTION_IN = 'in'
20
+ DIRECTION_OUT = 'out'
21
+ FAILED_MESSAGE = 'failed'
22
+ SUCCESS_MESSAGE = 'success'
23
+
24
+ module UdooNeoRest
25
+
26
+ class Base < Sinatra::Application
27
+
28
+ # Have Sinatra listen on all interfaces
29
+ set :bind, '0.0.0.0'
30
+
31
+ #############################################################################
32
+ # Message constructor
33
+ #
34
+ # status : the status of the operation
35
+ # message : the message to be displayed
36
+ #
37
+ def self.status_message(status, message)
38
+ "{'status' : '#{status}', 'message' : '#{message}'}"
39
+ end
40
+
41
+ #############################################################################
42
+ # Construct the status message when no errors occurred
43
+ #
44
+ # message : the message to be displayed
45
+ #
46
+ def self.status_ok(message = '')
47
+ status_message(SUCCESS_MESSAGE, message)
48
+ end
49
+
50
+ #############################################################################
51
+ # Construct the status message when an error occurred
52
+ #
53
+ # message : the message to be displayed
54
+ #
55
+ def self.status_error(message)
56
+ status_message(FAILED_MESSAGE, message)
57
+ end
58
+
59
+ #############################################################################
60
+ # Echo a value to a file
61
+ #
62
+ # value : the value to echo to the file
63
+ # file : the file to echo the value too
64
+ #
65
+ def self.echo(value, file)
66
+ begin
67
+ File.write(file, value)
68
+ rescue Errno::EINVAL
69
+ # close always error on the udoo gpios - cause unknown
70
+ rescue Exception => e
71
+ return e.message
72
+ end
73
+ ''
74
+ end
75
+
76
+ #############################################################################
77
+ # Cat a file
78
+ #
79
+ # file : the file to cat
80
+ #
81
+ def self.cat(file)
82
+ File.read(file).chomp
83
+ end
84
+
85
+ #############################################################################
86
+ # Calculate the Barometer/Temp value from raw and scale values
87
+ #
88
+ def self.sensor_calc(sensor)
89
+ raw = UdooNeoRest::Base.cat(UdooNeoRest::Base.sensor_path(sensor) + '_raw').to_i
90
+ scale = UdooNeoRest::Base.cat(UdooNeoRest::Base.sensor_path(sensor) + '_scale').to_f
91
+ UdooNeoRest::Base.status_ok(raw * scale)
92
+ end
93
+
94
+ #############################################################################
95
+ # Build the path to common sensors
96
+ #
97
+ # sensor : the sensor name
98
+ #
99
+ def self.sensor_path(sensor)
100
+ "/sys/class/i2c-dev/i2c-1/device/1-0060/iio:device0/in_#{sensor}"
101
+ end
102
+
103
+ #############################################################################
104
+ # Build the path to common axis sensors
105
+ #
106
+ # sensor : the sensor name
107
+ #
108
+ def self.axis_path(sensor)
109
+ "/sys/class/misc/Freescale#{sensor}"
110
+ end
111
+
112
+ #############################################################################
113
+ # Build the path to common axis sensors to enable/disable
114
+ #
115
+ # sensor : the sensor name
116
+ #
117
+ def self.axis_path_enable(sensor)
118
+ UdooNeoRest::Base.axis_path(sensor) + '/enable'
119
+ end
120
+
121
+ #############################################################################
122
+ # Build the path to common axis sensors to retrieve data
123
+ #
124
+ # sensor : the sensor name
125
+ #
126
+ def self.axis_path_data(sensor)
127
+ UdooNeoRest::Base.axis_path(sensor) + '/data'
128
+ end
129
+
130
+ #############################################################################
131
+ # Cat a file contents and return the status
132
+ #
133
+ # file : the file to cat
134
+ #
135
+ def self.cat_and_status(file)
136
+ UdooNeoRest::Base.status_ok(UdooNeoRest::Base.cat file)
137
+ end
138
+
139
+ #############################################################################
140
+ # Enable or disable one of the axis sensors
141
+ #
142
+ # Value : 0 disables the axis, 1 enables it
143
+ #
144
+ def self.change_state(file, value)
145
+ result = UdooNeoRest::Base.echo value, file
146
+ result.empty? ? UdooNeoRest::Base.status_ok : UdooNeoRest::Base.status_error(result)
147
+ end
148
+
149
+ #############################################################################
150
+ # Import all the Sinatra routes
151
+ #
152
+ use UdooNeoRest::Value
153
+ use UdooNeoRest::Accelerometer
154
+ use UdooNeoRest::Barometer
155
+ use UdooNeoRest::Gyroscope
156
+ use UdooNeoRest::Magnetometer
157
+ use UdooNeoRest::Temperature
158
+ use UdooNeoRest::Export
159
+ use UdooNeoRest::Direction
160
+
161
+ #############################################################################
162
+ # Show the help documentation
163
+ #
164
+ get '/help' do
165
+ UdooNeoRest::Base.status_ok("Help documentation can be found here: #{HELP_URL}")
166
+ end
167
+
168
+ #############################################################################
169
+ # Default route to catch incorrect API calls
170
+ #
171
+ not_found do
172
+ UdooNeoRest::Base.status_error("This API call is not know. Please refer to the documentation #{HELP_URL}")
173
+ end
174
+ end
175
+
176
+ end
177
+
178
+ UdooNeoRest::Base.run!
179
+
180
+
181
+
182
+
183
+
@@ -0,0 +1,50 @@
1
+ module UdooNeoRest
2
+
3
+ class Accelerometer < Sinatra::Application
4
+
5
+ #############################################################################
6
+ # Routes
7
+ #
8
+ put '/accelerometer/enable' do
9
+ enable '1'
10
+ end
11
+
12
+ put '/accelerometer/disable' do
13
+ enable '0'
14
+ end
15
+
16
+ get '/accelerometer/value' do
17
+ data
18
+ end
19
+
20
+ get '/lazyrest/accelerometer/enable' do
21
+ enable '1'
22
+ end
23
+
24
+ get '/lazyrest/accelerometer/disable' do
25
+ enable '0'
26
+ end
27
+
28
+ get '/lazyrest/accelerometer/value' do
29
+ data
30
+ end
31
+
32
+ #############################################################################
33
+ # Enable/Disable the Accelerometer
34
+ #
35
+ # value : 0 = Disable, 1 = Enable
36
+ #
37
+ def enable(value)
38
+ UdooNeoRest::Base.change_state UdooNeoRest::Base.axis_path_enable('Accelerometer'), value
39
+ end
40
+
41
+ #############################################################################
42
+ # Get the value for the Accelerometer
43
+ #
44
+ def data
45
+ UdooNeoRest::Base.cat_and_status UdooNeoRest::Base.axis_path_data('Accelerometer')
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,18 @@
1
+ module UdooNeoRest
2
+
3
+ class Barometer < Sinatra::Application
4
+
5
+ #############################################################################
6
+ # Routes
7
+ #
8
+ get '/barometer/value' do
9
+ UdooNeoRest::Base.sensor_calc 'pressure'
10
+ end
11
+
12
+ get '/lazyrest/barometer/value' do
13
+ UdooNeoRest::Base.sensor_calc 'pressure'
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,109 @@
1
+ module UdooNeoRest
2
+
3
+ class Direction < Sinatra::Application
4
+
5
+ #############################################################################
6
+ # Routes
7
+ #
8
+ put '/gpio/:gpio/direction/:direction' do
9
+ direction_set_gpio params[:gpio], params[:direction]
10
+ end
11
+
12
+ put '/pin/:pin/direction/:direction' do
13
+ direction_set_pin params[:pin], params[:direction]
14
+ end
15
+
16
+ get '/gpio/:gpio/direction' do
17
+ direction_get_gpio params[:gpio]
18
+ end
19
+
20
+ get '/pin/:pin/direction' do
21
+ direction_get_pin params[:pin]
22
+ end
23
+
24
+ get '/lazyrest/gpio/:gpio/direction/:direction' do
25
+ direction_set_gpio params[:gpio], params[:direction]
26
+ end
27
+
28
+ get '/lazyrest/pin/:pin/direction/:direction' do
29
+ direction_set_pin params[:pin], params[:direction]
30
+ end
31
+
32
+ get '/lazyrest/gpio/:gpio/direction' do
33
+ direction_get_gpio params[:gpio]
34
+ end
35
+
36
+ get '/lazyrest/pin/:pin/direction' do
37
+ direction_get_pin params[:pin]
38
+ end
39
+
40
+ #############################################################################
41
+ # Get the value for a specific pin
42
+ #
43
+ # pin : the pin to be set (will be translated to GPIO)
44
+ #
45
+ def direction_get_pin(pin)
46
+
47
+ # Validate the pin
48
+ pin_ = ValidatePin.new pin
49
+ return pin_.error_message unless pin_.valid?
50
+
51
+ # Get the value after translating to gpio
52
+ direction_get_gpio pin_.to_gpio
53
+ end
54
+
55
+ #############################################################################
56
+ # Get the direction for a specific gpio
57
+ #
58
+ # gpio : the gpio to get
59
+ #
60
+ def direction_get_gpio(gpio)
61
+
62
+ # validate the gpio
63
+ gpio_ = ValidateGpio.new gpio
64
+ return gpio_.error_message unless gpio_.valid?
65
+
66
+ # get the direction
67
+ UdooNeoRest::Base.status_ok(UdooNeoRest::Base.cat "#{BASE_PATH}gpio#{gpio}/direction")
68
+ end
69
+
70
+ #############################################################################
71
+ # Set a specific pin to the nominated direction
72
+ #
73
+ # pin : the pin to be set (will be translated to GPIO)
74
+ # direction : the direction to be used
75
+ #
76
+ def direction_set_pin(pin, direction)
77
+
78
+ # valide the pin
79
+ pin_ = ValidatePin.new pin
80
+ return pin_.error_message unless pin_.valid?
81
+
82
+ # Set the direction after translating to gpio
83
+ direction_set_gpio pin_.to_gpio, direction
84
+ end
85
+
86
+ #############################################################################
87
+ # Set a specific gpio to the nominated direction
88
+ #
89
+ # gpio : the gpio to be set
90
+ # direction : the direction to be used
91
+ #
92
+ def direction_set_gpio(gpio, direction)
93
+
94
+ # validate the gpio
95
+ gpio_ = ValidateGpio.new gpio
96
+ return gpio_.error_message unless gpio_.valid?
97
+
98
+ # validate the direction
99
+ direction_ = ValidateDirection.new direction
100
+ return direction_.error_message unless direction_.valid?
101
+
102
+ # Send the command and if no error return an OK result else return the error
103
+ result = UdooNeoRest::Base.echo direction, "#{BASE_PATH}gpio#{gpio}/direction"
104
+ result.empty? ? UdooNeoRest::Base.status_ok : UdooNeoRest::Base.status_error(result)
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,67 @@
1
+ module UdooNeoRest
2
+
3
+ class Export < Sinatra::Application
4
+
5
+ #############################################################################
6
+ # Routes
7
+ #
8
+ post '/gpio/:gpio/export' do
9
+ export_gpio params[:gpio]
10
+ end
11
+
12
+ post '/pin/:pin/export' do
13
+ export_pin params[:pin]
14
+ end
15
+
16
+ get '/lazyrest/gpio/:gpio/export' do
17
+ export_gpio params[:gpio]
18
+ end
19
+
20
+ get '/lazyrest/pin/:pin/export' do
21
+ export_pin params[:pin]
22
+ end
23
+
24
+ #############################################################################
25
+ # Export using the pin
26
+ #
27
+ # pin : the pin to be exported
28
+ #
29
+ def export_pin(pin)
30
+
31
+ # Validate the pin
32
+ pin_ = ValidatePin.new pin
33
+ return pin_.error_message unless pin_.valid?
34
+
35
+ # Export the value after translating to gpio
36
+ export_gpio pin_.to_gpio
37
+ end
38
+
39
+ #############################################################################
40
+ # Export using the gpio
41
+ #
42
+ # gpio : the gpio to be exported
43
+ #
44
+ def export_gpio(gpio)
45
+
46
+ # lets make sure the gpio is good
47
+ gpio_ = ValidateGpio.new gpio
48
+ return gpio_.error_message unless gpio_.valid?
49
+
50
+ # send the command
51
+ result = UdooNeoRest::Base.echo gpio, "#{BASE_PATH}export"
52
+
53
+ # return ok if all is well
54
+ return UdooNeoRest::Base.status_ok if result.empty?
55
+
56
+ # provide some constructive feedback on the root cause of this specific error
57
+ if result =~ /resource busy/
58
+ return UdooNeoRest::Base.status_error('Resource Busy error occurred. Maybe the gpio has already been exported. It only needs to be exported once.')
59
+ end
60
+
61
+ # otherwise just return the error
62
+ UdooNeoRest::Base.status_error(result)
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,50 @@
1
+ module UdooNeoRest
2
+
3
+ class Gyroscope < Sinatra::Application
4
+
5
+ #############################################################################
6
+ # Routes
7
+ #
8
+ put '/gyroscope/enable' do
9
+ enable '1'
10
+ end
11
+
12
+ put '/gyroscope/disable' do
13
+ enable '0'
14
+ end
15
+
16
+ get '/gyroscope/value' do
17
+ data
18
+ end
19
+
20
+ get '/lazyrest/gyroscope/enable' do
21
+ enable '1'
22
+ end
23
+
24
+ get '/lazyrest/gyroscope/disable' do
25
+ enable '0'
26
+ end
27
+
28
+ get '/lazyrest/gyroscope/value' do
29
+ data
30
+ end
31
+
32
+ #############################################################################
33
+ # Enable/Disable the Gyroscope
34
+ #
35
+ # value : 0 = Disable, 1 = Enable
36
+ #
37
+ def enable(value)
38
+ UdooNeoRest::Base.change_state UdooNeoRest::Base.axis_path_enable('Gyroscope'), value
39
+ end
40
+
41
+ #############################################################################
42
+ # Get the value for the Gyroscope
43
+ #
44
+ def data
45
+ UdooNeoRest::Base.cat_and_status UdooNeoRest::Base.axis_path_data('Gyroscope')
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ module UdooNeoRest
2
+
3
+ class Magnetometer < Sinatra::Application
4
+
5
+ #############################################################################
6
+ # Routes
7
+ #
8
+ put '/magnetometer/enable' do
9
+ enable '1'
10
+ end
11
+
12
+ put '/magnetometer/disable' do
13
+ enable '0'
14
+ end
15
+
16
+ get '/magnetometer/value' do
17
+ data
18
+ end
19
+
20
+ get '/lazyrest/magnetometer/enable' do
21
+ enable '1'
22
+ end
23
+
24
+ get '/lazyrest/magnetometer/disable' do
25
+ enable '0'
26
+ end
27
+
28
+ get '/lazyrest/magnetometer/value' do
29
+ data
30
+ end
31
+
32
+ #############################################################################
33
+ # Enable/Disable the magnetometer
34
+ #
35
+ # value : 0 = Disable, 1 = Enable
36
+ #
37
+ def enable(value)
38
+ UdooNeoRest::Base.change_state UdooNeoRest::Base.axis_path_enable('Magnetometer'), value
39
+ end
40
+
41
+ #############################################################################
42
+ # Get the value for the magnetometer
43
+ #
44
+ def data
45
+ UdooNeoRest::Base.cat_and_status UdooNeoRest::Base.axis_path_data('Magnetometer')
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,18 @@
1
+ module UdooNeoRest
2
+
3
+ class Temperature < Sinatra::Application
4
+
5
+ #############################################################################
6
+ # Routes
7
+ #
8
+ get '/temperature/value' do
9
+ UdooNeoRest::Base.sensor_calc 'temp'
10
+ end
11
+
12
+ get '/lazyrest/temperature/value' do
13
+ UdooNeoRest::Base.sensor_calc 'temp'
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,119 @@
1
+ module UdooNeoRest
2
+
3
+ #############################################################################
4
+ # Base validation class. Override the valid? method
5
+ #
6
+ # value : the value to be validated
7
+ #
8
+ class Validate
9
+
10
+ attr_reader :error_message
11
+ attr_accessor :value
12
+
13
+ def initialize(value)
14
+ @value = value
15
+ @error_message = nil
16
+ valid?
17
+ end
18
+
19
+ def valid?
20
+ raise 'SubclassShouldOverrideValid'
21
+ end
22
+
23
+ end
24
+
25
+ #############################################################################
26
+ # Validate the Direction parameter
27
+ #
28
+ # value : the direction value to be validated
29
+ #
30
+ class ValidateDirection < Validate
31
+
32
+ def valid?
33
+ if (@value != DIRECTION_IN ) && (@value != DIRECTION_OUT)
34
+ @error_message = UdooNeoRest::Base.status_error("Direction value of '#{@value}' is invalid. Should only be 'in' or 'out'.")
35
+ return false
36
+ end
37
+
38
+ @error_message = nil
39
+ true
40
+ end
41
+
42
+ end
43
+
44
+ #############################################################################
45
+ # Validate the GPIO parameter
46
+ #
47
+ # value : the gpio value to be validated
48
+ #
49
+ class ValidateGpio < Validate
50
+
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(',')}.")
54
+ return false
55
+ end
56
+
57
+ @error_message = nil
58
+ true
59
+ end
60
+
61
+ end
62
+
63
+ #############################################################################
64
+ # Validate the Value parameter
65
+ #
66
+ # value : the value to be validated
67
+ #
68
+ class ValidateValue < Validate
69
+
70
+ def valid?
71
+ if (@value != VALUE_LOW ) && (@value != VALUE_HIGH)
72
+ @error_message = UdooNeoRest::Base.status_error("Value of '#{@value}' is invalid. Should be one of #{VALUE_LOW} or #{VALUE_HIGH}.")
73
+ return false
74
+ end
75
+
76
+ @error_message = nil
77
+ true
78
+ end
79
+
80
+ end
81
+
82
+ #############################################################################
83
+ # Validate the Pin parameter
84
+ #
85
+ # value : the pin value to be validated
86
+ #
87
+ class ValidatePin < Validate
88
+
89
+ def initialize(value)
90
+ @value = value.to_i
91
+ @error_message = nil
92
+ valid?
93
+ end
94
+
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.")
98
+ return false
99
+ end
100
+
101
+ @error_message = nil
102
+ true
103
+ end
104
+
105
+ ###########################################################################
106
+ # Convert a PIN reference to a GPIO reference as all the commands use GPIO
107
+ #
108
+ def to_gpio
109
+ return nil unless valid?
110
+ GPIOS[@value-16]
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+
117
+
118
+
119
+
@@ -0,0 +1,117 @@
1
+ module UdooNeoRest
2
+
3
+ class Value < Sinatra::Application
4
+
5
+ #############################################################################
6
+ # Routes
7
+ #
8
+ put '/gpio/:gpio/value/:value' do
9
+ value_set_gpio params[:gpio], params[:value]
10
+ end
11
+
12
+ put '/pin/:pin/value/:value' do
13
+ value_set_pin params[:pin], params[:value]
14
+ end
15
+
16
+ get '/gpio/:gpio/value' do
17
+ value_get_gpio params[:gpio]
18
+ end
19
+
20
+ get '/pin/:pin/value' do
21
+ value_get_pin params[:pin]
22
+ end
23
+
24
+ get '/lazyrest/gpio/:gpio/value/:value' do
25
+ value_set_gpio params[:gpio], params[:value]
26
+ end
27
+
28
+ get '/lazyrest/pin/:pin/value/:value' do
29
+ value_set_pin params[:pin], params[:value]
30
+ end
31
+
32
+ get '/lazyrest/gpio/:gpio/value' do
33
+ value_get_gpio params[:gpio]
34
+ end
35
+
36
+ get '/lazyrest/pin/:pin/value' do
37
+ value_get_pin params[:pin]
38
+ end
39
+
40
+ #############################################################################
41
+ # Get the value for a specific pin
42
+ #
43
+ # pin : the pin to be set (will be translated to GPIO)
44
+ #
45
+ def value_get_pin(pin)
46
+
47
+ # Validate the pin
48
+ pin_ = ValidatePin.new pin
49
+ return pin_.error_message unless pin_.valid?
50
+
51
+ # Get the value after translating to gpio
52
+ value_get_gpio pin_.to_gpio
53
+ end
54
+
55
+ #############################################################################
56
+ # Get the value for a specific gpio
57
+ #
58
+ # gpio : the gpio to get
59
+ #
60
+ def value_get_gpio(gpio)
61
+
62
+ # Validate the gpio
63
+ gpio_ = ValidateGpio.new gpio
64
+ return gpio_.error_message unless gpio_.valid?
65
+
66
+ # Get the value
67
+ UdooNeoRest::Base.status_ok(UdooNeoRest::Base.cat "#{BASE_PATH}gpio#{gpio}/value")
68
+ end
69
+
70
+ #############################################################################
71
+ # Set a specific pin to the nominated value
72
+ #
73
+ # pin : the pin to be set (will be translated to GPIO)
74
+ # value : the value to be used
75
+ #
76
+ def value_set_pin(pin, value)
77
+
78
+ # Validate the pin
79
+ pin_ = ValidatePin.new pin
80
+ return pin_.error_message unless pin_.valid?
81
+
82
+ # Set the value after translating to gpio
83
+ value_set_gpio pin_.to_gpio, value
84
+ end
85
+
86
+ #############################################################################
87
+ # Set a specific gpio to the nominated value
88
+ #
89
+ # gpio : the gpio to be set
90
+ # value : the value to be used
91
+ #
92
+ def value_set_gpio(gpio, value)
93
+
94
+ # Validate the gpio
95
+ gpio_ = ValidateGpio.new gpio
96
+ return gpio_.error_message unless gpio_.valid?
97
+
98
+ # Validate the value
99
+ value = ValidateValue.new value
100
+ return value.error_message unless value.valid?
101
+
102
+ # Send the command and if no error return an OK result
103
+ result = UdooNeoRest::Base.echo value, "#{BASE_PATH}gpio#{gpio}/value"
104
+ return UdooNeoRest::Base.status_ok if result.empty?
105
+
106
+ # Check for a common error and provide some advice
107
+ if result =~ /not permitted/
108
+ return UdooNeoRest::Base.status_error('Operation not permitted error occurred. Has the gpio been set to output mode?')
109
+ end
110
+
111
+ # Otherwise just return the error
112
+ UdooNeoRest::Base.status_error result
113
+ end
114
+
115
+ end
116
+
117
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: udooneorest
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Sullivan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Rest API for interacting with UDOO Neo GPIOs, motion sensors and brick
28
+ sensors
29
+ email: mark@sullivans.id.au
30
+ executables:
31
+ - udooneorest
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - Gemfile
36
+ - bin/udooneorest
37
+ - lib/udooneorest.rb
38
+ - lib/udooneorest/accelerometer.rb
39
+ - lib/udooneorest/barometer.rb
40
+ - lib/udooneorest/direction.rb
41
+ - lib/udooneorest/export.rb
42
+ - lib/udooneorest/gyroscope.rb
43
+ - lib/udooneorest/magnetometer.rb
44
+ - lib/udooneorest/temperature.rb
45
+ - lib/udooneorest/validators.rb
46
+ - lib/udooneorest/value.rb
47
+ homepage: http://rubygems.org/gems/udooneorest
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.2.2
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Rest API for interacting with UDOO Neo
71
+ test_files: []