src/power/android/SDL_syspower.c
author Ryan C. Gordon
Tue, 29 Dec 2015 02:29:56 -0500
changeset 9986 081fbd89a347
parent 9619 b94b6d0bff0f
child 9998 f67cf37e9cd4
permissions -rw-r--r--
NetBSD: improved joystick support (thanks, Thomas!).

This patch skips non-joystick HID devices and gives joysticks on NetBSD
a human readable name.

Fixes Bugzilla #3178.
slouken@6887
     1
/*
slouken@6887
     2
  Simple DirectMedia Layer
slouken@9619
     3
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
slouken@6887
     4
slouken@6887
     5
  This software is provided 'as-is', without any express or implied
slouken@6887
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@6887
     7
  arising from the use of this software.
slouken@6887
     8
slouken@6887
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@6887
    10
  including commercial applications, and to alter it and redistribute it
slouken@6887
    11
  freely, subject to the following restrictions:
slouken@6887
    12
slouken@6887
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@6887
    14
     claim that you wrote the original software. If you use this software
slouken@6887
    15
     in a product, an acknowledgment in the product documentation would be
slouken@6887
    16
     appreciated but is not required.
slouken@6887
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@6887
    18
     misrepresented as being the original software.
slouken@6887
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@6887
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@6450
    22
slouken@6450
    23
#ifndef SDL_POWER_DISABLED
slouken@6450
    24
#if SDL_POWER_ANDROID
slouken@6450
    25
slouken@6450
    26
#include "SDL_power.h"
slouken@6450
    27
slouken@6450
    28
#include "../../core/android/SDL_android.h"
slouken@6450
    29
slouken@6450
    30
SDL_bool
slouken@6450
    31
SDL_GetPowerInfo_Android(SDL_PowerState * state, int *seconds, int *percent)
slouken@6450
    32
{
slouken@6450
    33
    int battery;
slouken@6450
    34
    int plugged;
slouken@6450
    35
    int charged;
slouken@6450
    36
slouken@6450
    37
    if (Android_JNI_GetPowerInfo(&plugged, &charged, &battery, seconds, percent) != -1) {
slouken@6450
    38
        if (plugged) {
slouken@6450
    39
            if (charged) {
slouken@6450
    40
                *state = SDL_POWERSTATE_CHARGED;
slouken@6450
    41
            } else if (battery) {
slouken@6450
    42
                *state = SDL_POWERSTATE_CHARGING;
slouken@6450
    43
            } else {
slouken@6450
    44
                *state = SDL_POWERSTATE_NO_BATTERY;
slouken@6450
    45
                *seconds = -1;
slouken@6450
    46
                *percent = -1;
slouken@6450
    47
            }
slouken@6450
    48
        } else {
slouken@6450
    49
            *state = SDL_POWERSTATE_ON_BATTERY;
slouken@6450
    50
        }
slouken@6450
    51
    } else {
slouken@6450
    52
        *state = SDL_POWERSTATE_UNKNOWN;
slouken@6450
    53
        *seconds = -1;
slouken@6450
    54
        *percent = -1;
slouken@6450
    55
    }
slouken@6450
    56
slouken@6450
    57
    return SDL_TRUE;
slouken@6450
    58
}
slouken@6450
    59
slouken@6450
    60
#endif /* SDL_POWER_ANDROID */
slouken@6450
    61
#endif /* SDL_POWER_DISABLED */
philipp@7164
    62
philipp@7164
    63
/* vi: set ts=4 sw=4 expandtab: */