C

Qt Quick Ultralite freertos_multitask Example

/****************************************************************************** ** ** Copyright (C) 2023 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 "hardwarecontrol.h" HardwareControl::HardwareControl() : fanSpeed(1) , ledCycleCount(0) { ledCycleTimer.onTimeout([this]() { ledToggle(); }); } void HardwareControl::updateSpeed(int newSpeed) { fanSpeed.setValue(newSpeed); updateFanSpeed(); updateLedSpeed(); } void HardwareControl::updateLedSpeed() { int interval = speedToLedToggleInterval(fanSpeed.value()); if (interval > 0) { ledCycleTimer.setInterval(interval); ledCycleTimer.start(); } else { ledCycleTimer.stop(); } } void HardwareControl::updateFanSpeed() { fanRotationPeriodChanged(fanSpeed.value() == 0 ? 0 : 5000 / (fanSpeed.value() * 3)); } static HardwareControlEventQueue eventQueue; void postEventsToUI(HardwareEvent &event) { eventQueue.postEvent(event); } void HardwareControl::ledToggle() { static bool ledOn = false; static int cycleCount = 0; static HardwareEvent event; if (ledOn) { cycleCount++; cycleCount = cycleCount < 0 ? 0 : cycleCount; } ledOn = !ledOn; event.id = HardwareEventId::LedCycleCount; event.data = cycleCount; postEventsToUI(event); } void HardwareControlEventQueue::onEvent(const HardwareEvent &event) { if (event.id == HardwareEventId::LedCycleCount) HardwareControl::instance().ledCycleCount.setValue(event.data); else if (event.id == HardwareEventId::FanRotationPeriod) HardwareControl::instance().fanRotationPeriodChanged(event.data); }