You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
823 B
47 lines
823 B
#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;
|
|
}
|
|
|