Jump to content
The simFlight Network Forums

Function, var and comparison


Recommended Posts

Hi,

The code below doesn't work, and i don't understand why. GearStateVal value is send to Gearr_Down_Up function, and is compared to a var called GearState. Values of both vaqrs are shown with ipc.display, and are right. So why the comparison will never work ? If values of 16383 or 0 are sent, the comparison work and it will work. If vGearValState is sent, with values of 16383 or 0, it will not work ... 

Why ? 0 is 0 ... and 16383 is 16383 ...

Thank you for your help ...

 

Regards,

Oliver

function Gear_Lever()
	gear_nose=ipc.readUD(0x0BEC)
	gear_left=ipc.readUD(0x0BF0)
	gear_right=ipc.readUD(0x0BF4)
	GearStateVal = gear_nose + gear_left + gear_right
	
	Gear_Down_Up(GearStateVal)
end
	

function Gear_Down_Up(GearStateVal)    
    -- Gear_Lever_DOWN bit : 2^19= 524288
	-- PDMG EVT_GEAR_LEVER (69632 + 768)
    testVar = ipc.readUD(0x3360)
	dev = ipc.get("dev")
	wrf = ipc.get("wrf")
	
    if logic.And(testVar,0x80000) ~= 0  then
		gear_nose=ipc.readUD(0x0BEC)
		gear_left=ipc.readUD(0x0BF0)
		gear_right=ipc.readUD(0x0BF4)
		GearState = gear_nose + gear_left + gear_right			
		ipc.control(66080,16383)	-- OFFSET FSX OK
				
		while GearState ~= GearStateVal do
						
			gear_nose=ipc.readUD(0x0BEC)
			gear_left=ipc.readUD(0x0BF0)
			gear_right=ipc.readUD(0x0BF4)
		    GearState = gear_nose + gear_left + gear_right	
			ipc.display("RUN --> N : " .. gear_nose .." L : " .. gear_left .. " R : " .. gear_right .. "\n"
					   .. "        GearStateVal : " .. GearStateVal) --.. " / GearState : " .. state)			
			s = string.char(0,56)
			com.writefeature (dev, s, wrf)
			
		end
	end
end	

 

Link to comment
Share on other sites

2 hours ago, odrezet77 said:

The code below doesn't work, and i don't understand why. GearStateVal value is send to Gearr_Down_Up function, and is compared to a var called GearState. Values of both vaqrs are shown with ipc.display, and are right. So why the comparison will never work ? If values of 16383 or 0 are sent, the comparison work and it will work. If vGearValState is sent, with values of 16383 or 0, it will not work ... 

But GearStateVal is the addition of three values, 16383 + 16383 + 16383 is NOT = 16383.

Sorry, but I don't understand your code or what you are trying to do. It makes no sense to me adding three gear state values together.

Pete

 

Link to comment
Share on other sites

Well, I should have reread my post before posting. 

GearStateVal should be 0 or 49149 if everything is ok.  All gears down or up.

I just want to manage my PDMG gears with my saitek switch panel. 

3 Lights are green if all gear are down and ok.  3 Lights are off when all gears are up and ok.  3 lights are red when gears are operating.

If a gear is not fully up or down, its lights is red.

My whole code works fine when comparison is ok (when Gear_Down_Up is called with a "manual" value and not a result of 3 ipc.read values)

Oliver.

function Gear_Lever()
	gear_nose=ipc.readUD(0x0BEC)
	gear_left=ipc.readUD(0x0BF0)
	gear_right=ipc.readUD(0x0BF4)
	GearStateVal = gear_nose + gear_left + gear_right
	
	Gear_Down_Up(GearStateVal)
end
	

function Gear_Down_Up(GearStateVal)    
	-- PDMG EVT_GEAR_LEVER (69632 + 768)
    testVar = ipc.readUD(0x3360)
	dev = ipc.get("dev")
	wrf = ipc.get("wrf")
	
    if logic.And(testVar,0x80000) ~= 0  then
		gear_nose=ipc.readUD(0x0BEC)
		gear_left=ipc.readUD(0x0BF0)
		gear_right=ipc.readUD(0x0BF4)
		GearState = gear_nose + gear_left + gear_right			
		ipc.control(66080,16383)	-- OFFSET FSX OK
				
		while GearState ~= GearStateVal do
						
			gear_nose=ipc.readUD(0x0BEC)
			gear_left=ipc.readUD(0x0BF0)
			gear_right=ipc.readUD(0x0BF4)
		    GearState = gear_nose + gear_left + gear_right	
			ipc.display("RUN --> N : " .. gear_nose .." L : " .. gear_left .. " R : " .. gear_right .. "\n"
					   .. "        GearStateVal : " .. GearStateVal) --.. " / GearState : " .. state)			
			s = string.char(0,56)
			com.writefeature (dev, s, wrf)
			
		end
		
		
		if gear_nose ~= 16383  then
			r1=1
			g1=0
		else
			r1=0
			g1=1
		end
				
		if gear_left ~= 16383  then 
			r2=1
			g2=0
		else
			r2=0
			g2=1
		end
				
		if gear_right ~= 16383  then 
			r3=1
			g3=0
		else
			r3=0
			g3=1
		end
		
				
		-- Concaténation des valeurs dans une chaîne
		val = "" .. r1 .. ""  .. r2 .. ""  .. r3 .. "" .. "" .. g1 .. ""  .. g2 .. ""  .. g3 
		-- Conversion en binaire de la chaîne val convertie en nombre
		valBIN = (tonumber(val,2))
		s = string.char(0, valBIN)
		com.writefeature (dev, s, wrf)

	else

		ipc.control(66079,0)		-- OFFSET FSX OK
				
		while GearState ~= GearStateVal do
			
			gear_nose=ipc.readUW(0x0BEC)
			gear_left=ipc.readUW(0x0BF4)
			gear_right=ipc.readUW(0x0BF0)
			GearState=gear_nose + gear_left + gear_right
			ipc.display("RUN --> N : " .. gear_nose .." L : " .. gear_left .. " R : " .. gear_right .. "\n"
					   .. "        GearStateVal : " .. GearStateVal) -- .. " / GearState : " .. state)
			s = string.char(0,56)
			com.writefeature (dev, s, wrf)
		end
		
		if gear_nose ~= 0x00000000 then 
			r1=1
			g1=0
		else
			r1=0
			g1=1
		end
		
		if gear_left ~= 0x00000000 then 
			r2=1
			g2=0
		else
			r2=0
			g2=1
		end
				
		if gear_right ~= 0x00000000 then 
			r3=1
			g3=0
		else
			r3=0
			g3=1
		end
		
		-- Concaténation des valeurs dans une chaîne
		val = "" .. r1 .. ""  .. r2 .. ""  .. r3 .. "" .. "" .. g1 .. ""  .. g2 .. ""  .. g3 
		-- Conversion en binaire de la chaîne val convertie en nombre
		valBIN = (tonumber(val,2))
		if valBIN == 07 then
			s = string.char(0, 00)
		 else
			s = string.char(0, valBIN)
		end	
	
		com.writefeature (dev, s, wrf)
	end
end        

 

Link to comment
Share on other sites

Which comparison are you referring to?  I'm afraid I still don't understand your code.

Have you tried enabling the Lua debug/trace option on the Logging tab, before running your plugin? It will show the lines (by number) executed, and the values when they change.

 

Link to comment
Share on other sites

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.