Vous n'êtes pas identifié(e).
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.
tu appelles un ami ?
ç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]
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]
regarde mon post #46, je te dis comment appeler la nouvelle fonction avec 2 paramètres:
Pour finir avec l'étape 1, partout ou tu appelles stby_freq_com1(NewFreq), il faut mettre à jour pour passer ce deuxième paramètre (note que j'en ai profité pour renommer la fonction puisqu'elle ne se limite plus à COM1):
- stby_freq(65058, NewFreq) si tu veux continuer à changer COM1 SBY
- ou stby_freq(65094, NewFreq) si tu veux tester si ca fonctionne avec COM2 SBY
Dans le post #5, j'explique comment obtenir le code de la variable Majestic à partir de son nom.
Donc oui, COM1= 65058.
Je n'ai pas vérifié pour COM2, tu as mentionné 65094, je t'ai cru sur parole.
Ce que tu as fait (et je confirme que ca ne peut pas marcher):
function stby_freq_com1(65058, bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
MJCD8_Write(q400_freq, (65058)
end
et ce que je te demande et que je t'ai donné dans mon message précédent avec l'explication du pourquoi:
function stby_freq(variable, bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
MJCD8_Write(q400_freq, variable)
end
ps: et je t'ai aussi dit que j'avais renommé la fonction puisqu'on change son comportement.
Hello kzw313
il faut y aller étape par étape.
La fonction MJCD8_Write(value, variable) prend 2 paramètres: la variable et la valeur que tu veux écrire.
La fonction stby_freq_com1 appelle MJCD8_Write mais ne prend qu'un seul paramètre (bcd_freq) qui est la valeur.
function stby_freq_com1(bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
MJCD8_Write(q400_freq, 65058)
end
Donc la fonction actuelle utilise une valeur pré-définie (65058) pour donner la variable à écrire à MJCD8_Write.
Tu cherches à étendre les possibilités de ton script pour écrire dans une autre variable (ex COM2).
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
Pour finir avec l'étape 1, partout ou tu appelles stby_freq_com1(NewFreq), il faut mettre à jour pour passer ce deuxième paramètre (note que j'en ai profité pour renommer la fonction puisqu'elle ne se limite plus à COM1):
- stby_freq(65058, NewFreq) si tu veux continuer à changer COM1 SBY
- ou stby_freq(65094, NewFreq) si tu veux tester si ca fonctionne avec COM2 SBY
L'étape 2 consiste à passer la valeur 65058 ou 65094 via une nouvelle variable, ce qui permettra à ton script de passer de l'un à l'autre.
J'espère que ca t'aide et que tu comprends un minimum.
cordialement
Regarde la fonction MJCD8_Write(value, variable), c'est celle ci qui écrit la fréquence dans la variable du Majestic.
Elle prend deux paramètres, la variable (pour l'instant 65058 qui correspond à EFISdata_->ARCDUs[0].stby_freq_com[0]) et la valeur (fréquence dans notre cas).
Donc si tu veux maintenant pouvoir écrire la fréquence dans une variable COM1 ou COM2, il faut aussi avoir un 2e paramètre dans stby_freq_com1(bcd_freq) --> par exemple stby_freq_com1(variable, bcd_freq)
à toi de modifier le code de cette fonction pour prendre en compte ce nouveau paramètre.
Salut,
oui maintenant c'est à toi de travailler
Etape 1:
Nous avons créé une fonction pour écrire dans la variable COM1 SBY du Q400: 65058
function stby_freq_com1(bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
MJCD8_Write(q400_freq, 65058)
end
Donc, il faudrait que tu ajoutes un 2e paramètre à cette fonction pour pouvoir donner une autre variable que COM1.
Dans un premier temps, ajoute ce 2e paramètre, utilise le à la place de 65058 et modifie tous les appels à la fonction pour passer ce 2e paramètre avec la valeur 65058.
Etape 2 (quand tu as fini avec succès l'étape 1):
Recherche la variable: freqloc
Elle est utilisée pour justement spécifier s'il faut écrire la fréquence dans COM1, COM2, NAV1 ou NAV2 dans les radios par défaut.
Il faut utiliser le même principe pour le Q400.
En début de sujet, j'ai expliqué comment trouver le code de la variable COM1 du Majestic (65058).
Il te faut donc trouver les codes pour COM2, puis NAV1/NAV2 si tu veux tout câbler.
Etape 3:
Il te suffit de créer une nouvelle variable "q400_freqloc" et de la mettre à jour en même temps que freqloc avec les codes que tu as trouvés à l'étape 2.
Ensuite tu remplaces la valeur 65058 par la variable "q400_freqloc" quand tu appelles ta fonction "stby_freq_com1" (que tu pourrais d'ailleurs renommer)
N'hésite pas à partager tes progrès.
Bonne chance ! =W
En regardant à tête reposée ma fonction de conversion de format, je pense avoir trouvé l'erreur:
Remplace la fonction par celle ci (j'ai mis en gras ce que j'ai corrigé):
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
ok j'essaierai de lancer mon simu ce week-end, au moins la valeur de la fréquence n'est plus corrompue, je retrouve bien les fréquences que tu rentres.
Je dois merder qq part dans la conversion vers le format du Q400.
Essaie ca, j'ai vu une erreur qui peut expliquer le comportement étrange
function BCD_to_MJC8Q400(bcd_freq)
digit4= 10000*logic.Shr(bcd_freq, 12)
digit3= logic.And(bcd_freq, 0x0F00)
digit3= 1000*logic.Shr(bcd_freq, 8)
digit2= logic.And(bcd_freq, 0x00F0)
digit2= 100*logic.Shr(bcd_freq, 4)
digit1= 10*logic.And(bcd_freq, 0x000F)
local mjc8q400_freq= digit1+digit2+digit3+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_com1(bcd_freq)
local q400_freq= BCD_to_MJC8Q400(bcd_freq)
ipc.log("NewFreq (BCD)= " .. bcd_freq)
ipc.log("Q400Freq= " .. q400_freq)
MJCD8_Write(q400_freq, 65058)
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 --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
stby_freq_com1(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_com1(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_com1(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
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 ???????????
stby_freq_com1(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_com1(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_com1(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_com1(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]
bizarre
peux tu copier le script modifié stp ?
quelle est la fréquence que tu tapes au clavier ?
si je regarde uniquement la variable d'origine NewFreq, je vois 128.00, puis 3 fois 123.00
on avance.
Modifie la fonction comme suit:
function stby_freq_com1(NewFreq)
local q400_freq= BCD_to_MJC8Q400(NewFreq)
ipc.log("NewFreq (BCD)= " .. NewFreq)
ipc.log("Q400Freq= " .. q400_freq)
MJCD8_Write(q400_freq, 65058)
end
Lance ton simu, change tes fréquences comme décrit et ensuite, ouvre le répertoire "Modules" de ton simu (là ou tu as du mettre les scripts).
Il y a un fichier FSUIPCx.log (x étant la version de ton FSUIPC).
Tu devrais voir dedans les logs que j'ai rajoutés dans la fonction ci-dessus.
copie moi ces lignes et peut etre que je comprendrais ou est l'erreur.
Je n'ai pas le plaisir de connaitre Linda, elle est jolie ?
Tu mélanges deux choses différentes.
Avec linda, tu peux affecter des "fonctions" Ã des touches/boutons/etc.
Donc soit tu as 4 touches sur ton joystick de dispo et il faut écrire les 4 fonctions pour incrémenter/décrémenter les deux parties de la fréquence (entière et décimale), soit tu oublies et tu reviens à ton idée de départ d'utiliser NpCkeyData.
Les scripts NpCkeyData (de ce que j'ai vu rapidement) capturent les touches de ton clavier numérique pour rentrer une fréquence.
Je t'ai donné le code dans mon post précédent. En début de fichier, tu dois définir les deux fonctions dont tu as besoin:
- BCD_to_MJC8Q400
- MJCD8_Write
plus cette troisième qui appelle les deux précédentes:
function stby_freq_com1(NewFreq)
local q400_freq= BCD_to_MJC8Q400(NewFreq)
MJCD8_Write(q400_freq, 65058)
end
puis, dans le script, Ã chaque fois que tu vois l'instruction:
ipc.writeUW(freqloc, NewFreq) -- update radio panel
tu changes comme suit:
ipc.writeUW(freqloc, NewFreq) -- update radio panel
stby_freq_com1(NewFreq)
Dernier conseil:
Avant de modifier quoique ce soit, installe les scripts NpCkeyData et vérifie que tu arrives à modifier la fréquence COM1 sur un avion de base. C'est la base de vérifier que tout fonctionne avant d'entreprendre des modifs.
Tu ne réponds pas à ma question
Je ne demande pas ou tu as mis ma fonction mais la fonction MJCD8_Write
Je soupçonne que tu as du trouver sur la toile un exemple utilisant cette fonction MJCD8_Write mais que tu ne l'as jamais définie.
Insère les deux fonctions suivantes en début de fichier comme suit:
--Al Klayton, 14Nov2013
function BCD_to_MJC8Q400(bcd_freq)
digit4= 10000*logic.Shr(bcd_freq, 12)
digit3= logic.And(bcd_freq, 0x0F00)
digit3= 1000*logic.Shr(bcd_freq, 8)
digit2= logic.And(NewFreq, 0x00F0)
digit2= 100*logic.Shr(NewFreq, 4)
digit1= 10*logic.And(NewFreq, 0x000F)
local mjc8q400_freq= digit1+digit2+digit3+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
onoff = ipc.get("ONOFF")
PS: fais attention, j'ai vu que tu as copié plusieurs fois la fonction BCD_to_MJC8Q400 dans le script. Tu ne dois la déclarer qu'une seule, en début de fichier, tel que ci dessus
Tu as modifié le script initial pour appeler cette fonction:
MJCD8_Write(q400_freq, 65058)
donc ou est cette fonction ?
la fonction BCD_to_MJC8Q400 est faite pour convertir le format de fréquence, il ne faut pas l'appeler à partir d'une touche mais dans ton script.
Ou as tu mis la fonction MJCD8_Write ?
tu peux mettre la fonction BCD_to_MJC8Q400 dans le même fichier que MJCD8_Write
tu es ambitieux de te lancer dans une telle aventure
je ne peux pas tester alors je ne te garantis rien, d'autant que le script est complexe malgré tout.
Tes changements ne fonctionnent pas parce que FSX (et donc ton script) utilise un format BCD pour encoder les fréquences.
Il faudrait réécrire toute la logique du script qui capture les touches numériques.
Je te propose une solution intermédiaire, on laisse la logique telle qu'elle est, et on convertit à la volée la fréquence au format BCD en décimal pour appeler la fonction du Majestic.
Sauf erreur de ma part, cette fonction devrait convertir le format BCD en format compatible avec le Q400:
function BCD_to_MJC8Q400(bcd_freq)
digit4= 10000*logic.Shr(bcd_freq, 12)
digit3= logic.And(bcd_freq, 0x0F00)
digit3= 1000*logic.Shr(bcd_freq, 8)
digit2= logic.And(NewFreq, 0x00F0)
digit2= 100*logic.Shr(NewFreq, 4)
digit1= 10*logic.And(NewFreq, 0x000F)
local mjc8q400_freq= digit1+digit2+digit3+digit4
return mjc8q400_freq
end
A chaque fois que tu vois une écriture de la fréquence sur la radio FSX: ipc.writeUW(freqloc, NewFreq)
tu appelles les deux fonctions suivantes (et tu conserves l'appel à ipc.writeUW...):
q400_freq= BCD_to_MJC8Q400(NewFreq)
MJCD8_Write(q400_freq, 65058)
je croise les doigts....
Hello
pas trop le temps alors j'espère que tu maitrises un peu le LUA
le bout de code dans ton script qui lit la fréquence COM1:
if acr == "COM_1" then
CurrFreq = ipc.readUW(0x311A) --get freq of active radio
freqloc= 0x311A
idéalement, il faudrait la remplacer avec la lecture de la variable COM1 du Majestic (ie MJC_Read)
Et déjà pour t'entrainer, le bout de code qui écrit la valeur COM1 dans la radio de base FSX:
NewFreq = logic.Or(DigitSpace, movPARAM+0x0900) --add on temp 3rd freq digit = 9
ipc.writeUW(freqloc, NewFreq) -- update radio panel
Il faut remplacer le ipc.writeUW par l'appel à ta fonction: stby_freq_com1 (NewFreq)
PS: Il faut certainement convertir le format de NewFreq (format FSX) au format Majestic.
PS2: je te fais ca rapide car ton script est complexe et il gère toutes les fréquences COM1, COM2, NAV1, NAV2
mais si tu comprends la modif pour COM1, tu sauras l'adapter pour les autres fréquences
Bon dimanche
oui c'est sur, c'est plus clair avec la vidéo.
Du coup, tu as toutes les infos que tu voulais ? le script LUA de la vidéo capture les touches du clavier pour rentrer diverses fréquences, donc il te faut l'adapter pour écrire la fréquence dans la bonne variable du Majestic.
Tu as déjà la fonction pour écrire la fréquence standby du COM1:
function stby_freq_com1 (freq)
MJCD8_Write(freq, 65058).
end
Tu n'as plus qu'à appeler cette fonction à partir de ton script pour commencer.
Il faudra certainement convertir le format de la fréquence COM. Ton script semble prendre tous les digits (1 3 5 . 7 7 5) alors que la variable Majestic ne prend que les 5 derniers digits sans le point de séparation.
Si tu as du mal, partage le bout de code, et on verra ce qu'on peut faire.
Hello kzw123
Non, tu ne vas pas écrire une fonction par fréquence, tu ajoutes la fréquence en paramètre de ta fonction:
function stby_freq_com1 (freq)
MJCD8_Write(freq, 65058).
end
Et tu appelles ta fonction avec la fréquence voulue:
- pour 135.775 --> stby_freq_com1(35775)
- pour 124.800 --> stby_freq_com1(24800)
- etc
Ce qui veut dire que pour faire la boucle, il va falloir que tu lises d'abord la fréquence standby, tu la modifies selon ta guise et tu écris la nouvelle fréquence.
La lecture des variables majestic fonctionne de la même manière: freq= MJCD8_Read(65058).
(le paramètre du read étant le code de la variable Majestic)
en effet, la question n'est pas claire.
La fonction LUA de kzw313 est correcte, pour programmer le majestic, il faut bien appeler MJCD8_Write ou MJCD8_Read.
Le code est donné quelque part pour ces deux fonctions LUA (je peux le retrouver si c'était la question).
Si la question est de comprendre l'appel à :
MJCD8_Write(35775, 65058)
Le premier paramètre est la fréquence: 35775 ==> (1) 35.775
Le deuxième paramètre correspond à la variable interne EFISdata_->ARCDUs[0].stby_freq_com[0]
Pour obtenir le code qui correspond à cette variable, il faut utiliser l'utilitaire de Majestic: IntVarCRCGen.exe
Tu rentres le nom de la variable (EFISdata_->ARCDUs[0].stby_freq_com[0]), il te donne son code à utiliser comme deuxième paramètre: 65058.
bon courage
Salut Armand,
Il me semble me souvenir d'un bug comme celui-là avec d'autres avions.
Charge le Cessna par défaut, change le sélecteur de carburant de LEFT vers BOTH, et recharge l'ATR.
Essaye de voir si ça marche.
moi je parie sur Boufogre, ca tient la route
Bizarre cette erreur "grossière" dans le panel.cfg
mais en toute logique, puisque les deux jauges sont dupliquées, elles devraient afficher la même valeur (celle du réservoir 1) et Armand observe que seul un réservoir se vide... et en plus, sur 3 addons différents
Suis curieux d'avoir le verdict car c'est un truc de fou cette histoire.
Propulsé par FluxBB