C

Qt Safe Monitor: Qt Quick Ultralite Example on Bare-Metal Traveo II

// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

#include "simulator.h"
#include "DemoStatus.h"

void Simulator::tick(SafeRenderer::qint delta)
{
    timestamp += delta;
    SimulationStep *step = &steps[stepIndex];

    if (timestamp > previousValueUpdate + updatePeriod) {

        if (currentSpeed < step->targetSpeed) {
            currentSpeed += 2;
        } else if (currentSpeed > step->targetSpeed) {
            currentSpeed--;
        }

        qul_application_set_speed(currentSpeed);
        qul_application_send_value_change_event();

        previousValueUpdate = timestamp;
    }

    if (timestamp > (previousStepUpdate + step->duration)) {

        stepIndex = (stepIndex + 1) % stepCount;

        const SimulationStep &newStep = steps[stepIndex];
        beamsState         = newStep.beamsOn;
        engineState        = newStep.engineOn;
        batteryState       = newStep.batteryOn;
        oilState           = newStep.oilOn;
        screenFailureState = newStep.screenFailureOn;

        qul_application_set_safe_beams_state(beamsState);
        qul_application_set_safe_engine_state(engineState);
        qul_application_set_safe_battery_state(batteryState);
        qul_application_set_safe_oil_state(oilState);
        qul_application_set_screen_failure_state(screenFailureState);
        qul_application_send_value_change_event();

        previousStepUpdate = timestamp;
    }

}