Class: UdooNeoRest::Direction

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

Instance Method Summary collapse

Instance Method Details

#direction_get_gpio(gpio) ⇒ Object

Get the direction for a specific gpio

gpio : the gpio to get



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

def direction_get_gpio(gpio)

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

  # get the direction
  UdooNeoRest::Base.cat_and_status "#{BASE_PATH}gpio#{gpio}/direction"
end

#direction_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/direction.rb', line 45

def direction_get_pin(pin)

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

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

#direction_set_gpio(gpio, direction) ⇒ Object

Set a specific gpio to the nominated direction

gpio : the gpio to be set direction : the direction to be used



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/udooneorest/direction.rb', line 92

def direction_set_gpio(gpio, direction)

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

  # validate the direction
  direction_     = ValidateDirection.new direction
  return direction_.error_message unless direction_.valid?

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

#direction_set_pin(pin, direction) ⇒ Object

Set a specific pin to the nominated direction

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



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

def direction_set_pin(pin, direction)

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

  # Set the direction after translating to gpio
  direction_set_gpio pin_.to_gpio, direction
end