2020-05-01 21:42:49 +01:00
|
|
|
#include "hid.h"
|
|
|
|
#include "joycon.h"
|
|
|
|
#include "../utils/btn.h"
|
2020-05-02 00:41:43 +01:00
|
|
|
#include "../gfx/gfx.h"
|
|
|
|
#include "../utils/types.h"
|
2020-05-03 01:00:04 +01:00
|
|
|
#include "../tegraexplorer/utils/utils.h"
|
2020-05-01 21:42:49 +01:00
|
|
|
|
|
|
|
static Inputs inputs = {0};
|
|
|
|
u16 LbaseX = 0, LbaseY = 0, RbaseX = 0, RbaseY = 0;
|
|
|
|
|
|
|
|
void hidInit(){
|
|
|
|
jc_init_hw();
|
|
|
|
}
|
|
|
|
|
|
|
|
Inputs *hidRead(){
|
|
|
|
jc_gamepad_rpt_t *controller = joycon_poll();
|
2020-05-02 00:41:43 +01:00
|
|
|
static bool errPrint = false;
|
|
|
|
|
2020-05-03 01:00:04 +01:00
|
|
|
if (controller->cap)
|
|
|
|
utils_takeScreenshot();
|
|
|
|
|
|
|
|
|
2020-05-02 00:41:43 +01:00
|
|
|
u8 btn = btn_read();
|
|
|
|
inputs.volp = (btn & BTN_VOL_UP) ? 1 : 0;
|
|
|
|
inputs.volm = (btn & BTN_VOL_DOWN) ? 1 : 0;
|
|
|
|
inputs.pow = (btn & BTN_POWER) ? 1 : 0;
|
2020-05-01 21:42:49 +01:00
|
|
|
|
|
|
|
inputs.a = controller->a;
|
|
|
|
inputs.b = controller->b;
|
|
|
|
inputs.x = controller->x;
|
|
|
|
inputs.y = controller->y;
|
|
|
|
inputs.r = controller->r;
|
|
|
|
inputs.l = controller->l;
|
|
|
|
inputs.zr = controller->zr;
|
|
|
|
inputs.zl = controller->zl;
|
|
|
|
inputs.minus = controller->minus;
|
|
|
|
inputs.plus = controller->plus;
|
|
|
|
inputs.home = controller->home;
|
|
|
|
inputs.cap = controller->cap;
|
|
|
|
|
2020-05-02 00:41:43 +01:00
|
|
|
if (controller->conn_l && controller->conn_r){
|
|
|
|
if (errPrint){
|
|
|
|
gfx_boxGrey(1008, 703, 1279, 719, 0xFF);
|
|
|
|
errPrint = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-05-02 13:06:56 +01:00
|
|
|
u32 x, y;
|
|
|
|
gfx_con_getpos(&x, &y);
|
2020-05-02 00:41:43 +01:00
|
|
|
gfx_con_setpos(1008, 703);
|
|
|
|
gfx_printf("%k%K%s %s MISS%k%K", COLOR_DEFAULT, COLOR_WHITE, (controller->conn_l) ? " " : "JOYL", (controller->conn_r) ? " " : "JOYR", COLOR_WHITE, COLOR_DEFAULT);
|
2020-05-02 13:06:56 +01:00
|
|
|
gfx_con_setpos(x, y);
|
2020-05-02 00:41:43 +01:00
|
|
|
errPrint = true;
|
|
|
|
}
|
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
if (controller->conn_l){
|
2020-05-01 23:50:08 +01:00
|
|
|
if ((LbaseX == 0 || LbaseY == 0) || controller->l3){
|
2020-05-01 21:42:49 +01:00
|
|
|
LbaseX = controller->lstick_x;
|
|
|
|
LbaseY = controller->lstick_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs.Lup = (controller->up || (controller->lstick_y > LbaseY + 500)) ? 1 : 0;
|
|
|
|
inputs.Ldown = (controller->down || (controller->lstick_y < LbaseY - 500)) ? 1 : 0;
|
|
|
|
inputs.Lleft = (controller->left || (controller->lstick_x < LbaseX - 500)) ? 1 : 0;
|
|
|
|
inputs.Lright = (controller->right || (controller->lstick_x > LbaseX + 500)) ? 1 : 0;
|
|
|
|
}
|
2020-05-02 00:41:43 +01:00
|
|
|
else {
|
|
|
|
inputs.Lup = inputs.volp;
|
|
|
|
inputs.Ldown = inputs.volm;
|
|
|
|
}
|
2020-05-01 21:42:49 +01:00
|
|
|
|
|
|
|
if (controller->conn_r){
|
2020-05-01 23:50:08 +01:00
|
|
|
if ((RbaseX == 0 || RbaseY == 0) || controller->r3){
|
2020-05-01 21:42:49 +01:00
|
|
|
RbaseX = controller->rstick_x;
|
|
|
|
RbaseY = controller->rstick_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs.Rup = (controller->rstick_y > RbaseY + 500) ? 1 : 0;
|
|
|
|
inputs.Rdown = (controller->rstick_y < RbaseY - 500) ? 1 : 0;
|
|
|
|
inputs.Rleft = (controller->rstick_x < RbaseX - 500) ? 1 : 0;
|
|
|
|
inputs.Rright = (controller->rstick_x > RbaseX + 500) ? 1 : 0;
|
|
|
|
}
|
2020-05-02 00:41:43 +01:00
|
|
|
else
|
|
|
|
inputs.a = inputs.pow;
|
2020-05-01 21:42:49 +01:00
|
|
|
|
|
|
|
return &inputs;
|
|
|
|
}
|
|
|
|
|
2020-05-02 00:41:43 +01:00
|
|
|
Inputs *hidWaitMask(u32 mask){
|
2020-05-01 21:42:49 +01:00
|
|
|
Inputs *in = hidRead();
|
2020-05-02 22:51:16 +01:00
|
|
|
|
2020-05-02 23:30:05 +01:00
|
|
|
while (in->buttons & mask)
|
2020-05-02 22:51:16 +01:00
|
|
|
hidRead();
|
|
|
|
|
2020-05-02 23:30:05 +01:00
|
|
|
while (!(in->buttons & mask)){
|
|
|
|
hidRead();
|
2020-05-01 21:42:49 +01:00
|
|
|
}
|
2020-05-02 23:30:05 +01:00
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
return in;
|
2020-05-02 00:41:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Inputs *hidWait(){
|
|
|
|
Inputs *in = hidRead();
|
|
|
|
|
|
|
|
while (in->buttons)
|
|
|
|
hidRead();
|
|
|
|
|
|
|
|
while (!(in->buttons))
|
|
|
|
hidRead();
|
|
|
|
return in;
|
2020-05-02 19:53:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hidConnected(){
|
|
|
|
jc_gamepad_rpt_t *controller = joycon_poll();
|
|
|
|
return (controller->conn_l && controller->conn_r) ? 1 : 0;
|
2020-05-01 21:42:49 +01:00
|
|
|
}
|