'' SDL2-Example program:
'' Simple test of power subsystem.
'' translated by TJF 2013
'/*
  'Copyright (C) 1997-2013 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.
'*/

#INCLUDE ONCE "SDL2/SDL2.bi"

SUB report_power()
  DIM AS INTEGER seconds, percent
  DIM AS SDL_PowerState state = SDL_GetPowerInfo(@seconds, @percent)
  DIM AS ZSTRING PTR statestr = NULL

  SDL_Log(!"SDL-reported power info...\n")
  SELECT CASE AS CONST state
  CASE SDL_POWERSTATE_UNKNOWN    : statestr = @"Unknown"
  CASE SDL_POWERSTATE_ON_BATTERY : statestr = @"On battery"
  CASE SDL_POWERSTATE_NO_BATTERY : statestr = @"No battery"
  CASE SDL_POWERSTATE_CHARGING   : statestr = @"Charging"
  CASE SDL_POWERSTATE_CHARGED    : statestr = @"Charged"
  CASE ELSE                      : statestr = @"!!API ERROR!!"
  END SELECT

  SDL_Log(!"State: %s\n", statestr)

  IF percent = -1 THEN
    SDL_Log(!"Percent left: unknown\n")
  ELSE
    SDL_Log(!"Percent left: %d%%\n", percent)
  END IF

  IF seconds = -1 THEN
    SDL_Log(!"Time left: unknown\n")
  ELSE
    SDL_Log(!"Time left: %d minutes, %d seconds\n", _
            CAST(INTEGER, seconds / 60), CAST(INTEGER, seconds MOD 60))
  END IF
END SUB


'/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO)

IF SDL_Init(0) = -1 THEN
  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, !"SDL_Init() failed: %s\n", SDL_GetError())
  END 1
END IF

report_power()

SDL_Quit()
