Skip to content

Commit

Permalink
Fixed progress value and progress bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankkopp committed Mar 16, 2022
1 parent cbcb374 commit ba312ba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
32 changes: 17 additions & 15 deletions src/instruments/src/EFB/Presets/Widgets/AircraftPresets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@ export const AircraftPresets = () => {
const [loadPresetProgress] = useSimVar('L:A32NX_LOAD_AIRCRAFT_PRESET_PROGRESS', 'number', 100);

// Sets the LVAR to tell the wasm to load the preset into the aircraft
function loadPreset(presetID: number, presetName: string) {
function loadPreset(presetID: number) {
setLoadPresetVar(presetID);
toast.success(`Loading Preset: ${presetID}: ${presetName}`, {
autoClose: 250,
hideProgressBar: true,
closeButton: false,
});
}

const AIRCRAFT_PRESETS: {index: number, name: string}[] = [
const AIRCRAFT_PRESETS: { index: number, name: string }[] = [
{ index: 1, name: 'Cold & Dark' },
{ index: 2, name: 'Turnaround' },
{ index: 3, name: 'Ready for Pushback' },
Expand All @@ -39,16 +34,23 @@ export const AircraftPresets = () => {
];

return (
<div className="p-4 mt-4 space-y-4 rounded-lg border-2 border-theme-accent h-content-section-reduced">
<div className="flex flex-row justify-center items-center p-2 space-x-2 h-14 rounded-md border-2 border-theme-accent">
{ loadPresetVar ? (
<div className="p-4 mt-4 space-y-4 h-content-section-reduced rounded-lg border-2 border-theme-accent">
<div
className="flex flex-row justify-center items-center p-2 space-x-2 h-14 rounded-md border-2 border-theme-accent"
>
{loadPresetVar ? (
<>
<div className="overflow-hidden w-full h-full rounded-md bg-theme-accent">
<div className="h-full bg-theme-highlight" style={{ width: `${loadPresetProgress}%`, transition: 'width 0.5s ease' }} />
<div
className="overflow-hidden w-full h-full bg-theme-accent rounded-md"
>
<div
className="h-full bg-theme-highlight"
style={{ width: `${loadPresetProgress * 100}%`, transition: 'width 0.1s ease' }}
/>
</div>

<div
className="flex items-center px-4 h-full rounded-md border-2 transition duration-100 bg-theme-highlight text-theme-body hover:bg-theme-body hover:text-theme-highlight border-theme-highlight"
className="flex items-center px-4 h-full text-theme-body hover:text-theme-highlight bg-theme-highlight hover:bg-theme-body rounded-md border-2 border-theme-highlight transition duration-100"
onClick={() => setLoadPresetVar(0)}
>
Cancel
Expand All @@ -64,9 +66,9 @@ export const AircraftPresets = () => {
{AIRCRAFT_PRESETS.map(({ index, name }) => (
<div
className={`flex justify-center items-center h-24 rounded-md border-2 transition duration-100 text-theme-text hover:text-theme-body bg-theme-accent hover:bg-theme-highlight border-theme-accent ${loadPresetVar && loadPresetVar !== index && 'opacity-50 pointer-events-none'}`}
onClick={() => loadPreset(index, name)}
onClick={() => loadPreset(index)}
>
{ name }
{name}
</div>
))}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/presets/src/Aircraft/AircraftPreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void AircraftPreset::onUpdate(double deltaTime) {

// new loading process
std::cout << "PRESETS: Aircraft Preset Start" << std::endl;
setProgressAircraftPreset(0);
setProgressAircraftPreset(0.0);
currentLoadingTime = 0;
currentDelay = 0;
currentStep = 0;
Expand All @@ -48,14 +48,14 @@ void AircraftPreset::onUpdate(double deltaTime) {
// check if all preset steps are done
if (currentStep >= currentProcedure->size()) {
std::cout << "PRESETS: Aircraft Preset Done " << std::endl;
setProgressAircraftPreset(100);
setProgressAircraftPreset(0);
setLoadAircraftPresetRequest(0);
loadingIsActive = false;
return;
}

// progress
setProgressAircraftPreset(((double) currentStep / currentProcedure->size()) * 100);
setProgressAircraftPreset((double) currentStep / currentProcedure->size());

// update run timer
currentLoadingTime += deltaTime * 1000;
Expand Down
4 changes: 2 additions & 2 deletions src/presets/src/Aircraft/AircraftPreset.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ class AircraftPreset {
* Reads the preset loading request variable.
* @return INT64 signifying the preset to be loaded
*/
INT64
FLOAT64
progressAircraftPreset() { return get_named_variable_value(ProgressAircraftPreset); }

/**
* Sets the loading request value. Typically used to reset to 0 after the preset has been loaded.
* @param value usually loadFromData to 0 to reset the request.
*/
void setProgressAircraftPreset(
INT64 value) { set_named_variable_value(ProgressAircraftPreset, value); }
FLOAT64 value) { set_named_variable_value(ProgressAircraftPreset, value); }
};
11 changes: 8 additions & 3 deletions src/presets/src/Aircraft/AircraftProcedures.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ static vector<ProcedureStep>* TURNAROUND_CONFIG_ON = new vector<ProcedureStep>{
{"BAT1 On", false, 0, 100, "(L:A32NX_OVHD_ELEC_BAT_1_PB_IS_AUTO) 1 ==", "1 (>L:A32NX_OVHD_ELEC_BAT_1_PB_IS_AUTO)"},
{"BAT2 On", false, 0, 3000, "(L:A32NX_OVHD_ELEC_BAT_2_PB_IS_AUTO) 1 ==", "1 (>L:A32NX_OVHD_ELEC_BAT_2_PB_IS_AUTO)"},
{"EXT PWR ON", false, 0, 3000, "(L:A32NX_ELEC_AC_1_BUS_IS_POWERED)", "(A:EXTERNAL POWER ON:1, BOOL) ! if{ 1 (>K:TOGGLE_EXTERNAL_POWER) }"},
{"APU Master On", false, 0, 3000, "(L:A32NX_OVHD_APU_MASTER_SW_PB_IS_ON) 1 ==", "1 (>L:A32NX_OVHD_APU_MASTER_SW_PB_IS_ON)"},
{"APU Start On", false, 0, 1000, "(L:A32NX_OVHD_APU_START_PB_IS_AVAILABLE) 1 == "
"(L:A32NX_OVHD_APU_START_PB_IS_ON) 1 == or", "1 (>L:A32NX_OVHD_APU_START_PB_IS_ON)"},
{"APU Master On", false, 0, 3000, "((L:A32NX_ENGINE_STATE:2) 1 =="
"(L:A32NX_ENGINE_STATE:2) 1 == or) "
"(L:A32NX_OVHD_APU_MASTER_SW_PB_IS_ON) 1 == or", "1 (>L:A32NX_OVHD_APU_MASTER_SW_PB_IS_ON)"},
// FIXME: The expected state check does not work correctly.
{"APU Start On", false, 0, 1000, "((L:A32NX_ENGINE_STATE:2) 1 == "
"(L:A32NX_ENGINE_STATE:2) 1 == or)"
"((L:A32NX_OVHD_APU_START_PB_IS_AVAILABLE) 1 == "
"(L:A32NX_OVHD_APU_START_PB_IS_ON) 1 == or) or", "1 (>L:A32NX_OVHD_APU_START_PB_IS_ON)"},
{"AC BUS Avail Check", true, 1, 2000, "", "(L:A32NX_ELEC_AC_1_BUS_IS_POWERED)"},
{"Nav & Logo Lt On", false, 0, 1000, "(A:LIGHT LOGO, Bool) (A:LIGHT NAV, Bool) and", "1 (>K:2:LOGO_LIGHTS_SET) 1 (>K:2:NAV_LIGHTS_SET)"},

Expand Down

0 comments on commit ba312ba

Please sign in to comment.