Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I have built an overhead panel for my sim that has some switches for example Taxi Lights and Landing Lights.

Although I have used Lua before I have spent hours on trying to get these switches to work.

I know that the light switch data is held in 0x0D0C  offset but I can not figure out how to extract the individual bits to allow me to modify them and then write them back to the offset. I think it involves some logic.and  command but its all beyond me unfortunately.

Or am I on the wrong track altogether and is there an easier way.

Could anyone please help with a little sample code that reads offset  extracts bit 3 , if its off turn it on and vice versa and write it back to 0x0D0C.

I have read all the stuff that comes with FSUIPC  but to no avail

 

Thanks heaps

 

Owen Moore

Posted

Owen
Not tested, logicly seems like it should work.
Uses the Logic Library and the IPC Library operation:  ipc.togglebitsUW
Both in the document - ~\Modules\FSUIPC Documents\FSUIPC Lua Library.pdf.
The key is to turn the bit(s) to check into its decimal or hex equivalent as the logic mask. (if multiple, add bits up)

Hope it helps,
Roman

--[[
PARAMETERS
1 = If landing light is off, turn it on
2 = If landing light is on, turn it off
3 = If taxi light is off, turn it on
4 = if taxi light is on, turn it off
]]

lights = ipc.readUW(0x0D0C)

-- param #1 landing light on
if ipcPARAM == 1 and logic.Nand(lights, 4) then
	ipc.togglebitsUW(0x0D0C, 4)
end

-- param #2 landing light off
if ipcPARAM == 2 and logic.And(lights, 4) then
	ipc.togglebitsUW(0x0D0C, 4)
end

-- param #3 taxi light on
if ipcPARAM == 3 and logic.Nand(lights, 8) then
	ipc.togglebitsUW(0x0D0C, 8)
end

-- param #4 taxi light off
if ipcPARAM == 4 and logic.And(lights, 8) then
	ipc.togglebitsUW(0x0D0C, 8)
end
Posted

Hi,

How are your switches connected to the simulator? Are they recognized as normal buttons? In that case you simply can assign the appropriate controls to it without LUA programming (TOGGLE_TAXI_LIGHTS, LANDING_LIGHTS_TOGGLE).

Rgds
Reinhard

Posted
2 hours ago, aua668 said:

Hi,

How are your switches connected to the simulator? Are they recognized as normal buttons? In that case you simply can assign the appropriate controls to it without LUA programming (TOGGLE_TAXI_LIGHTS, LANDING_LIGHTS_TOGGLE).

Rgds
Reinhard

Yes they are recognized as normal buttons but I haven't been able to find where in FSUIPC to assign TOGGLE_TAXI_LIGHTS, LANDING_LIGHTS_TOGGLE).

Thanks

 

Owen

Posted

Thank you for all your help. i have now got my switches all working with ideas from your code examples. Instead off togglebit I used set and clear bit for better control.

 

If I may ask another couple of questions

I now understand how to work with the switches but I also have a park brake switch and can not figure out how to write to offset 0BC8 as it seems to take a value from 0 to 32767 when all I really want is on or off.

I note in the offset pdf there is a field for size but how does that relate to the following

UB unsigned 8-bit byte
UW unsigned 16-bit word
UD unsigned 32-bit dword
SB signed 8-bit byte
SW signed 16-bit word
SD signed 32-bit dword
DD signed 64-bit value
DBL 64-bit double floating point
FLT 32-bit single floating point
STR string of ASCII characters (in this case the preceding number,
n, gives the length not a repeat count)

 

I am sure there is a correlation to these two and I note that 0D0C has a size of 2 and that we used sw in the lights example

 

Again thanks for your help

 

Owen

Posted

Hi,

the size in FSUIPCx Offset Status.pdf is as always given in Byte. A Byte has 8 Bit. The max values ov signed and unsigned you will find online. For your example of Parking Brake

Quote

0BC8  2  Parking brake:  0=off,  32767=on

this is a unsigned word (16 Bit uint)

Quote

Integer Types

The following table provides the details of standard integer types with their storage sizes and value ranges −

Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 8 bytes -9223372036854775808 to 9223372036854775807
unsigned long 8 bytes 0 to 18446744073709551615
Quote

Floating-Point Types

The following table provide the details of standard floating-point types with storage sizes and value ranges and their precision −

Type Storage size Value range Precision
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places

Using the Logging facility will help you a lot, for your question you can read the value for Parking Brake set is 32767 as the manual says.

image.thumb.png.30b9b48a4ff0865973fc302ceb7c6471.png

Thomas

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.