//=============================================================================================================================
//
// Copyright (c) 2015-2022 VisionStar Information Technology (Shanghai) Co., Ltd. All Rights Reserved.
// EasyAR is the registered trademark or trademark of VisionStar Information Technology (Shanghai) Co., Ltd in China
// and other countries for the augmented reality technology developed by VisionStar Information Technology (Shanghai) Co., Ltd.
//
//=============================================================================================================================

#include "helloar.hpp"

#include "easyar/types.hpp"

#include <string>
#include <cstdio>
#include <iostream>
#include <thread>

int main(int argc, char **argv)
{
    auto isQuited = false;

    auto result = easyar::Engine::initialize("===PLEASE ENTER YOUR KEY HERE===");
    if (!result) {
        std::printf("Initialization failed.\n");
        return 1;
    }
    if (!easyar::CameraDevice::isAvailable()) {
        std::printf("CameraDevice not available.\n");
        return 1;
    }
    if (!easyar::ImageTracker::isAvailable()) {
        std::printf("ImageTracker not available.\n");
        return 1;
    }

    std::thread t([&] {
        initialize();
        start();
        while (!isQuited) {
            std::this_thread::sleep_for(std::chrono::milliseconds(5));
            nextFrame();
        }
    });

    std::string line;
    while (true) {
        std::getline(std::cin, line);
        if (line == "quit") {
            isQuited = true;
            t.join();
            break;
        } else {
            std::printf("unknown command\n");
        }
    }

    stop();
    finalize();

    return 0;
}
