#include <dv-processing/io/camera/davis.hpp>

#include <chrono>

int main() {
	using namespace std::chrono_literals;

	// Open a DAVIS camera (DVXplorer also has triggers)
	dv::io::camera::DAVIS capture{};

	// Depending on the incoming signal, enable the detection of the desired type of pattern, here we enable everything.
	// Enable rising edge detection
	capture.setDetectorRisingEdges(true);
	// Enable falling edge detection
	capture.setDetectorFallingEdges(true);
	// Enable detector
	capture.setDetectorRunning(true);

	// Run the loop while camera is still connected
	while (capture.isRunning()) {
		// Read trigger batch, check whether it is correct.
		// The method does not wait for data to arrive, it returns immediately with
		// the latest available data or if no data is available, returns a `std::nullopt`.
		if (const auto triggers = capture.getNextTriggerBatch(); triggers.has_value() && !triggers->empty()) {
			std::cout << "Received " << triggers->size() << " Triggers" << std::endl;
		}
		else {
			// No data has arrived yet, short sleep to reduce CPU load.
			std::this_thread::sleep_for(1ms);
		}
	}

	return 0;
}
