C
Qt Quick Ultralite Automotive 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/lights.h" #include <algorithm> namespace Simulation { Lights::Lights() { for (int i = 0; i < LIGHTS_NUM; ++i) { resetLight((LightType) i); } } void Lights::update(uint32_t tick) { for (int i = 0; i < LIGHTS_NUM; ++i) { if (_lightTimers[i] > 0) { _lightTimers[i] -= std::min(tick, _lightTimers[i]); if (_lightTimers[i] == 0) { _lightStates[i] = !_lightStates[i]; } } } } void Lights::resetLight(LightType light, bool enabled) { _lightStates[light] = enabled; _lightTimers[light] = 0; } void Lights::setLightState(LightType light, bool enabled, uint32_t duration) { _lightStates[light] = enabled; _lightTimers[light] = duration; if (light == TurnLeft && enabled) { // Turn signals are mutually exclusive resetLight(TurnRight); } else if (light == TurnRight && enabled) { // Turn signals are mutually exclusive resetLight(TurnLeft); } else if (light == LowBeam && !enabled) { // High beams can't be on w/o low beams resetLight(HighBeam); } else if (light == HighBeam && enabled) { // Low beams must go off with high beams if (!getLightState(LowBeam)) { setLightState(LowBeam, enabled, duration); } } } bool Lights::getLightState(LightType light) const { return _lightStates[light]; } } // namespace Simulation