LUA Projects > General Discussions


(1/2) > >>

Trevor Hale:
This file gets put into your FSUIPC MODULES DIRECTORY.

Once FSX is Loaded and FSUIPC Starts, this file runs.

Lets look at the bottom of the code.

--- Quote ---
-- Arduino Gauges/Servos
event.offset (0x0be0, "UD", "call_flaps") -- aircraft Flaps
event.offset (0x02c8, "SD", "call_vertical") -- aircraft Vertical Speed
event.offset (0x0be0, "UD", "call_flaps") -- aircraft Flaps
event.offset (0x0b7c, "UD", "call_lfuel") -- aircraft Left Fuel

event.offset (0x0b94, "UD", "call_rfuel") -- aircraft Right Fuel

event.offset (0x0bc2, "SW", "call_trim") -- aircraft Trim
event.offset (0x0e8c, "SW", "call_oat") -- aircraft Outside Air Temp

--- End quote ---

these lines of code specify the "FSUIPC OFFSETS" I am looking for in FSX to change.

event.offset (Means that I am looking for an offset change)
0x (means Offset Location in HEX)
0E8C (Is the OFFSET ADDERSS taken from this list -->
S (means Signed bit "Could be a + or a - Value)
W (Means WORD which is a representation of 16 Bits which is the size of the offset from this list "2nd column" --> -->

call_oat (means when the offset changes go to the "Function Block" in the program called call_oat)

Are you with me so far?  Good.

Now we will look at the easy part of the code...

--- Quote ----- Open Seial Port and connect to Arduino
speed = 115200
handshake = 0
serial_wait = 100
inited = 0
states = {}
dev ="COM3", speed, handshake) -- Change Port Number for your Arduino
if dev == 0 then
    ipc.display("Could not open device port")

-- Finish Serial Connect

--- End quote ---

This just works, its humble jumble..  it basically just tells the LUA Script where the ardino is.
Just change the COM3 to Com1, Com2, Com4 or whatever comp port your arduino is connected to.

Lastly Look at the meat of the CODE

--- Quote ---function call_oat (offset, value)
    value = (value/256)
    ipc.log ("writes com = ?c"..string.format("%04d", value).. "\n")
    com.write (dev, "?c" .. string.format("%04d", value) .. "\n")

--- End quote ---

function call_oat (offset, value)   "Think of this as the title of the function block that runs when that offset changes. (Remember above we said to come here?)"
value = (value/256) "this means whatever value the offset changed to, divide it by 256 and go on."
ipc.log ("writes com = ?c"..string.format("%04d", value).. "\n") " basically is humble jumble for when this offset changes write the value to fsuipc.log so I can watch if it is working - HOWEVER I USE THE ?c as a trigger for my Arduino program to know when I am sending outside Air Temperature Value"

com.write (dev, "?c" .. string.format("%04d", value) .. "\n") Same thing as above only this is what it is sending to the COM PORT (ARDUINO) again the ?c in my arduino code means OUTSIDE AIR TEMP

ipc.sleep(serial_wait) " Means give the com port a break, it gets tired (Serial_wait) was defined at 100 in the Serial port setup we did above which means 100 mili seconds."

end "means I can go on to the next offset that changes.

Thats it, that is my lua code explained.  now if you have specific questions, I can try to answer them.

I attached my LUA Code to this post also for ease of explanation.  NOW, This is 1/2 of the code...  I will detail the arduino code in a different post.  remember, this just sends the data to the com port.  In the Arduino, that code needs to tell your gauge what to do with that code when it gets the message.

And if you don't know WHAT FSUIPC IS or DOES.  You need to do a lot of reading, because until you understand that..  this is still not going to be of any help to you.[/quote]

Hey Trev, I hope you didn't do that just for me Jk haha!, thanks for detail explaination, starting to make sence thanks for help, so is cold beer!



...what's this "FSCIUPD" thingy you speak of?  ::)

Trevor Hale:
LOL @ Ray thats funny..  I have no idea :)

Mike, Yes I did, and I will try to get time to do the same thing for my Arduino code also..  But things are very busy right now.

I will try.


Thanks for posting that explanation. Quite helpful.  I understand most of it but am new to Arduino. Was gifted an Uno recently so dabbling into the Arduino sketch coding. Want to use it for displaying seven segment displays in an NGX FSX environment.

The Lua code you  that similar to a 'sketch' code or does one have to download another program to run Lua code? I'm currently digging into the Links2FS interface and playing around with small sketches .



[0] Message Index

[#] Next page

Go to full version