Skip to content

Commit

Permalink
fix: use period_visual_frame in 320 fadec (flybywiresim#8170)
Browse files Browse the repository at this point in the history
* fix: use period_visual_frame in 320 fadec

* fix: remaining usages of PERIOD_ONCE and cleanup
  • Loading branch information
Saschl authored Aug 23, 2023
1 parent 038cb4b commit bb697bf
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 53 deletions.
4 changes: 2 additions & 2 deletions fbw-a32nx/src/wasm/fadec_a320/src/FadecGauge.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class FadecGauge {
}

isConnected = true;
simConnectRequestData();

return true;
}
Expand All @@ -104,7 +105,6 @@ class FadecGauge {
bool onUpdate(double deltaTime) {
if (isConnected == true) {
// read simulation data from simconnect
simConnectRequestData();
simConnectReadData();
// detect pause
if ((simulationData.simulationTime == previousSimulationTime) || (simulationData.simulationTime < 0.2)) {
Expand Down Expand Up @@ -141,7 +141,7 @@ class FadecGauge {

// request data
HRESULT result = SimConnect_RequestDataOnSimObject(hSimConnect, 0, DataTypesID::SimulationDataTypeId, SIMCONNECT_OBJECT_ID_USER,
SIMCONNECT_PERIOD_ONCE);
SIMCONNECT_PERIOD_VISUAL_FRAME);

// check result of data request
if (result != S_OK) {
Expand Down
20 changes: 0 additions & 20 deletions fbw-a32nx/src/wasm/fbw_a320/src/interface/SimConnectInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,26 +1090,6 @@ bool SimConnectInterface::prepareClientDataDefinitions() {
return SUCCEEDED(result);
}

bool SimConnectInterface::requestReadData() {
// check if we are connected
if (!isConnected) {
return false;
}

// request data
if (!requestData()) {
return false;
}

// read data
if (!readData()) {
return false;
}

// success
return true;
}

bool SimConnectInterface::requestData() {
// check if we are connected
if (!isConnected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ class SimConnectInterface {

void setSampleTime(double sampleTime);

bool requestReadData();

bool requestData();

bool readData();
Expand Down
2 changes: 1 addition & 1 deletion fbw-a380x/src/wasm/fadec_a380/src/FadecGauge.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class FadecGauge {
}

isConnected = true;
// read simulation data from simconnect
simConnectRequestData();

return true;
Expand All @@ -127,6 +126,7 @@ class FadecGauge {
/// <returns>True if successful, false otherwise.</returns>
bool onUpdate(double deltaTime) {
if (isConnected == true) {
// read simulation data from simconnect
simConnectReadData();
// detect pause
if ((simulationData.simulationTime == previousSimulationTime) || (simulationData.simulationTime < 0.2)) {
Expand Down
9 changes: 8 additions & 1 deletion fbw-a380x/src/wasm/fbw_a380/src/FlyByWireInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ bool FlyByWireInterface::connect() {
flightDataRecorder.initialize();

// connect to sim connect
return simConnectInterface.connect(clientDataEnabled, autopilotStateMachineEnabled, autopilotLawsEnabled, flyByWireEnabled, primDisabled,
bool success = simConnectInterface.connect(clientDataEnabled, autopilotStateMachineEnabled, autopilotLawsEnabled, flyByWireEnabled, primDisabled,
secDisabled, facDisabled, throttleAxis, spoilersHandler, flightControlsKeyChangeAileron,
flightControlsKeyChangeElevator, flightControlsKeyChangeRudder,
disableXboxCompatibilityRudderAxisPlusMinus, enableRudder2AxisMode, idMinimumSimulationRate->get(),
idMaximumSimulationRate->get(), limitSimulationRateByPerformance);
// request data
if (!simConnectInterface.requestData()) {
std::cout << "WASM: Request data failed!" << std::endl;
return false;
}

return success;
}

void FlyByWireInterface::disconnect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,34 +1108,14 @@ bool SimConnectInterface::prepareClientDataDefinitions() {
return SUCCEEDED(result);
}

bool SimConnectInterface::requestReadData() {
// check if we are connected
if (!isConnected) {
return false;
}

// request data
if (!requestData()) {
return false;
}

// read data
if (!readData()) {
return false;
}

// success
return true;
}

bool SimConnectInterface::requestData() {
// check if we are connected
if (!isConnected) {
return false;
}

// request data
HRESULT result = SimConnect_RequestDataOnSimObject(hSimConnect, 0, 0, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_ONCE);
HRESULT result = SimConnect_RequestDataOnSimObject(hSimConnect, 0, 0, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_VISUAL_FRAME);

// check result of data request
if (result != S_OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ class SimConnectInterface {

void setSampleTime(double sampleTime);

bool requestReadData();

bool requestData();

bool readData();
Expand Down
9 changes: 5 additions & 4 deletions fbw-a380x/src/wasm/flypad-backend/src/FlyPadBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ bool FlyPadBackend::initialize() {
aircraftPresetPtr->initialize();
pushbackPtr->initialize();

// read simulation data from simconnect
simConnectRequestData();

std::cout << "FLYPAD_BACKEND: SimConnect connected." << std::endl;
return (result == S_OK);
}

bool FlyPadBackend::onUpdate(double deltaTime) {
if (isConnected) {
// read simulation data from simconnect
simConnectRequestData();
simConnectProcessMessages();

// detect pause
Expand Down Expand Up @@ -113,8 +114,8 @@ bool FlyPadBackend::simConnectRequestData() const {
HRESULT result = S_OK;

// Request data for each data structure - remember to increase the request id.
result &= SimConnect_RequestDataOnSimObject(hSimConnect, 0, DataStructureIDs::SimulationDataID, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_ONCE);
result &= SimConnect_RequestDataOnSimObject(hSimConnect, 1, DataStructureIDs::PushbackDataID, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_ONCE);
result &= SimConnect_RequestDataOnSimObject(hSimConnect, 0, DataStructureIDs::SimulationDataID, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_VISUAL_FRAME);
result &= SimConnect_RequestDataOnSimObject(hSimConnect, 1, DataStructureIDs::PushbackDataID, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_VISUAL_FRAME);

if (result != S_OK) {
return false;
Expand Down

0 comments on commit bb697bf

Please sign in to comment.