* @brief Compiles the script, runs setup(), and arms the loop scheduler. */
| 354 | * @brief Compiles the script, runs setup(), and arms the loop scheduler. |
| 355 | */ |
| 356 | void DataModel::ControlScriptWorker::start(const QString& source) |
| 357 | { |
| 358 | stop(); |
| 359 | |
| 360 | if (source.trimmed().isEmpty()) |
| 361 | return; |
| 362 | |
| 363 | QString errorOut; |
| 364 | if (!compile(source, errorOut)) { |
| 365 | Q_EMIT scriptError(errorOut); |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | runSetup(); |
| 370 | |
| 371 | if (m_loaded && m_loopFn.isCallable()) { |
| 372 | if (!m_loopTimer) { |
| 373 | m_loopTimer = new QTimer(this); |
| 374 | m_loopTimer->setSingleShot(true); |
| 375 | m_loopTimer->setTimerType(Qt::PreciseTimer); |
| 376 | connect(m_loopTimer, &QTimer::timeout, this, &ControlScriptWorker::runLoopTick); |
| 377 | } |
| 378 | |
| 379 | m_loopTimer->start(kLoopRearmMs); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * @brief Stops the loop timer and releases the engine. |
no test coverage detected