Added handheld controls

This commit is contained in:
Maschell 2017-12-31 18:52:44 +01:00
parent 747ff207c0
commit e71fac665b
2 changed files with 17 additions and 12 deletions

View File

@ -4,8 +4,6 @@ Based on: https://github.com/vgmoose/sdl-hello-world
Back to the roots. Back in 2008 I started with writing homebrew on Wii. The first "game" I created was "Push A".
Now, almost 10 years later, I quickly wrote a new version for the Switch.
Maybe only works with detached Joy-Cons.
Have fun!

27
input.c
View File

@ -9,16 +9,7 @@ void PADDestroy(){
hid_finalize();
}
void PADRead(struct PADData* data){
// reset buttons
data->btns_h = 0b00000000;
// scan for controller
hid_controller_t* num8 = hid_get_shared_memory()->controllers;
hid_controller_state_entry_t ent = num8->main.entries[num8->main.latest_idx];
// process inputs
static void readInputInternal(struct PADData* data,hid_controller_state_entry_t ent ){
data->btns_h |= ((ent.button_state & JOYPAD_A)? BUTTON_A : 0);
data->btns_h |= ((ent.button_state & JOYPAD_B)? BUTTON_B : 0);
data->btns_h |= ((ent.button_state & JOYPAD_UP)? BUTTON_UP : 0);
@ -28,3 +19,19 @@ void PADRead(struct PADData* data){
data->btns_h |= ((ent.button_state & JOYPAD_START)? BUTTON_PLUS : 0);
data->btns_h |= ((ent.button_state & JOYPAD_SELECT)? BUTTON_MINUS : 0);
}
void PADRead(struct PADData* data){
// reset buttons
data->btns_h = 0b00000000;
// scan for controller
hid_controller_t* num = hid_get_shared_memory()->controllers;
hid_controller_t* num8 = hid_get_shared_memory()->controllers;
hid_controller_state_entry_t ent = num->main.entries[num->main.latest_idx];
hid_controller_state_entry_t ent8 = num8->main.entries[num8->main.latest_idx];
// process inputs
readInputInternal(data,ent);
readInputInternal(data,ent8);
}