Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pfd now displays mach above 0.4 #12

Open
wants to merge 6 commits into
base: Cross
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions B78XH/B78XH.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
<LinkIncremental>true</LinkIncremental>
<TargetExt>.wasm</TargetExt>
<IncludePath>$(MSFS_IncludePath);$(CPP_EXTERNALS)\include\NANOVG;</IncludePath>
<OutDir>..\..\..\..\WebstormProjects\B78XH-INTERIOR\SimObjects\Airplanes\Asobo_B787_10\panel</OutDir>
</PropertyGroup>
<OutDir>..\..\..\..\WebstormProjects\B78XH-INTERIOR\SimObjects\Airplanes\Asobo_B787_10\panel</OutDir> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|MSFS'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.wasm</TargetExt>
Expand Down Expand Up @@ -303,7 +302,7 @@
<ClCompile Include="TCPVHFPageControl.cpp" />
<ClCompile Include="TCPWXRPageControl.cpp" />
<ClCompile Include="TCPXPDRPageControl.cpp" />
<ClCompile Include="Timer.cpp" />
<ClCompile Include="Counter.cpp" />
<ClCompile Include="TuningControlPanelALTNNAVPage.cpp" />
<ClCompile Include="TuningControlPanelGPWSPage.cpp" />
<ClCompile Include="TuningControlPanelSATCOMPage.cpp" />
Expand Down Expand Up @@ -535,6 +534,7 @@
<ClInclude Include="TCPVHFPageControl.h" />
<ClInclude Include="TCPWXRPageControl.h" />
<ClInclude Include="TCPXPDRPageControl.h" />
<ClInclude Include="Counter.h" />
<ClInclude Include="Timer.h" />
<ClInclude Include="TokenVars.h" />
<ClInclude Include="TuningControlPanelALTNNAVPage.h" />
Expand Down
7 changes: 5 additions & 2 deletions B78XH/B78XH.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
<ClCompile Include="PFDRadioAltitudeIndicator.cpp">
<Filter>Source Files\Gauges\PFD</Filter>
</ClCompile>
<ClCompile Include="Timer.cpp">
<ClCompile Include="Counter.cpp">
<Filter>Source Files\Tools\Timers</Filter>
</ClCompile>
<ClCompile Include="PFDBaroIndicator.cpp">
Expand Down Expand Up @@ -867,7 +867,7 @@
<ClInclude Include="PFDRadioAltitudeIndicator.h">
<Filter>Source Files\Gauges\PFD</Filter>
</ClInclude>
<ClInclude Include="Timer.h">
<ClInclude Include="Counter.h">
<Filter>Source Files\Tools\Timers</Filter>
</ClInclude>
<ClInclude Include="PFDBaroIndicator.h">
Expand Down Expand Up @@ -1332,6 +1332,9 @@
<ClInclude Include="MFDNDControl.h">
<Filter>Source Files\Controls\Controls\MFD\ND</Filter>
</ClInclude>
<ClInclude Include="Timer.h">
<Filter>Source Files\Tools\Timers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
Expand Down
20 changes: 10 additions & 10 deletions B78XH/Timer.cpp → B78XH/Counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.


#include "Timer.h"
#include "Counter.h"

auto Timer::start() -> void {
auto Counter::start() -> void {
this->isStarted = true;
this->isFinished = false;
}

auto Timer::restart() -> void {
auto Counter::restart() -> void {
this->reset();
this->isFinished = false;
}

auto Timer::stop() -> void {
auto Counter::stop() -> void {
this->isStarted = false;
}

auto Timer::stop(bool force) -> void {
auto Counter::stop(bool force) -> void {
this->autoStart = false;
this->isStarted = false;
}

auto Timer::reset() -> void {
auto Counter::reset() -> void {
this->internalValue = 0;
}

auto Timer::update(double value) -> void {
auto Counter::update(double value) -> void {
if (this->isFinished) {
return;
}
Expand All @@ -53,14 +53,14 @@ auto Timer::update(double value) -> void {
}
}

auto Timer::value() const -> double {
auto Counter::value() const -> double {
return this->internalValue;
}

auto Timer::finished() const -> bool {
auto Counter::finished() const -> bool {
return this->isFinished;
}

auto Timer::started() const -> bool {
auto Counter::started() const -> bool {
return this->isStarted;
}
45 changes: 45 additions & 0 deletions B78XH/Counter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// B78XH-wasm
// Copyright (C) 2022 Heavy Division
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.


#pragma once

class Counter {

public:

Counter(double target_value, bool auto_start = false)
: targetValue(target_value), autoStart(auto_start) {}

auto reset() -> void;
auto update(double value) -> void;

auto start() -> void;
auto restart() -> void;
auto stop() -> void;
auto stop(bool force) -> void;
auto value() const -> double;
auto finished() const -> bool;
auto started() const -> bool;

protected:
double targetValue;
double internalValue = 0;
bool isStarted = false;
bool isFinished = false;
bool autoStart = false;

};
68 changes: 64 additions & 4 deletions B78XH/PFDAirspeedIndicatorApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.


#include "PFDAirspeedIndicatorApplication.h"

#include <cmath>

#include "Tools/Tools.h"
#include "Simplane.h"
#include "Timer.h"
#include "string"

using Colors = Tools::Colors;

Expand All @@ -33,6 +32,30 @@ void PFDAirspeedIndicatorApplication::render(sGaugeDrawData* data) {
drawStallStrips();
drawOverSpeedStrips();
drawSpeedMarkers(data->dt);

this->machSpeed = Simplane::aircraft::state::machSpeed();

if (this->shouldDrawMach()) {
this->machLimit = 0.38;
if (this->shouldStartTimer()) {
this->timer.start();
}

this->timer.update(data->dt);
if (!this->timer.finished() && this->timer.started()) {
this->drawHighlight();
}

this->drawMach();
}
else {
this->machLimit = 0.4;
this->timer.restart();
this->timer.stop();
}

this->lastMachSpeed = this->machSpeed;

nvgRestore(this->nvgContext);
}

Expand Down Expand Up @@ -567,3 +590,40 @@ void PFDAirspeedIndicatorApplication::drawTargetPointer() {
nvgResetTransform(this->nvgContext);
nvgRestore(this->nvgContext);
}

void PFDAirspeedIndicatorApplication::drawMach() {
nvgFontFace(this->nvgContext, "roboto");
nvgFontSize(this->nvgContext, 38.0f);
nvgFillColor(this->nvgContext, Colors::white);
nvgTextAlign(this->nvgContext, NVG_ALIGN_LEFT);
nvgBeginPath(this->nvgContext);
auto machSpeed_string = Tools::formatToFixed(machSpeed, 3);
machSpeed_string.erase(0, machSpeed_string.find_first_not_of('0'));
{
nvgText(this->nvgContext, 8, 513, machSpeed_string.c_str(), nullptr);
nvgFill(this->nvgContext);

}
}


void PFDAirspeedIndicatorApplication::drawHighlight() {
nvgStrokeColor(this->nvgContext, Colors::white);
nvgStrokeWidth(this->nvgContext, 2.0f);
nvgBeginPath(this->nvgContext);
{
nvgRect(this->nvgContext, 0, 490, 70, 25);
nvgStroke(this->nvgContext);
}
}

bool PFDAirspeedIndicatorApplication::shouldStartTimer() const {

return this->lastMachSpeed < 0.4 && this->machSpeed >= 0.4;

}

bool PFDAirspeedIndicatorApplication::shouldDrawMach() const {

return this->machSpeed > this->machLimit;
}
59 changes: 37 additions & 22 deletions B78XH/PFDAirspeedIndicatorApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,43 @@
#include "V2SpeedMarker.h"
#include "VRefSpeedMarker.h"
#include "VRSpeedMarker.h"
#include "Counter.h"
#include "Timer.h"

class PFDAirspeedIndicatorApplication: public Application {

private:
inline static V1SpeedMarker v1SpeedMarker = V1SpeedMarker("V1", false);
inline static V2SpeedMarker v2SpeedMarker = V2SpeedMarker("V2", false);
inline static VRSpeedMarker vRSpeedMarker = VRSpeedMarker("VR", false);
inline static VRefSpeedMarker vRefSpeedMarker = VRefSpeedMarker("REF", false);
inline static FlapsSpeedMarker currentFlapsMarker = FlapsSpeedMarker("", true);
inline static FlapsSpeedMarker nextFlapsMarker = FlapsSpeedMarker("", true);
void drawVSpeedMarkers(double v1, double v2, double vR, double deltaTime);
void drawNOVSpeedMessage();
void drawSpeedMarkers(double deltaTime);
bool shouldDrawFlapsMarkers(double indicatedAltitude, double flightPhase);
void drawOverSpeedStrips();
void drawStallStrips();
void drawProtStrip();
void drawStrips();
void drawBackground();
void drawGraduations();
void drawCursor();
void drawTargetPointer();
public:
auto render(sGaugeDrawData* data) -> void override;
};
private:
inline static V1SpeedMarker v1SpeedMarker = V1SpeedMarker("V1", false);
inline static V2SpeedMarker v2SpeedMarker = V2SpeedMarker("V2", false);
inline static VRSpeedMarker vRSpeedMarker = VRSpeedMarker("VR", false);
inline static VRefSpeedMarker vRefSpeedMarker = VRefSpeedMarker("REF", false);
inline static FlapsSpeedMarker currentFlapsMarker = FlapsSpeedMarker("", true);
inline static FlapsSpeedMarker nextFlapsMarker = FlapsSpeedMarker("", true);

Timer timer = Timer(10);

double machSpeed;
double lastMachSpeed;
double machLimit;


void drawVSpeedMarkers(double v1, double v2, double vR, double deltaTime);
void drawNOVSpeedMessage();
void drawSpeedMarkers(double deltaTime);
bool shouldDrawFlapsMarkers(double indicatedAltitude, double flightPhase);
void drawOverSpeedStrips();
void drawStallStrips();
void drawProtStrip();
void drawStrips();
void drawBackground();
void drawGraduations();
void drawCursor();
void drawTargetPointer();
void drawMach();
void drawHighlight();
bool shouldStartTimer() const;
bool shouldDrawMach() const;

public:
auto render(sGaugeDrawData* data) -> void override;
};
4 changes: 2 additions & 2 deletions B78XH/PFDRadioAltitudeIndicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


#pragma once
#include "Timer.h"
#include "Counter.h"
#include "MSFS/Render/nanovg.h"


Expand All @@ -32,5 +32,5 @@ class PFDRadioAltitudeIndicator {
double passDelta = -1;
double altitude = 0;
double lastAltitude = 0;
Timer deltaTimer = Timer(10);
Counter deltaTimer = Counter(10);
};
4 changes: 2 additions & 2 deletions B78XH/PFDRadioAltitudeIndicatorApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once
#include "Application.h"
#include "Timer.h"
#include "Counter.h"

class PFDRadioAltitudeIndicatorApplication : public Application {
public:
Expand All @@ -33,5 +33,5 @@ class PFDRadioAltitudeIndicatorApplication : public Application {
double passDelta = -1;
double altitude = 0;
double lastAltitude = 0;
Timer deltaTimer = Timer(10);
Counter deltaTimer = Counter(10);
};
3 changes: 3 additions & 0 deletions B78XH/SimConnectConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ auto SimConnectConnector::prepareDataDefinitions() -> void {
this->connectionResult = SimConnect_AddToDataDefinition(simConnectHandle, DEFINITION_AIRCRAFT_STATE,
"MAX GROSS WEIGHT", "Pounds");

this->connectionResult = SimConnect_AddToDataDefinition(simConnectHandle, DEFINITION_AIRCRAFT_STATE,
"AIRSPEED MACH", "mach");

/*
* Autopilot - State
*/
Expand Down
1 change: 1 addition & 0 deletions B78XH/SimConnectData.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ namespace SimConnectData {
double headingMagneticGround;
double weight;
double maxWeight;
double machSpeed;

/*
* Calculated
Expand Down
5 changes: 5 additions & 0 deletions B78XH/Simplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace Simplane {
auto weight() -> double;
auto maxWeight() -> double;
auto maxGrossWeight() -> double;
auto machSpeed() -> double;
}
}

Expand Down Expand Up @@ -1407,3 +1408,7 @@ inline auto Simplane::equipment::radioNav::unit4::name() -> char* {
inline auto Simplane::equipment::radioNav::unit4::ident() -> char* {
return SimConnectData::Equipment::RadioNav::unit4.ident;
}

inline auto Simplane::aircraft::state::machSpeed() -> double {
return SimConnectData::Aircraft::state.machSpeed;
}
Loading