1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-08 13:11:54 +00:00

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);

View file

@ -15,6 +15,7 @@
#include "../../utils/sprintf.h"
#include "../script/parser.h"
#include "../emmc/emmcoperations.h"
#include "../../hid/hid.h"
extern char *currentpath;
extern char *clipboard;
@ -36,23 +37,25 @@ int delfile(const char *path, const char *filename){
void viewbytes(char *path){
FIL in;
u8 print[2048];
u8 print[1024];
u32 size;
QWORD offset = 0;
int res;
Inputs *input = hidRead();
while (input->buttons & (KEY_POW | KEY_B));
gfx_clearscreen();
if ((res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING))){
gfx_errDisplay("viewbytes", res, 1);
return;
}
while (btn_read() & BTN_POWER);
while (1){
f_lseek(&in, offset * 16);
if ((res = f_read(&in, &print, 2048 * sizeof(u8), &size))){
if ((res = f_read(&in, &print, 1024 * sizeof(u8), &size))){
gfx_errDisplay("viewbytes", res, 2);
return;
}
@ -60,16 +63,16 @@ void viewbytes(char *path){
gfx_con_setpos(0, 31);
gfx_hexdump(offset * 16, print, size * sizeof(u8));
res = btn_read();
input = hidRead();
if (!res)
res = btn_wait();
if (!(input->buttons))
input = hidWait();
if (res & BTN_VOL_DOWN && 2048 * sizeof(u8) == size)
if (input->Ldown && 1024 * sizeof(u8) == size)
offset++;
if (res & BTN_VOL_UP && offset > 0)
if (input->Lup && offset > 0)
offset--;
if (res & BTN_POWER)
if (input->buttons & (KEY_POW | KEY_B))
break;
}
f_close(&in);

View file

@ -8,6 +8,7 @@
#include "../../utils/util.h"
#include "../../mem/heap.h"
#include "../common/common.h"
#include "../../hid/hid.h"
int printerrors = true;
@ -22,12 +23,12 @@ void gfx_clearscreen(){
gfx_boxGrey(0, 703, 1279, 719, 0xFF);
gfx_boxGrey(0, 0, 1279, 15, 0xFF);
gfx_con_setpos(0, 0);
gfx_printf("Tegraexplorer v1.5.2 | Battery: %3d%%", battery >> 8);
gfx_printf("Tegraexplorer v1.5.2 | Battery: %3d%%\n", battery >> 8);
RESETCOLOR;
}
int gfx_message(u32 color, const char* message, ...){
u32 gfx_message(u32 color, const char* message, ...){
va_list ap;
va_start(ap, message);
@ -37,10 +38,10 @@ int gfx_message(u32 color, const char* message, ...){
gfx_vprintf(message, ap);
va_end(ap);
return btn_wait();
return hidWait()->buttons;
}
int gfx_errDisplay(char *src_func, int err, int loc){
u32 gfx_errDisplay(char *src_func, int err, int loc){
if (!printerrors)
return 0;
@ -61,27 +62,24 @@ int gfx_errDisplay(char *src_func, int err, int loc){
RESETCOLOR;
while (btn_read() != 0);
return btn_wait();
return hidWait()->buttons;
}
int gfx_makewaitmenu(char *hiddenmessage, int timer){
int res;
u32 start = get_tmr_s();
while (btn_read() != 0);
Inputs *input = NULL;
while(1){
res = btn_read();
input = hidRead();
if (res & BTN_VOL_DOWN || res & BTN_VOL_UP)
if (input->buttons & (KEY_VOLM | KEY_VOLP | KEY_B))
return 0;
if (start + timer > get_tmr_s())
gfx_printf("\r<Wait %d seconds> ", timer + start - get_tmr_s());
else if (res & BTN_POWER)
else if (input->a)
return 1;
else

View file

@ -7,8 +7,8 @@
#define RESETCOLOR gfx_printf("%k%K", COLOR_WHITE, COLOR_DEFAULT)
void gfx_clearscreen();
int gfx_message(u32 color, const char* message, ...);
int gfx_errDisplay(char *src_func, int err, int loc);
u32 gfx_message(u32 color, const char* message, ...);
u32 gfx_errDisplay(char *src_func, int err, int loc);
int gfx_makewaitmenu(char *hiddenmessage, int timer);
void gfx_printlength(int size, char *toprint);
void gfx_printandclear(char *in, int length, int endX);

View file

@ -153,7 +153,7 @@ int menu_make(menu_entry *entries, int amount, char *toptext){
gfx_printf("Type: %s", (entries[currentpos].property & ISDIR) ? "Dir " : "File");
}
else
gfx_boxGrey(800, 223, 1279, 271, 0x1B);
gfx_boxGrey(800, 144, 1279, 190, 0x1B);
gfx_con_setpos(0, 703);
SWAPCOLOR(COLOR_DEFAULT);

View file

@ -37,8 +37,8 @@ void MainMenu_SDCard(){
void MainMenu_EMMC(){
gfx_clearscreen();
gfx_printf("You're about to enter EMMC\nModifying anything here\n can result in a BRICK!\n\nPlease only continue\n if you know what you're doing\n\nPress Vol+/- to return\n");
if (gfx_makewaitmenu("Press Power to enter", 4)){
gfx_printf("You're about to enter EMMC\nModifying anything here\n can result in a BRICK!\n\nPlease only continue\n if you know what you're doing\n\nPress B to return\n");
if (gfx_makewaitmenu("Press A to enter", 4)){
/*
connect_mmc(SYSMMC);
@ -92,8 +92,8 @@ void MainMenu_SDFormat(){
if (res > 0){
gfx_clearscreen();
gfx_printf("Are you sure you want to format your sd?\nThis will delete everything on your SD card\nThis action is irreversible!\n\nPress Vol+/- to cancel\n");
if(gfx_makewaitmenu("Press Power to continue", 10)){
gfx_printf("Are you sure you want to format your sd?\nThis will delete everything on your SD card\nThis action is irreversible!\n\nPress B to cancel\n");
if(gfx_makewaitmenu("Press A to continue", 10)){
if (format(res)){
sd_unmount();
}