forked from devnoname120/vitacompanion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_definitions.c
81 lines (69 loc) · 1.92 KB
/
cmd_definitions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdbool.h>
#include <vitasdk.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "cmd_definitions.h"
#define COUNT_OF(arr) (sizeof(arr)/sizeof(arr[0]))
const cmd_definition cmd_definitions[] = {
{
.name = "destroy",
.arg_count = 0,
.executor = &cmd_destroy
},
{
.name = "launch",
.arg_count = 1,
.executor = &cmd_launch
},
{
.name = "reboot",
.arg_count = 0,
.executor = &cmd_reboot
},
{
.name = "screen",
.arg_count = 1,
.executor = &cmd_screen
}
};
const cmd_definition *cmd_get_definition(char *cmd_name) {
for (unsigned int i=0; i < COUNT_OF(cmd_definitions); i ++) {
if (!strcmp(cmd_name, cmd_definitions[i].name)) {
return &(cmd_definitions[i]);
}
}
return NULL;
}
void cmd_destroy(char **arg_list, size_t arg_count, char *res_msg) {
sceAppMgrDestroyOtherApp();
strcpy(res_msg, "Apps destroyed.\n");
}
void cmd_launch(char **arg_list, size_t arg_count, char *res_msg) {
char uri[32];
snprintf(uri, 32, "psgm:play?titleid=%s", arg_list[1]);
for (int i = 0; i < 40; i++) {
if (sceAppMgrLaunchAppByUri(0xFFFFF, uri) != 0) {
break;
}
sceKernelDelayThread(10000);
}
strcpy(res_msg, "Launched.\n");
}
void cmd_reboot(char **arg_list, size_t arg_count, char *res_msg) {
scePowerRequestColdReset();
strcpy(res_msg, "Rebooting...\n");
}
void cmd_screen(char **arg_list, size_t arg_count, char *res_msg) {
char *state = arg_list[1];
if (!strcmp(state, "on")) {
scePowerRequestDisplayOn();
strcpy(res_msg, "Turning display on...\n");
} else if (!strcmp(state, "off")) {
scePowerRequestDisplayOff();
strcpy(res_msg, "Turning display off...\n");
} else {
strcpy(res_msg, "Error: param should be 'on' or 'off'\n");
}
}