-
Notifications
You must be signed in to change notification settings - Fork 545
/
sysconfig.c
148 lines (128 loc) · 4.52 KB
/
sysconfig.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* This file is part of Luma3DS
* Copyright (C) 2016-2017 Aurora Wright, TuxSH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include <3ds.h>
#include "menus/sysconfig.h"
#include "memory.h"
#include "draw.h"
#include "fmt.h"
#include "utils.h"
#include "ifile.h"
Menu sysconfigMenu = {
"System configuration menu",
.nbItems = 2,
{
{ "Toggle LEDs", METHOD, .method = &SysConfigMenu_ToggleLEDs },
{ "Toggle Wireless", METHOD, .method = &SysConfigMenu_ToggleWireless },
}
};
void SysConfigMenu_ToggleLEDs(void)
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "System configuration menu");
Draw_DrawString(10, 30, COLOR_WHITE, "Press A to toggle, press B to go back.");
Draw_DrawString(10, 50, COLOR_RED, "WARNING:");
Draw_DrawString(10, 60, COLOR_WHITE, " * Entering sleep mode will reset the LED state!");
Draw_DrawString(10, 70, COLOR_WHITE, " * LEDs cannot be toggled when the battery is low!");
Draw_FlushFramebuffer();
Draw_Unlock();
u32 pressed = waitInputWithTimeout(1000);
if(pressed & BUTTON_A)
{
mcuHwcInit();
u8 result;
mcuHwcReadRegister(0x28, &result, 1);
result = ~result;
mcuHwcWriteRegister(40, &result, 1);
mcuHwcExit();
}
else if(pressed & BUTTON_B)
return;
}
while(!terminationRequest);
}
void SysConfigMenu_ToggleWireless(void)
{
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
bool nwmRunning = false;
u32 pidList[0x40];
s32 processAmount;
svcGetProcessList(&processAmount, pidList, 0x40);
for(s32 i = 0; i < processAmount; i++)
{
Handle processHandle;
Result res = svcOpenProcess(&processHandle, pidList[i]);
if(R_FAILED(res))
continue;
char processName[8] = {0};
svcGetProcessInfo((s64 *)&processName, processHandle, 0x10000);
svcCloseHandle(processHandle);
if(!strncmp(processName, "nwm", 4))
{
nwmRunning = true;
break;
}
}
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "System configuration menu");
Draw_DrawString(10, 30, COLOR_WHITE, "Press A to toggle, press B to go back.");
u8 wireless = (*(vu8 *)((0x10140000 | (1u << 31)) + 0x180));
if(nwmRunning)
{
Draw_DrawString(10, 50, COLOR_WHITE, "Current status:");
Draw_DrawString(100, 50, (wireless ? COLOR_GREEN : COLOR_RED), (wireless ? " ON " : " OFF"));
}
else
{
Draw_DrawString(10, 50, COLOR_RED, "NWM isn't running.");
Draw_DrawString(10, 60, COLOR_RED, "If you're currently on Test Menu,");
Draw_DrawString(10, 70, COLOR_RED, "exit then press R+RIGHT to toggle the WiFi.");
Draw_DrawString(10, 80, COLOR_RED, "Otherwise, simply exit and wait a few seconds.");
}
Draw_FlushFramebuffer();
Draw_Unlock();
u32 pressed = waitInputWithTimeout(1000);
if(pressed & BUTTON_A && nwmRunning)
{
nwmExtInit();
NWMEXT_ControlWirelessEnabled(!wireless);
nwmExtExit();
}
else if(pressed & BUTTON_B)
return;
}
while(!terminationRequest);
}