| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <string.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- int flag = 0;
- int freq = 0;
- int duration = 0;
- unsigned char buf[4];
- int fd = 0;
- int ret = 0;
- if(argc != 4)
- {
- printf("Usage: %s on 2 2400\n", argv[0]);
- return 1;
- }
- if(strcmp(argv[1], "on") == 0)
- {
- flag = 1;
- }
- else if(strcmp(argv[1], "off") == 0)
- {
- flag = 0;
- }
- else
- {
- printf("Usage: %s on 2 2400\n", argv[0]);
- return 1;
- }
- freq = atoi(argv[3]);
- duration = atoi(argv[2]);
- memset(buf, 0, sizeof(buf));
- buf[0] = flag;
- buf[1] = freq&0xff;
- buf[2] = (freq>>8)&0xff;
- buf[3] = duration&0xff;
- fd = open("/dev/buzzer", O_RDWR);
- if(fd < 0)
- {
- printf("open /dev/buzzer failed\n");
- return 1;
- }
- ret = write(fd, buf, sizeof(buf));
- if(ret < 0)
- {
- printf("write /dev/buzzer failed\n");
- return 1;
- }
- close(fd);
- }
|