Difference between revisions of "Hw button add"
Jump to navigation
Jump to search
(14 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
'''hw_button_add''' is used to add a hardware button to your instrument. | '''hw_button_add''' is used to add a hardware button to your instrument. | ||
== 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_button_id = hw_button_add(name, pressed_callback, released_callback)''' | |||
{| class="wikitable" | |||
|- | |||
! # !! Argument !! Type !! Description | |||
|- | |||
| 1 || '''name''' || ''String'' || A functional name to define the button. | |||
|- | |||
| 2 || '''pressed_callback''' || ''Function'' || This function will be called when the button is pressed. | |||
|- | |||
| 3 || '''released_callback''' || ''Function'' || This function will be called when the button is released. | |||
|- | |||
|} | |||
=== Return value === | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 15: | Line 37: | ||
|} | |} | ||
== Arguments == | === Example === | ||
<source lang="lua"> | |||
-- Callback function which is called when the button is pressed | |||
function button_pressed() | |||
print("button pressed") | |||
end | |||
-- Callback function which is called when the button is released | |||
function button_released() | |||
print("button released") | |||
end | |||
-- Create the button. The actual pin used can be configured in Air Manager. | |||
hw_button_add("Power button", button_pressed, button_released) | |||
</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_button_id = hw_button_add(hw_id, pressed_callback, released_callback)''' | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 29: | Line 76: | ||
|} | |} | ||
== Example == | === Return value === | ||
{| class="wikitable" | |||
|- | |||
! Argument !! Type !! Description | |||
|- | |||
| '''hw_button_id''' || ''ID'' || This value can be used for further reference. | |||
|} | |||
=== Example === | |||
<source lang="lua"> | <source lang="lua"> |
Latest revision as of 19:18, 11 October 2018
Description
hw_button_id = hw_button_add(name, pressed_callback, released_callback) (from AM/AP 3.5) hw_button_id = hw_button_add(hw_id, pressed_callback, released_callback)
hw_button_add is used to add a hardware button to your instrument.
Named
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_button_id = hw_button_add(name, pressed_callback, released_callback)
# | Argument | Type | Description |
---|---|---|---|
1 | name | String | A functional name to define the button. |
2 | pressed_callback | Function | This function will be called when the button is pressed. |
3 | released_callback | Function | This function will be called when the button is released. |
Return value
Argument | Type | Description |
---|---|---|
hw_button_id | ID | This value can be used for further reference. |
Example
-- Callback function which is called when the button is pressed
function button_pressed()
print("button pressed")
end
-- Callback function which is called when the button is released
function button_released()
print("button released")
end
-- Create the button. The actual pin used can be configured in Air Manager.
hw_button_add("Power button", button_pressed, button_released)
Hardware Id's
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_button_id = hw_button_add(hw_id, pressed_callback, released_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 | pressed_callback | Function | This function will be called when the button is pressed. |
3 | released_callback | Function | This function will be called when the button is released. |
Return value
Argument | Type | Description |
---|---|---|
hw_button_id | ID | This value can be used for further reference. |
Example
-- Callback function which is called when the button is pressed
function button_pressed()
print("button pressed")
end
-- Callback function which is called when the button is released
function button_released()
print("button released")
end
-- Bind to Raspberry Pi 2, Header P1, Pin 40
hw_button_add("RPI_V2_P1_40", button_pressed, button_released)