From 8e12e64b680f165d344a93fb6917f9fec3bac281 Mon Sep 17 00:00:00 2001 From: marwik15 Date: Sat, 7 May 2022 17:42:06 +0200 Subject: Implement SIGINT support --- examples/sinewave/sinewave_example.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/sinewave/sinewave_example.cpp b/examples/sinewave/sinewave_example.cpp index 606cab2..781b594 100644 --- a/examples/sinewave/sinewave_example.cpp +++ b/examples/sinewave/sinewave_example.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -9,11 +10,20 @@ #include + +volatile bool signalEnd = false; + +void sig_handler(int signum) { + signalEnd = true; +} + using seconds = std::chrono::duration; using Clock = std::chrono::high_resolution_clock; int main(int argc, char* argv[]) { + signal(SIGINT, sig_handler); + seconds interval{ 0.01 }; int i = 0; int samples; @@ -44,7 +54,7 @@ int main(int argc, char* argv[]) { hwd::sinewave::set_frequency(10); hwd::sinewave::set_phase(30); - while (1) { + while (!signalEnd) { if (i >= samples) break; i++; -- cgit v1.1