Add warning when low battery level for joysticks
This commit is contained in:
parent
e05c0b095d
commit
feb0b0a68c
@ -207,6 +207,10 @@ void InputManager::update(float dt)
|
||||
m_timer -= dt;
|
||||
if(m_timer < 0) m_timer_in_use = false;
|
||||
}
|
||||
#ifndef SERVER_ONLY
|
||||
for (auto& controller : m_sdl_controller)
|
||||
controller.second->checkPowerLevel();
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -18,12 +18,17 @@
|
||||
#ifndef SERVER_ONLY
|
||||
|
||||
#include "input/sdl_controller.hpp"
|
||||
#include "guiengine/message_queue.hpp"
|
||||
#include "input/device_config.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/gamepad_device.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#include <SDL_version.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
@ -31,6 +36,7 @@
|
||||
SDLController::SDLController(int device_id)
|
||||
: m_gamepad(NULL)
|
||||
{
|
||||
m_last_power_level_time = StkTime::getMonoTimeMs();
|
||||
m_irr_event = {};
|
||||
m_irr_event.EventType = irr::EET_JOYSTICK_INPUT_EVENT;
|
||||
memset(m_prev_axes, 0,
|
||||
@ -220,6 +226,27 @@ void SDLController::handleAxisInputSense(const SDL_Event& event)
|
||||
m_prev_axes[axis_idx]);
|
||||
} // handleAxisInputSense
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void SDLController::checkPowerLevel()
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 4)
|
||||
const uint64_t time_now = StkTime::getMonoTimeMs();
|
||||
if (time_now > m_last_power_level_time + 60000)
|
||||
{
|
||||
m_last_power_level_time = time_now;
|
||||
SDL_JoystickPowerLevel pl = SDL_JoystickCurrentPowerLevel(m_joystick);
|
||||
if (pl == SDL_JOYSTICK_POWER_EMPTY || pl == SDL_JOYSTICK_POWER_LOW)
|
||||
{
|
||||
core::stringw msg =
|
||||
_("%s has low battery level.", SDL_JoystickName(m_joystick));
|
||||
MessageQueue::add(MessageQueue::MT_ERROR, msg);
|
||||
// Check 5 min later
|
||||
m_last_power_level_time += 240000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} // checkPowerLevel
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifdef ANDROID
|
||||
void SDLController::handleDirectScanCode(const SDL_Event& event)
|
||||
|
@ -49,6 +49,8 @@ private:
|
||||
irr::SEvent m_irr_event;
|
||||
|
||||
int16_t m_prev_axes[irr::SEvent::SJoystickEvent::NUMBER_OF_AXES];
|
||||
|
||||
uint64_t m_last_power_level_time;
|
||||
#ifdef ANDROID
|
||||
void handleDirectScanCode(const SDL_Event& event);
|
||||
#endif
|
||||
@ -148,6 +150,8 @@ public:
|
||||
} // handleButton
|
||||
// ------------------------------------------------------------------------
|
||||
SDL_GameController* getGameController() const { return m_game_controller; }
|
||||
// ------------------------------------------------------------------------
|
||||
void checkPowerLevel();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user