From a689ba41dadad0093f7545dd8999d41a165ceb98 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Tue, 15 Aug 2023 20:45:39 +1000 Subject: Initial refactor of plugin system (darwin only) Darwin only for now since that's what I'm on, will migrate the others a bit later. Trying out a different plugin system that probably makes more sense as an interface to each other. Might shuffle things around even more later. This is based somewhat on Tsoding's audio visualiser plugin system, I thought that was way more elegant (the 'state' object), as opposed to whatever the hell we were doing. --- board/simple_board.h | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'board/simple_board.h') diff --git a/board/simple_board.h b/board/simple_board.h index f0997c7..1a264de 100644 --- a/board/simple_board.h +++ b/board/simple_board.h @@ -1,36 +1,32 @@ #include "board.h" -static struct board_data board_data; - #define WAV_LEN(W) PREPROC_CONCAT(W,_len) #define PREPROC_CONCAT(A, B) A ## B -void board_on_down(void) +void board_on_down(struct board_state *state) { + (void) state; #ifdef BOARD_DOWN_WAV - board_data.sound_play(BOARD_DOWN_WAV, WAV_LEN(BOARD_DOWN_WAV)); + state->sound_play(BOARD_DOWN_WAV, WAV_LEN(BOARD_DOWN_WAV)); #endif } -void board_on_up(void) +void board_on_up(struct board_state *state) { + (void) state; #ifdef BOARD_UP_WAV - board_data.sound_play(BOARD_UP_WAV, WAV_LEN(BOARD_UP_WAV)); + state->sound_play(BOARD_UP_WAV, WAV_LEN(BOARD_UP_WAV)); #endif } -static struct board board = { - .on_down = &board_on_down, - .on_up = &board_on_up, +void board_init(struct board_state *state) +{ #ifdef BOARD_NAME - .name = BOARD_NAME, + state->name = BOARD_NAME; #else - .name = "Generic Board", + state->name = "Generic Board"; #endif -}; -struct board *board_init(struct board_data data) -{ - board_data = data; - return &board; + state->on_down = &board_on_down; + state->on_up = &board_on_up; } -- cgit