From 0f2e579674f7de206596d5698be13cb537a1c2c0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sat, 2 Jan 2021 12:51:32 +0100 Subject: [PATCH 1/6] Create BatteryInfo struct. --- Source/Engine/Platform/BatteryInfo.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Source/Engine/Platform/BatteryInfo.h diff --git a/Source/Engine/Platform/BatteryInfo.h b/Source/Engine/Platform/BatteryInfo.h new file mode 100644 index 000000000..c46bde59e --- /dev/null +++ b/Source/Engine/Platform/BatteryInfo.h @@ -0,0 +1,16 @@ +// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved. + +#pragma once + +#include "Engine/Core/Types/BaseTypes.h" + +API_STRUCT() struct BatteryInfo +{ +DECLARE_SCRIPTING_TYPE_MINIMAL(BatteryInfo); + + API_FIELD() byte ACLineStatus; + + API_FIELD() byte BatteryLifePercent; + + API_FIELD() uint32 BatteryLifeTime; +}; From a4607385fd604e328c332e925d4ba0124743f4c5 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sat, 2 Jan 2021 12:53:20 +0100 Subject: [PATCH 2/6] Adding GetBatteryInfo() to PlatformBase. --- Source/Engine/Platform/Base/PlatformBase.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Engine/Platform/Base/PlatformBase.h b/Source/Engine/Platform/Base/PlatformBase.h index f0a2baf43..86e760b3c 100644 --- a/Source/Engine/Platform/Base/PlatformBase.h +++ b/Source/Engine/Platform/Base/PlatformBase.h @@ -11,6 +11,7 @@ struct CPUInfo; struct MemoryStats; struct ProcessMemoryStats; struct CreateWindowSettings; +struct BatteryInfo; // ReSharper disable CppFunctionIsNotImplemented @@ -548,6 +549,11 @@ public: /// static void SetHighDpiAwarenessEnabled(bool enable); + /// + /// Gets the battery information. + /// + API_PROPERTY() static BatteryInfo GetBatteryInfo(); + /// /// Gets the screen DPI setting. /// From 624ab4b8dd9e527c06a0c6d455015d8bfc795065 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sat, 2 Jan 2021 12:54:16 +0100 Subject: [PATCH 3/6] Implementing GetBatteryInfo() to Win32Platform. --- Source/Engine/Platform/Win32/Win32Platform.cpp | 13 +++++++++++++ Source/Engine/Platform/Win32/Win32Platform.h | 1 + 2 files changed, 14 insertions(+) diff --git a/Source/Engine/Platform/Win32/Win32Platform.cpp b/Source/Engine/Platform/Win32/Win32Platform.cpp index 5bf724de2..317b6f232 100644 --- a/Source/Engine/Platform/Win32/Win32Platform.cpp +++ b/Source/Engine/Platform/Win32/Win32Platform.cpp @@ -5,6 +5,7 @@ #include "Engine/Platform/Platform.h" #include "Engine/Platform/MemoryStats.h" #include "Engine/Platform/CPUInfo.h" +#include "Engine/Platform/BatteryInfo.h" #include "Engine/Core/Types/Guid.h" #include "Engine/Core/Types/String.h" #include "Engine/Core/Math/Math.h" @@ -15,6 +16,7 @@ #include #include #include +#include #pragma comment(lib, "Iphlpapi.lib") namespace @@ -308,6 +310,17 @@ bool Win32Platform::Is64BitPlatform() #endif } +BatteryInfo Win32Platform::GetBatteryInfo() +{ + BatteryInfo info; + SYSTEM_POWER_STATUS status; + GetSystemPowerStatus(&status); + info.ACLineStatus = status.ACLineStatus; + info.BatteryLifePercent = status.BatteryLifePercent; + info.BatteryLifeTime = status.BatteryLifeTime; + return info; +} + CPUInfo Win32Platform::GetCPUInfo() { return CpuInfo; diff --git a/Source/Engine/Platform/Win32/Win32Platform.h b/Source/Engine/Platform/Win32/Win32Platform.h index dd584cea9..c162c53e6 100644 --- a/Source/Engine/Platform/Win32/Win32Platform.h +++ b/Source/Engine/Platform/Win32/Win32Platform.h @@ -43,6 +43,7 @@ public: _aligned_free(ptr); } static bool Is64BitPlatform(); + static BatteryInfo GetBatteryInfo(); static CPUInfo GetCPUInfo(); static int32 GetCacheLineSize(); static MemoryStats GetMemoryStats(); From e9f72dbbbffbc6d12569a31bd9268ee81f15e10d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sat, 2 Jan 2021 13:15:15 +0100 Subject: [PATCH 4/6] Adding ACLineStatus enum. --- Source/Engine/Platform/BatteryInfo.h | 33 ++++++++++++++++++- .../Engine/Platform/Win32/Win32Platform.cpp | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Platform/BatteryInfo.h b/Source/Engine/Platform/BatteryInfo.h index c46bde59e..ba05d7992 100644 --- a/Source/Engine/Platform/BatteryInfo.h +++ b/Source/Engine/Platform/BatteryInfo.h @@ -4,13 +4,44 @@ #include "Engine/Core/Types/BaseTypes.h" +/// +/// Power supply status. +/// +API_ENUM() enum class ACLineStatus : byte +{ + /// + /// Power supply is not connected. + /// + Offline = 0, + /// + /// Power supply is connected. + /// + Online = 1, + /// + /// Unknown status. + /// + Unknown = 255 +}; + +/// +/// Contains information about power supply (Battery). +/// API_STRUCT() struct BatteryInfo { DECLARE_SCRIPTING_TYPE_MINIMAL(BatteryInfo); - API_FIELD() byte ACLineStatus; + /// + /// Power supply status. + /// + API_FIELD() ACLineStatus ACLineStatus; + /// + /// Battery percentage left. + /// API_FIELD() byte BatteryLifePercent; + /// + /// Remaining battery life time in second. + /// API_FIELD() uint32 BatteryLifeTime; }; diff --git a/Source/Engine/Platform/Win32/Win32Platform.cpp b/Source/Engine/Platform/Win32/Win32Platform.cpp index 317b6f232..ee73ffac2 100644 --- a/Source/Engine/Platform/Win32/Win32Platform.cpp +++ b/Source/Engine/Platform/Win32/Win32Platform.cpp @@ -315,7 +315,7 @@ BatteryInfo Win32Platform::GetBatteryInfo() BatteryInfo info; SYSTEM_POWER_STATUS status; GetSystemPowerStatus(&status); - info.ACLineStatus = status.ACLineStatus; + info.ACLineStatus = (ACLineStatus)status.ACLineStatus; info.BatteryLifePercent = status.BatteryLifePercent; info.BatteryLifeTime = status.BatteryLifeTime; return info; From 3ed2e010fa1754bfeb8426d489384a6ed0d16f30 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sat, 2 Jan 2021 14:55:30 +0100 Subject: [PATCH 5/6] Bumping new file copyright to 2021. --- Source/Engine/Platform/BatteryInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Platform/BatteryInfo.h b/Source/Engine/Platform/BatteryInfo.h index ba05d7992..146f3f562 100644 --- a/Source/Engine/Platform/BatteryInfo.h +++ b/Source/Engine/Platform/BatteryInfo.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved. +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #pragma once From 21ec0f103eb2ce3fa4e7620a71c45e50786cd141 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Sat, 2 Jan 2021 18:41:00 +0100 Subject: [PATCH 6/6] Implementing GetBatteryInfo() in PlatformBase. --- Source/Engine/Platform/Base/PlatformBase.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Engine/Platform/Base/PlatformBase.cpp b/Source/Engine/Platform/Base/PlatformBase.cpp index 2a0e23aea..d53ff8acc 100644 --- a/Source/Engine/Platform/Base/PlatformBase.cpp +++ b/Source/Engine/Platform/Base/PlatformBase.cpp @@ -19,6 +19,7 @@ #include "Engine/Engine/CommandLine.h" #include "Engine/Engine/Engine.h" #include "Engine/Utilities/StringConverter.h" +#include "Engine/Platform/BatteryInfo.h" #include // Check types sizes @@ -381,6 +382,11 @@ void PlatformBase::SetHighDpiAwarenessEnabled(bool enable) { } +BatteryInfo PlatformBase::GetBatteryInfo() +{ + return BatteryInfo(); +} + int32 PlatformBase::GetDpi() { return 96;