shell: implement buzzer command
This commit is contained in:
parent
5730538c5f
commit
b369e3a1c0
1 changed files with 47 additions and 0 deletions
47
source/shell/buzzer.c
Normal file
47
source/shell/buzzer.c
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <buzzer.h>
|
||||||
|
#include <console.h>
|
||||||
|
|
||||||
|
extern struct buzzer buzzers[];
|
||||||
|
extern size_t nbuzzers;
|
||||||
|
|
||||||
|
int shell_buzzer(struct console *con, size_t argc, const char **argv)
|
||||||
|
{
|
||||||
|
struct buzzer *buzzer;
|
||||||
|
size_t buzzer_id = 0;
|
||||||
|
uint32_t freq = 0;
|
||||||
|
int state = 0;
|
||||||
|
|
||||||
|
if (argc >= 3)
|
||||||
|
freq = strtoul(argv[2], NULL, 0);
|
||||||
|
|
||||||
|
if (argc >= 2)
|
||||||
|
state = (strcmp(argv[1], "on") == 0);
|
||||||
|
|
||||||
|
if (argc >= 1)
|
||||||
|
buzzer_id = strtoul(argv[0], NULL, 0);
|
||||||
|
|
||||||
|
fprintf(con->fp, "%u %d %u\n", buzzer_id, state, freq);
|
||||||
|
|
||||||
|
if (buzzer_id > nbuzzers) {
|
||||||
|
fprintf(con->fp, "error: invalid buzzer ID %d\n", buzzer_id);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
buzzer = buzzers + buzzer_id;
|
||||||
|
|
||||||
|
if (!state) {
|
||||||
|
buzzer_disable(buzzer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (freq)
|
||||||
|
buzzer_set_freq(buzzer, freq);
|
||||||
|
|
||||||
|
buzzer_enable(buzzer);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue