Interfacer une carte EFDE sans SIOC avec OCUSBMapper ?

Pour voir quelque chose tu dois mettre un print("je verifie_mon_code") à un emplacement ou tu veux vérifier que le code est bien exécuté.

Je l'ai fait pour la touche LVL_CHANGE et je vois bien apparaître mon print() dans le fichier "monfichierlog.txt"
 
  • Like
Les réactions: Avro
Les print n'ont aucun effet :

Code:
--[[
*****************************************************************************************
* Program Script Name    :    RJ85.EFDE_OVH
*
* Author Name            :    Emmanuel v1.00
*
*   Revisions:
*   -- DATE --    --- REV NO ---        --- DESCRIPTION ---
*      31/01/2020   1.0.0                Création
*
*
*
*
*****************************************************************************************
--]]



--*************************************************************************************--
--**                                   XLUA GLOBALS                                   **--
--*************************************************************************************--

--[[

SIM_PERIOD - this cont'ains the duration of the current frame in seconds (so it is alway a
fraction).  Use this to normalize rates,  e.g. to add 3 units of fuel per second in a
per-frame callback you’d do fuel = fuel + 3 * SIM_PERIOD.

IN_REPLAY - evaluates to 0 if replay is off, 1 if replay mode is on

--]]


--*************************************************************************************--
--**                                    CONSTANTS                                     **--
--*************************************************************************************--

USB_DEVICE = 1

--*************************************************************************************--
--**                                 GLOBAL VARIABLES                                 **--
--*************************************************************************************--



--*************************************************************************************--
--**                                 LOCAL VARIABLES                                  **--
--*************************************************************************************--

local simDR_seatBelts = 0

--*************************************************************************************--
--**                              FIND X-PLANE DATAREFS                                 **--
--*************************************************************************************--

simDR_seatBelts                    = find_dataref("sim/cockpit2/switches/fasten_seat_belts")

print("simDR_seatBelts : "..simDR_seatBelts)

--*************************************************************************************--
--**                                FIND X-PLANE COMMANDS                                **--
--*************************************************************************************--

-- toggle switches
ovh_seatBelts_on                = find_dataref("sim/s'ystems/seatbelt_sign_toggle")


--*************************************************************************************--
--**                               FIND CUSTOM DATAREFS                                  **--
--*************************************************************************************--


usbDR_input_digital          = find_dataref("pikitanga/ocusbmapper/usb1/input/digital")
--[[
usbDR_input_analog           = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/input/analog")
usbDR_input_analog_notshow   = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/analog/notshow")
usbDR_output_allon           = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/allon")
usbDR_output_dspl            = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/dspl")
usbDR_output_dspl_brightness = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/dspl/brightness")
usbDR_output_leds            = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/leds")
--]]

--*************************************************************************************--
--**                               FIND CUSTOM COMMANDS                               **--
--*************************************************************************************--



--*************************************************************************************--
--**                         CREATE READ-ONLY CUSTOM DATAREFS                            **--
--*************************************************************************************--



--*************************************************************************************--
--**                        READ-WRITE CUSTOM DATAREF HANDLERS                          **--
--*************************************************************************************--



--*************************************************************************************--
--**                        CREATE READ-WRITE CUSTOM DATAREFS                         **--
--*************************************************************************************--



--*************************************************************************************--
--**                              CUSTOM COMMAND HANDLERS                             **--
--*************************************************************************************--



--*************************************************************************************--
--**                               CREATE CUSTOM COMMANDS                               **--
--*************************************************************************************--



--*************************************************************************************--
--**                              X-PLANE COMMAND HANDLERS                            **--
--*************************************************************************************--



--*************************************************************************************--
--**                              REPLACE X-PLANE COMMANDS                               **--
--*************************************************************************************--



--*************************************************************************************--
--**                               WRAP X-PLANE COMMANDS                               **--
--*************************************************************************************--



--*************************************************************************************--
--**                                OBJECT CONSTRUCTORS                                  **--
--*************************************************************************************--



--*************************************************************************************--
--**                                   CREATE OBJECTS                                    **--
--*************************************************************************************--



--*************************************************************************************--
--**                                  SYSTEM FUNCTIONS                                **--
--*************************************************************************************--

function process_switches()

    if usbDR_input_digital[5] == 1 and simDR_seatBelts == 0 then
        ovh_seatBelts_on:once()
        ovh_seatBelts_on:once()
        simDR_seatBelts = 2
        print("usbDR_input_digital[4 et 5] simDR_seatBelts == 0 : "..usbDR_input_digital[4] .. " / " .. usbDR_input_digital[5] .. " / " .. simDR_seatBelts)
    end
    if usbDR_input_digital[5] == 1 and simDR_seatBelts == 1 then
        ovh_seatBelts_on:once()
        simDR_seatBelts = 2
        print("usbDR_input_digital[4 et 5] simDR_seatBelts == 1 : "..usbDR_input_digital[4] .. " / " .. usbDR_input_digital[5] .. " / " .. simDR_seatBelts)
    end
    if usbDR_input_digital[5] == 0 and simDR_seatBelts == 2 then
        ovh_seatBelts_on:once()
        simDR_seatBelts = 0
        print("usbDR_input_digital[4 et 5] simDR_seatBelts == 2 : "..usbDR_input_digital[4] .. " / " .. usbDR_input_digital[5] .. " / " .. simDR_seatBelts)
    end

end

function process_buttons()
end

function process_dials()

end

function process_leds()

end

function process_displays()

    --[[
    
    0 - 9     = corresponding digit
    10        = blank
    11        = -
    12 - 15 = varies depending on the hardware device eg MCP 13 is an "A"
    
    --]]

end

function process_encoders()

end


--*************************************************************************************--
--**                                XLUA EVENT CALLBACKS                                **--
--*************************************************************************************--

--function aircraft_load() end

--function aircraft_unload() end

--function flight_start() end

--function flight_crash() end

function before_physics()

    process_switches()
    process_buttons()
    process_dials()
    process_leds()
    process_displays()
    process_encoders()

end

--function after_physics() end

--function after_replay() end

--*************************************************************************************--
--**                                SUB-MODULE PROCESSING                                **--
--*************************************************************************************--

-- dofile("")
 
Le fichier log que tu as créé ne bouge pas du tout ? Toujours à 0 ?
 
Salut !

sim/cockpit2/switches/fasten_seat_belts
ça ne marche pas avec cette dataref ?

ou sim/cockpit/switches/fasten_seat_belts

sim/cockpit pour les monomoteurs
sim/cockpit2 pour les avions avec plusieurs moteurs/réacteurs
 
Dernière édition:
RJ85, 4 moteurs :)

Sinon, quelle que soit la variante, c'est pareil !

Dommage, c'était trop beau pour fonctionner.
 
quand tu regardes dans le script overhead xlua du 737 laminar , ils utilisent quelle datataref ?
le simu est éteint ...
 
Je n'ai pas trouvé ce script dans les éléments à télécharger, tu l'as ?
 
il n'a pas fait de script pour l'overhead du 737 Laminar , , les systèmes n'étant pas assez complet mais ça te permet de voir les datarefs ... de mémoire regarde le dossier switches car il n'est pas du tout organisé comme dans le zibo ...

il faut regarder dans le dossier plugin xlua du 737 laminar !
 
Les dataref mis a parts, si tes scripts LUA ne sont pas executés, on ira pas loin.
 
Si tu veux bien tester avec le 737 Laminar ...
- exécute une console Windows en mode administrateur
- tape la commande suivante X-Plane.exe >logFD.txt
- Lance un vol en choisissant le 737 laminar

Déjà, sans modification de script, j'ai une trace dans mon fichier LOGFD.TXT de tous les scripts qui se lancent

Code:
Running C:\Program Files (x86)/X-Plane 11/Aircraft/Laminar Research/Boeing B737-800/plugins/xlua/init.lua/
C:\Program Files (x86)/X-Plane 11/Aircraft/Laminar Research/Boeing B737-800/plugins/xlua/scripts/B738.annunciators/B738.annunciators.lua
Running init script
Running module in namespace
Running C:\Program Files (x86)/X-Plane 11/Aircraft/Laminar Research/Boeing B737-800/plugins/xlua/init.lua/
C:\Program Files (x86)/X-Plane 11/Aircraft/Laminar Research/Boeing B737-800/plugins/xlua/scripts/B738.chrono/B738.chrono.lua
Running init script
Running module in namespace
Running C:\Program Files (x86)/X-Plane 11/Aircraft/Laminar Research/Boeing B737-800/plugins/xlua/init.lua/
C:\Program Files (x86)/X-Plane 11/Aircraft/Laminar Research/Boeing B737-800/plugins/xlua/scripts/B738.comms/B738.comms.lua
Running init script
Running module in namespace
Running C:\Program Files (x86)/X-Plane 11/Aircraft/Laminar Research/Boeing B737-800/plugins/xlua/init.lua/
C:\Program Files (x86)/X-Plane 11/Aircraft/Laminar Research/Boeing B737-800/plugins/xlua/scripts/B738.fire/B738.fire.lua
Running init script
Running module in namespace
../..
 
  • Like
Les réactions: Avro
X-Plane.exe >logFD.txt

J'avais fait X-Plane.exe > logFD.txt et visiblement l'espace a son importance !

Voilà donc le résultat de mon programme. J'ai ajouté des tostring() pour simDR_seatBelts par exemple.

Got allocator: 0000000023270010
Got Lua: 0000000023270378
[SASL INFO] loading panel
[SASL INFO] loading time_logic
[SASL INFO] loading engine_soundLL
[SASL INFO] loading engine_soundLM
[SASL INFO] loading engine_soundRM
[SASL INFO] loading engine_soundRR
[SASL INFO] loading r1
[SASL INFO] loading start
[SASL INFO] Avionics loaded
Running scripts/RJ85.EFDE_OVH/RJ85.EFDE_OVH.lua
simDR_seatBelts : table: 0x21281858
Running scripts/RJ85.opencockpits_mcp/RJ85.opencockpits_mcp.lua
WARNING: dataref laminar/B738/engine/eng2_N1_bug is used but not defined.
WARNING: dataref laminar/B738/engine/eng1_N1_bug is used but not defined.
WARNING: dataref laminar/B738/autopilot/autothrottle_status is used but not defined.
WARNING: dataref laminar/B738/autopilot/vnav_status1 is used but not defined.
WARNING: dataref laminar/B738/autopilot/n1_pos is used but not defined.
WARNING: dataref laminar/B738/autopilot/disconnect_pos is used but not defined.
WARNING: dataref sim/s'ystems/seatbelt_sign_toggle is used but not defined.
NAVT: Airspace: 107254 usec
NAVT: NavData: 3736311 usec
NAVT: Navaids: 128119 usec
NAVT: Fixes: 247600 usec
NAVT: Airways: 418679 usec
Main menu decided unilaterally that you need to init a flight!
PERLIN AVERAGE: 127
BAD GAMMA: Resources/default scenery/sim objects/dynamic/Nimitz.png
BAD GAMMA: Resources/default scenery/sim objects/dynamic/Nimitz_lit.png
BAD GAMMA: Resources/default scenery/sim objects/dynamic/Perry.png
BAD GAMMA: Resources/default scenery/sim objects/dynamic/Perry_lit.png
Set boat to (-777300.31, -1786087.38, 4357699.50), heading 8.000000 for approach
parse_voice_pack: Resources/default scenery/default atc dat/voices/default pilot/default_pilot.voc: 824260 usec
parse_voice_pack: Resources/default scenery/default atc dat/voices/default/default.voc: 796046 usec

Du coup mon test simDR_seatBelts == 1 then ne doit pas fonctionner.
 
Ah, c'est mieux ...

Là je te laisse mettre des print() dans le code pour le suivre à la trace ...
 
Dis moi, simDR_seatBelts : table: 0x21281858 c'est le contenue de la dataref ?
C'est pas 0 ou 1 ?
 
Dis moi, simDR_seatBelts : table: 0x21281858 c'est le contenue de la dataref ?
C'est pas 0 ou 1 ?

C'est 0, 1 ou 2 quand je regarde dans DataRefTool mais là effectivement c'est différent. Je ne sais quoi en penser.
 
J'ai repris mon code et aujourd'hui, ça marche !

Code:
simDR_seatBelts                = find_dataref("sim/cockpit2/switches/fasten_seat_belts")

function process_switches()
    if usbDR_input_digital[5] == 1 then
        simDR_seatBelts = 2
    end
    if usbDR_input_digital[5] == 0 then
        simDR_seatBelts = 0
    end
end

Je vais poursuivre l'œuvre d'une vie ;)
 
Bravo !
Je n'en dout'ais pas ! il fallait trouver le truc !
 
Le code final et qui fonctionne. Fini SIOC.

Code:
--[[
*****************************************************************************************
* Program Script Name    :    RJ85.EFDE_OVH
*
* Author Name            :    Emmanuel v1.00
*
*   Revisions:
*   -- DATE --    --- REV NO ---        --- DESCRIPTION ---
*      31/01/2020   1.0.0                Création
*
*
*
*
*****************************************************************************************
--]]



--*************************************************************************************--
--**                                   XLUA GLOBALS                                   **--
--*************************************************************************************--

--[[

SIM_PERIOD - this cont'ains the duration of the current frame in seconds (so it is alway a
fraction).  Use this to normalize rates,  e.g. to add 3 units of fuel per second in a
per-frame callback you’d do fuel = fuel + 3 * SIM_PERIOD.

IN_REPLAY - evaluates to 0 if replay is off, 1 if replay mode is on

--]]


--*************************************************************************************--
--**                                    CONSTANTS                                     **--
--*************************************************************************************--

USB_DEVICE = 1

--*************************************************************************************--
--**                                 GLOBAL VARIABLES                                 **--
--*************************************************************************************--



--*************************************************************************************--
--**                                 LOCAL VARIABLES                                  **--
--*************************************************************************************--

--local var = 0

--*************************************************************************************--
--**                              FIND X-PLANE DATAREFS                                 **--
--*************************************************************************************--

battery                        = find_dataref("sim/cockpit/electrical/battery_on")
APU1                        = find_dataref("sim/cockpit2/electrical/APU_starter_switch")
APU2                        = find_dataref("sim/cockpit2/electrical/APU_running")
seatBelts                    = find_dataref("sim/cockpit2/switches/fasten_seat_belts")
pumps                        = find_dataref("sim/cockpit2/fuel/fuel_tank_pump_on")
apu_gen                        = find_dataref("sim/cockpit2/electrical/APU_generator_on")
eng_gens                    = find_dataref("sim/cockpit2/electrical/generator_on")
startmaster                    = find_dataref("sim/cockpit2/switches/avionics_power_on")
startengine                    = find_dataref("sim/cockpit2/engine/actuators/ignition_key")
startselect                    = find_dataref("sim/cockpit2/switches/custom_slider_on")

--*************************************************************************************--
--**                                FIND X-PLANE COMMANDS                                **--
--*************************************************************************************--

-- toggle switches


--*************************************************************************************--
--**                               FIND CUSTOM DATAREFS                                  **--
--*************************************************************************************--


usbDR_input_digital          = find_dataref("pikitanga/ocusbmapper/usb1/input/digital")
--[[
usbDR_input_analog           = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/input/analog")
usbDR_input_analog_notshow   = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/analog/notshow")
usbDR_output_allon           = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/allon")
usbDR_output_dspl            = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/dspl")
usbDR_output_dspl_brightness = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/dspl/brightness")
usbDR_output_leds            = find_dataref("pikitanga/ocusbmapper/usb" .. USB_DEVICE .. "/output/leds")
--]]

--*************************************************************************************--
--**                               FIND CUSTOM COMMANDS                               **--
--*************************************************************************************--



--*************************************************************************************--
--**                         CREATE READ-ONLY CUSTOM DATAREFS                            **--
--*************************************************************************************--



--*************************************************************************************--
--**                        READ-WRITE CUSTOM DATAREF HANDLERS                          **--
--*************************************************************************************--



--*************************************************************************************--
--**                        CREATE READ-WRITE CUSTOM DATAREFS                         **--
--*************************************************************************************--



--*************************************************************************************--
--**                              CUSTOM COMMAND HANDLERS                             **--
--*************************************************************************************--



--*************************************************************************************--
--**                               CREATE CUSTOM COMMANDS                               **--
--*************************************************************************************--



--*************************************************************************************--
--**                              X-PLANE COMMAND HANDLERS                            **--
--*************************************************************************************--



--*************************************************************************************--
--**                              REPLACE X-PLANE COMMANDS                               **--
--*************************************************************************************--



--*************************************************************************************--
--**                               WRAP X-PLANE COMMANDS                               **--
--*************************************************************************************--



--*************************************************************************************--
--**                                OBJECT CONSTRUCTORS                                  **--
--*************************************************************************************--



--*************************************************************************************--
--**                                   CREATE OBJECTS                                    **--
--*************************************************************************************--



--*************************************************************************************--
--**                                  SYSTEM FUNCTIONS                                **--
--*************************************************************************************--

function process_switches()

    if usbDR_input_digital[0] == 1 then
        eng_gens[0] = 1
    end
    if usbDR_input_digital[0] == 0 then
        eng_gens[0] = 0
    end

    if usbDR_input_digital[1] == 1 then
        seatBelts = 2
    end
    if usbDR_input_digital[1] == 0 then
        seatBelts = 0
    end

    if usbDR_input_digital[2] == 1 then
        apu_gen = 1
    end
    if usbDR_input_digital[2] == 0 then
        apu_gen = 0
    end

    if usbDR_input_digital[3] == 1 then
        eng_gens[3] = 1
    end
    if usbDR_input_digital[3] == 0 then
        eng_gens[3] = 0
    end

    if usbDR_input_digital[4] == 1 then
        battery = 1
    end
    if usbDR_input_digital[4] == 0 then
        battery = 0
    end

    if usbDR_input_digital[5] == 1 then
        APU1 = 2
        APU2 = 2
    end
    if usbDR_input_digital[5] == 0 then
        APU1 = 0
        APU2 = 0
    end

    if usbDR_input_digital[6] == 1 then
        startmaster = 1
    end
    if usbDR_input_digital[6] == 0 then
        startmaster = 0
    end

    if usbDR_input_digital[7] == 1 then
        -- startselect[23] est utilisé pour le sélecteur du moteur à démarrer
        startengine[startselect[23]] = 4
    end
    if usbDR_input_digital[7] == 0 then
        startengine[startselect[23]] = 3
    end

    if usbDR_input_digital[10] == 1 then
        pumps[2] = 1
    end
    if usbDR_input_digital[10] == 0 then
        pumps[2] = 0
    end

    if usbDR_input_digital[9] == 1 then
        pumps[0] = 1
        pumps[1] = 1
        pumps[3] = 1
    end
    if usbDR_input_digital[9] == 0 then
        pumps[0] = 0
        pumps[1] = 0
        pumps[3] = 0
    end

end

function process_buttons()
end

function process_dials()

end

function process_leds()

end

function process_displays()

    --[[

    0 - 9     = corresponding digit
    10        = blank
    11        = -
    12 - 15 = varies depending on the hardware device eg MCP 13 is an "A"

    --]]

end

function process_encoders()

end

--*************************************************************************************--
--**                                XLUA EVENT CALLBACKS                                **--
--*************************************************************************************--

-- function aircraft_load() end

--function aircraft_unload() end

--function flight_start() end

--function flight_crash() end


function before_physics()

    process_switches()
    process_buttons()
    process_dials()
    process_leds()
    process_displays()
    process_encoders()

end

--function after_physics() end

--function after_replay() end

--*************************************************************************************--
--**                                SUB-MODULE PROCESSING                                **--
--*************************************************************************************--

-- dofile("")
 
Emmanuel, il y a un petit truc que je ne comprends pas bien... o_O

Bon, je précise que je n'ai pas XPlane et donc je ne maîtrise pas ses besoins en écriture LUA (Surtout l'"Event" de déclanchement et son comportement!...)...

Mais dans une écriture comme cela, et quelque soit le language, tu demandes à faire deux itérations.

Code:
function process_switches()

    if usbDR_input_digital[5] == 1 then

        simDR_seatBelts = 2

    end

    if usbDR_input_digital[5] == 0 then

        simDR_seatBelts = 0

    end

end



Si tes inputs ne peuvent avoir que ces deux valeurs [1 & 0], pourquoi ne pas écrire :


Code:
function process_switches()
    if usbDR_input_digital[5] == 1 then
        simDR_seatBelts = 2
    else
        simDR_seatBelts = 0
    end
end

Tu gagnes en temps machine... Tu n'as plus qu'une seule itération. ;)
 
Dernière édition:
@Ptipilot, je connais bien la programmation : else, elseif, case, conditions ternaires () ? : En LUA, else fonctionne mais semble avoir un comportement parfois inattendu pour nos besoins. Qui confirme, @Playrec ?
 
J'aurais fait comme @Ptipilot ...

Ou alors ce serait grave comme comportement de LUA ;)
C'est quand même les bases d'un langage :unsure:
 
En LUA, else fonctionne mais semble avoir un comportement parfois inattendu pour nos besoins.
Concernant LUA en interfaçage avec Prepar3D, j'en ai des kilomètres à mon actif et le comportement du 'if... elseif... else' est tout à fait standard.
Mon interrogation était plutôt son intégration avec XPlane que je ne maîtrise pas.

C'est pourquoi, je me suis permis d'intervenir sur ce point dans votre débat. ;)


Voici comme exemple une partie de mon code pour un bouton pour le PMDG 737NGX
Code:
function NGX_ENG1_START()
    local Current_Event_ID = (THIRD_PARTY_EVENT_ID_MIN + 119)
    NGX_IGN_left()
    local Test_Switch = ipc.readLvar('ngx_switch_119_a')
    if Test_Switch == 0 then
            -- Remise à OFF à partir de GRD
            ipc.control(Current_Event_ID, Mouse_Flag_Wheel_Up)
            
    elseif Test_Switch == 10 then    
            -- Mise à GRD à partir de OFF
            ipc.control(Current_Event_ID, Mouse_Flag_Wheel_Down)
            
    elseif Test_Switch == 20 then    
            -- Mise à GRD à partir de CONT
            ipc.control(Current_Event_ID, Mouse_Flag_Wheel_Down)
            ipc.control(Current_Event_ID, Mouse_Flag_Wheel_Down)
            
    elseif Test_Switch == 30 then    
            -- Mise à GRD à partir de FLT
            ipc.control(Current_Event_ID, Mouse_Flag_Wheel_Down)
            ipc.control(Current_Event_ID, Mouse_Flag_Wheel_Down)
            ipc.control(Current_Event_ID, Mouse_Flag_Wheel_Down)
            
    else
        -- Nothing
        
    end
    
end
 
Dernière édition:
Hello,

Et moi j'aurais écrit (dans les mêmes hypothèses) simDR_seatBelts = usbDR_input_digital[5] * 2 ;)
(certes avec un petit commentaire parce que lorsqu'on relit ceci 2 ans après...)
 
  • Like
Les réactions: Avro
Ok pour le fonctionnement entre la carte EFDE et le Plugin.
@fab je te prends une carte IO pour commencer à faire mumuse ;G)
 
  • Like
Les réactions: Avro
Le cordonnier mal chaussé ! LoL ! :p
 
Retour
Haut