mirror of https://github.com/encounter/SDL.git
switch: add power support
This commit is contained in:
parent
e3a6834904
commit
4eb5d77750
|
@ -2008,14 +2008,12 @@ elseif(NINTENDO_SWITCH)
|
|||
set(SOURCE_FILES ${SOURCE_FILES} ${SWITCH_JOYSTICK_SOURCES})
|
||||
set(HAVE_SDL_JOYSTICK TRUE)
|
||||
endif()
|
||||
#[[
|
||||
if(SDL_POWER)
|
||||
set(SDL_POWER_SWITCH 1)
|
||||
file(GLOB SWITCH_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/switch/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${SWITCH_POWER_SOURCES})
|
||||
set(HAVE_SDL_POWER TRUE)
|
||||
endif()
|
||||
]]
|
||||
if(SDL_TIMERS)
|
||||
set(SDL_TIMER_SWITCH 1)
|
||||
file(GLOB SWITCH_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/switch/*.c)
|
||||
|
|
|
@ -74,6 +74,9 @@ static SDL_GetPowerInfo_Impl implementations[] = {
|
|||
#ifdef SDL_POWER_EMSCRIPTEN /* handles Emscripten */
|
||||
SDL_GetPowerInfo_Emscripten,
|
||||
#endif
|
||||
#ifdef SDL_POWER_SWITCH /* handles Nintendo Switch. */
|
||||
SDL_GetPowerInfo_SWITCH,
|
||||
#endif
|
||||
|
||||
#ifdef SDL_POWER_HARDWIRED
|
||||
SDL_GetPowerInfo_Hardwired,
|
||||
|
|
|
@ -40,6 +40,7 @@ SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
|
|||
SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_SWITCH(SDL_PowerState *, int *, int *);
|
||||
|
||||
/* this one is static in SDL_power.c */
|
||||
/* SDL_bool SDL_GetPowerInfo_Hardwired(SDL_PowerState *, int *, int *);*/
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifndef SDL_POWER_DISABLED
|
||||
#if SDL_POWER_SWITCH
|
||||
|
||||
#include <switch.h>
|
||||
#include "SDL_power.h"
|
||||
|
||||
SDL_bool
|
||||
SDL_GetPowerInfo_SWITCH(SDL_PowerState * state, int *seconds,
|
||||
int *percent)
|
||||
{
|
||||
PsmChargerType chargerType;
|
||||
u32 charge;
|
||||
double age;
|
||||
Result rc;
|
||||
|
||||
rc = psmGetChargerType(&chargerType);
|
||||
if (R_FAILED(rc)) {
|
||||
*state = SDL_POWERSTATE_UNKNOWN;
|
||||
*seconds = -1;
|
||||
*percent = -1;
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
psmGetBatteryChargePercentage(&charge);
|
||||
*percent = (int) charge;
|
||||
|
||||
psmGetBatteryAgePercentage(&age);
|
||||
*seconds = (int) age;
|
||||
|
||||
if(chargerType == PsmChargerType_EnoughPower) {
|
||||
*state = SDL_POWERSTATE_CHARGED;
|
||||
} else {
|
||||
// TODO: check if device charging...
|
||||
*state = SDL_POWERSTATE_CHARGING;
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_SWITCH */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
Loading…
Reference in New Issue