Description
hw_dial_id = hw_dial_add(name, callback) (from AM/AP 3.5)
hw_dial_id = hw_dial_add(name, type, callback) (from AM/AP 3.5)
hw_dial_id = hw_dial_add(name, acceleration, callback) (from AM/AP 3.5)
hw_dial_id = hw_dial_add(name, type, acceleration, callback) (from AM/AP 3.5)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, callback)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, callback)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, acceleration, callback)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, acceleration, callback)
hw_dial_id is used to add a hardware rotary encoder to your instrument.
Named
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_dial_id = hw_dial_add(name, callback)
hw_dial_id = hw_dial_add(name, type, callback)
hw_dial_id = hw_dial_add(name, acceleration, callback)
hw_dial_id = hw_dial_add(name, type, acceleration, callback)
# |
Argument |
Type |
Description
|
1 |
name |
String |
A functional name to define the rotary encoder.
|
2 |
type |
String |
(Optional) Type of rotary encoder. Can be "TYPE_1_DETENT_PER_PULSE", "TYPE_2_DETENT_PER_PULSE" or "TYPE_4_DETENT_PER_PULSE".
|
3 |
acceleration |
Number |
(Optional) A multiplier that will make the dial generate extra callbacks when the dial is being rotated faster. The multiplier is the maximum number of callbacks of one dial tick when this dial is being rotated at maximum speed.
|
4 |
callback |
Function |
This function will be called when the rotary encoder rotates (both ways). The callback will provide one argument, direction, which is 1 for clockwise rotation, and -1 for counterclockwise rotation.
|
Return value
Argument |
Type |
Description
|
hw_dial_id |
ID |
This value can be used for further reference. Its good practice to store this hw_input_id in your logic code.
|
Example
-- Callback function which is called when the rotary encoder is turned
-- direction 1 : The dial turned clockwise
-- direciton -1: The dial turned counterclockwise
function dial_change(direction)
if direction == 1 then
print("The dial turned clockwise")
end
if direction == -1 then
print("The dial turned counterclockwise")
end
end
-- Create a new rotary encoder
hw_dial_add("Heading", dial_change)
Hardware Id's
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_dial_id = hw_dial_add(hw_id_a, hw_id_b, callback)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, callback)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, acceleration, callback)
hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, acceleration, callback)
# |
Argument |
Type |
Description
|
1 |
hw_id_a |
String |
The is the reference to first (A) rotary encoder pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
|
2 |
hw_id_b |
String |
The is the reference to second (B) rotary encoder pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
|
3 |
type |
String |
(Optional) Type of rotary encoder. Can be "TYPE_1_DETENT_PER_PULSE", "TYPE_2_DETENT_PER_PULSE" or "TYPE_4_DETENT_PER_PULSE".
|
4 |
acceleration |
Number |
(Optional) A multiplier that will make the dial generate extra callbacks when the dial is being rotated faster. The multiplier is the maximum number of callbacks of one dial tick when this dial is being rotated at maximum speed.
|
5 |
callback |
Function |
This function will be called when the rotary encoder rotates (both ways). The callback will provide one argument, direction, which is 1 for clockwise rotation, and -1 for counterclockwise rotation.
|
Return value
Argument |
Type |
Description
|
hw_dial_id |
ID |
This value can be used for further reference. Its good practice to store this hw_input_id in your logic code.
|
Example
-- Callback function which is called when the rotary encoder is turned
-- direction 1 : The dial turned clockwise
-- direciton -1: The dial turned counterclockwise
function dial_change(direction)
if direction == 1 then
print("The dial turned clockwise")
end
if direction == -1 then
print("The dial turned counterclockwise")
end
end
-- Bind to Raspberry Pi 2, Header P1, Pin 38 and 40
hw_dial_add("RPI_V2_P1_38", "RPI_V2_P1_40", dial_change)
Schematic example