Hw switch add

From Sim Innovations Wiki
Revision as of 21:26, 11 October 2018 by Admin (talk | contribs) (Undo revision 2768 by Admin (talk))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Description

hw_switch_id = hw_switch_add(name, nr_pins, callback) (from AM/AP 3.5)
hw_switch_id = hw_switch_add(hw_id_0, hw_id_1, hw_pos_n,callback)

switch_add is used to add a hardware switch. Every position on the switch should use one hardware input.

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_switch_id = hw_switch_add(name, nr_pins, callback)
# Argument Type Description
1 name String A functional name to define the switch.
2 nr_pins Number Number of input pins used for this switch.
3 callback Function This function will be called when the switch changed position.

Return value

Argument Type Description
hw_switch_id ID This value can be used for further reference.

Example

-- This function is called every time the switch has a new position
function switch_callback(position)
  print("The switch got changed to position " .. position)
end

-- Create a new 3 position switch
hw_switch_add("Ignition", 3, switch_callback)

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_switch_id = hw_switch_add(hw_id_0, hw_id_1, hw_pos_n,callback)
# Argument Type Description
1 hw_id_0 String The is the reference to first switch input. You can choose to bind to an existing Hardware ID (Hardware_id_list).
2 hw_id_1 String The is the reference to the second switch input. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n hw_id_n String The hw_id for all other positions you might need. This is limitless
n+1 callback Function This function will be called when the switch changed position.

Return value

Argument Type Description
hw_switch_id ID This value can be used for further reference.

Example

-- This function is called every time the switch has a new position
function switch_callback(position)
  print("The switch got changed to position " .. position)
end

-- Bind to Raspberry Pi 2, Header P1, Pin 38 and 40
hw_switch_add("RPI_V2_P1_38", "RPI_V2_P1_40", switch_callback)

Schematic example

Switch-pull-up.png