Difference between revisions of "Hw switch add"

From Sim Innovations Wiki
Jump to navigation Jump to search
(Undo revision 2768 by Admin (talk))
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Description ==
== Description ==


  '''hw_switch_id = hw_switch_add(name, nr_pins, callback)''' (from AM 3.5)
  '''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)'''
  '''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.
'''switch_add''' is used to add a hardware switch. Every position on the switch should use one hardware input.


== Return value ==  
== Named ==
{{tip| Available from AM/AP 3.5.}}
 
Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED').<br/>
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)'''
 
{| class="wikitable"
|-
! # !! 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 ===


{| class="wikitable"
{| class="wikitable"
Line 15: Line 36:
|}
|}


== Arguments ==
=== Example ===


<source lang="lua">
-- 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)
</source >
== Hardware Id's ==
{{warning| 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)'''


{| class="wikitable"
{| class="wikitable"
Line 31: Line 72:
|}
|}


== Example ==  
=== Return value ===
 
{| class="wikitable"
|-
! Argument !! Type !! Description
|-
| '''hw_switch_id ''' || ''ID'' || This value can be used for further reference.
|}
 
=== Example ===


<source lang="lua">
<source lang="lua">

Latest revision as of 19:26, 11 October 2018

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