Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add power battery% access #5871

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,17 @@ bool _OS::is_vsync_enabled() const {
return OS::get_singleton()->is_vsync_enabled();
}

PowerState _OS::get_power_state() {
return OS::get_singleton()->get_power_state();
}

int _OS::get_power_seconds_left() {
return OS::get_singleton()->get_power_seconds_left();
}

int _OS::get_power_percent_left() {
return OS::get_singleton()->get_power_percent_left();
}

/*
enum Weekday {
Expand Down Expand Up @@ -1117,6 +1128,10 @@ void _OS::_bind_methods() {

ClassDB::bind_method(_MD("set_use_vsync","enable"),&_OS::set_use_vsync);
ClassDB::bind_method(_MD("is_vsync_enabled"),&_OS::is_vsync_enabled);

ClassDB::bind_method(_MD("get_power_state"),&_OS::get_power_state);
ClassDB::bind_method(_MD("get_power_seconds_left"),&_OS::get_power_seconds_left);
ClassDB::bind_method(_MD("get_power_percent_left"),&_OS::get_power_percent_left);

BIND_CONSTANT( DAY_SUNDAY );
BIND_CONSTANT( DAY_MONDAY );
Expand Down Expand Up @@ -1155,6 +1170,12 @@ void _OS::_bind_methods() {
BIND_CONSTANT( SYSTEM_DIR_MUSIC );
BIND_CONSTANT( SYSTEM_DIR_PICTURES );
BIND_CONSTANT( SYSTEM_DIR_RINGTONES );

BIND_CONSTANT( POWERSTATE_UNKNOWN );
BIND_CONSTANT( POWERSTATE_ON_BATTERY );
BIND_CONSTANT( POWERSTATE_NO_BATTERY );
BIND_CONSTANT( POWERSTATE_CHARGING );
BIND_CONSTANT( POWERSTATE_CHARGED );

}

Expand Down
5 changes: 5 additions & 0 deletions core/bind/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "os/dir_access.h"
#include "os/thread.h"
#include "os/semaphore.h"
#include "os/power.h"


class _ResourceLoader : public Object {
Expand Down Expand Up @@ -309,6 +310,10 @@ class _OS : public Object {
void set_use_vsync(bool p_enable);
bool is_vsync_enabled() const;

PowerState get_power_state();
int get_power_seconds_left();
int get_power_percent_left();

static _OS *get_singleton() { return singleton; }

_OS();
Expand Down
10 changes: 10 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,16 @@ bool OS::is_vsync_enabled() const{
}


PowerState OS::get_power_state() {
return POWERSTATE_UNKNOWN;
}
int OS::get_power_seconds_left() {
return -1;
}
int OS::get_power_percent_left() {
return -1;
}

OS::OS() {
last_error=NULL;
singleton=this;
Expand Down
6 changes: 6 additions & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
#include "vector.h"
#include "engine.h"
#include "os/main_loop.h"
#include "power.h"
#include <stdarg.h>


/**
@author Juan Linietsky <reduzio@gmail.com>
*/
Expand Down Expand Up @@ -401,6 +403,10 @@ friend class Main;

virtual void set_use_vsync(bool p_enable);
virtual bool is_vsync_enabled() const;

virtual PowerState get_power_state();
virtual int get_power_seconds_left();
virtual int get_power_percent_left();

bool is_hidpi_allowed() const { return _allow_hidpi; }
OS();
Expand Down
44 changes: 44 additions & 0 deletions core/os/power.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*************************************************************************/
/* power.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#ifndef CORE_OS_POWER_H_
#define CORE_OS_POWER_H_


typedef enum
{
POWERSTATE_UNKNOWN, /**< cannot determine power status */
POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */
POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */
POWERSTATE_CHARGING, /**< Plugged in, charging battery */
POWERSTATE_CHARGED /**< Plugged in, battery charged */
} PowerState;


#endif /* CORE_OS_POWER_H_ */
1 change: 1 addition & 0 deletions platform/android/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ android_files = [
'java_glue.cpp',
'cpu-features.c',
'java_class_wrapper.cpp'
'power_android.cpp'
]

# env.Depends('#core/math/vector3.h', 'vector3_psp.h')
Expand Down
2 changes: 2 additions & 0 deletions platform/android/os_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_

input = memnew( InputDefault );
input->set_fallback_mapping("Default Android Gamepad");

power_manager = memnew( power_android );
}

void OS_Android::set_main_loop( MainLoop * p_main_loop ) {
Expand Down
3 changes: 3 additions & 0 deletions platform/android/os_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "os/input.h"
#include "drivers/unix/os_unix.h"
#include "os/main_loop.h"
#include "power_android.h"
#include "servers/physics/physics_server_sw.h"
#include "servers/audio_server.h"
#include "servers/physics_2d/physics_2d_server_sw.h"
Expand Down Expand Up @@ -142,6 +143,8 @@ class OS_Android : public OS_Unix {
SetKeepScreenOnFunc set_keep_screen_on_func;
AlertFunc alert_func;

power_android *power_manager;

public:

// functions used by main to initialize/deintialize the OS
Expand Down
Loading