#include <why-irq.h>
#include <why-time.h>
#include <why-sensor.h>
#include <print>
#include <list>

using sensor_data = std::pair<uint64_t/*timestamp*/, uint64_t/*value*/>;
std::list<sensor_data> the_data;

int main()
{
    Why::init();

    Why::RandomSensor sensor(0, 100);
    auto isr = [&sensor](int irqnum){
        the_data.emplace_back(                         // <-- produce
            Why::now_monotonic(), sensor.get_value());
    };

    Why::IRQ::connect(2, isr);

    while (true) {
        if (the_data.size()) {                         // <-- consume
            auto [timestamp, value] = the_data.front();
            the_data.pop_front();
            std::println("timestamp={}, value={}", timestamp, value);
        }
        else
            /*power management?*/;
    }
    return 0;
}
