74 lines
1.9 KiB
C
74 lines
1.9 KiB
C
#include <stdio.h>
|
|
#include "command.h "
|
|
#include "command.h"
|
|
#include "input.h"
|
|
|
|
|
|
|
|
|
|
// this is the underlying function
|
|
int printButton(const char* string) {
|
|
return printf(string);
|
|
}
|
|
|
|
void commandWrapper(void* args, void* ret) {
|
|
// we cast ret to a int and then place the return val in to it
|
|
*(int*)(ret) = printButton(*(const char**)(args));
|
|
}
|
|
|
|
|
|
Inputs_e getinput() {
|
|
return BUTTON_DOWN;
|
|
}
|
|
|
|
|
|
// this is the only part i dont like
|
|
const char* button_up_cmd_args = "up button pressed";
|
|
int button_up_cmd_return_val = 0; // dont leave thing uninstalised
|
|
|
|
const char* button_left_cmd_args = "left button pressed";
|
|
int button_left_cmd_return_val = 0; // dont leave thing uninstalised
|
|
|
|
const char* button_right_cmd_args = "right button pressed";
|
|
int button_right_cmd_return_val = 0; // dont leave thing uninstalised
|
|
|
|
const char* button_down_cmd_args = "down button pressed";
|
|
int button_down_cmd_return_val = 0; // dont leave thing uninstalised
|
|
|
|
static Input_t input_device = (Input_t){
|
|
.button_up_cmd = (Command_t){
|
|
.args = (void*)(&button_up_cmd_args),
|
|
.ret = (void*)(&button_up_cmd_return_val),
|
|
.command = &commandWrapper,
|
|
},
|
|
.button_left_cmd = (Command_t){
|
|
.args = (void*)(&button_left_cmd_args),
|
|
.ret = (void*)(&button_left_cmd_return_val),
|
|
.command = &commandWrapper,
|
|
},
|
|
.button_right_cmd = (Command_t){
|
|
.args = (void*)(&button_right_cmd_args),
|
|
.ret = (void*)(&button_right_cmd_return_val),
|
|
.command = &commandWrapper,
|
|
},
|
|
.button_down_cmd = (Command_t){
|
|
.args = (void*)(&button_down_cmd_args),
|
|
.ret = (void*)(&button_down_cmd_return_val),
|
|
.command = &commandWrapper,
|
|
},
|
|
.handle = (InputHandler_t) {
|
|
.getInput = &getinput,
|
|
}
|
|
};
|
|
|
|
int main() {
|
|
|
|
// we have our input now we will handle it
|
|
handleInput(input_device);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|