🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.9 KiB

  1. /*
  2. Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely.
  9. */
  10. /* Simple test of power subsystem. */
  11. #include <stdio.h>
  12. #include "SDL.h"
  13. static void
  14. report_power(void)
  15. {
  16. int seconds, percent;
  17. const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
  18. char *statestr = NULL;
  19. SDL_Log("SDL-reported power info...\n");
  20. switch (state) {
  21. case SDL_POWERSTATE_UNKNOWN:
  22. statestr = "Unknown";
  23. break;
  24. case SDL_POWERSTATE_ON_BATTERY:
  25. statestr = "On battery";
  26. break;
  27. case SDL_POWERSTATE_NO_BATTERY:
  28. statestr = "No battery";
  29. break;
  30. case SDL_POWERSTATE_CHARGING:
  31. statestr = "Charging";
  32. break;
  33. case SDL_POWERSTATE_CHARGED:
  34. statestr = "Charged";
  35. break;
  36. default:
  37. statestr = "!!API ERROR!!";
  38. break;
  39. }
  40. SDL_Log("State: %s\n", statestr);
  41. if (percent == -1) {
  42. SDL_Log("Percent left: unknown\n");
  43. } else {
  44. SDL_Log("Percent left: %d%%\n", percent);
  45. }
  46. if (seconds == -1) {
  47. SDL_Log("Time left: unknown\n");
  48. } else {
  49. SDL_Log("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
  50. (int) (seconds % 60));
  51. }
  52. }
  53. int
  54. main(int argc, char *argv[])
  55. {
  56. /* Enable standard application logging */
  57. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  58. if (SDL_Init(0) == -1) {
  59. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
  60. return 1;
  61. }
  62. report_power();
  63. SDL_Quit();
  64. return 0;
  65. }
  66. /* end of testpower.c ... */