#include #include #include #include #include #include #include #include using namespace std::chrono_literals; using Clock = std::chrono::high_resolution_clock; int main(int argc, char* argv[]) { std::chrono::milliseconds interval{ 10ms }; int samples = 300, i = 0; bool end = false; std::function infinite = []() {}; std::function limited = [&end, &i, &samples]() { if (i > samples) end = true; i++; }; auto& gen = infinite; if (argc == 3) { try { interval = std::chrono::milliseconds(std::stoi(argv[1])); samples = std::stoi(argv[2]); gen = limited; } catch (const std::invalid_argument& ia) { std::cerr << "Invalid argument: " << ia.what() << '\n'; return 0; } } hwd::sinewave::set_amplitude(11); hwd::sinewave::set_frequency(10); hwd::sinewave::set_phase(30); while (!end) { const auto endTime = Clock::now() + interval; std::cout << hwd::sinewave::get_point() << std::endl; std::this_thread::sleep_until(endTime); gen(); } return 0; }