Skip to content

Commit

Permalink
Added TRK, closes #5. Added Mach and TAS, closes #4. Fixed a couple o…
Browse files Browse the repository at this point in the history
…f bugs
  • Loading branch information
BeneSim committed Jun 18, 2017
1 parent 99e9806 commit 17ff49f
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 21 deletions.
3 changes: 3 additions & 0 deletions html/heading.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<td class="primary-font primary-color">&#176;</td>
</tr>
<tr id="trk-row">
<td class="secondary-font secondary-color">TRK:&nbsp;</td>
<td id="trk" class="primary-font primary-color three-digit right">225</td>
<td class="primary-font primary-color">&#176;</td>
</tr>
</table>
</div>
Expand Down
5 changes: 5 additions & 0 deletions html/js/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ function setupHeading(data_refs) {
$("#hdg").text(data_refs["widget/heading/prepend_zeros"].data ? prependZeros(new_value, 3) : new_value);
});

$("#trk").text(data_refs["widget/heading/prepend_zeros"].data ? prependZeros(data_refs["sim/trk"].data, 3) : data_refs["sim/trk"].data);
data_refs["sim/trk"].dataChanged.connect(function (new_value) {
$("#trk").text(data_refs["widget/heading/prepend_zeros"].data ? prependZeros(new_value, 3) : new_value);
});

function setHdgPointer(val) {
$("#hdg_pointer").attr("transform", "rotate(" + val + ",50,50)");
}
Expand Down
8 changes: 8 additions & 0 deletions html/js/speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ function setupSpeed(data_refs) {

attachToToggle($("#speed"), data_refs["widget/speed/enabled"]);
attachToToggle($("#ias-row"), data_refs["widget/speed/ias_enabled"]);
attachToToggle($("#tas-row"), data_refs["widget/speed/tas_enabled"]);
attachToToggle($("#gs-row"), data_refs["widget/speed/gs_enabled"]);
attachToToggle($("#mach-row"), data_refs["widget/speed/mach_enabled"]);

attachToText($("#ias"), data_refs["sim/ias"]);
attachToText($("#tas"), data_refs["sim/tas"]);
attachToText($("#gs"), data_refs["sim/gs"]);

$("#mach").text(parseFloat(data_refs["sim/mach"].data).toFixed(2));
data_refs["sim/mach"].dataChanged.connect(function (new_value) {
$("#mach").text(parseFloat(new_value).toFixed(2));
});

function setIasPointer(val) {
$("#ias_pointer").attr("transform", "rotate(" + (180 * getRatio(val, data_refs["flight/max_ias"].data) - 120) + ",50,50)");
}
Expand Down
3 changes: 2 additions & 1 deletion html/performance.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<table>
<tr id="fps-row">
<td class="secondary-font secondary-color">FPS:&nbsp;</td>
<td id="fps" class="primary-font primary-color three-digit right" colspan="2" >60</td>
<td id="fps" class="primary-font primary-color three-digit right" >60</td>
<td></td>
</tr>
<tr id="vas-row">
<td class="secondary-font secondary-color">VAS:&nbsp;</td>
Expand Down
30 changes: 20 additions & 10 deletions html/speed.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,26 @@
</g>
</svg>
<table>
<tr id="ias-row">
<td class="secondary-font secondary-color">IAS:&nbsp;</td>
<td id="ias" class="primary-font primary-color three-digit right">10</td>
<td class="primary-font primary-color">kt</td>
</tr>
<tr id="gs-row">
<td class="secondary-font secondary-color">GS:&nbsp;</td>
<td id="gs" class="primary-font primary-color three-digit right">15</td>
<td class="primary-font primary-color">kt</td>
</tr>
<tr id="ias-row">
<td class="secondary-font secondary-color">IAS:&nbsp;</td>
<td id="ias" class="primary-font primary-color three-digit right">10</td>
<td class="primary-font primary-color">kt</td>
</tr>
<tr id="tas-row">
<td class="secondary-font secondary-color">TAS:&nbsp;</td>
<td id="tas" class="primary-font primary-color three-digit right">10</td>
<td class="primary-font primary-color">kt</td>
</tr>
<tr id="gs-row">
<td class="secondary-font secondary-color">GS:&nbsp;</td>
<td id="gs" class="primary-font primary-color three-digit right">15</td>
<td class="primary-font primary-color">kt</td>
</tr>
<tr id="mach-row">
<td class="secondary-font secondary-color">MACH:&nbsp;</td>
<td id="mach" class="primary-font primary-color four-digit right">15</td>
<td></td>
</tr>
</table>
</div>
</body>
Expand Down
16 changes: 15 additions & 1 deletion html/widgets.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,21 @@
<td id="ias" class="primary-font primary-color three-digit right">10</td>
<td class="primary-font primary-color">kt</td>
</tr>
<tr id="tas-row">
<td class="secondary-font secondary-color">TAS:&nbsp;</td>
<td id="tas" class="primary-font primary-color three-digit right">10</td>
<td class="primary-font primary-color">kt</td>
</tr>
<tr id="gs-row">
<td class="secondary-font secondary-color">GS:&nbsp;</td>
<td id="gs" class="primary-font primary-color three-digit right">15</td>
<td class="primary-font primary-color">kt</td>
</tr>
<tr id="mach-row">
<td class="secondary-font secondary-color">MACH:&nbsp;</td>
<td id="mach" class="primary-font primary-color four-digit right">15</td>
<td></td>
</tr>
</table>
</div>
<div id="heading" class="tabs">
Expand All @@ -152,6 +162,9 @@
<td class="primary-font primary-color">&#176;</td>
</tr>
<tr id="trk-row">
<td class="secondary-font secondary-color">TRK:&nbsp;</td>
<td id="trk" class="primary-font primary-color three-digit right">225</td>
<td class="primary-font primary-color">&#176;</td>
</tr>
</table>
</div>
Expand Down Expand Up @@ -241,7 +254,8 @@
<table>
<tr id="fps-row">
<td class="secondary-font secondary-color">FPS:&nbsp;</td>
<td id="fps" class="primary-font primary-color three-digit right" colspan="2" >60</td>
<td id="fps" class="primary-font primary-color three-digit right">60</td>
<td></td>
</tr>
<tr id="vas-row">
<td class="secondary-font secondary-color">VAS:&nbsp;</td>
Expand Down
4 changes: 2 additions & 2 deletions html/wind.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
<line x1="5" x2="5" y1="5" y2="95" stroke-width="5" class="primary-stroke" />
</svg>
<table>
<tr>
<tr id="dir-row">
<td class="secondary-font secondary-color">DIR:&nbsp;</td>
<td id="wind_dir" class="primary-font primary-color three-digit right">43</td>
<td class="primary-font primary-color">&#176;</td>
</tr>
<tr>
<tr id="mag-row">
<td class="secondary-font secondary-color">MAG:&nbsp;</td>
<td id="wind_mag" class="primary-font primary-color three-digit right">8</td>
<td class="primary-font primary-color">kt</td>
Expand Down
3 changes: 3 additions & 0 deletions include/flightsimconnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class FlightSimConnector : public QObject

void parsedIas(double ias);
void parsedGs(double gs);
void parsedTas(double tas);
void parsedMach(double gs);
void parsedHdg(double hdg);
void parsedTrk(double trk);
void parsedAltitude(double altitude);
void parsedVs(double vs);
void parsedWindDir(double wind_dir);
Expand Down
31 changes: 29 additions & 2 deletions qml/BOWidgetSpeed.qml
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,49 @@ BOGroupBox {
}

BOSwitch {
id: gs_enabled_switch
id: tas_enabled_switch

anchors.top: ias_enabled_switch.bottom
anchors.left: parent.left

name: "Show TAS"
description: "Enable TAS readout."
data_ref: data_ref_manager.getDataRef("widget/speed/tas_enabled")

visible: enabled_switch.checked
}

BOSwitch {
id: gs_enabled_switch

anchors.top: tas_enabled_switch.bottom
anchors.left: parent.left

name: "Show GS"
description: "Enable GS readout."
data_ref: data_ref_manager.getDataRef("widget/speed/gs_enabled")

visible: enabled_switch.checked
}

BOSwitch {
id: mach_enabled_switch

anchors.top: gs_enabled_switch.bottom
anchors.left: parent.left

name: "Show Mach"
description: "Enable Mach readout."
data_ref: data_ref_manager.getDataRef("widget/speed/mach_enabled")

visible: enabled_switch.checked
}


BOSwitch {
id: custom_style_switch

anchors.top: gs_enabled_switch.bottom
anchors.top: mach_enabled_switch.bottom
anchors.left: parent.left

name: "Custom Style"
Expand Down
5 changes: 5 additions & 0 deletions src/datarefmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ DataRefManager::DataRefManager(QObject *parent) : QObject(parent)
{
data_ref_map_["sim/ias"] = new DataRef(0, false, this);
data_ref_map_["sim/gs"] = new DataRef(0, false, this);
data_ref_map_["sim/tas"] = new DataRef(0, false, this);
data_ref_map_["sim/mach"] = new DataRef(0.0, false, this);
data_ref_map_["sim/hdg"] = new DataRef(0, false, this);
data_ref_map_["sim/trk"] = new DataRef(0, false, this);
data_ref_map_["sim/alt"] = new DataRef(0, false, this);
data_ref_map_["sim/vs"] = new DataRef(0, false, this);
data_ref_map_["sim/pitch"] = new DataRef(0, false, this);
Expand Down Expand Up @@ -123,6 +126,8 @@ DataRefManager::DataRefManager(QObject *parent) : QObject(parent)
data_ref_map_["widget/speed/secondary_font"] = new DataRef(QFont(), true, this);
data_ref_map_["widget/speed/ias_enabled"] = new DataRef(true, true, this);
data_ref_map_["widget/speed/gs_enabled"] = new DataRef(true, true, this);
data_ref_map_["widget/speed/tas_enabled"] = new DataRef(false, true, this);
data_ref_map_["widget/speed/mach_enabled"] = new DataRef(false, true, this);

data_ref_map_["widget/heading/enabled"] = new DataRef(true, true, this);
data_ref_map_["widget/heading/custom_style"] = new DataRef(false, true, this);
Expand Down
57 changes: 52 additions & 5 deletions src/flightsimconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <windows.h>
#include "FSUIPC_User.h"
#include <cstdint>
#include <QtMath>

FlightSimConnector::FlightSimConnector(QObject *parent) : QObject(parent), _connected(false), _data_rate(1)
{
Expand Down Expand Up @@ -105,18 +106,38 @@ void FlightSimConnector::pollData()
return;
}

int32_t tas = 0;
if (pollValue<int32_t, 4>(0x2B8, tas)) {
emit parsedTas(tas/128.0);
} else {
return;
}

int32_t gs = 0;
double gs_final = 0.0;
if (pollValue<int32_t, 4>(0x2B4, gs)) {
emit parsedGs(gs/65536.0*1.94384);
gs_final = gs/65536.0*1.94384;
emit parsedGs(gs_final);
} else {
return;
}

int16_t mach = 0;
double mach_final = 0.0;
if (pollValue<int16_t, 4>(0x11C6, mach)) {
mach_final = mach / 20480.0;
emit parsedMach(mach_final);
} else {
return;
}

int32_t hdg = 0;
double hdg_final = 0.0;
if (pollValue<int32_t, 4>(0x580, hdg)) {
double hdg_tmp = hdg * 360.0 / (65536.0 * 65536.0) - (mag_var * 360.0 / 65536.0);
hdg_final = hdg * 360.0 / (65536.0 * 65536.0) - (mag_var * 360.0 / 65536.0);
hdg_final = hdg_final >= 0.0 ? hdg_final : 360.0 + hdg_final;

emit parsedHdg(hdg_tmp >= 0.0? hdg_tmp : 360.0 + hdg_tmp);
emit parsedHdg(hdg_final);
} else {
return;
}
Expand All @@ -136,15 +157,20 @@ void FlightSimConnector::pollData()
}

int16_t wind_dir = 0;
double wind_dir_final = 0;
if (pollValue<int16_t, 2>(0xE92, wind_dir)) {
emit parsedWindDir(wind_dir >= 0.0? wind_dir * 360.0 / 65536.0 : 360.0 + wind_dir * 360.0 / 65536.0);
wind_dir_final = wind_dir * 360.0 / 65536.0;
wind_dir_final = wind_dir_final >= 0.0 ? wind_dir_final : 360.0 + wind_dir_final;
emit parsedWindDir(wind_dir_final);
} else {
return;
}

int16_t wind_mag = 0;
double wind_mag_final = 0.0;
if (pollValue<int16_t, 2>(0xE90, wind_mag)) {
emit parsedWindMag(wind_mag);
wind_mag_final = wind_mag;
emit parsedWindMag(wind_mag_final);
} else {
return;
}
Expand Down Expand Up @@ -232,6 +258,27 @@ void FlightSimConnector::pollData()
} else {
return;
}

double wca_final = 0.0;
double trk_final = hdg_final;
if (gs_final > 0.0) {
wca_final = qRadiansToDegrees(
qAsin(
qSin(qDegreesToRadians(hdg_final - wind_dir_final)) * wind_mag_final / gs_final
)
);

}

trk_final = trk_final + wca_final;
if (trk_final > 360.0) {
trk_final = trk_final - 360.0;
} else if (trk_final < 0.0) {
trk_final = 360.0 + trk_final;
}

emit parsedTrk(trk_final);

}

void FlightSimConnector::setDataRate(const QVariant &data_rate)
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ int main(int argc, char *argv[])

QObject::connect(flight_sim_connector, &FlightSimConnector::parsedIas, qobject_cast<DataRef*>(data_ref_manager.getDataRef("sim/ias")), &DataRef::setData);
QObject::connect(flight_sim_connector, &FlightSimConnector::parsedGs, qobject_cast<DataRef*>(data_ref_manager.getDataRef("sim/gs")), &DataRef::setData);
QObject::connect(flight_sim_connector, &FlightSimConnector::parsedTas, qobject_cast<DataRef*>(data_ref_manager.getDataRef("sim/tas")), &DataRef::setData);
QObject::connect(flight_sim_connector, &FlightSimConnector::parsedMach, qobject_cast<DataRef*>(data_ref_manager.getDataRef("sim/mach")), &DataRef::setData);
QObject::connect(flight_sim_connector, &FlightSimConnector::parsedHdg, qobject_cast<DataRef*>(data_ref_manager.getDataRef("sim/hdg")), &DataRef::setData);
QObject::connect(flight_sim_connector, &FlightSimConnector::parsedTrk, qobject_cast<DataRef*>(data_ref_manager.getDataRef("sim/trk")), &DataRef::setData);
QObject::connect(flight_sim_connector, &FlightSimConnector::parsedPitch, qobject_cast<DataRef*>(data_ref_manager.getDataRef("sim/pitch")), &DataRef::setData);
QObject::connect(flight_sim_connector, &FlightSimConnector::parsedBank, qobject_cast<DataRef*>(data_ref_manager.getDataRef("sim/bank")), &DataRef::setData);
QObject::connect(flight_sim_connector, &FlightSimConnector::parsedAltitude, qobject_cast<DataRef*>(data_ref_manager.getDataRef("sim/alt")), &DataRef::setData);
Expand Down

0 comments on commit 17ff49f

Please sign in to comment.