C

Qt Quick Ultralite Motorcycle Cluster Demo

/****************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
#include "simulation/big/states.h" #include "MotorCluster/TellTalesModel.h" #include "MotorCluster/MainModel.h" #include "mathutils.h" using namespace MotorCluster; namespace { MainModel &mainModel = MainModel::instance(); TellTalesModel &tellTalesModel = TellTalesModel::instance(); const uint32_t ChangeStateDelay = 750; } // namespace namespace IntroStateConstants { const uint32_t InitialDelay = 1000; const uint32_t TellTalesResetParkDelay = 500; const uint32_t TellTalesResetAirbagDelay = 300; const uint32_t FinalDelay = 500; } // namespace IntroStateConstants namespace Simulation { // --- Intro state IntroState::IntroState(const StateId &nextState) : _nextState(nextState) {} void IntroState::onEnter(const StateId &, const Layer &layer, Machine &sm) { _step = Step_Blank; mainModel.tripValue.setValue(247); mainModel.odoValue.setValue(5891); mainModel.tempValue.setValue(21); mainModel.timeHourValue.setValue(14); mainModel.timeMinuteValue.setValue(13); mainModel.bottomElementsVisible.setValue(false); mainModel.speedometerVisible.setValue(false); mainModel.roundGaugesVisible.setValue(false); mainModel.rangeVisible.setValue(false); mainModel.telltalesVisible.setValue(false); mainModel.bgLinesLeftActive.setValue(false); mainModel.bgLinesRightActive.setValue(false); mainModel.bgRoadActive.setValue(false); mainModel.speedValue.setValue(0); mainModel.rpm.setValue(0); mainModel.gear.setValue(0); mainModel.logoAnimationStart.setValue(false); mainModel.rpmAnimationTime.setValue(1000); sm.requestUpdate(IntroStateConstants::InitialDelay, false, layer); } void IntroState::onUpdate(uint32_t, const Layer &layer, Machine &sm) { using namespace IntroStateConstants; _step = static_cast<Step>(_step + 1); switch (_step) { case Step_ShowBLinkers: mainModel.leftTurnSignal.setValue(true); mainModel.rightTurnSignal.setValue(true); sm.requestUpdate(50, false, layer); break; case Step_ShowLogo: mainModel.logoAnimationStart.setValue(true); sm.requestUpdate(1200, false, layer); break; case Step_ShowTellTales: mainModel.leftTurnSignal.setValue(false); mainModel.rightTurnSignal.setValue(false); mainModel.telltalesVisible.setValue(true); sm.requestUpdate(400, false, layer); break; case Step_ShowTachoScale: mainModel.tachoScaleActive.setValue(true); mainModel.tachoUpperFrameActive.setValue(true); mainModel.tachoBottomFrameActive.setValue(true); sm.requestUpdate(300, false, layer); break; case Step_ShowBottomElements: mainModel.bottomElementsVisible.setValue(true); sm.requestUpdate(600, false, layer); break; case Step_ShowBgLines: mainModel.bgLinesLeftActive.setValue(true); mainModel.bgLinesRightActive.setValue(true); sm.requestUpdate(600, false, layer); break; case Step_ShowBgRoad: mainModel.bgRoadActive.setValue(true); sm.requestUpdate(600, false, layer); break; case Step_ShowSpeedometer: mainModel.speedometerVisible.setValue(true); mainModel.rangeVisible.setValue(true); sm.requestUpdate(400, false, layer); break; case Step_ShowGauges: mainModel.roundGaugesVisible.setValue(true); sm.requestUpdate(2500, false, layer); break; case Step_RpmToMax: mainModel.rpm.setValue(16000); sm.requestUpdate(1000, false, layer); break; case Step_RpmToZero: mainModel.rpm.setValue(1000); sm.requestUpdate(1000, false, layer); break; case Step_Done: sm.changeState(_nextState, layer, ChangeStateDelay); break; default: break; } } // --- EndSate EndState::EndState(const StateId &nextState) : _nextState(nextState) {} void EndState::onEnter(const StateId &, const Layer &layer, Machine &sm) { _step = Step_Blank; sm.requestUpdate(10, false, layer); } void EndState::onUpdate(uint32_t, const Layer &layer, Machine &sm) { _step = static_cast<Step>(_step + 1); switch (_step) { case Step_HideBgLines: mainModel.bgLinesLeftActive.setValue(false); mainModel.bgLinesRightActive.setValue(false); sm.requestUpdate(600, false, layer); break; case Step_HideRoad: mainModel.bgRoadActive.setValue(false); sm.requestUpdate(500, false, layer); break; case Step_HideGauges: mainModel.roundGaugesVisible.setValue(false); sm.requestUpdate(1000, false, layer); break; case Step_HideBottomElements: mainModel.bottomElementsVisible.setValue(false); sm.requestUpdate(500, false, layer); break; case Step_HideTellTales: mainModel.speedometerVisible.setValue(false); mainModel.telltalesVisible.setValue(false); mainModel.rangeVisible.setValue(false); sm.requestUpdate(500, false, layer); break; case Step_HideTachoScale: mainModel.tachoScaleActive.setValue(false); sm.requestUpdate(500, false, layer); break; case Step_HideTacho: mainModel.rpm.setValue(1000); sm.requestUpdate(500, false, layer); break; case Step_HideTachoFramesTop: mainModel.tachoUpperFrameActive.setValue(false); mainModel.tachoBottomFrameActive.setValue(false); sm.requestUpdate(700, false, layer); break; case Step_Done: sm.changeState(_nextState, layer, ChangeStateDelay); break; default: break; } } void EndState::onLeave(const StateId &, const Layer &, Machine &) { mainModel.fuelLevel.setValue(30); } } // namespace Simulation