aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-04-28 21:54:45 +1000
committerNicholas Tay <nick@windblume.net>2022-04-28 21:54:45 +1000
commit30547ed47ab653586073ae87d0c986c14ddaf241 (patch)
treeec565bb08ae384abd07f5e6e49651a30f26b4af3
parent1783cfd9965c38d60cea3daff172c6657983719b (diff)
downloadclak-30547ed47ab653586073ae87d0c986c14ddaf241.tar.gz
clak-30547ed47ab653586073ae87d0c986c14ddaf241.tar.bz2
clak-30547ed47ab653586073ae87d0c986c14ddaf241.zip
Iterate boards in C
-rw-r--r--Makefile4
-rw-r--r--clak.c18
2 files changed, 19 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 2635da2..c2a94a6 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,9 @@ $(NAME): $(NAME).c $(BOARD_FILES) board/boards.h
board/boards.h:
printf "#ifndef BOARD_DEFAULTS_H\n#define BOARD_DEFAULTS_H\n\n" > board/boards.h
for board in $(BOARDS); do echo "#include \"$$board/board.h\"" >> board/boards.h; done
- printf "\n#endif /* BOARD_DEFAULTS_H */" >> board/boards.h
+ printf "\n#define BOARDS " >> board/boards.h
+ for board in $(BOARDS); do printf "BOARD(\"$$board\", board_$${board}_board_down_wav) " >> board/boards.h; done
+ printf "\n\n#endif /* BOARD_DEFAULTS_H */" >> board/boards.h
$(BOARD_FILES): %.h: %_down.wav
xxd -i "$<" "$@"
diff --git a/clak.c b/clak.c
index 3a0c5bf..5e947e9 100644
--- a/clak.c
+++ b/clak.c
@@ -3,15 +3,29 @@
#include <windows.h>
#include "board/boards.h"
+#define BOARD(str, buf) { .name = str, .wav = buf },
+
+typedef struct {
+ char *name;
+ unsigned char* wav;
+} Board;
+
+Board boards[] = {
+ BOARDS
+};
+int const boards_n = sizeof(boards) / sizeof(boards[0]);
int main(void)
{
float volume = 0.05;
DWORD channel_volume = volume * 0xFFFF;
waveOutSetVolume(NULL, (channel_volume << 16) | channel_volume);
- while (1) {
- PlaySound((const char *) board_mxblue_board_down_wav, NULL, SND_MEMORY | SND_SYNC | SND_NODEFAULT);
+
+ for (int i = 0; i < boards_n; ++i) {
+ printf("name: %s\n", boards[i].name);
+ PlaySound((const char *) boards[i].wav, NULL, SND_MEMORY | SND_SYNC | SND_NODEFAULT);
Sleep(500);
}
+
return 0;
} \ No newline at end of file