Compare commits

..

20 Commits
sandia ... main

Author SHA1 Message Date
086116422f Merge pull request 'Update sandia git path and commit' (#8) from nez/libreshop_client:sandia_update into main
Reviewed-on: libreshop/libreshop_client#8
2023-07-28 18:17:34 +00:00
1bf7af7226 Merge branch 'main' into sandia_update 2023-07-28 18:17:15 +00:00
dc8d2ab523 Merge pull request 'Create input macros' (#6) from input_macros into main
Reviewed-on: libreshop/libreshop_client#6
2023-07-28 18:14:28 +00:00
1b0469f5de Update sandia git path and commit 2023-07-28 20:03:55 +02:00
b8ee888756 include input_macros.h in main.c 2023-07-27 14:56:50 +03:00
1a9807450f create input macros header file 2023-07-27 14:55:33 +03:00
2fd1b3f10e Merge pull request 'jansson' (#5) from jansson into main
Reviewed-on: emilyd/libreshop_client#5
2023-07-21 13:59:03 +00:00
3cb478a7d2 Merge pull request 'HTTP demo with Jansson for JSON parsing' (#4) from nez/libreshop_client:main into jansson
Reviewed-on: emilyd/libreshop_client#4
2023-07-21 13:53:23 +00:00
nez
efd99afe06 Merge branch 'main' into main 2023-07-21 13:48:12 +00:00
nez
a1c4428d37 HTTP demo with Jansson for JSON parsing 2023-07-21 13:44:07 +00:00
27cdc9cc0b JSON parsing example 2023-07-21 15:39:29 +02:00
6f627a88aa Add jansson.h + for-loop hack for header skip on http req 2023-07-21 09:47:59 +02:00
b15de193d5 Merge pull request 'add debug header file' (#3) from debug_helper into main
Reviewed-on: emilyd/libreshop_client#3
2023-07-21 06:37:36 +00:00
0ebd26d561 add breaks to switch statement, oops... 2023-07-21 09:33:58 +03:00
d9593f3fa0 add noisy debug_pause variation 2023-07-21 09:32:06 +03:00
51a1bf7f0e add warning if user is on a debug build 2023-07-21 09:31:35 +03:00
630133f77a add commented out debug header to main.c 2023-07-21 09:12:42 +03:00
df30905389 debugging header file 2023-07-21 09:07:34 +03:00
7003a9c8a3 debug pause function 2023-07-21 09:07:21 +03:00
c6bbfcac10 Merge pull request 'merge sandia' (#2) from sandia into main
Reviewed-on: emilyd/libreshop_client#2
2023-07-21 06:00:49 +00:00
7 changed files with 99 additions and 7 deletions

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "source/sandia"]
path = source/sandia
url = https://git.donut.eu.org/nez/sandia-Wii.git
url = https://git.donut.eu.org/libreshop/sandia-Wii.git

View File

@ -33,13 +33,13 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lwiiuse -lbte -logc -lm
LIBS := -lwiiuse -lbte -logc -lm -ljansson
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=
LIBDIRS := $(PORTLIBS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional

17
source/debug.c Normal file
View File

@ -0,0 +1,17 @@
// debug features for libreshop_client
#include <stdio.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
void debug_pause() {
while(1) {
WPAD_ScanPads();
if (WPAD_ButtonsDown(0)) break;
}
}
void debug_npause() {
printf("Press any button to continue...\n");
VIDEO_WaitVSync();
debug_pause();
}

7
source/debug.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef DEBUG_H
#define DEBUG_H
void debug_pause();
void debug_npause();
#endif

24
source/input_macros.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef INPUT_MACROS_H
#define INPUT_MACROS_H
#include <wiiuse/wpad.h>
// Input definitions table
// TODO: GameCube controller support
// Macro name Classic Controller Wii Remote
#define INPUT_BUTTON_HOME (WPAD_CLASSIC_BUTTON_HOME || WPAD_BUTTON_HOME )
#define INPUT_BUTTON_PLUS (WPAD_CLASSIC_BUTTON_PLUS || WPAD_BUTTON_PLUS )
#define INPUT_BUTTON_MINUS (WPAD_CLASSIC_BUTTON_MINUS || WPAD_BUTTON_MINUS )
#define INPUT_BUTTON_A (WPAD_CLASSIC_BUTTON_Y || WPAD_BUTTON_A )
#define INPUT_BUTTON_B (WPAD_CLASSIC_BUTTON_B || WPAD_BUTTON_B )
#define INPUT_BUTTON_X (WPAD_CLASSIC_BUTTON_X || WPAD_BUTTON_1 )
#define INPUT_BUTTON_Y (WPAD_CLASSIC_BUTTON_A || WPAD_BUTTON_2 )
#define INPUT_BUTTON_UP (WPAD_CLASSIC_BUTTON_UP || WPAD_BUTTON_UP )
#define INPUT_BUTTON_DOWN (WPAD_CLASSIC_BUTTON_DOWN || WPAD_BUTTON_DOWN )
#define INPUT_BUTTON_LEFT (WPAD_CLASSIC_BUTTON_LEFT || WPAD_BUTTON_LEFT )
#define INPUT_BUTTON_RIGHT (WPAD_CLASSIC_BUTTON_RIGHT || WPAD_BUTTON_RIGHT )
#endif // INPUT_MACROS_H

View File

@ -3,9 +3,16 @@
#include <gccore.h>
#include <network.h>
#include <wiiuse/wpad.h>
#include <jansson.h>
#include <stdbool.h>
#include "sandia/sandia.h"
#include "input_macros.h"
// Uncomment if this is a development build
//#include "debug.h"
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
@ -26,8 +33,10 @@ void logprint(int type, char *message) {
break;
case 2:
printf("\x1b[34m[\x1b[31m--\x1b[34m]");
break;
case 3:
printf("\x1b[31m!!\x1b[34m]");
break;
default:
printf(" ");
}
@ -68,6 +77,9 @@ int main(int argc, char **argv) {
printheader();
logprint(0, "Welcome to LibreShop!\n");
#ifdef DEBUG_H
logprint(2, "Warning! You are running a DEBUG build.\n");
#endif
logprint(0, "Initializing network.\n");
ret = if_config(localip, netmask, gateway, TRUE, 20);
@ -79,7 +91,39 @@ int main(int argc, char **argv) {
sandia req = sandia_create("libreshop.donut.eu.org", 80);
sandia_response res = sandia_get_request(&req, "/");
printf("\n%s\n", res.body);
bool lastWasNewline = false;
int resBodyLength = strlen(res.body);
for (int i = 0; i < resBodyLength; i++) {
if (res.body[i] == '\r') continue;
if (res.body[i] == '\n') {
if (lastWasNewline) {
int rBL = resBodyLength - i;
char* body = malloc(rBL);
for (int j = 0; j < rBL; j++) {
body[j] = res.body[j + i + 1];
}
json_error_t error;
json_t *root = json_loads(body, 0, &error);
if (!root || !json_is_array(root)) {
printf("failed decoding\n");
}
else {
printf("%s\n", body);
for (int j = 0; j < json_array_size(root); j++) {
json_t *data = json_array_get(root, j);
printf("%s\n", json_string_value(data));
}
}
break;
}
else lastWasNewline = true;
}
else lastWasNewline = false;
}
printf("\n");
sandia_close(&req);
} else {
logprint(0, "Network configuration failed :(\n");
@ -90,8 +134,8 @@ int main(int argc, char **argv) {
u32 pressed = WPAD_ButtonsDown(0);
if ( pressed & WPAD_BUTTON_HOME ) {
logprint(0, "HOME pressed, quitting!");
if ( pressed && INPUT_BUTTON_HOME ) {
logprint(0, "HOME pressed, quitting!\n");
exit(0);
}

@ -1 +1 @@
Subproject commit 9b383cdda825ab4ba2767102b06cbd5dc734dae9
Subproject commit 8f4d62429b06bb851f03c21c7796ae69f78541a8