Vous n'êtes pas identifié(e).
je résume
function stby_freq_com1(bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
MJCD8_Write(q400_freq, 65058)
end
bcd_freq = Valeur
65058 = variable
Donc la fonction actuelle utilise une valeur pré-définie (65058) pour donner la variable à écrire à MJCD8_Write.
Donc il faut modifier la fonction pour ajouter la "variable" en paramètre:
function stby_freq(variable, bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
MJCD8_Write(q400_freq, variable)
end
ce que j'ai mis pour COM1
function stby_freq(65058, bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
MJCD8_Write(q400_freq, 65058)
end
stby_freq(65058, NewFreq) si tu veux continuer à changer COM1 SBY
ipc.writeUW(freqloc, NewFreq)
stby_freq(65058, NewFreq) <-----------modification de toute les appeles stby_freq
PS : jai fait un essaie qu'avec COM1
ça ne veut pas marcher
Dernière modification par kzw313 (02-03-2021 19:00:15)
Hors ligne
essaie ca, je n'ai pas testé et j'espère que je n'ai pas encore fait d'erreur de copier-coller.
si ca marche, tu reprendras mes explications, peut etre que tu comprendras mieux.
function BCD_to_MJC8Q400(bcd_freq)
digit4= logic.Shr(bcd_freq, 12)
digit3= logic.And(bcd_freq, 0x0F00)
digit3= logic.Shr(digit3, 8)
digit2= logic.And(bcd_freq, 0x00F0)
digit2= logic.Shr(digit2, 4)
digit1= logic.And(bcd_freq, 0x000F)
local mjc8q400_freq= 10*digit1+100*digit2+1000*digit3+10000*digit4
return mjc8q400_freq
end
function MJCD8_Write(value, variable)
ipc.writeLvar("MJC_VAR_WRITE_VALUE", value)
ipc.writeLvar("MJC_VAR_WRITE_CODE", variable)
end
function stby_freq(variable, bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
MJCD8_Write(q400_freq, variable)
end
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
q400_variable= 65058 -- Q400 COM1 STBY
--get location of active radio freq
elseif acr=="COM_2" then
CurrFreq = ipc.readUW(0x311C)
freqloc= 0x311C
q400_variable= 65094 -- Q400 COM2 STBY
elseif acr=="NAV_1" then
CurrFreq = ipc.readUW(0x311E)
freqloc= 0x311E
q400_variable= 65254 -- A TOI DE JOUER
elseif acr=="NAV_2" then
CurrFreq = ipc.readUW(0x3120)
freqloc= 0x3120
q400_variable= 65309 -- A TOI DE JOUER
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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 ???????????
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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]
Hors ligne
salut Zigou
Donc il faut modifier la fonction pour ajouter la "variable" en paramètre:
function stby_freq(variable, bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
MJCD8_Write(q400_freq, variable)
end
a coter de la plaque moi j'été
moi qui croyez qu'il fallait mètre les VARIABLE en chiffre variable = 65058
bravo tu est un pro du LUA je glisserai un mot a LINDA
La radio COM1&2 fonctionne très bien je règle Com1 ou Com2
autre chose il ya un problème avec radio NAV
1 - NAV_2= q400_variable= 65290 et non pas 65309
2 - en changent les fréquences elles ne son pas correcte
nav1 112.050 = 120.500
nav2 114.020 = 90.000
le log
154488 LUA.0: NewFreq (BCD)= 4096
154488 LUA.0: Q400Freq= 10000
154738 LUA.0: NewFreq (BCD)= 4608
154738 LUA.0: Q400Freq= 12000
155034 LUA.0: NewFreq (BCD)= 4608
155034 LUA.0: Q400Freq= 12000
156750 LUA.0: NewFreq (BCD)= 4613
156750 LUA.0: Q400Freq= 12050
168622 LUA.0: NewFreq (BCD)= 4096
168622 LUA.0: Q400Freq= 10000
168872 LUA: "H:\fsx\Modules\NpCkeyData.lua": killed
169480 LUA.0: NewFreq (BCD)= 2304
169480 LUA.0: Q400Freq= 9000
Dernière modification par kzw313 (02-03-2021 22:05:47)
Hors ligne
ça veut dire que Majestic n'utilise pas le même format de fréquence pour COM et NAV.
j'ai tenté de deviner le format de NAV à partir de ton log car il n'est pas documenté dans leur fichier de variables.
Sans aucune certitude
Q400_COM1= 65058
Q400_COM2= 65094
Q400_NAV1= 65254
Q400_NAV2= 65290
function BCD_to_MJC8Q400(bcd_freq)
digit4= logic.Shr(bcd_freq, 12)
digit3= logic.And(bcd_freq, 0x0F00)
digit3= logic.Shr(digit3, 8)
digit2= logic.And(bcd_freq, 0x00F0)
digit2= logic.Shr(digit2, 4)
digit1= logic.And(bcd_freq, 0x000F)
local mjc8q400_freq= digit1+10*digit2+100*digit3+1000*digit4
return mjc8q400_freq
end
function MJCD8_Write(value, variable)
ipc.writeLvar("MJC_VAR_WRITE_VALUE", value)
ipc.writeLvar("MJC_VAR_WRITE_CODE", variable)
end
function stby_freq(variable, bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
if variable==Q400_COM1 or variable==Q400_COM2 then
MJCD8_Write(10*q400_freq, variable)
elseif variable==Q400_NAV1 or variable==Q400_NAV2 then
MJCD8_Write(10000+q400_freq, variable)
end
end
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
q400_variable= Q400_COM1
--get location of active radio freq
elseif acr=="COM_2" then
CurrFreq = ipc.readUW(0x311C)
freqloc= 0x311C
q400_variable= Q400_COM2
elseif acr=="NAV_1" then
CurrFreq = ipc.readUW(0x311E)
freqloc= 0x311E
q400_variable= Q400_NAV1
elseif acr=="NAV_2" then
CurrFreq = ipc.readUW(0x3120)
freqloc= 0x3120
q400_variable= Q400_NAV2
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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 ???????????
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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
stby_freq(q400_variable, NewFreq)
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]
Hors ligne
Salut Zigou
j aimerai te demander si tu a un moment , tu peut nous faire a moi et au autre semeur comme moi qui ne sait connaisse rien en LUA un tutoral le plus détailler possible ça serai bien de ta part Merci
Hors ligne
Bonsoir kzw313
le LUA est un langage de script, je ne peux pas faire de tutoriel, il faut avoir des bases de programmation.
Tu trouveras plein d'infos sur internet si tu as envie d'apprendre.
Une fois cet apprentissage, il faut comprendre comment l'appliquer à FSX/P3D.
Mais je le répète, la base est déjà d'avoir des connaissances en programmation.
Hors ligne
Propulsé par FluxBB