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

[3.5 | Switch] Implement LibNX psm.h for power_switch.cpp #5

Merged
merged 2 commits into from
Jan 24, 2024
Merged
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
1 change: 0 additions & 1 deletion platform/switch/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Import("env")
files = [
"godot_switch.cpp",
"os_switch.cpp",
"power_switch.cpp",
"joypad_switch.cpp",
"context_gl_switch_egl.cpp",
]
Expand Down
38 changes: 32 additions & 6 deletions platform/switch/os_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ Error OS_Switch::initialize(const VideoMode &p_desired, int p_video_driver, int
}
joypad = memnew(JoypadSwitch(input));

power_manager = memnew(PowerSwitch);
if (R_SUCCEEDED(psmInitialize())) {
OS_Switch::psm_initialized = true;
}

AudioDriverManager::initialize(p_audio_driver);

Expand All @@ -195,8 +197,8 @@ void OS_Switch::finalize() {
memdelete(joypad);
visual_server->finish();
memdelete(visual_server);
memdelete(power_manager);
memdelete(gl_context);
psmExit();
}

void OS_Switch::finalize_core() {
Expand Down Expand Up @@ -505,15 +507,39 @@ void OS_Switch::hide_virtual_keyboard() {
}

OS::PowerState OS_Switch::get_power_state() {
return power_manager->get_power_state();
if (!OS_Switch::psm_initialized) {
return OS::POWERSTATE_UNKNOWN;
}

bool enough_power;
psmIsEnoughPowerSupplied(&enough_power);

if (!enough_power) {
return OS::PowerState::POWERSTATE_ON_BATTERY;
}

int percentage = OS_Switch::get_power_percent_left();

if (percentage == 100) {
return OS::PowerState::POWERSTATE_CHARGED;
}

return OS::PowerState::POWERSTATE_CHARGING;
}

int OS_Switch::get_power_seconds_left() {
return power_manager->get_power_seconds_left();
WARN_PRINT("power_seconds_left is not implemented on this platform, defaulting to -1");
return -1;
}

int OS_Switch::get_power_percent_left() {
return power_manager->get_power_percent_left();
if (!OS_Switch::psm_initialized) {
return -1;
}

u32 voltage_percentage;
psmGetBatteryChargePercentage(&voltage_percentage);
return (int)voltage_percentage;
}

String OS_Switch::get_executable_path() const {
Expand Down Expand Up @@ -554,8 +580,8 @@ OS_Switch::OS_Switch() {
main_loop = nullptr;
visual_server = nullptr;
input = nullptr;
power_manager = nullptr;
gl_context = nullptr;

AudioDriverManager::add_driver(&driver_audren);

swkbdInlineCreate(&inline_keyboard);
Expand Down
4 changes: 2 additions & 2 deletions platform/switch/os_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "drivers/audren/audio_driver_audren.h"
#include "joypad_switch.h"
#include "main/input_default.h"
#include "power_switch.h"
#include "servers/visual/visual_server_raster.h"

class OS_Switch : public OS {
Expand All @@ -43,14 +42,15 @@ class OS_Switch : public OS {
VideoMode current_videomode;
VisualServer *visual_server;
InputDefault *input;
PowerSwitch *power_manager;
ContextGLSwitchEGL *gl_context;
JoypadSwitch *joypad;
AudioDriverAudren driver_audren;
String switch_execpath;

SwkbdInline inline_keyboard;

bool psm_initialized = false;

protected:
virtual void initialize_core();
virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
Expand Down
52 changes: 0 additions & 52 deletions platform/switch/power_switch.cpp

This file was deleted.

49 changes: 0 additions & 49 deletions platform/switch/power_switch.h

This file was deleted.

Loading