blob: 606cab2e66c5a2ed2b84d5eb03ef2d75b510de4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include <unistd.h>
#include <chrono>
#include <functional>
#include <iostream>
#include <stdexcept>
#include <string>
#include <thread>
#include <hwd.h>
using seconds = std::chrono::duration<double>;
using Clock = std::chrono::high_resolution_clock;
int main(int argc, char* argv[]) {
seconds interval{ 0.01 };
int i = 0;
int samples;
int opt;
try {
while ((opt = getopt(argc, argv, "n:i:")) != -1) {
switch (opt) {
case 'i':
interval = seconds{ std::stod(optarg) };
break;
case 'n':
samples = std::stoi(optarg);
break;
default:
std::cerr << "Usage: " << argv[0] << " [-i interval][-n samples]"<<std::endl;
return 1;
}
}
}
catch (const std::invalid_argument& ia) {
std::cerr << "Invalid argument: " << ia.what() << '\n';
return 1;
}
hwd::sinewave::set_amplitude(11);
hwd::sinewave::set_frequency(10);
hwd::sinewave::set_phase(30);
while (1) {
if (i >= samples) break;
i++;
const auto endTime = Clock::now() + interval;
std::cout << hwd::sinewave::get_point() << std::endl;
std::this_thread::sleep_until(endTime);
}
return 0;
}
|