mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
@@ -215,6 +215,7 @@ namespace swift::simplugin::xplane
|
|||||||
void CSimulatorXPlane::setFlightNetworkConnected(bool connected)
|
void CSimulatorXPlane::setFlightNetworkConnected(bool connected)
|
||||||
{
|
{
|
||||||
if (connected && !this->isShuttingDownOrDisconnected()) { m_serviceProxy->resetFrameTotals(); }
|
if (connected && !this->isShuttingDownOrDisconnected()) { m_serviceProxy->resetFrameTotals(); }
|
||||||
|
m_serviceProxy->setFlightNetworkConnected(connected);
|
||||||
CSimulatorPluginCommon::setFlightNetworkConnected(connected);
|
CSimulatorPluginCommon::setFlightNetworkConnected(connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -358,6 +358,11 @@ namespace swift::simplugin::xplane
|
|||||||
|
|
||||||
void CXSwiftBusServiceProxy::resetFrameTotals() { m_dbusInterface->callDBus(QLatin1String("resetFrameTotals")); }
|
void CXSwiftBusServiceProxy::resetFrameTotals() { m_dbusInterface->callDBus(QLatin1String("resetFrameTotals")); }
|
||||||
|
|
||||||
|
void CXSwiftBusServiceProxy::setFlightNetworkConnected(bool connected)
|
||||||
|
{
|
||||||
|
m_dbusInterface->callDBus(QLatin1String("setFlightNetworkConnected"), connected);
|
||||||
|
}
|
||||||
|
|
||||||
double CXSwiftBusServiceProxy::getLatitudeDeg() const
|
double CXSwiftBusServiceProxy::getLatitudeDeg() const
|
||||||
{
|
{
|
||||||
return m_dbusInterface->callDBusRet<double>(QLatin1String("getLatitudeDeg"));
|
return m_dbusInterface->callDBusRet<double>(QLatin1String("getLatitudeDeg"));
|
||||||
|
|||||||
@@ -212,6 +212,9 @@ namespace swift::simplugin::xplane
|
|||||||
//! \copydoc XSwiftBus::CService::resetFrameTotals
|
//! \copydoc XSwiftBus::CService::resetFrameTotals
|
||||||
void resetFrameTotals();
|
void resetFrameTotals();
|
||||||
|
|
||||||
|
//! \copydoc XSwiftBus::CService::setFlightNetworkConnected
|
||||||
|
void setFlightNetworkConnected(bool connected);
|
||||||
|
|
||||||
//! @{
|
//! @{
|
||||||
//! \copydoc XSwiftBus::CService::getLatitudeDeg
|
//! \copydoc XSwiftBus::CService::getLatitudeDeg
|
||||||
double getLatitudeDeg() const;
|
double getLatitudeDeg() const;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ add_library(xswiftbus SHARED
|
|||||||
command.h
|
command.h
|
||||||
config.cpp
|
config.cpp
|
||||||
config.h
|
config.h
|
||||||
|
custom_datarefs.h
|
||||||
datarefs.h
|
datarefs.h
|
||||||
dbuscallbacks.h
|
dbuscallbacks.h
|
||||||
dbusconnection.cpp
|
dbusconnection.cpp
|
||||||
|
|||||||
24
src/xswiftbus/custom_datarefs.h
Normal file
24
src/xswiftbus/custom_datarefs.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright (C) swift Project Community / Contributors
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||||
|
|
||||||
|
#ifndef SWIFT_SIM_XSWIFTBUS_CUSTOM_DATAREFS_H
|
||||||
|
#define SWIFT_SIM_XSWIFTBUS_CUSTOM_DATAREFS_H
|
||||||
|
|
||||||
|
namespace XSwiftBus
|
||||||
|
{
|
||||||
|
//! Is swift connected to a network?
|
||||||
|
struct TSwiftNetworkConnected
|
||||||
|
{
|
||||||
|
//! Dataref name
|
||||||
|
static constexpr const char *name() { return "org/swift-project/xswiftbus/connected"; }
|
||||||
|
//! Can be written to?
|
||||||
|
static constexpr bool writable = false;
|
||||||
|
//! Dataref type
|
||||||
|
using type = int;
|
||||||
|
//! Not an array dataref
|
||||||
|
static constexpr bool is_array = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace XSwiftBus
|
||||||
|
|
||||||
|
#endif // SWIFT_SIM_XSWIFTBUS_CUSTOM_DATAREFS_H
|
||||||
@@ -223,6 +223,58 @@ namespace XSwiftBus
|
|||||||
XPLMDataRef m_ref;
|
XPLMDataRef m_ref;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Class providing a custom variable + dataref
|
||||||
|
* \tparam DataRefTraits The trait class representing the dataref.
|
||||||
|
*/
|
||||||
|
template <class DataRefTraits>
|
||||||
|
class CustomDataRef
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
CustomDataRef()
|
||||||
|
{
|
||||||
|
if constexpr (std::is_same_v<typename DataRefTraits::type, int>)
|
||||||
|
{
|
||||||
|
m_ref = XPLMRegisterDataAccessor(DataRefTraits::name(), xplmType_Int, 0, read, NULL, NULL, NULL, NULL,
|
||||||
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, this, NULL);
|
||||||
|
}
|
||||||
|
else { XPLMDebugString("Unsupported custom dataref type\n"); }
|
||||||
|
if (!m_ref)
|
||||||
|
{
|
||||||
|
XPLMDebugString("Missing dataref:");
|
||||||
|
XPLMDebugString(DataRefTraits::name());
|
||||||
|
XPLMDebugString("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomDataRef(const CustomDataRef &) = delete;
|
||||||
|
CustomDataRef &operator=(const CustomDataRef &) = delete;
|
||||||
|
CustomDataRef(CustomDataRef &&other) = delete;
|
||||||
|
CustomDataRef &operator=(CustomDataRef &&other) = delete;
|
||||||
|
~CustomDataRef()
|
||||||
|
{
|
||||||
|
if (m_ref) { XPLMUnregisterDataAccessor(m_ref); }
|
||||||
|
}
|
||||||
|
|
||||||
|
static typename DataRefTraits::type read(void *refcon)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<CustomDataRef *>(refcon)->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! True if the dataref exists
|
||||||
|
bool isValid() const { return m_ref != nullptr; }
|
||||||
|
|
||||||
|
//! Set the value
|
||||||
|
void set(typename DataRefTraits::type val) { m_datarefVal = val; }
|
||||||
|
|
||||||
|
//! Get the value
|
||||||
|
typename DataRefTraits::type get() const { return m_datarefVal; }
|
||||||
|
|
||||||
|
XPLMDataRef m_ref;
|
||||||
|
typename DataRefTraits::type m_datarefVal;
|
||||||
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void DataRefImpl::implSet<int>(int d)
|
inline void DataRefImpl::implSet<int>(int d)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ R"XML(<node>
|
|||||||
</method>
|
</method>
|
||||||
<method name="resetFrameTotals">
|
<method name="resetFrameTotals">
|
||||||
</method>
|
</method>
|
||||||
|
<method name="setFlightNetworkConnected">
|
||||||
|
<arg type="b" direction="in"/>
|
||||||
|
</method>
|
||||||
<method name="getLatitudeDeg">
|
<method name="getLatitudeDeg">
|
||||||
<arg type="d" direction="out"/>
|
<arg type="d" direction="out"/>
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ namespace XSwiftBus
|
|||||||
{
|
{
|
||||||
this->updateMessageBoxFromSettings();
|
this->updateMessageBoxFromSettings();
|
||||||
m_framePeriodSampler->show();
|
m_framePeriodSampler->show();
|
||||||
|
m_swiftNetworkConnected.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicitly in cpp file to allow use of forward declaration
|
// Explicitly in cpp file to allow use of forward declaration
|
||||||
@@ -136,6 +137,8 @@ namespace XSwiftBus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CService::setFlightNetworkConnected(bool connected) { m_swiftNetworkConnected.set(connected); }
|
||||||
|
|
||||||
void CService::addTextMessage(const std::string &text, double red, double green, double blue)
|
void CService::addTextMessage(const std::string &text, double red, double green, double blue)
|
||||||
{
|
{
|
||||||
if (text.empty()) { return; }
|
if (text.empty()) { return; }
|
||||||
@@ -509,6 +512,14 @@ namespace XSwiftBus
|
|||||||
maybeSendEmptyDBusReply(wantsReply, sender, serial);
|
maybeSendEmptyDBusReply(wantsReply, sender, serial);
|
||||||
queueDBusCall([=]() { resetFrameTotals(); });
|
queueDBusCall([=]() { resetFrameTotals(); });
|
||||||
}
|
}
|
||||||
|
else if (message.getMethodName() == "setFlightNetworkConnected")
|
||||||
|
{
|
||||||
|
maybeSendEmptyDBusReply(wantsReply, sender, serial);
|
||||||
|
bool connected = false;
|
||||||
|
message.beginArgumentRead();
|
||||||
|
message.getArgument(connected);
|
||||||
|
queueDBusCall([=]() { setFlightNetworkConnected(connected); });
|
||||||
|
}
|
||||||
else if (message.getMethodName() == "getLatitudeDeg")
|
else if (message.getMethodName() == "getLatitudeDeg")
|
||||||
{
|
{
|
||||||
queueDBusCall([=]() { sendDBusReply(sender, serial, getLatitudeDeg()); });
|
queueDBusCall([=]() { sendDBusReply(sender, serial, getLatitudeDeg()); });
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "datarefs.h"
|
#include "datarefs.h"
|
||||||
#include "messages.h"
|
#include "messages.h"
|
||||||
#include "terrainprobe.h"
|
#include "terrainprobe.h"
|
||||||
|
#include "custom_datarefs.h"
|
||||||
#include <XPLM/XPLMNavigation.h>
|
#include <XPLM/XPLMNavigation.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -119,6 +120,9 @@ namespace XSwiftBus
|
|||||||
//! Reset the monitoring of total miles and minutes lost due to low frame rate.
|
//! Reset the monitoring of total miles and minutes lost due to low frame rate.
|
||||||
void resetFrameTotals();
|
void resetFrameTotals();
|
||||||
|
|
||||||
|
//! Set the current connection state
|
||||||
|
void setFlightNetworkConnected(bool connected);
|
||||||
|
|
||||||
//! Get aircraft latitude in degrees
|
//! Get aircraft latitude in degrees
|
||||||
double getLatitudeDeg() const { return m_latitude.get(); }
|
double getLatitudeDeg() const { return m_latitude.get(); }
|
||||||
|
|
||||||
@@ -349,6 +353,7 @@ namespace XSwiftBus
|
|||||||
DataRef<xplane::data::sim::graphics::scenery::async_scenery_load_in_progress> m_sceneryIsLoading;
|
DataRef<xplane::data::sim::graphics::scenery::async_scenery_load_in_progress> m_sceneryIsLoading;
|
||||||
int m_sceneryWasLoading = 0;
|
int m_sceneryWasLoading = 0;
|
||||||
|
|
||||||
|
CustomDataRef<TSwiftNetworkConnected> m_swiftNetworkConnected;
|
||||||
StringDataRef<xplane::data::sim::aircraft::view::acf_livery_path> m_liveryPath;
|
StringDataRef<xplane::data::sim::aircraft::view::acf_livery_path> m_liveryPath;
|
||||||
StringDataRef<xplane::data::sim::aircraft::view::acf_ICAO> m_icao;
|
StringDataRef<xplane::data::sim::aircraft::view::acf_ICAO> m_icao;
|
||||||
StringDataRef<xplane::data::sim::aircraft::view::acf_descrip> m_descrip;
|
StringDataRef<xplane::data::sim::aircraft::view::acf_descrip> m_descrip;
|
||||||
|
|||||||
Reference in New Issue
Block a user