Hi Steeler,
Thanks for the response.
I modified the code as suggested, but not having any luck in getting the Seatbelt Switch to change when I press “i” on KB. System-A320Neo default in MSFS 1.16.2.0 on Windows 10 latest on an ASUS TUF Gaming A15 laptop.
The code is in SetData.cpp and I am building the executable on a MSVS2019.
Sorry, I am pasting the code here, seems I cant attach the .cpp file.
// Copyright (c) Asobo Studio, All rights reserved. www.asobostudio.com
//------------------------------------------------------------------------------
//
// SimConnect Set Data Sample
//
// Description:
// When z is pressed, the user aircraft is moved
//MeMe23May2021-when “i” is pressed! z is already AP toggle
// to a new location
//------------------------------------------------------------------------------
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
//MeMe25May2021-do we need below for bool
#include <stdbool.h>
#include “SimConnect.h”
int quit = 0;
HANDLE hSimConnect = NULL;
static enum GROUP_ID {
GROUP_6,
};
static enum INPUT_ID {
INPUT_6,
};
static enum EVENT_ID{
EVENT_SIM_START,
EVENT_6,
};
static enum DATA_DEFINE_ID {
DEFINITION_6,
};
static enum DATA_REQUEST_ID {
REQUEST_6,
};
//MeMe24May2021-added struct
//MeMe1Jun2021-changed per Steeler Forum from bool seatbelt;Try int
struct structseatbelt
{
int seatbelt;
};
structseatbelt sb;
void CALLBACK MyDispatchProcSD(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
HRESULT hr;
switch(pData->dwID)
{
//MeMe24May2021-added from ThrottleControl sample!
case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
{
SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
switch(pObjData->dwRequestID)
{
case REQUEST_6:
{
// Read and set the initial seatbelt value
structseatbelt *pS = (structseatbelt*)&pObjData->dwData;
sb.seatbelt = pS->seatbelt;
printf("\nREQUEST_USERID received, seatbelt = %d", pS->seatbelt);
// Now turn the input events on
hr = SimConnect_SetInputGroupState(hSimConnect, INPUT_6, SIMCONNECT_STATE_ON);
}
default:
break;
}
break;
}
case SIMCONNECT_RECV_ID_EVENT:
{
SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;
switch(evt->uEventID)
{
case EVENT_SIM_START:
{
//MeMe24May2021-added from throttlecontrol sample!!
hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_6, DEFINITION_6, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_ONCE);
}
break;
case EVENT_6:
{
/*MeMe23May2021- SIMCONNECT_DATA_INITPOSITION Init;
Init.Altitude = 5000.0;
Init.Latitude = 47.64210;
Init.Longitude = -122.13010;
Init.Pitch = 0.0;
Init.Bank = -1.0;
Init.Heading = 180.0;
Init.OnGround = 0;
Init.Airspeed = 60;
hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_6, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(Init), &Init );*/
if (0 == sb.seatbelt) sb.seatbelt = 1;
else sb.seatbelt = 0;
printf("\nValue seatbelt:%d\n", sb.seatbelt);
hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_6, SIMCONNECT_OBJECT_ID_USER, NULL, 0, sizeof(sb), &sb);
printf("\nhr after EVENT_6 received and data sent=%d",hr);
printf("\nEVENT_6 received and data sent");
//MeMe1Jun2021-not needed?
//hr = SimConnect_SetInputGroupState(hSimConnect, INPUT_6, SIMCONNECT_STATE_ON);
}
break;
default:
break;
}
break;
}
case SIMCONNECT_RECV_ID_QUIT:
{
quit = 1;
break;
}
default:
//MeMe23May2021-added \n at end!!?? printf("\nReceived:%d",pData->dwID);
printf("\nReceived:%d\n", pData->dwID);
break;
}
}
void testDataSet()
{
HRESULT hr;
//MeMe24May2021-redundant sb.seatbelt = 1;
if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Set Data", NULL, 0, 0, 0)))
{
//MeMe23May2021-added \n at end!!?? printf("\nConnected to Flight Simulator!");
printf("\nConnected to Flight Simulator!\n");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_6, "CABIN SEATBELTS ALERT SWITCH", "Bool", SIMCONNECT_DATATYPE_INT32);
// Request a simulation start event
hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
// Create a custom event
hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_6, "My.i");
// Link the custom event to some keyboard keys, and turn the input event off
hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT_6, "i", EVENT_6);
// Sign up for notifications for EVENT_6
hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_6, EVENT_6);
//MeMe24May2021-added from throttle sample
printf("\nPlease launch a flight");
while( 0 == quit )
{
SimConnect_CallDispatch(hSimConnect, MyDispatchProcSD, NULL);
Sleep(1);
}
hr = SimConnect_Close(hSimConnect);
}
}
int __cdecl _tmain(int argc, _TCHAR* argv[])
{
testDataSet();
return 0;
}
Can I trouble you to give me one more time a tip what is wrong, thenks a ton.
Anantha Krishnan