-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
55 lines (45 loc) · 1.34 KB
/
main.c
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
#import <CoreFoundation/CoreFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#define kDefaultVibrateCount 1
#define kDefaultVibrateDelay 500
void usage() {
printf("Usage: vibrate [dn]\n");
printf(" -d <delay> The delay, in milliseconds, between vibrations. Default is 500ms.\n");
printf(" -n <amount> The number of times to vibrate. If not specified, vibrate once.\n");
printf(" -? Print this help.\n");
}
int main (int argc, char** argv) {
// command argument stuff
int count;
int delay;
char* countval = NULL;
char* delayval = NULL;
// getopt flags
int c;
bool n = false;
bool d = false;
while ((c = getopt(argc, argv, "d:n:?")) != -1) {
switch (c) {
case 'n':
n = true;
countval = optarg;
break;
case 'd':
d = true;
delayval = optarg;
break;
case '?':
usage();
return 0;
}
}
if (d) delay = atoi(delayval);
else delay = kDefaultVibrateDelay;
if (n) count = atoi(countval);
else count = kDefaultVibrateCount;
for (int i = 0; i < count; i++) {
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
usleep(delay*1000);
}
return 0;
}