summaryrefslogtreecommitdiff
path: root/app/controller/main.cc
blob: a9ea5bd12db5acb63951eb56dd4e7cc93522cc27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <cstdlib>
#include <thread>
#include "serial-controller.hh"

int main(int argc, char** argv)
{
    if (argc != 2)
    {
        std::cerr << "Usage:\n";
		std::cerr << "  " << argv[0] << " <controller-path>" << std::endl;
		return EXIT_FAILURE;
    }

    auto const path = argv[1];
    auto controller = nes::app::test::serial_controller{ path };
    if (!controller.is_reliable())
    {
        return EXIT_FAILURE;
    }

    while (true)
    {
        auto const buttons = controller.read_buttons();
        if (!buttons.is_empty())
        {
            std::cout << "Buttons: " << buttons.get_raw_value() << std::endl;
        }
        std::this_thread::sleep_for(std::chrono::milliseconds(20));
    }

    return EXIT_SUCCESS;
}