Skip to content

Commit

Permalink
Rework is_steam_deck_detected function to detect unknown models
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordonbc committed May 11, 2024
1 parent e16f008 commit 07f1877
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 34 deletions.
1 change: 1 addition & 0 deletions HarmonyLinkLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ set(COMMON_INCLUDES

"include/Enums/EDevice.h"
"include/Enums/EPlatform.h"
"include/Enums/ESteamDeck.h"

"include/FString.h"
"include/HarmonyLinkLib.h"
Expand Down
1 change: 1 addition & 0 deletions HarmonyLinkLib/include/Enums/EDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace HarmonyLinkLib
{
enum class EDevice : uint8_t
{
UNKNOWN,
DESKTOP,
LAPTOP,
HANDHELD,
Expand Down
1 change: 1 addition & 0 deletions HarmonyLinkLib/include/Enums/EPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace HarmonyLinkLib
{
enum class EPlatform : uint8_t
{
UNKNOWN,
WINDOWS,
LINUX,
MAC,
Expand Down
29 changes: 29 additions & 0 deletions HarmonyLinkLib/include/Enums/ESteamDeck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <cstdint>

// Enum class for representing different types of devices
namespace HarmonyLinkLib
{
enum class ESteamDeck : uint8_t
{
NONE, // Device is not a steam deck
UNKNOWN, // Device is a steam deck but model cannot be determined
LCD,
OLED,
};
}
6 changes: 4 additions & 2 deletions HarmonyLinkLib/include/Structs/FDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

#include "Enums/EDevice.h"
#include "Enums/EPlatform.h"
#include "Enums/ESteamDeck.h"

namespace HarmonyLinkLib
{
// Struct to represent a specific device with both platform and device type
struct FDevice : HarmonyLinkStruct
{
EPlatform platform;
EDevice device;
EPlatform platform = EPlatform::UNKNOWN;
EDevice device = EDevice::UNKNOWN;
ESteamDeck steam_deck_model = ESteamDeck::NONE;
};
}
77 changes: 46 additions & 31 deletions HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <fmt/core.h>
#include <set>
#include <unordered_map>

#include "Utilities.h"

#include "WineUtilities.h"
Expand Down Expand Up @@ -169,51 +171,64 @@ namespace HarmonyLinkLib
new_device.device = EDevice::LAPTOP;
}

if (is_steam_deck_detected(new_device)) {
const ESteamDeck steam_deck_model = detect_steam_deck(new_device);

if (steam_deck_model != ESteamDeck::NONE) {
new_device.device = EDevice::STEAM_DECK;
new_device.steam_deck_model = steam_deck_model;
}
return std::make_shared<FDevice>(new_device);
}

// Helper function to check if the device is a Steam Deck
bool IPlatformUtilities::is_steam_deck_detected(const FDevice& device) {

ESteamDeck IPlatformUtilities::detect_steam_deck(const FDevice& device) {
// Check if the device is already identified as a Steam Deck
if (device.device == EDevice::STEAM_DECK) {
return true;
if (device.device == EDevice::STEAM_DECK && device.steam_deck_model != ESteamDeck::NONE) {
return device.steam_deck_model;
}

// Check for Steam Deck by OS version
if (const std::shared_ptr<FOSVerInfo> version = get_os_version()) {
if (version->variant_id == "steamdeck" && version->name == "SteamOS") {
return true;
}
ESteamDeck steam_deck_model = ESteamDeck::NONE;

// Retrieve and process CPU information
const std::shared_ptr<FCPUInfo> cpu_info = get_cpu_info();
if (!cpu_info) {
wprintf(L"CPU information not available.\n");
} else {
wprintf(L"OS version information not available.\n");
}

// Set of known Steam Deck CPU model names
const std::set<std::string> steam_deck_models = {
"amd custom apu 0405" // LCD Steam Deck
"amd custom apu 0932", // OLED Steam Deck
};

// Check for Steam Deck by CPU model name
if (const std::shared_ptr<FCPUInfo> cpu_info = get_cpu_info()) {
const FString cpu_model_lower = FString::to_lower(cpu_info->Model_Name);
for (const auto& model : steam_deck_models) {
if (cpu_model_lower == FString::to_lower(model.c_str())) {
wprintf(L"Steam Deck detected by CPU model name.\n");
return true;
// Convert the CPU model name to lower case once
FString cpu_model_lower = FString::to_lower(cpu_info->Model_Name);

// Map of CPU models to their corresponding Steam Deck models
static const std::unordered_map<FString, ESteamDeck> model_map = {
{FString::to_lower("amd custom apu 0405"), ESteamDeck::LCD},
{FString::to_lower("amd custom apu 0932"), ESteamDeck::OLED}
};

auto iterator = model_map.find(cpu_model_lower);
if (iterator != model_map.end()) {
steam_deck_model = iterator->second;
wprintf(L"Steam Deck detected by CPU model name: %hs.\n", cpu_model_lower.c_str());
}
}

// Check for Steam Deck by OS version only if no model has been detected yet
if (steam_deck_model == ESteamDeck::NONE)
{
if (const std::shared_ptr<FOSVerInfo> version = get_os_version())
{
if (version->variant_id == "steamdeck" && version->name == "SteamOS")
{
// Use UNKNOWN if OS matches but CPU model doesn't fit known profiles
steam_deck_model = ESteamDeck::UNKNOWN;
wprintf(L"Steam Deck OS detected but model is unknown.\n");
}
}
} else {
wprintf(L"CPU information not available.\n");
else
{
wprintf(L"OS version information not available.\n");
}
}

wprintf(L"Device is not a Steam Deck.\n");

return false;
return steam_deck_model;
}

bool IPlatformUtilities::is_connected_to_ac()
Expand Down
3 changes: 2 additions & 1 deletion HarmonyLinkLib/src/Platform/IPlatformUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include "Enums/ESteamDeck.h"
#include "Structs/FBattery.h"
#include "Structs/FCPUInfo.h"
#include "Structs/FDevice.h"
Expand Down Expand Up @@ -50,7 +51,7 @@ namespace HarmonyLinkLib
//virtual bool get_is_ethernet_connected() = 0;
//virtual bool get_is_external_input_detected() = 0;

bool is_steam_deck_detected(const FDevice& device);
ESteamDeck detect_steam_deck(const FDevice& device);
bool is_connected_to_ac();
bool is_charging();

Expand Down

0 comments on commit 07f1877

Please sign in to comment.