C
Qt Quick Ultralite multitask Example
/****************************************************************************** ** ** Copyright (C) 2024 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 "led_thread.h" #include "qul_thread.h" #include "led.h" static struct k_msgq ledControlQueue; void initLedControlQueue() { static int ledControlQueueData; k_msgq_init(&ledControlQueue, (char *) &ledControlQueueData, sizeof(int), 1); } struct k_msgq *getLedControlQueue() { return &ledControlQueue; } void Led_Thread(void *arg1, void *arg2, void *arg3) { (void) arg1; (void) arg2; (void) arg3; uint32_t speed = 1; uint32_t newSpeed = 0; int ledCycleCount = 0; bool ledOn = false; HardwareEvent ledEvent; while (true) { const k_timeout_t ticks = speed > 0 ? K_MSEC(350 / speed) : K_FOREVER; if (k_msgq_get(&ledControlQueue, &newSpeed, ticks) == 0) { speed = newSpeed; } BoardUtils::toggleLED(); if (ledOn) { ledCycleCount++; ledCycleCount = ledCycleCount < 0 ? 0 : ledCycleCount; } ledOn = !ledOn; ledEvent.id = HardwareEventId::LedCycleCount; ledEvent.data = ledCycleCount; postEventsToUI(ledEvent); k_yield(); } }