diff options
author | marwik15 <marwik15@gmail.com> | 2022-05-07 17:42:06 +0200 |
---|---|---|
committer | marwik15 <marwik15@gmail.com> | 2022-05-07 17:42:06 +0200 |
commit | 8e12e64b680f165d344a93fb6917f9fec3bac281 (patch) | |
tree | ca3aad3c2f25038f88f410b1ad108a9f866014bf | |
parent | 0c63ebc494d6e909eff6cfa15eb23960a0e2f015 (diff) | |
download | hwd-8e12e64b680f165d344a93fb6917f9fec3bac281.zip hwd-8e12e64b680f165d344a93fb6917f9fec3bac281.tar.gz hwd-8e12e64b680f165d344a93fb6917f9fec3bac281.tar.bz2 |
Implement SIGINT support
-rw-r--r-- | examples/sinewave/sinewave_example.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
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 <signal.h> #include <unistd.h> #include <chrono> @@ -9,11 +10,20 @@ #include <hwd.h> + +volatile bool signalEnd = false; + +void sig_handler(int signum) { + signalEnd = true; +} + using seconds = std::chrono::duration<double>; 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++; |