NpCkeyData.lua
[Spoiler]
--NpCkeyData Ver 14Aug13 2330, updated 21Aug13 1600 (decimal pt mod)
--Program shows frequency or code digits directly on radio panel
--Must enter first Com or Nav digit (a 1)
--Added Reset function 22Aug13
-- 25 Aug13, Uses temp freq digits to avoid no response from FSX do to freq to far out of limits
-- FSUIPC ipcPARAM parameter values:
--10 is decimal point
--11 is Com or Nav standby frequency swap
--12 is BackSpace
--13 is NumPadControl On/OFF
--14 is Reset active radio to first digit position
--27Aug1430 added altitude, heading and vertical speed entries for autopilot
-- 15 is Vertical Speed Up
-- 16 is Vertical Speed Down
--19Sept2013 added OBS setting function
--14Nov2013 added Airspeed function for Autopilot to support AutoThrottle
--Al Klayton, 14Nov2013
onoff = ipc.get("ONOFF")
acr = ipc.get("ACTIVE_RADIO")
keypos = ipc.get("KEY_POS") --First key postion is Most Significant Digit, MSD)
if onoff == nil then
ipc.set("ONOFF", "ON") --turn on NumPadRadio (NPR) as default
end
if ipcPARAM == 13 then -- NumPadRadio OnOff toggle code
textOnOff = "** ON **"
if onoff == nil or onoff == "ON" then
ipc.set("ONOFF", "OFF")
textOnOff = "** OFF **"
else
ipc.set("ONOFF", "ON")
end
ipc.writeSTR(0x3380, "Numpad Control " .. textOnOff)
ipc.writeSW(0x32FA, 3) --display for 3 sec
return
end
if (not(onoff == nil) and onoff == "OFF") then -- Do nothing if NumPadRadio is Off
return
end
if acr == nil then
ipc.writeSTR(0x3380, "No Function Selected ")
ipc.writeSW(0x32FA, 3); --Green bar msg for 3 sec
return
end
if ipcPARAM == 11 then --swap standby freq of active radio if Com or Nav radio
if acr == "COM_1" then
ipc.control(66372,1)
ipc.sleep(10) --delay 10msec
ipc.set("KEY_POS", 1) --reset back to first digit
elseif acr == "COM_2" then
ipc.control(66444, 1)
ipc.sleep(10)
ipc.set("KEY_POS", 1)
elseif acr == "NAV_1" then
ipc.control(66448, 1)
ipc.sleep(10)
ipc.set("KEY_POS", 1)
elseif acr == "NAV_2" then
ipc.control(66452, 1)
ipc.sleep(10)
ipc.set("KEY_POS", 1)
else
ipc.writeSTR(0x3380, "Select Com or Nav Radio")
ipc.writeSW(0x32FA, 3)
end
return
end --end swap
if ipcPARAM==14 then
ipc.set("KEY_POS", 1) --RESET back to first digit
return
end
if ipcPARAM == 12 then
--check for backspace 1 digit
if keypos > 1 then -- do nothing if keypos is 1
keypos=keypos-1
ipc.set("KEY_POS", keypos)
end
return
end --end BackSpace
if ipcPARAM >=0 and ipcPARAM <=10 then --only single digits or decimal point
if acr=="COM_1" or acr=="COM_2" or acr=="NAV_1" or acr=="NAV_2" then --Nav freqs 108 to 117.95 MHz in 0.05MHz steps
--Com freqs from 108 to 136.975MHz in 0.025MHz steps but only 2 decimal places used
if ipcPARAM == 10 then -- decimal pt
keypos=5 --point to next digit
ipc.set("KEY_POS", keypos) --save next digit position
return
end
if keypos==7 then -- reset keypos if last digit entered since no BackSpace
keypos=1
end
if acr == "COM_1" then
CurrFreq = ipc.readUW(0x311A) --get freq of active radio
freqloc= 0x311A --get location of active radio freq
elseif acr=="COM_2" then
CurrFreq = ipc.readUW(0x311C)
freqloc= 0x311C
elseif acr=="NAV_1" then
CurrFreq = ipc.readUW(0x311E)
freqloc= 0x311E
elseif acr=="NAV_2" then
CurrFreq = ipc.readUW(0x3120)
freqloc= 0x3120
end
if keypos==1 then
if ipcPARAM==1 then
keypos=keypos+1 --point to position 2 next
ipc.set("KEY_POS", keypos) --save keypos value for next iteration
return
else
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
end
end
if keypos==2 then
freqdig3=logic.And(CurrFreq, 0x0F00) -- isolate 3rd freq digit
if (acr=="COM_1" or acr=="COM_2")then
if ipcPARAM < 1 or ipcPARAM > 3 then -- 2nd digit of Com freq must be 1, 2 or 3
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
elseif ipcPARAM == 1 and freqdig3 < 0x800 then -- if true, temp freqwill be to low; note freqdig3 in 100s place
DigitSpace=logic.And(CurrFreq, 0x00FF) -- create space for new freq digit and tempfreqdig at correct position
movPARAM=logic.Shl(ipcPARAM, 12) -- move new digit to correct position
NewFreq = logic.Or(DigitSpace, movPARAM+0x0900) --add on temp 3rd freq digit = 9
ipc.writeUW(freqloc, NewFreq) -- update radio panel
keypos=keypos+1
elseif ipcPARAM == 3 and freqdig3 > 0x600 then -- if true, temp freq will be to high; note freqdig3 in 100s place
DigitSpace=logic.And(CurrFreq, 0x00FF) -- create space for new freq digit and tempfreqdig at correct position
movPARAM=logic.Shl(ipcPARAM, 12) -- move new digit to correct position
NewFreq = logic.Or(DigitSpace, movPARAM+0x0000) --add in new 2nd digit and temp 3rd freq digit = 0
ipc.writeUW(freqloc, NewFreq) -- update radio panel
keypos=keypos+1
else
movPARAM=logic.Shl(ipcPARAM, 12) --temp freq will be within limits
DigitSpace=logic.And(CurrFreq, 0x0FFF) -- create space for new freq digit
NewFreq=logic.Or(DigitSpace, movPARAM) -- move new digit to correct position
ipc.writeUW(freqloc, NewFreq) -- update radio panel
keypos=keypos+1
end
end
if (acr=="NAV_1" or acr=="NAV_2")then
if ipcPARAM < 0 or ipcPARAM > 1 then --2nd digit of Nav freq must be 0 or 1
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
elseif ipcPARAM == 0 and freqdig3 < 0x800 then -- if true, temp freqwill be to low; note freqdig3 in 100s place
DigitSpace=logic.And(CurrFreq, 0x00FF) -- create space for new freq digit and tempfreqdig at correct position
movPARAM=logic.Shl(ipcPARAM, 12) -- move new digit to correct position
NewFreq = logic.Or(DigitSpace, movPARAM+0x0900) --add in new 2nd digit and temp 3rd freq digit = 9
ipc.writeUW(freqloc, NewFreq) -- update radio panel
keypos=keypos+1
elseif ipcPARAM == 1 and freqdig3 > 700 then -- if true, temp freq will be to high; note freqdig3 in 100s place
DigitSpace=logic.And(CurrFreq, 0x00FF) -- create space for new freq digit and tempfreqdig at correct position
movPARAM=logic.Shl(ipcPARAM, 12) -- move new digit to correct position
NewFreq = logic.Or(DigitSpace, movPARAM+0x0000) --add in new 2nd digit and temp 3rd freq digit = 0
ipc.writeUW(freqloc, NewFreq) -- update radio panel
keypos=keypos+1
else
movPARAM=logic.Shl(ipcPARAM, 12) --temp freq will be within limits ;move new digit to correct position
DigitSpace=logic.And(CurrFreq, 0x0FFF) -- create space for new freq digit
NewFreq=logic.Or(DigitSpace, movPARAM) -- move new digit to correct position
ipc.writeUW(freqloc, NewFreq) -- update radio panel
keypos=keypos+1
end
end -- point to position 3
elseif keypos==3 then
movPARAM=logic.Shl(ipcPARAM, 8) -- move new digit to correct position
DigitSpace=logic.And(CurrFreq, 0xF0FF) -- create space for new freq digit at correct position
NewFreq=logic.Or(DigitSpace, movPARAM) -- place digit
if (acr=="COM_1" or acr=="COM_2") and (NewFreq < 0x1800 or NewFreq >= 0x3700) then -- check for valid # entry
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
elseif (acr=="NAV_1" or acr=="NAV_2") and (NewFreq < 0x0800 or NewFreq >= 0x1800) then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
else
ipc.writeUW(freqloc, NewFreq) -- digit valid, update radio panel
keypos=keypos+1
end
-- no longer need the following since checked for decimal pt above
-- elseif keypos==4 and ipcPARAM==10 then -- 10 indicates decimal pt
-- keypos=keypos+1 -- ignore input but update position
elseif keypos==4 and not(ipcPARAM==10) then -- if true, this is digit for 5th position
movPARAM=logic.Shl(ipcPARAM, 4) -- move new digit to correct position
DigitSpace=logic.And(CurrFreq, 0xFF0F) -- create space for new freq digit at correct position
NewFreq=logic.Or(DigitSpace, movPARAM) -- place digit
ipc.writeUW(freqloc, NewFreq) -- update radio panel
keypos=keypos+2 -- point to position 6 next
elseif keypos==5 then
movPARAM=logic.Shl(ipcPARAM, 4) -- move new digit to correct position
DigitSpace=logic.And(CurrFreq, 0xFF0F) -- create space for new freq digit at correct position
NewFreq=logic.Or(DigitSpace, movPARAM) -- place digit
ipc.writeUW(freqloc, NewFreq) -- update radio panel
keypos=keypos+1 -- point to digit 6 next
elseif keypos==6 then
if (acr=="COM_1" or acr=="COM_2") and not(ipcPARAM == 0 or ipcPARAM ==2 or ipcPARAM == 5 or ipcPARAM == 7) then -- because 0.025MHz channel spacing
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
elseif
( acr=="NAV_1" or acr=="NAV_2") and not(ipcPARAM == 0 or ipcPARAM ==5 ) then -- because 0.050MHz channel spacing
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
else
DigitSpace=logic.And(CurrFreq, 0xFFF0) -- create space for new freq digit at correct position
NewFreq=logic.Or(DigitSpace, ipcPARAM) -- place digit
ipc.writeUW(freqloc, NewFreq) -- update radio panel
keypos=keypos+1
end -- update keypos in case need to BkSpc
end
ipc.set("KEY_POS", keypos) --save keypos value for next iteration
return
end -- Com and Nav radios
if acr == "OBS_1" or acr == "OBS_2" then
if acr=="OBS_1" then
obs_loc=0x0C4E -- FSUIPC offset location for OBS_1
else
obs_loc=0x0C5E
end
-- FSUIPC offset location for OBS_2
if ipcPARAM==10 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #, no decimal pt
ipc.writeSW(0x32FA, 3)
return
end
if keypos==4 then -- reset keypos if last digit entered since no BackSpace
keypos=1
end
if keypos==1 then
if ipcPARAM >3 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
else
ipc.set("OBSdigit1", ipcPARAM) --save 100s place digit
keypos=keypos+1 --point to position 2 next
end
elseif keypos==2 then
obsdigit1 = ipc.get("OBSdigit1")
if obsdigit1==3 and ipcPARAM > 6 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #, max OBS is 360
ipc.writeSW(0x32FA, 3)
else
ipc.set("OBSdigit2", ipcPARAM) --save 1s0 place digit
keypos=keypos+1 --point to position 3 next
end
elseif keypos==3 then
obsdigit1 = ipc.get("OBSdigit1")
obsdigit2=ipc.get("OBSdigit2")
if obsdigit1==3 and obsdigit2==6 and not (ipcPARAM == 0) then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
else
ipc.set("OBSdigit3", ipcPARAM) --save 1s place digit
keypos=keypos+1 --point to position 4 to allow for Backspace
end
end
ipc.set("KEY_POS", keypos) --save keypos value for next iteration of program
if keypos==4 then
obsdigit1= ipc.get("OBSdigit1") -- get saved value
obsdigit2= ipc.get("OBSdigit2") -- get saved value
obsdigit3= ipc.get("OBSdigit3") -- get saved value
obs_deg = obsdigit1*100 + obsdigit2*10 + obsdigit3 --OBS value in degrees
ipc.writeUW(obs_loc, obs_deg) -- write deg info to appropriate offset
end -- end keypos=4
end --end OBS
if (acr=="ADF_1") or (acr=="ADF_2") then --note ADF freqs are from 190 to 1799.5 Khz
if ipcPARAM == 10 then -- decimal pt
keypos=6 --point to next digit
ipc.set("KEY_POS", keypos) --save next digit position
return
end
if keypos==7 then -- reset keypos if last digit entered since no BackSpace
keypos=1
end
if acr == "ADF_1" then
CurrFreqMiddle = ipc.readUW(0x034C) --get 3 middle freq digits of active radio
CurrFreqOuter = ipc.readUW(0x0356) --get 2 outside freq digits of active radio
freqlocMiddle= 0x034C --get locations of active radio freq digits
freqlocOuter=0x0356
elseif acr=="ADF_2" then
CurrFreqMiddle = ipc.readUW(0x02D4) --get 3 middle freq digits of active radio
CurrFreqOuter = ipc.readUW(0x02D6) --get 2 outside freq digits of active radio
freqlocMiddle= 0x02D4 --get locations of active radio freq digits
freqlocOuter=0x02D6
end
digit1=logic.And(logic.Shr(CurrFreqOuter, 8),0x000F)
digit2=logic.And(logic.Shr(CurrFreqMiddle,8),0x000F) --pass variables from previous iteration of program
digit3=logic.And(logic.Shr(CurrFreqMiddle,4),0x000F)
digit4=logic.And(CurrFreqMiddle,0x000F)
if keypos==1 then
if ipcPARAM==0 then
if digit2*100 + digit3*10 < 190 then -- min freq is 190KHz
DigitSpaceMiddle=logic.And(CurrFreqMiddle, 0xF0FF) --create space for new digit
NewFreqMiddle=logic.Or(DigitSpacMiddle, 0x0900) --make temp freq digit 9
ipc.writeUW(freqlocMiddle, NewFreqMiddle) -- write temp middle freq digit (note have to write middle freq when updating outer freq)
ipc.writeUW(freqlocOuter, NewFreqOuter) -- update radio panel
keypos=keypos+1 --point to position 2 next
ipc.set("KEY_POS", keypos) --save next position info for next iteration
else
NewFreqOuter=logic.And(CurrFreqOuter,0xF0FF)
ipc.writeUW(freqlocMiddle, CurrFreqMiddle) --apparently need to write middle freq when updating outer freq
ipc.writeUW(freqlocOuter, NewFreqOuter) -- update radio panel
keypos=keypos+1 --point to position 2 next
ipc.set("KEY_POS", keypos)
end
elseif ipcPARAM ==1 then
if digit2 > 7 then -- max freq is 1799.5KHz
NewFreqMiddle=logic.And(CurrFreqMiddle, 0xF0FF) -- temp freq digit = 0
DigitSpaceOuter=logic.And(CurrFreqOuter, 0xF0FF) -- create space for new freq digit at correct position
NewFreqOuter=logic.Or(DigitSpaceOuter,0x0100)
ipc.writeUW(freqlocMiddle, NewFreqMiddle) --apparently need to write middle freq when updating outer freq
ipc.writeUW(freqlocOuter, NewFreqOuter) -- update radio panel
keypos=keypos+1 --point to position 2 next
ipc.set("KEY_POS", keypos)
else
DigitSpaceOuter=logic.And(CurrFreqOuter, 0xF0FF) -- create space for new freq digit at correct position
NewFreqOuter=logic.Or(DigitSpaceOuter,0x0100)
ipc.writeUW(freqlocMiddle, CurrFreqMiddle) --apparently need to write middle freq when updating outer freq
ipc.writeUW(freqlocOuter, NewFreqOuter) -- update radio panel
keypos=keypos+1 --point to position 2 next
ipc.set("KEY_POS", keypos)
end
else
ipc.writeSTR(0x3380, "Invalid entry") -- invalid if first digit not 0 or 1
ipc.writeSW(0x32FA, 3)
return
end
elseif keypos==2 then
if (digit1==1 and ipcPARAM > 7) or (digit1==0 and ipcPARAM==0) then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
end
if digit1==0 and ipcPARAM==1 then --if true, next digit(digit 3) must be 9
DigitSpaceMiddle=logic.And(CurrFreqMiddle, 0xF00F) -- need space for ipcPARAM and temp freq digit
NewFreqMiddle=logic.Or(DigitSpaceMiddle, 0x0190)
ipc.writeUW(freqlocMiddle, NewFreqMiddle) -- only need to write middle freq when updating outer freq
keypos=keypos+1 --point to position 2 next
ipc.set("KEY_POS", keypos)
else
movPARAM=logic.Shl(ipcPARAM, 8) -- move new digit to correct position
DigitSpaceMiddle=logic.And(CurrFreqMiddle, 0xF0FF)
NewFreqMiddle=logic.Or(DigitSpaceMiddle, movPARAM)
ipc.writeUW(freqlocMiddle, NewFreqMiddle) --update radio panel
keypos=keypos+1 --point to position 2 next
ipc.set("KEY_POS", keypos)
end
elseif keypos==3 then
if digit1==0 and digit2==1 and not(ipcPARAM==9) then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
else
movPARAM=logic.Shl(ipcPARAM,4) -- move new digit to correct position
DigitSpace=logic.And(CurrFreqMiddle, 0xFF0F) -- create space for new freq digit at correct position
NewFreqMiddle=logic.Or(DigitSpace, movPARAM) -- place digit
ipc.writeUW(freqlocMiddle, NewFreqMiddle) -- update radio panel
keypos=keypos+1 --point to position 4 next
end
elseif keypos==4 then
DigitSpace=logic.And(CurrFreqMiddle, 0xFFF0) -- create space for new freq digit at correct position
NewFreqMiddle=logic.Or(DigitSpace, ipcPARAM) -- place digit
ipc.writeUW(freqlocMiddle, NewFreqMiddle) -- update radio panel
keypos=keypos+1 --point to position 5 next
-- no longer need the following since checked for decimal pt above
-- elseif keypos==5 and ipcPARAM==10 then -- ignore decimal pt input but update position
-- keypos=keypos+1 --point to position 6
elseif keypos==5 and not(ipcPARAM==10) then -- if true, this is digit for last position
if (digit1*1000+ digit2*100+ digit3*10+ digit4+ipcPARAM/10 >1799.5) then --max freq is 1750KHz
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
else
DigitSpace=logic.And(CurrFreqOuter, 0xFFF0) -- create space for new freq digit at correct position
NewFreqOuter=logic.Or(DigitSpace, ipcPARAM) -- place digit
ipc.writeUW(freqlocMiddle, CurrFreqMiddle) --apparently need to write middle freq when updating outer freq
ipc.writeUW(freqlocOuter, NewFreqOuter) -- update radio panel
keypos=keypos+2 -- update keypos in case need to BkSpc
end
elseif keypos==6 then
if (digit1*1000+ digit2*100+ digit3*10+ digit4+ipcPARAM/10 >1799.5) then --max freq is 1799.5KHz
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
else
DigitSpace=logic.And(CurrFreqOuter, 0xFFF0) -- create space for new freq digit at correct position
NewFreqOuter=logic.Or(DigitSpace, ipcPARAM) -- place digit
ipc.writeUW(freqlocMiddle, CurrFreqMiddle) --apparently need to write middle freq when updating outer freq
ipc.writeUW(freqlocOuter, NewFreqOuter) -- update radio panel
keypos=keypos+1 -- update keypos in case need to BkSpc
end --save keypos value for next iteration
end
ipc.set("KEY_POS", keypos)
return
end -- end ADF
-- end ipcPARAm between 0 and 10 for Com, Nav, ADF radios
if acr== "AP_ALT" then
if ipcPARAM==10 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #, no decimal pt
ipc.writeSW(0x32FA, 3)
return
end
if keypos==6 then -- reset keypos if last digit entered since no BackSpace
keypos=1
end
if keypos==1 then
ipc.set("ALT_1", ipcPARAM) --save 10,000 place digit
keypos=keypos+1 --point to position 2 next
elseif keypos==2 then
ipc.set("ALT_2", ipcPARAM) --save 1000 place digit
keypos=keypos+1 --point to position 3 next
elseif keypos==3 then
ipc.set("ALT_3", ipcPARAM) --save 100 place digit
keypos=keypos+1 --point to position 4 next
elseif keypos==4 then
if not( ipcPARAM==0)then
ipc.writeSTR(0x3380, "Invalid entry4, need 0") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return --10s place digit must be 0
else keypos=keypos+1 --point to position 5 next
end
elseif keypos==5 then
if not( ipcPARAM==0)then --1s place digit must be 0
ipc.writeSTR(0x3380, "Invalid entry5, need 0")
ipc.writeSW(0x32FA, 3)
return
else keypos=keypos+1 --point to position 6 incse BackSpace
end
end
ipc.set("KEY_POS", keypos) --save keypos value for next iteration of program
if keypos==6 then
alt1= ipc.get("ALT_1") -- get saved value
alt2= ipc.get("ALT_2") -- get saved value
alt3= ipc.get("ALT_3") -- get saved value
alt_ft = alt1*10000 + alt2*1000 +alt3*100 -- alt in feet; tens and unit place are assumed to be 0
alt_value = (alt_ft*65536)/3.28084 --FSUIPC offset value needed is altitude in meters times 65536
ipc.writeUD(0x07D4, alt_value)
end -- write altitude to offset
return
end --arc=AP_Alt
if acr== "AP_HDG" then
if ipcPARAM==10 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #, no decimal pt
ipc.writeSW(0x32FA, 3)
return
end
if keypos==4 then -- reset keypos if last digit entered since no BackSpace
keypos=1
end
if keypos==1 then
if ipcPARAM >3 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
else
ipc.set("HDG_1", ipcPARAM) --save 100s place digit
keypos=keypos+1 --point to position 2 next
end
elseif keypos==2 then
hdg1 = ipc.get("HDG_1")
if hdg1==3 and ipcPARAM > 6 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
else
ipc.set("HDG_2", ipcPARAM) --save 1s0 place digit
keypos=keypos+1 --point to position 3 next
end
elseif keypos==3 then
hdg1 = ipc.get("HDG_1")
hdg2=ipc.get("HDG_2")
if hdg1==3 and hdg2==6 and not (ipcPARAM == 0) then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
else
ipc.set("HDG_3", ipcPARAM) --save 1s place digit
keypos=keypos+1 --point to position 4 to allow for Backspace
end
end
ipc.set("KEY_POS", keypos) --save keypos value for next iteration of program
if keypos==4 then
hdg1= ipc.get("HDG_1") -- get saved value
hdg2= ipc.get("HDG_2") -- get saved value
hdg3= ipc.get("HDG_3") -- get saved value
hdg_deg = hdg1*100 + hdg2*10 + hdg3 -- heading in degrees
hdg_value = (hdg_deg*65536)/360 --FSUIPC offset value needed
ipc.writeUD(0x07CC, hdg_value) -- write deg info to offset
end -- end keypos=4
end -- end acr=AP_HDG
if acr== "AP_KTS" then -- Knots format is ###
if ipcPARAM==10 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #, no decimal pt
ipc.writeSW(0x32FA, 3)
return
end
if keypos==4 then -- reset keypos if last digit entered since no BackSpace
keypos=1
end
if keypos==1 then
ipc.set("KTS_1", ipcPARAM) --save 100s place digit
keypos=keypos+1 --point to position 2 next
elseif keypos==2 then
ipc.set("KTS_2", ipcPARAM) --save 10s place digit
keypos=keypos+1 --point to position 3 next
elseif keypos==3 then
kts1 = ipc.get("KTS_1")
kts2 = ipc.get("KTS_2")
if kts1==9 and kts2==9 and not (ipcPARAM == 0) then -- Max knots display is 990
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
else
ipc.set("KTS_3", ipcPARAM) --save 1s place digit
keypos=keypos+1 --point to position 4 to allow for Backspace
end
end
ipc.set("KEY_POS", keypos) --save keypos value for next iteration of program
if keypos==4 then
kts1= ipc.get("KTS_1") -- get saved value
kts2=ipc.get("KTS_2") -- get saved value
kts3= ipc.get("KTS_3") -- get saved value
knots = kts1*100 + kts2*10 + kts3 -- airspeed in knots
ipc.writeUW(0x07E2, knots) -- write airspeed info to offset
end -- end keypos=4
end -- end acr=AP_KTS
if acr== "AP_MACH" then --eventual MACHvformat is #.##
if keypos==5 then -- reset keypos if last digit entered since no BackSpace
keypos=1
end
if keypos==1 then
if ipcPARAM >1 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #, max MACH is 1.64
ipc.writeSW(0x32FA, 3)
return
else
ipc.set("MACH_1", ipcPARAM) --save units place digit
keypos=keypos+1 --point to position 2 next
end
elseif keypos==2 then
if not(ipcPARAM==10)then
ipc.writeSTR(0x3380, "Enter Decimal Point") --must be decimal pt
ipc.writeSW(0x32FA, 3)
else
keypos=keypos+1 --point to position 3 next
end
elseif keypos==3 then
mach1= ipc.get("MACH_1") -- get saved value
if (ipcPARAM==10) or (mach1==1 and ipcPARAM > 6) then --note have already checked that ipcPARAM values are between 0 & 10
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
else
ipc.set("MACH_2", ipcPARAM) --save tenth digit
keypos=keypos+1 -- point to position 4 next --point to position 5 to allow for Backspace
end
elseif keypos==4 then
mach1= ipc.get("MACH_1") -- get saved value
mach2= ipc.get("MACH_2") -- get saved value
if (ipcPARAM==10) or (mach1==1 and mach2==6 and ipcPARAM > 4)then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
else
ipc.set("MACH_3", ipcPARAM) --save hundredth digit
keypos=keypos+1 --point to position 5 to allow for Backspace
end
end
ipc.set("KEY_POS", keypos) --save keypos value for next iteration of program
if keypos==5 then
mach1= ipc.get("MACH_1") -- get saved value
mach2=ipc.get("MACH_2") -- get saved value
mach3= ipc.get("MACH_3") -- get saved value
mach = mach1 + mach2/10 + mach3/100 -- airspeed in Mach #
mach_value = (mach*65536) --FSUIPC offset value needed
ipc.writeUD(0x07E8, mach_value) -- write airspeed info to offset
end -- end keypos=5
end -- end acr=AP_MACH
end --ipcPARAM >=0 and ipcPARAM <=10
if (ipcPARAM >=0 and ipcPARAM <=10) or ipcPARAM==15 or ipcPARAM==16 then
if acr== "AP_VS" then
if ipcPARAM==10 then
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #, no decimal pt
ipc.writeSW(0x32FA, 3)
return
end
if keypos==6 then -- reset keypos if last digit entered since no BackSpace
keypos=1
end
if keypos==1 then --15 for VS up (e.g.,Num+), 16 for VS down e.g.,(Num-) signs
if not(ipcPARAM == 15 or ipcPARAM == 16) then
ipc.writeSTR(0x3380, "Invalid entry1, need + or -") --ipcPARAM invalid #, need + or - sign
ipc.writeSW(0x32FA, 3)
return
elseif ipcPARAM == 15 then
sign=1
ipc.set("SIGN",sign)
keypos=keypos+1
ipc.set("KEY_POS", keypos) --save keypos value for next iteration of program
return
else
sign=-1
ipc.set("SIGN",sign)
keypos=keypos+1
ipc.set("KEY_POS", keypos) --save keypos value for next iteration of program
return
end
end
if keypos==2 then
ipc.set("VS_2", ipcPARAM) --save 1000 place digit
keypos=keypos+1 --point to position 3 next
elseif keypos==3 then
ipc.set("VS_3", ipcPARAM) -- save 100s digit
keypos=keypos+1 --point to position 4 next
elseif keypos==4 then
if not( ipcPARAM==0)then
ipc.writeSTR(0x3380, "Invalid entry4, need 0") -- 10s digit must be 0, ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return --10s place digit must be 0
else keypos=keypos+1 --point to position 5 next
end
elseif keypos==5 then
if not( ipcPARAM==0)then --1s place digit must be 0
ipc.writeSTR(0x3380, "Invalid entry5, need 0")
ipc.writeSW(0x32FA, 3)
return
else keypos=keypos+1 --point to position 6 incase have BackSpace
end
end
ipc.set("KEY_POS", keypos) --save keypos value for next iteration of program
if keypos==6 then
vs2= ipc.get("VS_2") -- get saved value
vs3= ipc.get("VS_3") -- get saved value
sign=ipc.get("SIGN") -- get saved value
vs_ftpermin = sign*(vs2*1000 + vs3*100) --Vert Speed in ft/min; tens and unit place are assumed to be 0
ipc.writeSW(0x07F2,vs_ftpermin)
end
return
end
end --ipcPARAM from 0 to 10 or 15 or 16
if acr=="SQK" then
if ipcPARAM < 0 or ipcPARAM > 7 then --no digits >7 for transponder
ipc.writeSTR(0x3380, "Invalid entry") --ipcPARAM invalid #
ipc.writeSW(0x32FA, 3)
return
end
CurrCode = ipc.readUW(0x0354) --get code of active radio
codeloc= 0x0354 --get location of active radio code
if keypos==5 then -- reset keypos if last digit entered since no BackSpace
keypos=1
end
if keypos==1 then
movPARAM=logic.Shl(ipcPARAM,12) -- move new digit to correct position (unlike Com & Nav, 1st digit not always the same)
DigitSpace=logic.And(CurrCode , 0x0FFF) -- create space for new freq digit at correct position
NewCode=logic.Or(DigitSpace, movPARAM) -- place digit
ipc.writeUW(codeloc, NewCode) -- update radio panel
keypos=keypos+1 --point to position 2 next
elseif keypos==2 then
movPARAM=logic.Shl(ipcPARAM, 8) -- move new digit to correct position
DigitSpace=logic.And(CurrCode , 0xF0FF) -- create space for new freq digit at correct position
NewCode=logic.Or(DigitSpace, movPARAM) -- place digit
ipc.writeUW(codeloc, NewCode) -- update radio panel
keypos=keypos+1 --point to position 3 next
elseif keypos==3 then
movPARAM=logic.Shl(ipcPARAM,4) -- move new digit to correct position
DigitSpace=logic.And(CurrCode , 0xFF0F) -- create space for new freq digit at correct position
NewCode=logic.Or(DigitSpace, movPARAM) -- place digit
ipc.writeUW(codeloc, NewCode) -- update radio panel
keypos=keypos+1 --point to position 4 next
elseif keypos==4 then
DigitSpace=logic.And(CurrCode , 0xFFF0) -- create space for new freq digit at correct position
NewCode=logic.Or(DigitSpace, ipcPARAM) -- place digit
ipc.writeUW(codeloc, NewCode) -- update radio panel
keypos=keypos+1 -- update keypos in case need to BkSpc
end
ipc.set("KEY_POS", keypos) --save keypos value for next iteration of program
end -- end transponder, acr =SQK
[/Spoiler]
NpCsetCom.lua
--NpCsetCom 14Aug2013
-- Modified not to show frequencies on green bar
--Must enter first Com or Nav digit (a 1)
--Al Klayton, 1Oct2013
acr = ipc.get("ACTIVE_RADIO")
ipc.set("KEY_POS", 1)
onoff = ipc.get("ONOFF")
if (not(onoff == nil) and onoff == "OFF") then
return
end
if ipcPARAM == 1 then --setup for toggle code below
acr = "COM_2" --ipcPARAM =0 for toggle, =1 for COM_1 only, =2 for COM_2 only
else
if ipcPARAM == 2 then
acr = "COM_1"
end
end
if not(acr == nil) and acr == "COM_1" then
nacr = "COM_2" --do this code to setup for Com radio toggle
ipc.writeSTR(0x3380, nacr); --display delected radio on green bar
else
nacr = "COM_1" --do this code to setup for Com radio toggle
ipc.writeSTR(0x3380, nacr); --display delected radio on green bar
end
ipc.set("ACTIVE_RADIO", nacr);
ipc.writeSW(0x32FA, 3); --show active radio on green bar for 3 sec
Dernière modification par kzw313 (20-02-2021 22:48:40)