PushA_NX/input.c

38 lines
1.3 KiB
C
Raw Normal View History

2017-12-31 18:49:45 +01:00
#include "input.h"
#include<libtransistor/nx.h>
void PADInit(){
hid_init();
}
void PADDestroy(){
hid_finalize();
}
2017-12-31 18:52:44 +01:00
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);
data->btns_h |= ((ent.button_state & JOYPAD_DOWN)? BUTTON_DOWN : 0);
data->btns_h |= ((ent.button_state & JOYPAD_LEFT)? BUTTON_LEFT : 0);
data->btns_h |= ((ent.button_state & JOYPAD_RIGHT)? BUTTON_RIGHT : 0);
data->btns_h |= ((ent.button_state & JOYPAD_START)? BUTTON_PLUS : 0);
data->btns_h |= ((ent.button_state & JOYPAD_SELECT)? BUTTON_MINUS : 0);
}
2017-12-31 18:49:45 +01:00
void PADRead(struct PADData* data){
// reset buttons
data->btns_h = 0b00000000;
// scan for controller
2017-12-31 18:52:44 +01:00
hid_controller_t* num = hid_get_shared_memory()->controllers;
2017-12-31 19:00:14 +01:00
hid_controller_t* num8 = hid_get_shared_memory()->controllers + 8 ;
2017-12-31 18:49:45 +01:00
2017-12-31 18:52:44 +01:00
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];
2017-12-31 18:49:45 +01:00
// process inputs
2017-12-31 18:52:44 +01:00
readInputInternal(data,ent);
readInputInternal(data,ent8);
2017-12-31 18:49:45 +01:00
}