Created
June 4, 2020 03:35
-
-
Save licheegh/3dbdc8918325e8af8d4d13805cd0c350 to your computer and use it in GitHub Desktop.
open a pwm beeper on linux and send a frequency to it, pwm_beeper_test 1000 will beep a 1k sound for 1s.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdint.h> | |
| #include<string.h> | |
| #include<fcntl.h> | |
| #include<unistd.h> | |
| #include<stdio.h> | |
| #include<stdlib.h> | |
| #include<linux/input.h> | |
| #include<unistd.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| int fd, version, ret; | |
| struct input_event event; | |
| if ((fd = open("/dev/input/event2", O_RDWR)) < 0) { | |
| perror("beep test"); | |
| return 1; | |
| } | |
| event.type = EV_SND; | |
| event.code = SND_TONE; | |
| event.value = atoi(argv[1]); | |
| printf("will open event2 with SND_TONE %d\n",event.value); | |
| ret = write(fd, &event, sizeof(struct input_event)); | |
| printf("ret = %d\n", ret); | |
| sleep(1); | |
| event.value = 0; | |
| ret = write(fd, &event, sizeof(struct input_event)); | |
| printf("ret = %d\n", ret); | |
| close(fd); | |
| return ret; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment