Class: UdooNeoRest::Value

Inherits:
Sinatra::Application
  • Object
show all
Defined in:
lib/udooneorest/value.rb

Instance Method Summary collapse

Instance Method Details

#value_get_gpio(gpio) ⇒ Object

Get the value for a specific gpio

gpio : the gpio to get



60
61
62
63
64
65
66
67
68
# File 'lib/udooneorest/value.rb', line 60

def value_get_gpio(gpio)

  # Validate the gpio
  gpio_ = ValidateGpio.new gpio
  return gpio_.error_message unless gpio_.valid?

  # Get the value
  UdooNeoRest::Base.cat_and_status "#{BASE_PATH}gpio#{gpio}/value"
end

#value_get_pin(pin) ⇒ Object

Get the value for a specific pin

pin : the pin to be set (will be translated to GPIO)



45
46
47
48
49
50
51
52
53
# File 'lib/udooneorest/value.rb', line 45

def value_get_pin(pin)

  # Validate the pin
  pin_ = ValidatePin.new pin
  return pin_.error_message unless pin_.valid?

  # Get the value after translating to gpio
  value_get_gpio pin_.to_gpio
end

#value_set_gpio(gpio, value) ⇒ Object

Set a specific gpio to the nominated value

gpio : the gpio to be set value : the value to be used



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/udooneorest/value.rb', line 92

def value_set_gpio(gpio, value)

  # Validate the gpio
  gpio_          = ValidateGpio.new gpio
  return gpio_.error_message unless gpio_.valid?

  # Validate the value
  value_         = ValidateValue.new value
  return value_.error_message unless value_.valid?

  # Send the command and if no error return an OK result
  result         = UdooNeoRest::Base.echo value, "#{BASE_PATH}gpio#{gpio}/value"
  return UdooNeoRest::Base.status_ok if result.empty?

  # Check for a common error and provide some advice
  if result =~ /not permitted/
    return UdooNeoRest::Base.status_error('Operation not permitted error occurred. Has the gpio been set to output mode?')
  end

  # Otherwise just return the error
  UdooNeoRest::Base.status_error result
end

#value_set_pin(pin, value) ⇒ Object

Set a specific pin to the nominated value

pin : the pin to be set (will be translated to GPIO) value : the value to be used



76
77
78
79
80
81
82
83
84
# File 'lib/udooneorest/value.rb', line 76

def value_set_pin(pin, value)

  # Validate the pin
  pin_ = ValidatePin.new pin
  return pin_.error_message unless pin_.valid?

  # Set the value after translating to gpio
  value_set_gpio pin_.to_gpio, value
end