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 ROMFS := romfs
VERSION_MAJOR := 0 VERSION_MAJOR := 0
VERSION_MINOR := 2 VERSION_MINOR := 3
VERSION_MICRO := 2 VERSION_MICRO := 0
APP_TITLE := eBookReader APP_TITLE := eBookReader
APP_AUTHOR := SeanOMik 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. * NX-Shell Team - A good amount of the code is from an old version of their application.
### Building ### 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`: * Uses `freetype` and other libs which comes with `switch-portlibs` via `devkitPro pacman`:
``` ```
pacman -S libnx switch-portlibs pacman -S libnx switch-portlibs
@ -61,3 +61,8 @@ make mupdf
make make
``` ```
to build. 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_ClearScreen(RENDERER, backColor);
SDL_RenderClear(RENDERER); SDL_RenderClear(RENDERER);
hidScanInput(); //hidScanInput();
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); PadState pad;
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); 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) { /*if (!isWarningOnScreen && kDown & KEY_PLUS) {
break; break;
}*/ }*/
if (kDown & KEY_B) { if (kDown & HidNpadButton_B) {
if (!isWarningOnScreen) { if (!isWarningOnScreen) {
break; break;
} else { } else {
@ -76,7 +85,7 @@ void Menu_StartChoosing() {
} }
} }
if (kDown & KEY_A) { if (kDown & HidNpadButton_A) {
int bookIndex = 0; int bookIndex = 0;
for (const auto & entry : fs::directory_iterator(path)) { for (const auto & entry : fs::directory_iterator(path)) {
string filename = entry.path().filename().string(); 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) { if (choosenIndex != 0 && !isWarningOnScreen) {
choosenIndex--; choosenIndex--;
} else if (choosenIndex == 0) { } else if (choosenIndex == 0) {
@ -117,7 +126,7 @@ void Menu_StartChoosing() {
} }
} }
if (kDown & KEY_DDOWN) { if (kDown & HidNpadButton_Down) {
if (choosenIndex == amountOfFiles-1) { if (choosenIndex == amountOfFiles-1) {
choosenIndex = 0; choosenIndex = 0;
} else if (choosenIndex < amountOfFiles-1 && !isWarningOnScreen) { } else if (choosenIndex < amountOfFiles-1 && !isWarningOnScreen) {
@ -125,7 +134,7 @@ void Menu_StartChoosing() {
} }
} }
if (kDown & KEY_MINUS) { if (kDown & HidNpadButton_Minus) {
configDarkMode = !configDarkMode; configDarkMode = !configDarkMode;
} }

View File

@ -24,75 +24,86 @@ void Menu_OpenBook(char *path) {
bool helpMenu = false; 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()) { while(result >= 0 && appletMainLoop()) {
reader->draw(helpMenu); 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); padUpdate(&pad);
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
if (!helpMenu && kDown & KEY_DLEFT) { u64 kDown = padGetButtonsDown(&pad);
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { u64 kHeld = padGetButtons(&pad);
u64 kUp = padGetButtonsUp(&pad);
if (!helpMenu && kDown & HidNpadButton_Left) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->previous_page(1); reader->previous_page(1);
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->zoom_out(); reader->zoom_out();
} }
} else if (!helpMenu && kDown & KEY_DRIGHT) { } else if (!helpMenu && kDown & HidNpadButton_Right) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->next_page(1); reader->next_page(1);
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->zoom_in(); reader->zoom_in();
} }
} }
if (!helpMenu && kDown & KEY_R) { if (!helpMenu && kDown & HidNpadButton_R) {
reader->next_page(10); reader->next_page(10);
} else if (!helpMenu && kDown & KEY_L) { } else if (!helpMenu && kDown & HidNpadButton_L) {
reader->previous_page(10); reader->previous_page(10);
} }
if (!helpMenu && ((kDown & KEY_DUP) || (kHeld & KEY_RSTICK_UP))) { if (!helpMenu && ((kDown & HidNpadButton_Up) || (kHeld & HidNpadButton_StickRUp))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->zoom_in(); reader->zoom_in();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->previous_page(1); reader->previous_page(1);
} }
} else if (!helpMenu && ((kDown & KEY_DDOWN) || (kHeld & KEY_RSTICK_DOWN))) { } else if (!helpMenu && ((kDown & HidNpadButton_Down) || (kHeld & HidNpadButton_StickRDown))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->zoom_out(); reader->zoom_out();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->next_page(1); reader->next_page(1);
} }
} }
if (!helpMenu && kHeld & KEY_LSTICK_UP) { if (!helpMenu && kHeld & HidNpadButton_StickLUp) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_up(); reader->move_page_up();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_left(); reader->move_page_left();
} }
} else if (!helpMenu && kHeld & KEY_LSTICK_DOWN) { } else if (!helpMenu && kHeld & HidNpadButton_StickLDown) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_down(); reader->move_page_down();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_right(); reader->move_page_right();
} }
} else if (!helpMenu && kHeld & KEY_LSTICK_RIGHT) { } else if (!helpMenu && kHeld & HidNpadButton_StickLRight) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
//reader->move_page_up(); //reader->move_page_up();
reader->move_page_down(); reader->move_page_down();
} }
} else if (!helpMenu && kHeld & KEY_LSTICK_LEFT) { } else if (!helpMenu && kHeld & HidNpadButton_StickLLeft) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
//reader->move_page_down(); //reader->move_page_down();
reader->move_page_up(); reader->move_page_up();
} }
} }
if (kDown & KEY_B) { if (kDown & HidNpadButton_B) {
if (helpMenu) { if (helpMenu) {
helpMenu = !helpMenu; helpMenu = !helpMenu;
} else { } else {
@ -100,24 +111,24 @@ void Menu_OpenBook(char *path) {
} }
} }
if (!helpMenu && kDown & KEY_X) { if (!helpMenu && kDown & HidNpadButton_X) {
reader->permStatusBar = !reader->permStatusBar; reader->permStatusBar = !reader->permStatusBar;
} }
if (!helpMenu && kDown & KEY_LSTICK || kDown & KEY_RSTICK) { if (!helpMenu && kDown & HidNpadButton_StickL || kDown & HidNpadButton_StickR) {
reader->reset_page(); reader->reset_page();
} }
if (!helpMenu && kDown & KEY_Y) { if (!helpMenu && kDown & HidNpadButton_Y) {
reader->switch_page_layout(); reader->switch_page_layout();
} }
if (!helpMenu && kDown & KEY_MINUS) { if (!helpMenu && kUp & HidNpadButton_Minus) {
configDarkMode = !configDarkMode; configDarkMode = !configDarkMode;
reader->previous_page(0); reader->previous_page(0);
} }
if (kDown & KEY_PLUS) { if (kDown & HidNpadButton_Plus) {
helpMenu = !helpMenu; helpMenu = !helpMenu;
} }

View File

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