mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-23 02:11:54 +02:00
Open battery/USB file handlers only when needed.
This commit is contained in:
parent
7484ad2ef0
commit
0d9977e54c
@ -241,22 +241,6 @@ void GMenu2X::initCPULimits() {
|
|||||||
cpuFreqAppDefault = (cpuFreqAppDefault / cpuFreqMultiple) * cpuFreqMultiple;
|
cpuFreqAppDefault = (cpuFreqAppDefault / cpuFreqMultiple) * cpuFreqMultiple;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMenu2X::init() {
|
|
||||||
batteryHandle = 0;
|
|
||||||
usbHandle = 0;
|
|
||||||
acHandle = 0;
|
|
||||||
|
|
||||||
batteryHandle = fopen("/sys/class/power_supply/battery/capacity", "r");
|
|
||||||
usbHandle = fopen("/sys/class/power_supply/usb/online", "r");
|
|
||||||
acHandle = fopen("/sys/class/power_supply/ac/online", "r");
|
|
||||||
}
|
|
||||||
|
|
||||||
void GMenu2X::deinit() {
|
|
||||||
if (batteryHandle) fclose(batteryHandle);
|
|
||||||
if (usbHandle) fclose(usbHandle);
|
|
||||||
if (acHandle) fclose(acHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
GMenu2X::GMenu2X()
|
GMenu2X::GMenu2X()
|
||||||
{
|
{
|
||||||
usbnet = samba = inet = web = false;
|
usbnet = samba = inet = web = false;
|
||||||
@ -274,8 +258,6 @@ GMenu2X::GMenu2X()
|
|||||||
path = "";
|
path = "";
|
||||||
getExePath();
|
getExePath();
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
#ifdef UNLOCK_VT
|
#ifdef UNLOCK_VT
|
||||||
unlockVT();
|
unlockVT();
|
||||||
#endif
|
#endif
|
||||||
@ -348,8 +330,6 @@ void GMenu2X::quit() {
|
|||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
unsetenv("SDL_FBCON_DONT_CLEAR");
|
unsetenv("SDL_FBCON_DONT_CLEAR");
|
||||||
|
|
||||||
deinit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMenu2X::initBG() {
|
void GMenu2X::initBG() {
|
||||||
@ -1461,18 +1441,27 @@ typedef struct {
|
|||||||
} MMSP2ADC;
|
} MMSP2ADC;
|
||||||
|
|
||||||
unsigned short GMenu2X::getBatteryLevel() {
|
unsigned short GMenu2X::getBatteryLevel() {
|
||||||
|
FILE *batteryHandle = NULL,
|
||||||
|
*usbHandle = NULL;
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DINGUX) || defined(PLATFORM_NANONOTE)
|
||||||
|
usbHandle = fopen("/sys/class/power_supply/usb/online", "r");
|
||||||
|
#endif
|
||||||
if (usbHandle) {
|
if (usbHandle) {
|
||||||
int usbval = 0;
|
int usbval = 0;
|
||||||
fscanf(usbHandle, "%d", &usbval);
|
fscanf(usbHandle, "%d", &usbval);
|
||||||
rewind(usbHandle);
|
fclose(usbHandle);
|
||||||
if (usbval == 1)
|
if (usbval == 1)
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DINGUX) || defined(PLATFORM_NANONOTE)
|
||||||
|
batteryHandle = fopen("/sys/class/power_supply/battery/capacity", "r");
|
||||||
|
#endif
|
||||||
if (batteryHandle) {
|
if (batteryHandle) {
|
||||||
int battval = 0;
|
int battval = 0;
|
||||||
fscanf(batteryHandle, "%d", &battval);
|
fscanf(batteryHandle, "%d", &battval);
|
||||||
rewind(batteryHandle);
|
fclose(batteryHandle);
|
||||||
|
|
||||||
if (battval>90) return 5;
|
if (battval>90) return 5;
|
||||||
if (battval>70) return 4;
|
if (battval>70) return 4;
|
||||||
|
@ -85,7 +85,6 @@ private:
|
|||||||
@return A number representing battery charge. 0 means fully discharged. 5 means fully charged. 6 represents a gp2x using AC power.
|
@return A number representing battery charge. 0 means fully discharged. 5 means fully charged. 6 represents a gp2x using AC power.
|
||||||
*/
|
*/
|
||||||
unsigned short getBatteryLevel();
|
unsigned short getBatteryLevel();
|
||||||
FILE* batteryHandle, *usbHandle, *acHandle;
|
|
||||||
void browsePath(const std::string &path, std::vector<std::string>* directories, std::vector<std::string>* files);
|
void browsePath(const std::string &path, std::vector<std::string>* directories, std::vector<std::string>* files);
|
||||||
/*!
|
/*!
|
||||||
Starts the scanning of the nand and sd filesystems, searching for dge and gpu files and creating the links in 2 dedicated sections.
|
Starts the scanning of the nand and sd filesystems, searching for dge and gpu files and creating the links in 2 dedicated sections.
|
||||||
@ -116,10 +115,7 @@ private:
|
|||||||
void initServices();
|
void initServices();
|
||||||
void initFont();
|
void initFont();
|
||||||
void initMenu();
|
void initMenu();
|
||||||
|
|
||||||
void initCPULimits();
|
void initCPULimits();
|
||||||
void init();
|
|
||||||
void deinit();
|
|
||||||
|
|
||||||
void showManual();
|
void showManual();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user