EvenAR / node-simconnect

A cross platform SimConnect client library for Node.JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pressing the cdu buttons.

alptugidin opened this issue · comments

First of all, thank you for your help here. However, now I'm facing another issue. It's quite easy to interact with switches like landing lights because they only take a value of 1 or 0. But buttons don't work like that. When I press a button, its value becomes 100, and when I release it, it becomes 0. I can do this with my node app, but it only creates a pressing animation. There's no change on the screen.

const enum DefinitionID {
    CDU_A,
    LIVE_DATA
}

const dataToSet = new RawBuffer(0);
   dataToSet.clear();
   dataToSet.writeInt32(100);
   handle.setDataOnSimObject(DefinitionID.CDU_A, SimConnectConstants.OBJECT_ID_USER, {
     buffer: dataToSet,
     arrayCount: 0,
     tagged: false
   });

Not able to check atm, but I think all buttons in the PMDG aircraft has a dedicated event id. Perhaps you need to use those instead of the simulation variables?

In the PMDG SDK docs they use SimConnect_SetClientData for writing control events. With node-simconnect that would be something like this:

const PMDG_NG3_CONTROL_NAME = "PMDG_NG3_Control"
const PMDG_NG3_CONTROL_ID = 0x4E473333
const PMDG_NG3_CONTROL_DEFINITION = 0x4E473334

const dataToSet = new RawBuffer(0);
dataToSet.clear();
dataToSet.writeInt32(THIRD_PARTY_EVENT_ID_MIN + 573); // EVT_CDU_L_A found in PMDG_NG3_SDK.h
dataToSet.writeInt32(1); // 100 gave me a SIMCONNECT_EXCEPTION_OUT_OF_BOUNDS 

handle.mapClientDataNameToID(PMDG_NG3_CONTROL_NAME, PMDG_NG3_CONTROL_ID)
handle.addToClientDataDefinition(PMDG_NG3_CONTROL_DEFINITION, 0, 64, 0, 0) // 64 bits
handle.setClientData(PMDG_NG3_CONTROL_ID, PMDG_NG3_CONTROL_DEFINITION, 0, 0, 64, dataToSet.getBuffer()) // 64 bits

According to the manual this will write to a "command area" which the aircraft is continuously checking for new content, and you will need to wait for this area to be cleared (by subscribing for changes) before doing a new write.

However, the manual also shows how to use direct event triggering, which I was talking about. This seems like a simpler approach, but I guess it depends on your use case. I have added code for this in the PMDG sample

I'm a bit curious to why setDataOnSimObject (almost) works though. Did you try with the value 1 instead of 100? Did you get a SimConnect exception? Have you found an example where SimConnect_SetDataOnSimObject is used?