Hw input add

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

hw_input_id = hw_input_add(name, callback) (from AM/AP 3.5)
hw_input_id = hw_input_add(hw_id, callback)

hw_input_add is used to add a hardware input to your instrument.

Named

Info Available from AM/AP 3.5.

Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED').
Air Manager will present the user with a view where the assignment of pins can be done.

Arguments

hw_input_id = hw_input_add(name, callback)
# Argument Type Description
1 name String A functional name to define the input.
2 callback Function This function will be called when the input state changes. The callback will provide one argument, state, which is true when the input is high, and low when the pin is low.

Return value

Argument Type Description
hw_input_id ID This value can be used for further reference. Functions such as hw_input_read can use this hw_input_id. Its good practice to store this hw_input_id in your logic code.

Example

-- Callback function which is called when the input state changes
-- state true  : input is high
-- state false : input is low
function input_change(state)
  print("new state = " .. tostring(state) )
end

-- Create a new input
hw_input_add("My input", input_change)

Hardware Id's

Info Hardware Id's are not preferred, try to use named hardware instead.

Define the used pin(s) right away. This is not preferred, since changing of pin assignment can only be done by changing the instrument/panel lua script.

Arguments

hw_input_id = hw_input_add(hw_id, callback)
# Argument Type Description
1 hw_id String The is the reference to the input. You can choose to bind to an existing Hardware ID (Hardware_id_list).
2 callback Function This function will be called when the input state changes. The callback will provide one argument, state, which is true when the input is high, and low when the pin is low.

Return value

Argument Type Description
hw_input_id ID This value can be used for further reference. Functions such as hw_input_read can use this hw_input_id. Its good practice to store this hw_input_id in your logic code.

Example

-- Callback function which is called when the input state changes
-- state true  : input is high
-- state false : input is low
function input_change(state)
  print("new state = " .. tostring(state) )
end

-- Bind to Raspberry Pi 2, Header P1, Pin 40
hw_input_add("RPI_V2_P1_40", input_change)