/*
 * power.c -- power management
 *
 * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <SDL.h>

#include "power.h"

/*
 * SDL.getPowerInfo()
 * 
 * Returns:
 *	The state (SDL.powerState)
 *	The seconds remaining
 *	The percentage
 */
static int
l_getPowerInfo(lua_State *L)
{
	int secs, pct;
	SDL_PowerState state;

	state = SDL_GetPowerInfo(&secs, &pct);

	lua_pushinteger(L, state);
	lua_pushinteger(L, secs);
	lua_pushinteger(L, pct);

	return 3;
}

const struct luaL_Reg PowerFunctions[] = {
	{ "getPowerInfo",		l_getPowerInfo			},
	{ NULL,				NULL				}
};

/*
 * SDL.powerState
 */
const CommonEnum PowerState[] = {
	{ "Unknown",			SDL_POWERSTATE_UNKNOWN		},
	{ "OnBattery",			SDL_POWERSTATE_ON_BATTERY	},
	{ "NoBattery",			SDL_POWERSTATE_NO_BATTERY	},
	{ "Charging",			SDL_POWERSTATE_CHARGING		},
	{ "Charged",			SDL_POWERSTATE_CHARGED		},
	{ NULL,				-1				}
};
