diff options
Diffstat (limited to 'tradeshow/iot-sensortag/main.cpp')
-rw-r--r-- | tradeshow/iot-sensortag/main.cpp | 143 |
1 files changed, 60 insertions, 83 deletions
diff --git a/tradeshow/iot-sensortag/main.cpp b/tradeshow/iot-sensortag/main.cpp index 5164919..ba5324b 100644 --- a/tradeshow/iot-sensortag/main.cpp +++ b/tradeshow/iot-sensortag/main.cpp @@ -47,13 +47,6 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include <QApplication> -#include <QQmlApplicationEngine> -#include <QQuickWindow> -#include <QQmlContext> -#include <QCommandLineParser> -#include <QFontDatabase> -#include <QScreen> #if defined(RUNS_AS_HOST) #include "bluetoothdataprovider.h" @@ -67,77 +60,77 @@ #include "mockdataproviderpool.h" #ifdef AZURE_UPLOAD #include "cloudupdate.h" +#elif defined (MQTT_UPLOAD) +#include "mqttupdate.h" +#include "mqttdataprovider.h" +#include "mqttdataproviderpool.h" #endif #include "seriesstorage.h" +#include <QApplication> +#include <QQmlApplicationEngine> +#include <QQuickWindow> +#include <QQmlContext> +#include <QCommandLineParser> +#include <QFontDatabase> +#include <QScreen> + Q_DECLARE_LOGGING_CATEGORY(boot2QtDemos) Q_LOGGING_CATEGORY(boot2QtDemos, "boot2qt.demos.iot") +QString loggingOutput; +QQuickWindow *loggingItem{nullptr}; +void handleMessageOutput(QtMsgType, const QMessageLogContext &, const QString &text) +{ + loggingOutput.prepend("\n"); + loggingOutput.prepend(text); + + loggingOutput.chop(loggingOutput.size() - 1024); + if (loggingItem) + loggingItem->setProperty("loggingOutput", loggingOutput); +} + int main(int argc, char *argv[]) { + auto oldHandler = qInstallMessageHandler(handleMessageOutput); + // QtChars mandate using QApplication as it uses the graphics view fw QApplication app(argc, argv); QFontDatabase::addApplicationFont(QString::fromLatin1(":/resources/base/fonts/titilliumweb/TitilliumWeb-Regular.ttf")); app.setFont(QFont("Titillium Web", 13)); - DataProviderPool *dataProviderPool = 0; + DataProviderPool *remoteProviderPool = nullptr; + DataProviderPool *localProviderPool = nullptr; SeriesStorage seriesStorage; QCommandLineParser parser; - parser.addOptions({{"source", "Sensor data source", "cloud | sensor | mock"}, {"fullscreen", "Fullscreen mode", "true | false"}}); + parser.addOptions({{"fullscreen", "Fullscreen mode", "true | false"}}); parser.addHelpOption(); parser.process(app); - QString sensorSource = parser.value("source"); - - if (sensorSource.isEmpty()) - sensorSource = qgetenv("QT_IOT_DEMO_DATA_SOURCE"); - - if (sensorSource.isEmpty()) - // There is no wastorage package available for WinRT -#ifdef Q_OS_WINRT - sensorSource = "mock"; -#else - sensorSource = "cloud"; +#if defined(MQTT_UPLOAD) + remoteProviderPool = new MqttDataProviderPool; #endif - - if (sensorSource == QString("cloud").toLower()) { - qCDebug(boot2QtDemos) << "Running in cloud mode"; - dataProviderPool = new CloudDataProviderPool; - } #if defined(RUNS_AS_HOST) - else if (sensorSource == QString("sensor").toLower()) { - qCDebug(boot2QtDemos) << "Running in sensor mode"; - dataProviderPool = new DemoDataProviderPool; - // List of devices used in Embedded World - static_cast<SensorTagDataProviderPool*>(dataProviderPool)->setMacFilterList(QStringList() << - "24:71:89:BF:3B:82" << - "24:71:89:BC:44:82"); - } +// localProviderPool = new MockDataProviderPool; + localProviderPool = new DemoDataProviderPool; #endif - else if (sensorSource == QString("mock").toLower()){ - qCDebug(boot2QtDemos) << "Running in mock data mode"; - dataProviderPool = new MockDataProviderPool; - } - else { - qCDebug(boot2QtDemos) << "Unknown mode: " << sensorSource; - return 1; - } - - seriesStorage.setDataProviderPool(dataProviderPool); + seriesStorage.setDataProviderPool(remoteProviderPool); qmlRegisterType<SensorTagDataProvider>("SensorTag.DataProvider", 1, 0, "SensorTagData"); - qmlRegisterType<SensorTagDataProvider>("SensorTag.DataProvider", 1, 0, "ProviderState"); qmlRegisterType<DataProviderPool>("SensorTag.DataProvider", 1, 0, "DataProviderPool"); qmlRegisterType<SeriesStorage>("SensorTag.SeriesStorage", 1, 0, "SeriesStorage"); -#if defined(RUNS_AS_HOST) && defined(AZURE_UPLOAD) +#if defined(RUNS_AS_HOST) && (defined(AZURE_UPLOAD) || defined(MQTT_UPLOAD)) +#if AZURE_UPLOAD CloudUpdate update; - if (sensorSource == "sensor" || sensorSource == "mock") { - update.setDataProviderPool(dataProviderPool); - update.restart(); - } +# else + MqttUpdate update; +# endif + + update.setDataProviderPool(localProviderPool); + update.restart(); #endif #ifdef DEPLOY_TO_FS @@ -150,10 +143,15 @@ int main(int argc, char *argv[]) QString mainFile; QUrl styleFile; - QString uiVariant; - bool fullScreen; - int appWidth = 0; - int appHeight = 0; + QString uiVariant = QStringLiteral("small"); + bool fullScreen = +#ifdef Q_OS_ANDROID + true; +#else + false; +#endif + int appWidth = 1920; + int appHeight = 1080; QScreen* scr = qApp->screens().at(0); @@ -169,34 +167,8 @@ int main(int argc, char *argv[]) addressString.append(QLatin1Char('/')); } } -#if defined(UI_SMALL) - mainFile = namingScheme + QStringLiteral("/resources/small/MainSmall.qml"); - styleFile = namingScheme + QStringLiteral("/resources/small/StyleSmall.qml"); - - uiVariant = "small"; - fullScreen = true; - appWidth = 1920; - appHeight = 1080; - qCDebug(boot2QtDemos) << "Using SMALL UI variant"; -#elif defined(UI_MEDIUM) - mainFile =QStringLiteral("qrc:/resources/medium/MainMedium.qml"); - styleFile = QUrl("qrc:/resources/medium/StyleMedium.qml"); - uiVariant = "medium"; - fullScreen = true; - appWidth = 1920; - appHeight = 1080; - qCDebug(boot2QtDemos) << "Using MEDIUM UI variant"; -#elif defined(UI_LARGE) - mainFile = QStringLiteral("qrc:/resources/large/MainLarge.qml"); - styleFile = QUrl("qrc:/resources/large/StyleLarge.qml"); - uiVariant = "large"; - fullScreen = true; - appWidth = 3840; - appHeight = 2160; - qCDebug(boot2QtDemos) << "Using LARGE UI variant"; -#else -#error "Unknown UI form factor set in the project file" -#endif + mainFile = namingScheme + QStringLiteral("/resources/small/MainSmall.qml"); + styleFile = namingScheme + QStringLiteral("/resources/small/StyleSmall.qml"); qmlRegisterSingletonType(styleFile, "Style", 1,0, "Style"); @@ -221,12 +193,17 @@ int main(int argc, char *argv[]) if (fullScreen) item->showFullScreen(); - item->setProperty("dataProviderPool", QVariant::fromValue(dataProviderPool)); + item->setProperty("localProviderPool", QVariant::fromValue(localProviderPool)); + item->setProperty("remoteProviderPool", QVariant::fromValue(remoteProviderPool)); item->setProperty("contentFile", mainFile); item->setProperty("seriesStorage", QVariant::fromValue(&seriesStorage)); item->setProperty("addresses", addressString); + loggingItem = item; } int returnValue = app.exec(); - dataProviderPool->stopScanning(); + remoteProviderPool->stopScanning(); + + qInstallMessageHandler(oldHandler); + return returnValue; } |