Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit f07e1ed

Browse files
authored
Merge pull request #8 from Quest84/master
Fix deprecated hid functions
2 parents 2fae85c + 5ebf896 commit f07e1ed

File tree

5 files changed

+76
-50
lines changed

5 files changed

+76
-50
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ INCLUDES := include include/menus/book include/menus/book-chooser include/he
4545
ROMFS := romfs
4646

4747
VERSION_MAJOR := 0
48-
VERSION_MINOR := 2
49-
VERSION_MICRO := 2
48+
VERSION_MINOR := 3
49+
VERSION_MICRO := 0
5050

5151
APP_TITLE := eBookReader
5252
APP_AUTHOR := SeanOMik

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Light Mode Landscape Reading:
5050
* NX-Shell Team - A good amount of the code is from an old version of their application.
5151

5252
### Building
53-
* Release built with [libnx release v2.4.0](https://github.com/switchbrew/libnx).
53+
* Release built with [libnx release v.4.1.3](https://github.com/switchbrew/libnx).
5454
* Uses `freetype` and other libs which comes with `switch-portlibs` via `devkitPro pacman`:
5555
```
5656
pacman -S libnx switch-portlibs
@@ -61,3 +61,8 @@ make mupdf
6161
make
6262
```
6363
to build.
64+
65+
If you don't have twili debugger installed then delete the -ltwili flag on the Makefile to compile:
66+
```
67+
LIBS: -ltwili
68+
```

source/menus/book-chooser/MenuChooser.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,33 @@ void Menu_StartChoosing() {
5959
SDL_ClearScreen(RENDERER, backColor);
6060
SDL_RenderClear(RENDERER);
6161

62-
hidScanInput();
62+
//hidScanInput();
63+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
6364

64-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
65-
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
65+
PadState pad;
66+
padInitializeDefault(&pad);
67+
68+
padUpdate(&pad);
69+
70+
//u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
71+
//u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
72+
73+
u64 kDown = padGetButtonsDown(&pad);
74+
u64 kHeld = padGetButtons(&pad);
6675

6776
/*if (!isWarningOnScreen && kDown & KEY_PLUS) {
6877
break;
6978
}*/
7079

71-
if (kDown & KEY_B) {
80+
if (kDown & HidNpadButton_B) {
7281
if (!isWarningOnScreen) {
7382
break;
7483
} else {
7584
isWarningOnScreen = false;
7685
}
7786
}
7887

79-
if (kDown & KEY_A) {
88+
if (kDown & HidNpadButton_A) {
8089
int bookIndex = 0;
8190
for (const auto & entry : fs::directory_iterator(path)) {
8291
string filename = entry.path().filename().string();
@@ -109,23 +118,23 @@ void Menu_StartChoosing() {
109118
}
110119
}
111120

112-
if (kDown & KEY_DUP) {
121+
if (kDown & HidNpadButton_Up) {
113122
if (choosenIndex != 0 && !isWarningOnScreen) {
114123
choosenIndex--;
115124
} else if (choosenIndex == 0) {
116125
choosenIndex = amountOfFiles-1;
117126
}
118127
}
119128

120-
if (kDown & KEY_DDOWN) {
129+
if (kDown & HidNpadButton_Down) {
121130
if (choosenIndex == amountOfFiles-1) {
122131
choosenIndex = 0;
123132
} else if (choosenIndex < amountOfFiles-1 && !isWarningOnScreen) {
124133
choosenIndex++;
125134
}
126135
}
127136

128-
if (kDown & KEY_MINUS) {
137+
if (kDown & HidNpadButton_Minus) {
129138
configDarkMode = !configDarkMode;
130139
}
131140

@@ -171,4 +180,4 @@ void Menu_StartChoosing() {
171180

172181
SDL_RenderPresent(RENDERER);
173182
}
174-
}
183+
}

source/menus/book/menu_book_reader.cpp

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,103 +24,114 @@ void Menu_OpenBook(char *path) {
2424

2525
bool helpMenu = false;
2626

27+
// Configure our supported input layout: a single player with standard controller syles
28+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
29+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
30+
PadState pad;
31+
padInitializeDefault(&pad);
32+
//Touch_Process(&touchInfo);
33+
2734
while(result >= 0 && appletMainLoop()) {
2835
reader->draw(helpMenu);
2936

30-
hidScanInput();
37+
//hidScanInput();
38+
39+
//u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
40+
//u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
41+
42+
padUpdate(&pad);
3143

32-
//Touch_Process(&touchInfo);
44+
u64 kDown = padGetButtonsDown(&pad);
45+
u64 kHeld = padGetButtons(&pad);
46+
u64 kUp = padGetButtonsUp(&pad);
3347

34-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
35-
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
36-
37-
if (!helpMenu && kDown & KEY_DLEFT) {
38-
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
48+
if (!helpMenu && kDown & HidNpadButton_Left) {
49+
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
3950
reader->previous_page(1);
40-
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
51+
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
4152
reader->zoom_out();
4253
}
43-
} else if (!helpMenu && kDown & KEY_DRIGHT) {
44-
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
54+
} else if (!helpMenu && kDown & HidNpadButton_Right) {
55+
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
4556
reader->next_page(1);
46-
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
57+
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
4758
reader->zoom_in();
4859
}
4960
}
5061

51-
if (!helpMenu && kDown & KEY_R) {
62+
if (!helpMenu && kDown & HidNpadButton_R) {
5263
reader->next_page(10);
53-
} else if (!helpMenu && kDown & KEY_L) {
64+
} else if (!helpMenu && kDown & HidNpadButton_L) {
5465
reader->previous_page(10);
5566
}
5667

57-
if (!helpMenu && ((kDown & KEY_DUP) || (kHeld & KEY_RSTICK_UP))) {
58-
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
68+
if (!helpMenu && ((kDown & HidNpadButton_Up) || (kHeld & HidNpadButton_StickRUp))) {
69+
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
5970
reader->zoom_in();
60-
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
71+
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
6172
reader->previous_page(1);
6273
}
63-
} else if (!helpMenu && ((kDown & KEY_DDOWN) || (kHeld & KEY_RSTICK_DOWN))) {
64-
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
74+
} else if (!helpMenu && ((kDown & HidNpadButton_Down) || (kHeld & HidNpadButton_StickRDown))) {
75+
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
6576
reader->zoom_out();
66-
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
77+
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
6778
reader->next_page(1);
6879
}
6980
}
7081

71-
if (!helpMenu && kHeld & KEY_LSTICK_UP) {
72-
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
82+
if (!helpMenu && kHeld & HidNpadButton_StickLUp) {
83+
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
7384
reader->move_page_up();
74-
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
85+
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
7586
reader->move_page_left();
7687
}
77-
} else if (!helpMenu && kHeld & KEY_LSTICK_DOWN) {
78-
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
88+
} else if (!helpMenu && kHeld & HidNpadButton_StickLDown) {
89+
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
7990
reader->move_page_down();
80-
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
91+
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
8192
reader->move_page_right();
8293
}
83-
} else if (!helpMenu && kHeld & KEY_LSTICK_RIGHT) {
84-
if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
94+
} else if (!helpMenu && kHeld & HidNpadButton_StickLRight) {
95+
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
8596
//reader->move_page_up();
8697
reader->move_page_down();
8798
}
88-
} else if (!helpMenu && kHeld & KEY_LSTICK_LEFT) {
89-
if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
99+
} else if (!helpMenu && kHeld & HidNpadButton_StickLLeft) {
100+
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
90101
//reader->move_page_down();
91102
reader->move_page_up();
92103
}
93104
}
94105

95-
if (kDown & KEY_B) {
106+
if (kDown & HidNpadButton_B) {
96107
if (helpMenu) {
97108
helpMenu = !helpMenu;
98109
} else {
99110
break;
100111
}
101112
}
102113

103-
if (!helpMenu && kDown & KEY_X) {
114+
if (!helpMenu && kDown & HidNpadButton_X) {
104115
reader->permStatusBar = !reader->permStatusBar;
105116
}
106117

107-
if (!helpMenu && kDown & KEY_LSTICK || kDown & KEY_RSTICK) {
118+
if (!helpMenu && kDown & HidNpadButton_StickL || kDown & HidNpadButton_StickR) {
108119
reader->reset_page();
109120
}
110121

111-
if (!helpMenu && kDown & KEY_Y) {
122+
if (!helpMenu && kDown & HidNpadButton_Y) {
112123
reader->switch_page_layout();
113124
}
114125

115-
if (!helpMenu && kDown & KEY_MINUS) {
126+
if (!helpMenu && kUp & HidNpadButton_Minus) {
116127
configDarkMode = !configDarkMode;
117128
reader->previous_page(0);
118129
}
119130

120-
if (kDown & KEY_PLUS) {
131+
if (kDown & HidNpadButton_Plus) {
121132
helpMenu = !helpMenu;
122133
}
123-
134+
124135
/*if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
125136
float tapRegion = 120;
126137

source/status_bar.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ static char *Clock_GetCurrentTime(void) {
3333

3434
static void StatusBar_GetBatteryStatus(int x, int y) {
3535
u32 percent = 0;
36-
ChargerType state;
36+
//ChargerType state;
37+
PsmChargerType state;
3738
int width = 0;
3839
char buf[5];
3940

@@ -140,4 +141,4 @@ void StatusBar_DisplayTime(bool portriat) {
140141

141142
StatusBar_GetBatteryStatus(1260 - (timeWidth + helpWidth) - 110, (40 - timeHeight) / 2 + 34); // 34 is height of battery img
142143
}
143-
}
144+
}

0 commit comments

Comments
 (0)