Mercurial > hg > beaglert
comparison projects/scope/main.cpp @ 94:2fe6690fcab7
Added scope project, copied and edited from nodejsbeaglert
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 22 Jul 2015 11:38:41 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
93:8c7f537d0a21 | 94:2fe6690fcab7 |
---|---|
1 /* | |
2 * main.cpp | |
3 * | |
4 * Created on: Oct 24, 2014 | |
5 * Author: parallels | |
6 */ | |
7 #include <unistd.h> | |
8 #include <iostream> | |
9 #include <cstdlib> | |
10 #include <libgen.h> | |
11 #include <signal.h> | |
12 #include <getopt.h> | |
13 #include <BeagleRT.h> | |
14 | |
15 using namespace std; | |
16 | |
17 // Handle Ctrl-C by requesting that the audio rendering stop | |
18 void interrupt_handler(int var) | |
19 { | |
20 gShouldStop = true; | |
21 } | |
22 | |
23 // Print usage information | |
24 void usage(const char * processName) | |
25 { | |
26 cerr << "Usage: " << processName << " [options]" << endl; | |
27 | |
28 BeagleRT_usage(); | |
29 | |
30 cerr << " --frequency [-f] frequency: Set the frequency of the oscillator\n"; | |
31 cerr << " --help [-h]: Print this menu\n"; | |
32 } | |
33 | |
34 int main(int argc, char *argv[]) | |
35 { | |
36 BeagleRTInitSettings settings; // Standard audio settings | |
37 float frequency = 440.0; // Frequency of oscillator | |
38 | |
39 struct option customOptions[] = | |
40 { | |
41 {"help", 0, NULL, 'h'}, | |
42 {"frequency", 1, NULL, 'f'}, | |
43 {NULL, 0, NULL, 0} | |
44 }; | |
45 | |
46 // Set default settings | |
47 BeagleRT_defaultSettings(&settings); | |
48 | |
49 // Parse command-line arguments | |
50 while (1) { | |
51 int c; | |
52 if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) | |
53 break; | |
54 switch (c) { | |
55 case 'h': | |
56 usage(basename(argv[0])); | |
57 exit(0); | |
58 case 'f': | |
59 frequency = atof(optarg); | |
60 break; | |
61 case '?': | |
62 default: | |
63 usage(basename(argv[0])); | |
64 exit(1); | |
65 } | |
66 } | |
67 | |
68 // Initialise the PRU audio device | |
69 if(BeagleRT_initAudio(&settings, &frequency) != 0) { | |
70 cout << "Error: unable to initialise audio" << endl; | |
71 return -1; | |
72 } | |
73 | |
74 // Start the audio device running | |
75 if(BeagleRT_startAudio()) { | |
76 cout << "Error: unable to start real-time audio" << endl; | |
77 return -1; | |
78 } | |
79 | |
80 // Set up interrupt handler to catch Control-C and SIGTERM | |
81 signal(SIGINT, interrupt_handler); | |
82 signal(SIGTERM, interrupt_handler); | |
83 | |
84 // Run until told to stop | |
85 while(!gShouldStop) { | |
86 usleep(100000); | |
87 } | |
88 | |
89 // Stop the audio device | |
90 BeagleRT_stopAudio(); | |
91 | |
92 // Clean up any resources allocated for audio | |
93 BeagleRT_cleanupAudio(); | |
94 | |
95 // All done! | |
96 return 0; | |
97 } |