C

Qt Quick Ultralite Automotive Cluster Demo

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
#ifndef STATES_H
#define STATES_H

#include "simulation/smfwd.h"
#include "simulation/drivetrain.h"
#include "simulation/speedlimits.h"
#include "Automotive/MainModel.h"

namespace Simulation {
struct SimulationState : Machine::AbstractState
{
    void onEnter(const StateId &, const Layer &, Machine &) {}
    void onUpdate(uint32_t, const Layer &, Machine &) {}
    void onLeave(const StateId &, const Layer &, Machine &) {}
};

struct MenuState : SimulationState
{
    MenuState(const StateId &nextState);
    StateId _nextState;
};

struct ClusterModeState : public SimulationState
{
    ClusterModeState(Automotive::MainModel::ClusterMode);
    void onEnter(const StateId &prevState, const Layer &layer, Machine &sm);

private:
    Automotive::MainModel::ClusterMode mode;
};

struct IntroState : public ClusterModeState
{
    typedef void (*IntroFinishedCallback)(Machine &sm);
    IntroState(IntroFinishedCallback finishedCallback);

    void onEnter(const StateId &prevState, const Layer &layer, Machine &sm);
    void onUpdate(uint32_t tick, const Layer &layer, Machine &sm);
    void onLeave(const StateId &nextState, const Layer &layer, Machine &sm);

private:
    enum Step {
        Step_Blank,
        Step_ShowQtLogo,
        Step_ShowCluster,
        Step_ShowTellTales,
        Step_ShowGauges,
        Step_MaxGauges,
        Step_ResetGauges,
        Step_TellTalesResetLights,
        Step_TellTalesResetPark,
        Step_TellTalesResetAirbag,
        Step_Done
    } _step;

    IntroFinishedCallback _finishedCallback;
};

struct EndState : public SimulationState
{
    EndState(const StateId &nextState);
    void onEnter(const StateId &prevState, const Layer &layer, Machine &sm);

private:
    StateId _nextState;
};

struct PhoneState : public MenuState
{
    PhoneState(const StateId &nextState);
    void onEnter(const StateId &prevState, const Layer &layer, Machine &sm);
    void onUpdate(uint32_t tick, const Layer &layer, Machine &sm);

private:
    enum Step {
        Step_Blank,
        Step_ShowMenu,
        Step_ChangeTab,
        Step_ChooseNextContact,
        Step_ScrollToNextContact,
        Step_StartCall,
        Step_EndCall,
        Step_Done
    } _step;

    int8_t _contactsToScroll;
};

struct MediaPlayerState : public MenuState
{
    MediaPlayerState(const StateId &nextState);
    void onEnter(const StateId &prevState, const Layer &layer, Machine &sm);
    void onUpdate(uint32_t tick, const Layer &layer, Machine &sm);

private:
    enum Step { Step_Play, Step_ChangeTracks, Step_Done } _step;
    void nextStep(Step step);

    uint64_t _cumulatedTime;
    uint64_t _changeTracksDuration;
};

struct NaviState : public MenuState
{
    NaviState(const StateId &nextState);
    void onEnter(const StateId &prevState, const Layer &layer, Machine &sm);
    void onUpdate(uint32_t tick, const Layer &layer, Machine &sm);

private:
    enum Step { Step_Navi, Step_Done } _step;
    uint64_t _cumulatedTime;
};

struct DriveModeMenuState : public SimulationState
{
    void onEnter(const StateId &prevState, const Layer &layer, Machine &sm);
    void onUpdate(uint32_t tick, const Layer &layer, Machine &sm);

private:
    enum Step {
        Step_Blank,
        Step_DisplayDriveModeMenu,
        Step_SwitchDriveModeOption,
        Step_ChangeDriveMode,
        Step_Done
    } _step;
};

struct CarStatusMenuState : public SimulationState
{
    void onEnter(const StateId &prevState, const Layer &layer, Machine &sm);
};

struct LastTripMenuState : public SimulationState
{
    void onEnter(const StateId &prevState, const Layer &layer, Machine &sm);
};

struct InteractiveModeState : public SimulationState
{
    void onUpdate(uint32_t tick, const Layer &layer, Machine &sm);
};

} // namespace Simulation
#endif // STATES_H