Difference between revisions of "Hw dial add"

From Sim Innovations Wiki
Jump to navigation Jump to search
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Description ==
== 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(name, type, acceleration, debounce, 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, 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, acceleration, callback)'''
'''hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, acceleration, callback)'''
'''hw_dial_id = hw_dial_add(hw_id_a, hw_id_b, type, acceleration, debounce, callback)''' (from AM/AP 3.5)
'''hw_dial_id''' is used to add a hardware rotary encoder to your instrument.


'''hw_dial_id''' is used to add a hardware rotary encoder to your instrument.
== 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_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)'''
 
{| class="wikitable"
|-
! # !! 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 || '''debounce''' || ''Number'' || (Optional) Select different debounce time in milliseconds. Default is 4 ms.
|-
| 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 ==  
=== Return value ===  


{| class="wikitable"
{| class="wikitable"
Line 12: Line 47:
! Argument !! Type !! Description
! Argument !! Type !! Description
|-
|-
| '''hw_dial_id''' || ''String'' || This value can be used for further reference. Its good practice to store this hw_input_id in your logic code.
| '''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.
|}
|}


== Arguments ==
=== Example ===
 
<source lang="lua">
-- 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)
</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_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)'''


{| class="wikitable"
{| class="wikitable"
Line 25: Line 92:
|-
|-
| 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]]).
| 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.
| 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.
| 3 || '''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.
|-
| 5 || '''debounce''' || ''Number'' || (Optional) Select different debounce time in milliseconds. Default is 4 ms.
|-
| 6 || '''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 ===
 
{| class="wikitable"
|-
! 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 ==
=== Example ===


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

Latest revision as of 10:37, 12 February 2019

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(name, type, acceleration, debounce, 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 = hw_dial_add(hw_id_a, hw_id_b, type, acceleration, debounce, callback) (from AM/AP 3.5)

hw_dial_id is used to add a hardware rotary encoder 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_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 debounce Number (Optional) Select different debounce time in milliseconds. Default is 4 ms.
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

-- Create a new rotary encoder
hw_dial_add("Heading", dial_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_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 debounce Number (Optional) Select different debounce time in milliseconds. Default is 4 ms.
6 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

Rotary-encoder.png