Merge pull request #8 from Quest84/master

Fix deprecated hid functions
This commit is contained in:
SeanOMik 2021-07-13 13:34:48 -04:00 committed by GitHub
commit f07e1edfd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 51 deletions

View File

@ -45,8 +45,8 @@ INCLUDES := include include/menus/book include/menus/book-chooser include/he
ROMFS := romfs
VERSION_MAJOR := 0
VERSION_MINOR := 2
VERSION_MICRO := 2
VERSION_MINOR := 3
VERSION_MICRO := 0
APP_TITLE := eBookReader
APP_AUTHOR := SeanOMik

View File

@ -50,7 +50,7 @@ Light Mode Landscape Reading:
* NX-Shell Team - A good amount of the code is from an old version of their application.
### Building
* Release built with [libnx release v2.4.0](https://github.com/switchbrew/libnx).
* Release built with [libnx release v.4.1.3](https://github.com/switchbrew/libnx).
* Uses `freetype` and other libs which comes with `switch-portlibs` via `devkitPro pacman`:
```
pacman -S libnx switch-portlibs
@ -61,3 +61,8 @@ make mupdf
make
```
to build.
If you don't have twili debugger installed then delete the -ltwili flag on the Makefile to compile:
```
LIBS: -ltwili
```

View File

@ -59,16 +59,25 @@ void Menu_StartChoosing() {
SDL_ClearScreen(RENDERER, backColor);
SDL_RenderClear(RENDERER);
hidScanInput();
//hidScanInput();
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
PadState pad;
padInitializeDefault(&pad);
padUpdate(&pad);
//u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
u64 kDown = padGetButtonsDown(&pad);
u64 kHeld = padGetButtons(&pad);
/*if (!isWarningOnScreen && kDown & KEY_PLUS) {
break;
}*/
if (kDown & KEY_B) {
if (kDown & HidNpadButton_B) {
if (!isWarningOnScreen) {
break;
} else {
@ -76,7 +85,7 @@ void Menu_StartChoosing() {
}
}
if (kDown & KEY_A) {
if (kDown & HidNpadButton_A) {
int bookIndex = 0;
for (const auto & entry : fs::directory_iterator(path)) {
string filename = entry.path().filename().string();
@ -109,7 +118,7 @@ void Menu_StartChoosing() {
}
}
if (kDown & KEY_DUP) {
if (kDown & HidNpadButton_Up) {
if (choosenIndex != 0 && !isWarningOnScreen) {
choosenIndex--;
} else if (choosenIndex == 0) {
@ -117,7 +126,7 @@ void Menu_StartChoosing() {
}
}
if (kDown & KEY_DDOWN) {
if (kDown & HidNpadButton_Down) {
if (choosenIndex == amountOfFiles-1) {
choosenIndex = 0;
} else if (choosenIndex < amountOfFiles-1 && !isWarningOnScreen) {
@ -125,7 +134,7 @@ void Menu_StartChoosing() {
}
}
if (kDown & KEY_MINUS) {
if (kDown & HidNpadButton_Minus) {
configDarkMode = !configDarkMode;
}

View File

@ -24,75 +24,86 @@ void Menu_OpenBook(char *path) {
bool helpMenu = false;
// Configure our supported input layout: a single player with standard controller syles
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
PadState pad;
padInitializeDefault(&pad);
//Touch_Process(&touchInfo);
while(result >= 0 && appletMainLoop()) {
reader->draw(helpMenu);
hidScanInput();
//hidScanInput();
//Touch_Process(&touchInfo);
//u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
padUpdate(&pad);
if (!helpMenu && kDown & KEY_DLEFT) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
u64 kDown = padGetButtonsDown(&pad);
u64 kHeld = padGetButtons(&pad);
u64 kUp = padGetButtonsUp(&pad);
if (!helpMenu && kDown & HidNpadButton_Left) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->previous_page(1);
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->zoom_out();
}
} else if (!helpMenu && kDown & KEY_DRIGHT) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
} else if (!helpMenu && kDown & HidNpadButton_Right) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->next_page(1);
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->zoom_in();
}
}
if (!helpMenu && kDown & KEY_R) {
if (!helpMenu && kDown & HidNpadButton_R) {
reader->next_page(10);
} else if (!helpMenu && kDown & KEY_L) {
} else if (!helpMenu && kDown & HidNpadButton_L) {
reader->previous_page(10);
}
if (!helpMenu && ((kDown & KEY_DUP) || (kHeld & KEY_RSTICK_UP))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
if (!helpMenu && ((kDown & HidNpadButton_Up) || (kHeld & HidNpadButton_StickRUp))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->zoom_in();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->previous_page(1);
}
} else if (!helpMenu && ((kDown & KEY_DDOWN) || (kHeld & KEY_RSTICK_DOWN))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
} else if (!helpMenu && ((kDown & HidNpadButton_Down) || (kHeld & HidNpadButton_StickRDown))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->zoom_out();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->next_page(1);
}
}
if (!helpMenu && kHeld & KEY_LSTICK_UP) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
if (!helpMenu && kHeld & HidNpadButton_StickLUp) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_up();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_left();
}
} else if (!helpMenu && kHeld & KEY_LSTICK_DOWN) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
} else if (!helpMenu && kHeld & HidNpadButton_StickLDown) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_down();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_right();
}
} else if (!helpMenu && kHeld & KEY_LSTICK_RIGHT) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if (!helpMenu && kHeld & HidNpadButton_StickLRight) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
//reader->move_page_up();
reader->move_page_down();
}
} else if (!helpMenu && kHeld & KEY_LSTICK_LEFT) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if (!helpMenu && kHeld & HidNpadButton_StickLLeft) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
//reader->move_page_down();
reader->move_page_up();
}
}
if (kDown & KEY_B) {
if (kDown & HidNpadButton_B) {
if (helpMenu) {
helpMenu = !helpMenu;
} else {
@ -100,24 +111,24 @@ void Menu_OpenBook(char *path) {
}
}
if (!helpMenu && kDown & KEY_X) {
if (!helpMenu && kDown & HidNpadButton_X) {
reader->permStatusBar = !reader->permStatusBar;
}
if (!helpMenu && kDown & KEY_LSTICK || kDown & KEY_RSTICK) {
if (!helpMenu && kDown & HidNpadButton_StickL || kDown & HidNpadButton_StickR) {
reader->reset_page();
}
if (!helpMenu && kDown & KEY_Y) {
if (!helpMenu && kDown & HidNpadButton_Y) {
reader->switch_page_layout();
}
if (!helpMenu && kDown & KEY_MINUS) {
if (!helpMenu && kUp & HidNpadButton_Minus) {
configDarkMode = !configDarkMode;
reader->previous_page(0);
}
if (kDown & KEY_PLUS) {
if (kDown & HidNpadButton_Plus) {
helpMenu = !helpMenu;
}

View File

@ -33,7 +33,8 @@ static char *Clock_GetCurrentTime(void) {
static void StatusBar_GetBatteryStatus(int x, int y) {
u32 percent = 0;
ChargerType state;
//ChargerType state;
PsmChargerType state;
int width = 0;
char buf[5];