Ajust some gfx functions for joycon compatibility

This commit is contained in:
Such Meme, Many Skill
2020-05-02 01:41:43 +02:00
parent 9178813338
commit 2cced5bdac
7 changed files with 73 additions and 36 deletions

View File

@@ -1,6 +1,8 @@
#include "hid.h"
#include "joycon.h"
#include "../utils/btn.h"
#include "../gfx/gfx.h"
#include "../utils/types.h"
static Inputs inputs = {0};
u16 LbaseX = 0, LbaseY = 0, RbaseX = 0, RbaseY = 0;
@@ -11,6 +13,12 @@ void hidInit(){
Inputs *hidRead(){
jc_gamepad_rpt_t *controller = joycon_poll();
static bool errPrint = false;
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;
inputs.a = controller->a;
inputs.b = controller->b;
@@ -25,6 +33,18 @@ Inputs *hidRead(){
inputs.home = controller->home;
inputs.cap = controller->cap;
if (controller->conn_l && controller->conn_r){
if (errPrint){
gfx_boxGrey(1008, 703, 1279, 719, 0xFF);
errPrint = false;
}
}
else {
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);
errPrint = true;
}
if (controller->conn_l){
if ((LbaseX == 0 || LbaseY == 0) || controller->l3){
LbaseX = controller->lstick_x;
@@ -36,6 +56,10 @@ Inputs *hidRead(){
inputs.Lleft = (controller->left || (controller->lstick_x < LbaseX - 500)) ? 1 : 0;
inputs.Lright = (controller->right || (controller->lstick_x > LbaseX + 500)) ? 1 : 0;
}
else {
inputs.Lup = inputs.volp;
inputs.Ldown = inputs.volm;
}
if (controller->conn_r){
if ((RbaseX == 0 || RbaseY == 0) || controller->r3){
@@ -48,19 +72,27 @@ Inputs *hidRead(){
inputs.Rleft = (controller->rstick_x < RbaseX - 500) ? 1 : 0;
inputs.Rright = (controller->rstick_x > RbaseX + 500) ? 1 : 0;
}
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;
else
inputs.a = inputs.pow;
return &inputs;
}
Inputs *hidWaitForButton(u32 mask){
Inputs *hidWaitMask(u32 mask){
Inputs *in = hidRead();
while ((in->buttons & mask) == 0){
in = hidRead();
}
return in;
}
Inputs *hidWait(){
Inputs *in = hidRead();
while (in->buttons)
hidRead();
while (!(in->buttons))
hidRead();
return in;
}

View File

@@ -8,6 +8,9 @@
#define KEY_LDOWN BIT(17)
#define KEY_RUP BIT(7)
#define KEY_RDOWN BIT(6)
#define KEY_VOLP BIT(14)
#define KEY_VOLM BIT(15)
#define KEY_POW BIT(16)
typedef struct _inputs {
union {
@@ -47,4 +50,5 @@ typedef struct _inputs {
void hidInit();
Inputs *hidRead();
Inputs *hidWaitForButton(u32 mask);
Inputs *hidWait();
Inputs *hidWaitMask(u32 mask);