diff options
author | Nicholas Tay <nick@windblume.net> | 2022-05-07 17:45:46 +1000 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2022-05-07 17:45:46 +1000 |
commit | 740a0d2203a56033c630da2f11731f8f34df806d (patch) | |
tree | 0d05395faebef1d0a18513ab5806774f3b256bca | |
parent | 10f3f56692cee2a071792baad26fba6c78b665b6 (diff) | |
download | clak-740a0d2203a56033c630da2f11731f8f34df806d.tar.gz clak-740a0d2203a56033c630da2f11731f8f34df806d.tar.bz2 clak-740a0d2203a56033c630da2f11731f8f34df806d.zip |
Dynamically take in board name
-rw-r--r-- | clak.c | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -1,9 +1,10 @@ #include <stdio.h> #include <unistd.h> +#include <string.h> #include <windows.h> -#define VOLUME 0.05 +#define VOLUME 0.15 #include "board/boards.h" #define BOARD(str, buf) { .name = str, .wav = buf }, @@ -29,15 +30,30 @@ void sound_play(unsigned char* buffer) PlaySound((const char *) buffer, NULL, SND_MEMORY | SND_SYNC | SND_NODEFAULT); } -int main(void) +Board *get_board(char *board_name) { - sound_init(); - for (int i = 0; i < boards_n; ++i) { - printf("name: %s\n", boards[i].name); - sound_play(boards[i].wav); - sleep(0.5); + if (strcmp(boards[i].name, board_name) == 0) + return &boards[i]; + } + return NULL; +} + +int main(int argc, char **argv) +{ + Board *board; + if (argc < 2 || (board = get_board(argv[1])) == NULL) { + printf("Please provide a valid board name.\n"); + printf("Valid boards: "); + for (int i = 0; i < boards_n; ++i) { + printf("%s%s", boards[i].name, (i == boards_n - 1) ? "\n" : ", "); + } + return 1; } + sound_init(); + printf("name: %s\n", board->name); + sound_play(board->wav); + return 0; }
\ No newline at end of file |