News:

Simport Forum - Just Installed!

Main Menu

Recent posts

#1
FlyWithLua / FlyWithLua script example
Last post by dmahr - December 02, 2021, 04:43:46 PM
FlyWithLua is an X-Plane plugin which gives KBD03 boards access to datarefs and commands by simple (or complex) LUA scripts.

Information and download (login required) can be found here:

https://forums.x-plane.org/index.php?/files/file/38445-flywithlua-ng-next-generation-edition-for-x-plane-11-win-lin-mac/




Let us try to link a mechanical encoder to the OBS1 (omni bearing selector) of the CDI instrument #1.
Our encoder is connected to a KBD03 board and sends 'a' keystrokes when turned left and 's' when turned right.

A typical FlyWithLua script would look like this:

First define a variable we want to connect with the dataref associated with the OBS setting:

dataref("OBS1", "sim/cockpit2/radios/actuators/nav1_obs_deg_mag_pilot", "writable")

Next we fetch the  keystrokes of the KBD03:

if KEY_ACTION == "pressed" then
     ...


Then we can ask for a specific key (key 'a' in this case):

if KEY_ACTION == "pressed" then
     if (VKEY == 65) then
     -- 'a' key
          ...


Now we define the action for clockwise rotation:

if KEY_ACTION == "pressed" then
     if (VKEY == 65) then
     -- 'a' key
          OBS1 = OBS1 + 1     -- increment OBS1
     ...


And now for counterclockwise direction:

if KEY_ACTION == "pressed" then
     if (VKEY == 65) then
     -- 'a' key
          OBS1 = OBS1 + 1     -- increment OBS1
     elseif (VKEY == 83) then
     -- 's' key
          OBS1 = OBS1 - 1     -- decrement OBS1
     end
end


Let us also use the double encoder feature of the KBD03 with 'ctl+a' and 'ctl+s' for the second encoder.
When the pushbutton is pressed we dial the OBS fast then and when we press again we dial slow again.
Thus we modify the code:

if KEY_ACTION == "pressed" then
     if (VKEY == 65) then
          -- 'a' key
          if CONTROL_KEY then      -- Ctrl pressed
               OBS1 = OBS1 + 3     -- increment OBS1 by 3
          else
               OBS1 = OBS1 + 1     -- increment OBS1 by 1
          end
     elseif (VKEY == 83) then
      -- 's' key
          if CONTROL_KEY then
      -- Ctrl pressed
               OBS1 = OBS1 - 3     -- decrement OBS1 by 3
          else
               OBS1 = OBS1 - 1     -- decrement OBS1 by 1
          end
     end
end


if KEY_ACTION == "pressed" then
     if (VKEY == 65) then
     -- 'a' key
          OBS1 = OBS1 + 1     -- increment OBS1
     ...


And now for counterclockwise direction:

if KEY_ACTION == "pressed" then
     if (VKEY == 65) then
     -- 'a' key
          OBS1 = OBS1 + 1     -- increment OBS1
     elseif (VKEY == 83) then
     -- 's' key
          OBS1 = OBS1 - 1     -- decrement OBS1
     end
end


Let us also use the double encoder feature of the KBD03 with 'ctl+a' and 'ctl+s' for the second encoder.
When the pushbutton is pressed we dial the OBS fast then and when we press again we dial slow again.
Thus we modify the code:

if KEY_ACTION == "pressed" then
     if (VKEY == 65) then
          -- 'a' key
          if CONTROL_KEY then      -- Ctrl pressed
               OBS1 = OBS1 + 3     -- increment OBS1 by 3
          else
               OBS1 = OBS1 + 1     -- increment OBS1 by 1
          end
     elseif (VKEY == 83) then
      -- 's' key
          if CONTROL_KEY then
      -- Ctrl pressed
               OBS1 = OBS1 - 3     -- decrement OBS1 by 3
          else
               OBS1 = OBS1 - 1     -- decrement OBS1 by 1
          end
     end
end


Finally we wrap the code into a function which is called whenever a keystroke from the KBD03 is received.

function kbd03_event_handler()
     if KEY_ACTION == "pressed" then
          if (VKEY == 65) then
          -- 'a' key
               if CONTROL_KEY then      -- Ctrl pressed
                    OBS1 = OBS1 + 3     -- increment OBS1 by 3
               else
                    OBS1 = OBS1 + 1     -- increment OBS1 by 1
               end
          elseif (VKEY == 83) then
      -- 's' key
               if CONTROL_KEY then
      -- Ctrl pressed
                    OBS1 = OBS1 - 3     -- decrement OBS1 by 3
               else
                    OBS1 = OBS1 - 1     -- decrement OBS1 by 1
               end
          end
     end
end

do_on_keystroke("kbd03_event_handler()")


#2
Support / Configuration Utility Program
Last post by dmahr - December 02, 2021, 02:54:58 PM
The Configuration Utility Program can be found here:

https://simport.de/downloads/Kbd03CfgUtility_V301.zip
#3
Support / Instruction Booklet
Last post by dmahr - December 02, 2021, 02:51:31 PM
Download the Instruction Booklet (PDF) here:

https://simport.de/downloads/handbook%20KBD03.pdf
#4
Support / Where to buy
Last post by dmahr - December 02, 2021, 02:46:38 PM
#5
General Discussion / Welcome
Last post by dmahr - December 02, 2021, 01:35:12 PM
Welcome to Simport Forum!

We hope you enjoy using our forum.  If you have any problems, please feel free to ask us for assistance.

Thanks!
Admin