2020-05-01 21:42:49 +01:00
|
|
|
#include "hid.h"
|
2020-12-23 16:39:22 +00:00
|
|
|
#include <input/joycon.h>
|
|
|
|
#include <utils/btn.h>
|
2020-05-02 00:41:43 +01:00
|
|
|
#include "../gfx/gfx.h"
|
2020-12-23 16:39:22 +00:00
|
|
|
#include <utils/types.h>
|
|
|
|
#include <utils/util.h>
|
2021-01-01 10:43:31 +00:00
|
|
|
#include "../utils/utils.h"
|
2021-01-09 16:12:45 +00:00
|
|
|
#include "../tegraexplorer/tools.h"
|
2021-01-11 23:30:14 +00:00
|
|
|
#include <display/di.h>
|
2021-01-11 20:22:24 +00:00
|
|
|
#include "../config.h"
|
2020-05-01 21:42:49 +01:00
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
static Input_t inputs = {0};
|
2020-05-01 21:42:49 +01:00
|
|
|
u16 LbaseX = 0, LbaseY = 0, RbaseX = 0, RbaseY = 0;
|
|
|
|
|
|
|
|
void hidInit(){
|
|
|
|
jc_init_hw();
|
|
|
|
}
|
|
|
|
|
2021-01-11 20:22:24 +00:00
|
|
|
extern hekate_config h_cfg;
|
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
Input_t *hidRead(){
|
2020-05-01 21:42:49 +01:00
|
|
|
jc_gamepad_rpt_t *controller = joycon_poll();
|
2020-05-02 00:41:43 +01:00
|
|
|
|
2021-01-11 23:37:31 +00:00
|
|
|
inputs.buttons = 0;
|
|
|
|
u8 left_connected = 0;
|
|
|
|
u8 right_connected = 0;
|
2020-12-23 16:39:22 +00:00
|
|
|
|
2021-01-11 23:37:31 +00:00
|
|
|
if (controller != NULL){
|
2021-01-30 13:32:19 +00:00
|
|
|
if (controller->home && !h_cfg.t210b01)
|
2021-01-11 23:37:31 +00:00
|
|
|
RebootToPayloadOrRcm();
|
|
|
|
|
|
|
|
if (controller->cap)
|
|
|
|
TakeScreenshot();
|
|
|
|
|
|
|
|
inputs.buttons = controller->buttons;
|
|
|
|
|
|
|
|
left_connected = controller->conn_l;
|
|
|
|
right_connected = controller->conn_r;
|
|
|
|
}
|
2021-01-09 16:12:45 +00:00
|
|
|
|
2020-05-03 01:00:04 +01:00
|
|
|
|
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;
|
2020-12-23 16:39:22 +00:00
|
|
|
inputs.power = (btn & BTN_POWER) ? 1 : 0;
|
2020-05-02 00:41:43 +01:00
|
|
|
|
2021-01-11 23:37:31 +00:00
|
|
|
if (left_connected){
|
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;
|
|
|
|
}
|
|
|
|
|
2023-09-26 15:18:39 +01:00
|
|
|
inputs.up = (controller->up || inputs.volp || (controller->lstick_y > LbaseY + 500)) ? 1 : 0;
|
|
|
|
inputs.down = (controller->down || inputs.volm || (controller->lstick_y < LbaseY - 500)) ? 1 : 0;
|
2020-12-23 16:39:22 +00:00
|
|
|
inputs.left = (controller->left || (controller->lstick_x < LbaseX - 500)) ? 1 : 0;
|
|
|
|
inputs.right = (controller->right || (controller->lstick_x > LbaseX + 500)) ? 1 : 0;
|
2020-05-01 21:42:49 +01:00
|
|
|
}
|
2020-05-02 00:41:43 +01:00
|
|
|
else {
|
2020-12-23 16:39:22 +00:00
|
|
|
inputs.up = inputs.volp;
|
|
|
|
inputs.down = inputs.volm;
|
2020-05-02 00:41:43 +01:00
|
|
|
}
|
2020-05-01 21:42:49 +01:00
|
|
|
|
2021-01-11 23:37:31 +00:00
|
|
|
if (right_connected){
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
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-01 21:42:49 +01:00
|
|
|
}
|
2023-09-26 15:18:39 +01:00
|
|
|
inputs.a = inputs.a || inputs.power;
|
2020-05-01 21:42:49 +01:00
|
|
|
|
|
|
|
return &inputs;
|
|
|
|
}
|
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
Input_t *hidWaitMask(u32 mask){
|
|
|
|
Input_t *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
|
|
|
}
|
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
Input_t *hidWait(){
|
|
|
|
Input_t *in = hidRead();
|
2020-05-02 00:41:43 +01:00
|
|
|
|
|
|
|
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;
|
2023-09-26 15:18:39 +01:00
|
|
|
}
|