sys-clk: deprecate

This commit is contained in:
hanabbi
2023-10-31 06:00:01 +09:00
parent 12cb1a9527
commit aa37b019c2
103 changed files with 0 additions and 0 deletions

View File

@@ -1,14 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include <sysclk.h>
#include <sysclk/client/ipc.h>

View File

@@ -1,78 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#define TESLA_INIT_IMPL
#include <tesla.hpp>
#include "ui/gui/fatal_gui.h"
#include "ui/gui/main_gui.h"
class AppOverlay : public tsl::Overlay
{
public:
AppOverlay() {}
~AppOverlay() {}
virtual void exitServices() override {
sysclkIpcExit();
}
virtual std::unique_ptr<tsl::Gui> loadInitialGui() override
{
uint32_t apiVersion;
smInitialize();
tsl::hlp::ScopeGuard smGuard([] { smExit(); });
if(!sysclkIpcRunning())
{
return initially<FatalGui>(
"sys-clk is not running.\n\n"
"\n"
"Please make sure it is correctly\n\n"
"installed and enabled.\n\n"
"\n"
"Loader.kip is required to\n\n"
"use this version of sys-clk.",
""
);
}
if(R_FAILED(sysclkIpcInitialize()) || R_FAILED(sysclkIpcGetAPIVersion(&apiVersion)))
{
return initially<FatalGui>(
"Could not connect to sys-clk.\n\n"
"\n"
"Please make sure it is correctly\n\n"
"installed and enabled.",
""
);
}
if(SYSCLK_IPC_API_VERSION != apiVersion)
{
return initially<FatalGui>(
"Overlay not compatible with\n\n"
"the running sys-clk version.\n\n"
"\n"
"Please make sure everything is\n\n"
"installed and up to date.",
""
);
}
return initially<MainGui>();
}
};
int main(int argc, char **argv)
{
return tsl::loop<AppOverlay>(argc, argv);
}

View File

@@ -1,31 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include <tesla.hpp>
#include "../gui/base_gui.h"
class BaseFrame : public tsl::elm::HeaderOverlayFrame
{
public:
BaseFrame(BaseGui* gui) : tsl::elm::HeaderOverlayFrame(130) { // headerHeight
this->gui = gui;
}
void draw(tsl::gfx::Renderer* renderer) override
{
tsl::elm::HeaderOverlayFrame::draw(renderer);
this->gui->preDraw(renderer);
}
protected:
BaseGui* gui;
};

View File

@@ -1,26 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include <cstdio>
#define FREQ_DEFAULT_TEXT "Do not override"
static inline std::string formatListFreqMhz(std::uint32_t mhz)
{
if(mhz == 0)
return FREQ_DEFAULT_TEXT;
char buf[10];
return std::string(buf, snprintf(buf, sizeof(buf), "%u MHz", mhz));
}
static inline std::string formatListFreqHz(std::uint32_t hz) { return formatListFreqMhz(hz / 1000000); }

View File

@@ -1,137 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#include "app_profile_gui.h"
#include "../format.h"
#include "fatal_gui.h"
AppProfileGui::AppProfileGui(std::uint64_t applicationId, SysClkTitleProfileList* profileList)
{
this->applicationId = applicationId;
this->profileList = profileList;
}
AppProfileGui::~AppProfileGui()
{
delete this->profileList;
}
void AppProfileGui::openFreqChoiceGui(tsl::elm::ListItem* listItem, SysClkProfile profile, SysClkModule module)
{
tsl::changeTo<FreqChoiceGui>(this->profileList->mhzMap[profile][module], module, profile, [this, listItem, profile, module](std::uint32_t mhz) {
this->profileList->mhzMap[profile][module] = mhz;
listItem->setValue(formatListFreqMhz(this->profileList->mhzMap[profile][module]));
Result rc = sysclkIpcSetProfiles(this->applicationId, this->profileList);
if(R_FAILED(rc))
{
FatalGui::openWithResultCode("sysclkIpcSetProfiles", rc);
return false;
}
return true;
});
}
void AppProfileGui::addModuleListItem(SysClkProfile profile, SysClkModule module)
{
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(sysclkFormatModule(module, true));
listItem->setValue(formatListFreqMhz(this->profileList->mhzMap[profile][module]));
listItem->setClickListener([this, listItem, profile, module](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A)
{
this->openFreqChoiceGui(listItem, profile, module);
return true;
}
return false;
});
this->listElement->addItem(listItem);
}
void AppProfileGui::addProfileUI(SysClkProfile profile)
{
this->listElement->addItem(new tsl::elm::CategoryHeader(sysclkFormatProfile(profile, true)));
this->addModuleListItem(profile, SysClkModule_CPU);
this->addModuleListItem(profile, SysClkModule_GPU);
this->addModuleListItem(profile, SysClkModule_MEM);
}
void AppProfileGui::listUI()
{
if (this->applicationId != SYSCLK_GLOBAL_PROFILE_TID) {
SysClkConfigValueList* configList = new SysClkConfigValueList;
sysclkIpcGetConfigValues(configList);
bool globalGovernorEnabled = configList->values[SysClkConfigValue_GovernorExperimental];
if (globalGovernorEnabled) {
tsl::elm::ToggleListItem* cpuGovernorToggle = new tsl::elm::ToggleListItem("CPU Freq Governor",
GetGovernorEnabled(this->profileList->governorConfig, SysClkModule_CPU));
cpuGovernorToggle->setStateChangedListener([this](bool state) {
this->profileList->governorConfig = ToggleGovernor(this->profileList->governorConfig, SysClkModule_CPU, state);
Result rc = sysclkIpcSetProfiles(this->applicationId, this->profileList);
if (R_FAILED(rc))
FatalGui::openWithResultCode("sysclkIpcSetProfiles", rc);
});
this->listElement->addItem(cpuGovernorToggle);
tsl::elm::ToggleListItem* gpuGovernorToggle = new tsl::elm::ToggleListItem("GPU Freq Governor",
GetGovernorEnabled(this->profileList->governorConfig, SysClkModule_GPU));
gpuGovernorToggle->setStateChangedListener([this](bool state) {
this->profileList->governorConfig = ToggleGovernor(this->profileList->governorConfig, SysClkModule_GPU, state);
Result rc = sysclkIpcSetProfiles(this->applicationId, this->profileList);
if (R_FAILED(rc))
FatalGui::openWithResultCode("sysclkIpcSetProfiles", rc);
});
this->listElement->addItem(gpuGovernorToggle);
}
delete configList;
}
this->addProfileUI(SysClkProfile_Docked);
this->addProfileUI(SysClkProfile_Handheld);
this->addProfileUI(SysClkProfile_HandheldCharging);
this->addProfileUI(SysClkProfile_HandheldChargingOfficial);
this->addProfileUI(SysClkProfile_HandheldChargingUSB);
}
void AppProfileGui::changeTo(std::uint64_t applicationId)
{
SysClkTitleProfileList* profileList = new SysClkTitleProfileList;
Result rc = sysclkIpcGetProfiles(applicationId, profileList);
if(R_FAILED(rc))
{
delete profileList;
FatalGui::openWithResultCode("sysclkIpcGetProfiles", rc);
return;
}
tsl::changeTo<AppProfileGui>(applicationId, profileList);
}
void AppProfileGui::update()
{
BaseMenuGui::update();
if(this->context && this->applicationId != SYSCLK_GLOBAL_PROFILE_TID && this->applicationId != this->context->applicationId)
{
tsl::changeTo<FatalGui>(
"Application changed\n\n"
"\n"
"The running application changed\n\n"
"while editing was going on.",
""
);
}
}

View File

@@ -1,33 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include "../../ipc.h"
#include "base_menu_gui.h"
#include "freq_choice_gui.h"
class AppProfileGui : public BaseMenuGui
{
protected:
std::uint64_t applicationId;
SysClkTitleProfileList* profileList;
void openFreqChoiceGui(tsl::elm::ListItem* listItem, SysClkProfile profile, SysClkModule module);
void addModuleListItem(SysClkProfile profile, SysClkModule module);
void addProfileUI(SysClkProfile profile);
public:
AppProfileGui(std::uint64_t applicationId, SysClkTitleProfileList* profileList);
~AppProfileGui();
void listUI() override;
static void changeTo(std::uint64_t applicationId);
void update() override;
};

View File

@@ -1,40 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#include "base_gui.h"
#include "../elements/base_frame.h"
// #include "logo_rgba_bin.h"
#define LOGO_LABEL_X 40
#define LOGO_LABEL_Y 35
#define LOGO_LABEL_FONT_SIZE 20
#define VERSION_X 266
#define VERSION_Y LOGO_LABEL_Y
#define VERSION_FONT_SIZE SMALL_TEXT_SIZE
void BaseGui::preDraw(tsl::gfx::Renderer* renderer)
{
renderer->drawString("Sys-clk-OC overlay", false, LOGO_LABEL_X, LOGO_LABEL_Y, LOGO_LABEL_FONT_SIZE, TEXT_COLOR);
renderer->drawString(TARGET_VERSION, false, VERSION_X, VERSION_Y, VERSION_FONT_SIZE, DESC_COLOR);
}
tsl::elm::Element* BaseGui::createUI()
{
BaseFrame* rootFrame = new BaseFrame(this);
rootFrame->setContent(this->baseUI());
return rootFrame;
}
void BaseGui::update()
{
this->refresh();
}

View File

@@ -1,27 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include <tesla.hpp>
#include "../style.h"
class BaseGui : public tsl::Gui
{
public:
BaseGui() {}
~BaseGui() {}
virtual void preDraw(tsl::gfx::Renderer* renderer);
void update() override;
tsl::elm::Element* createUI() override;
virtual tsl::elm::Element* baseUI() = 0;
virtual void refresh() {}
};

View File

@@ -1,114 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#include "base_menu_gui.h"
#include "fatal_gui.h"
BaseMenuGui::BaseMenuGui()
{
this->context = nullptr;
this->lastContextUpdate = 0;
this->listElement = nullptr;
}
BaseMenuGui::~BaseMenuGui()
{
if(this->context)
{
delete this->context;
}
}
void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer)
{
BaseGui::preDraw(renderer);
if(this->context)
{
char buf[32];
renderer->drawString("App ID: ", false, 40, 60, SMALL_TEXT_SIZE, DESC_COLOR);
snprintf(buf, sizeof(buf), "%016lX", context->applicationId);
renderer->drawString(buf, false, 100, 60, SMALL_TEXT_SIZE, VALUE_COLOR);
renderer->drawString("Profile: ", false, 266, 60, SMALL_TEXT_SIZE, DESC_COLOR);
renderer->drawString(sysclkFormatProfile(context->profile, true), false, 322, 60, SMALL_TEXT_SIZE, VALUE_COLOR);
static struct
{
SysClkModule m;
std::uint32_t x;
} freqOffsets[SysClkModule_EnumMax] = {
{ SysClkModule_CPU, 80 },
{ SysClkModule_GPU, 200 },
{ SysClkModule_MEM, 320 },
};
for(unsigned int i = 0; i < SysClkModule_EnumMax; i++)
{
std::uint32_t hz = this->context->freqs[freqOffsets[i].m];
snprintf(buf, sizeof(buf), "%u MHz", hz / 1000000);
renderer->drawString(buf, false, freqOffsets[i].x, 85, SMALL_TEXT_SIZE, VALUE_COLOR);
}
renderer->drawString("CPU:", false, 40, 85, SMALL_TEXT_SIZE, DESC_COLOR);
renderer->drawString("GPU:", false, 160, 85, SMALL_TEXT_SIZE, DESC_COLOR);
renderer->drawString("MEM:", false, 270, 85, SMALL_TEXT_SIZE, DESC_COLOR);
static struct
{
SysClkThermalSensor s;
std::uint32_t x;
} tempOffsets[SysClkModule_EnumMax] = {
{ SysClkThermalSensor_SOC, 80 },
{ SysClkThermalSensor_PCB, 200 },
{ SysClkThermalSensor_Skin, 320 },
};
renderer->drawString("SOC:", false, 40, 110, SMALL_TEXT_SIZE, DESC_COLOR);
renderer->drawString("PCB:", false, 160, 110, SMALL_TEXT_SIZE, DESC_COLOR);
renderer->drawString("Skin:", false, 270, 110, SMALL_TEXT_SIZE, DESC_COLOR);
for(unsigned int i = 0; i < SysClkModule_EnumMax; i++)
{
std::uint32_t millis = this->context->temps[tempOffsets[i].s];
snprintf(buf, sizeof(buf), "%u.%u °C", millis / 1000, (millis - millis / 1000 * 1000) / 100);
renderer->drawString(buf, false, tempOffsets[i].x, 110, SMALL_TEXT_SIZE, VALUE_COLOR);
}
}
}
void BaseMenuGui::refresh()
{
std::uint64_t ticks = armGetSystemTick();
if(armTicksToNs(ticks - this->lastContextUpdate) > 500000000UL)
{
this->lastContextUpdate = ticks;
if(!this->context)
{
this->context = new SysClkContext;
}
Result rc = sysclkIpcGetCurrentContext(this->context);
if(R_FAILED(rc))
{
FatalGui::openWithResultCode("sysclkIpcGetCurrentContext", rc);
return;
}
}
}
tsl::elm::Element* BaseMenuGui::baseUI()
{
tsl::elm::List* list = new tsl::elm::List();
this->listElement = list;
this->listUI();
return list;
}

View File

@@ -1,30 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include "../../ipc.h"
#include "base_gui.h"
class BaseMenuGui : public BaseGui
{
protected:
SysClkContext* context;
std::uint64_t lastContextUpdate;
tsl::elm::List* listElement;
public:
BaseMenuGui();
~BaseMenuGui();
void preDraw(tsl::gfx::Renderer* renderer) override;
tsl::elm::Element* baseUI() override;
void refresh() override;
virtual void listUI() = 0;
};

View File

@@ -1,67 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#include "fatal_gui.h"
FatalGui::FatalGui(const std::string message, const std::string info)
{
this->message = message;
this->info = info;
}
void FatalGui::openWithResultCode(std::string tag, Result rc)
{
char rcStr[32];
std::string info = tag;
info.append(rcStr, snprintf(rcStr, sizeof(rcStr), "\n\n[0x%x] %04d-%04d", rc, R_MODULE(rc), R_DESCRIPTION(rc)));
tsl::changeTo<FatalGui>(
"Could not connect to sys-clk.\n\n"
"\n"
"Please make sure everything is\n\n"
"correctly installed and enabled.",
info
);
}
tsl::elm::Element* FatalGui::baseUI()
{
tsl::elm::CustomDrawer* drawer = new tsl::elm::CustomDrawer([this](tsl::gfx::Renderer* renderer, u16 x, u16 y, u16 w, u16 h) {
renderer->drawString("\uE150", false, 40, 210, 40, TEXT_COLOR);
renderer->drawString("Fatal error", false, 100, 210, 30, TEXT_COLOR);
std::uint32_t txtY = 255;
if(!this->message.empty())
{
txtY += renderer->drawString(this->message.c_str(), false, 40, txtY, 23, TEXT_COLOR).second;
txtY += 55;
}
if(!this->info.empty())
{
renderer->drawString(this->info.c_str(), false, 40, txtY, 18, DESC_COLOR);
}
});
return drawer;
}
bool FatalGui::handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight)
{
if((keysDown & HidNpadButton_A) == HidNpadButton_A || (keysDown & HidNpadButton_B) == HidNpadButton_B)
{
while(tsl::Overlay::get()->getCurrentGui() != nullptr) {
tsl::goBack();
}
return true;
}
return false;
}

View File

@@ -1,29 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include <list>
#include "base_gui.h"
class FatalGui : public BaseGui
{
protected:
std::string message;
std::string info;
public:
FatalGui(const std::string message, const std::string info);
~FatalGui() {}
tsl::elm::Element* baseUI() override;
bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight);
static void openWithResultCode(std::string tag, Result rc);
};

View File

@@ -1,65 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#include "freq_choice_gui.h"
#include "../format.h"
#include "fatal_gui.h"
FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedMHz, SysClkModule module, SysClkProfile profile, FreqChoiceListener listener)
{
this->hzTable = new SysClkFrequencyTable;
Result rc = sysclkIpcGetFrequencyTable(module, profile, hzTable);
if (R_FAILED(rc)) {
FatalGui::openWithResultCode("sysclkIpcGetFrequencyTable", rc);
}
this->selectedMHz = selectedMHz;
this->listener = listener;
}
FreqChoiceGui::~FreqChoiceGui() {
delete this->hzTable;
}
tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t mhz, bool selected)
{
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(formatListFreqMhz(mhz));
listItem->setValue(selected ? "\uE14B" : "");
listItem->setClickListener([this, mhz](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->listener)
{
if(this->listener(mhz))
{
tsl::goBack();
}
return true;
}
return false;
});
return listItem;
}
void FreqChoiceGui::listUI()
{
this->listElement->addItem(this->createFreqListItem(0, this->selectedMHz == 0));
size_t idx = 0;
uint32_t freq;
while(idx < FREQ_TABLE_MAX_ENTRY_COUNT && (freq = this->hzTable->freq[idx]))
{
uint32_t mhz = freq / 1000'000;
this->listElement->addItem(this->createFreqListItem(mhz, mhz == this->selectedMHz));
idx++;
}
}

View File

@@ -1,33 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include <list>
#include "base_menu_gui.h"
using FreqChoiceListener = std::function<bool(std::uint32_t mhz)>;
#define FREQ_DEFAULT_TEXT "Do not override"
class FreqChoiceGui : public BaseMenuGui
{
protected:
std::uint32_t selectedMHz;
SysClkFrequencyTable* hzTable;
FreqChoiceListener listener;
tsl::elm::ListItem* createFreqListItem(std::uint32_t mhz, bool selected);
public:
FreqChoiceGui(std::uint32_t selectedMHz, SysClkModule module, SysClkProfile profile, FreqChoiceListener listener);
~FreqChoiceGui();
void listUI() override;
};

View File

@@ -1,83 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#include "global_override_gui.h"
#include "fatal_gui.h"
#include "../format.h"
GlobalOverrideGui::GlobalOverrideGui()
{
for(std::uint16_t m = 0; m < SysClkModule_EnumMax; m++)
{
this->listItems[m] = nullptr;
this->listHz[m] = 0;
}
}
void GlobalOverrideGui::openFreqChoiceGui(SysClkModule module)
{
tsl::changeTo<FreqChoiceGui>(this->context->overrideFreqs[module] / 1000'000, module, this->context->profile, [this, module](std::uint32_t mhz) {
Result rc = sysclkIpcSetOverride(module, mhz * 1000'000);
if(R_FAILED(rc))
{
FatalGui::openWithResultCode("sysclkIpcSetOverride", rc);
return false;
}
this->lastContextUpdate = armGetSystemTick();
this->context->overrideFreqs[module] = mhz * 1000'000;
return true;
});
}
void GlobalOverrideGui::addModuleListItem(SysClkModule module)
{
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(sysclkFormatModule(module, true));
listItem->setValue(formatListFreqMhz(0));
listItem->setClickListener([this, module](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A)
{
this->openFreqChoiceGui(module);
return true;
}
return false;
});
this->listElement->addItem(listItem);
this->listItems[module] = listItem;
}
void GlobalOverrideGui::listUI()
{
this->addModuleListItem(SysClkModule_CPU);
this->addModuleListItem(SysClkModule_GPU);
this->addModuleListItem(SysClkModule_MEM);
}
void GlobalOverrideGui::refresh()
{
BaseMenuGui::refresh();
if(this->context)
{
for(std::uint16_t m = 0; m < SysClkModule_EnumMax; m++)
{
if(this->listItems[m] != nullptr && this->listHz[m] != this->context->overrideFreqs[m])
{
this->listItems[m]->setValue(formatListFreqHz(this->context->overrideFreqs[m]));
this->listHz[m] = this->context->overrideFreqs[m];
}
}
}
}

View File

@@ -1,31 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include "../../ipc.h"
#include "base_menu_gui.h"
#include "freq_choice_gui.h"
class GlobalOverrideGui : public BaseMenuGui
{
protected:
tsl::elm::ListItem* listItems[SysClkModule_EnumMax];
std::uint32_t listHz[SysClkModule_EnumMax];
void openFreqChoiceGui(SysClkModule module);
void addModuleListItem(SysClkModule module);
public:
GlobalOverrideGui();
~GlobalOverrideGui() {}
void listUI() override;
void refresh() override;
};

View File

@@ -1,92 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#include "main_gui.h"
#include "fatal_gui.h"
#include "app_profile_gui.h"
#include "global_override_gui.h"
#include "misc_gui.h"
void MainGui::listUI()
{
this->enabledToggle = new tsl::elm::ToggleListItem("Enable", false);
enabledToggle->setStateChangedListener([this](bool state) {
Result rc = sysclkIpcSetEnabled(state);
if(R_FAILED(rc))
{
FatalGui::openWithResultCode("sysclkIpcSetEnabled", rc);
}
this->lastContextUpdate = armGetSystemTick();
this->context->enabled = state;
});
this->listElement->addItem(this->enabledToggle);
tsl::elm::ListItem* appProfileItem = new tsl::elm::ListItem("Edit app profile");
appProfileItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{
AppProfileGui::changeTo(this->context->applicationId);
return true;
}
return false;
});
this->listElement->addItem(appProfileItem);
this->listElement->addItem(new tsl::elm::CategoryHeader("Advanced"));
tsl::elm::ListItem* globalOverrideItem = new tsl::elm::ListItem("Temporary overrides");
globalOverrideItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A)
{
tsl::changeTo<GlobalOverrideGui>();
return true;
}
return false;
});
this->listElement->addItem(globalOverrideItem);
tsl::elm::ListItem* globalProfileItem = new tsl::elm::ListItem("Global profile");
globalProfileItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{
AppProfileGui::changeTo(SYSCLK_GLOBAL_PROFILE_TID);
return true;
}
return false;
});
this->listElement->addItem(globalProfileItem);
tsl::elm::ListItem* miscItem = new tsl::elm::ListItem("Miscellaneous");
miscItem->setClickListener([this](u64 keys) {
if((keys & HidNpadButton_A) == HidNpadButton_A && this->context)
{
tsl::changeTo<MiscGui>();
return true;
}
return false;
});
this->listElement->addItem(miscItem);
}
void MainGui::refresh()
{
BaseMenuGui::refresh();
if(this->context)
{
this->enabledToggle->setState(this->context->enabled);
}
}

View File

@@ -1,25 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include "base_menu_gui.h"
class MainGui : public BaseMenuGui
{
protected:
tsl::elm::ToggleListItem* enabledToggle;
public:
MainGui() {}
~MainGui() {}
void listUI() override;
void refresh() override;
};

View File

@@ -1,183 +0,0 @@
/* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#include "misc_gui.h"
#include "fatal_gui.h"
#include "../format.h"
MiscGui::MiscGui()
{
smInitialize();
this->configList = new SysClkConfigValueList {};
this->chargeInfo = new PsmChargeInfo {};
this->i2cInfo = new I2cInfo {};
sysclkIpcGetIsMariko(&this->isMariko);
}
MiscGui::~MiscGui()
{
delete this->configList;
delete this->chargeInfo;
delete this->i2cInfo;
this->configToggles.clear();
smExit();
}
void MiscGui::addConfigToggle(SysClkConfigValue configVal, const char* altName = nullptr) {
const char* configName = altName ? altName : sysclkFormatConfigValue(configVal, true);
tsl::elm::ToggleListItem* toggle = new tsl::elm::ToggleListItem(configName, this->configList->values[configVal]);
toggle->setStateChangedListener([this, configVal](bool state) {
this->configList->values[configVal] = uint64_t(state);
Result rc = sysclkIpcSetConfigValues(this->configList);
if (R_FAILED(rc))
FatalGui::openWithResultCode("sysclkIpcSetConfigValues", rc);
this->lastContextUpdate = armGetSystemTick();
});
this->listElement->addItem(toggle);
this->configToggles[configVal] = toggle;
}
void MiscGui::updateConfigToggles() {
for (const auto& [value, toggle] : this->configToggles) {
if (toggle != nullptr)
toggle->setState(this->configList->values[value]);
}
}
void MiscGui::listUI()
{
// Config list
sysclkIpcGetConfigValues(this->configList);
this->listElement->addItem(new tsl::elm::CategoryHeader("Config"));
addConfigToggle(SysClkConfigValue_AutoCPUBoost, this->isMariko ? nullptr : "Auto CPU Boost (Unsafe)");
addConfigToggle(SysClkConfigValue_SyncReverseNXMode);
addConfigToggle(SysClkConfigValue_GovernorExperimental);
// Charging Current
this->chargingCurrentHeader = new tsl::elm::CategoryHeader("");
this->listElement->addItem(this->chargingCurrentHeader);
constexpr size_t current_steps = CHARGING_CURRENT_MA_LIMIT / 100;
this->chargingCurrentBar = new StepTrackBarIcon("", current_steps + 1);
this->chargingCurrentBar->setProgress(this->configList->values[SysClkConfigValue_ChargingCurrentLimit]);
this->chargingCurrentBar->setValueChangedListener([this](u8 val) {
if (val < 1) {
val = 1;
this->chargingCurrentBar->setProgress(val);
}
if (val > current_steps) {
val = current_steps;
this->chargingCurrentBar->setProgress(val);
}
uint32_t current_ma = val * 100;
this->configList->values[SysClkConfigValue_ChargingCurrentLimit] = current_ma;
snprintf(chargingCurrentBarDesc, sizeof(chargingCurrentBarDesc), "Charging Current: %lu mA (Now: %+d mA)", this->configList->values[SysClkConfigValue_ChargingCurrentLimit], (int)this->i2cInfo->batCurrent);
this->chargingCurrentHeader->setText(chargingCurrentBarDesc);
Result rc = sysclkIpcSetConfigValues(this->configList);
if (R_FAILED(rc))
FatalGui::openWithResultCode("sysclkIpcSetConfigValues", rc);
this->lastContextUpdate = armGetSystemTick();
});
this->listElement->addItem(this->chargingCurrentBar);
// Charging Limit
this->chargingLimitHeader = new tsl::elm::CategoryHeader("");
this->listElement->addItem(this->chargingLimitHeader);
this->chargingLimitBar = new StepTrackBarIcon("", 100 + 1);
this->chargingLimitBar->setProgress(this->configList->values[SysClkConfigValue_ChargingLimitPercentage]);
this->chargingLimitBar->setValueChangedListener([this](u8 val) {
if (val < 20) {
val = 20;
this->chargingLimitBar->setProgress(val);
}
this->configList->values[SysClkConfigValue_ChargingLimitPercentage] = val;
snprintf(chargingLimitBarDesc, sizeof(chargingLimitBarDesc), "Battery Charging Limit: %lu%% (Now: %u%%)", this->configList->values[SysClkConfigValue_ChargingLimitPercentage], this->batteryChargePerc);
this->chargingLimitHeader->setText(chargingLimitBarDesc);
this->chargingLimitBar->setIcon(PsmGetBatteryStateIcon(this->chargeInfo));
Result rc = sysclkIpcSetConfigValues(this->configList);
if (R_FAILED(rc))
FatalGui::openWithResultCode("sysclkIpcSetConfigValues", rc);
this->lastContextUpdate = armGetSystemTick();
});
this->listElement->addItem(this->chargingLimitBar);
this->listElement->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer* renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString("\uE016 Long-term use may render the battery gauge \ninaccurate!", false, x, y + 20, SMALL_TEXT_SIZE, DESC_COLOR);
}), SMALL_TEXT_SIZE * 2 + 20);
// Temporary toggles
this->listElement->addItem(new tsl::elm::CategoryHeader("Temporary toggles"));
this->chargingDisabledOverrideToggle = new tsl::elm::ToggleListItem("Force Disable Charging", false);
chargingDisabledOverrideToggle->setStateChangedListener([this](bool state) {
Result rc = sysclkIpcSetBatteryChargingDisabledOverride(state);
if (R_FAILED(rc))
FatalGui::openWithResultCode("sysclkIpcSetBatteryChargingDisabledOverride", rc);
this->lastContextUpdate = armGetSystemTick();
});
this->listElement->addItem(this->chargingDisabledOverrideToggle);
this->backlightToggle = new tsl::elm::ToggleListItem("Screen Backlight", false);
backlightToggle->setStateChangedListener([this](bool state) {
LblUpdate(true);
});
this->listElement->addItem(this->backlightToggle);
// Info
this->listElement->addItem(new tsl::elm::CategoryHeader("Info"));
this->listElement->addItem(new tsl::elm::CustomDrawer([this](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString(this->infoNames, false, x, y + 20, SMALL_TEXT_SIZE, DESC_COLOR);
renderer->drawString(this->infoVals, false, x + 120, y + 20, SMALL_TEXT_SIZE, VALUE_COLOR);
}), SMALL_TEXT_SIZE * 12 + 20);
}
void MiscGui::refresh() {
BaseMenuGui::refresh();
if (this->context && ++frameCounter >= 60)
{
frameCounter = 0;
sysclkIpcGetConfigValues(this->configList);
updateConfigToggles();
PsmUpdate();
this->chargingLimitBar->setIcon(PsmGetBatteryStateIcon(this->chargeInfo));
bool chargingDisabledOverride;
Result rc = sysclkIpcGetBatteryChargingDisabledOverride(&chargingDisabledOverride);
if (R_FAILED(rc))
FatalGui::openWithResultCode("sysclkIpcGetBatteryChargingDisabledOverride", rc);
this->chargingDisabledOverrideToggle->setState(chargingDisabledOverride);
LblUpdate();
this->backlightToggle->setState(lblstatus);
this->chargingCurrentBar->setProgress(this->configList->values[SysClkConfigValue_ChargingCurrentLimit] / 100);
snprintf(chargingCurrentBarDesc, sizeof(chargingCurrentBarDesc), "Charging Current: %lu mA (Now: %+d mA)", this->configList->values[SysClkConfigValue_ChargingCurrentLimit], (int)this->i2cInfo->batCurrent);
this->chargingCurrentHeader->setText(chargingCurrentBarDesc);
this->chargingLimitBar->setProgress(this->configList->values[SysClkConfigValue_ChargingLimitPercentage]);
snprintf(chargingLimitBarDesc, sizeof(chargingLimitBarDesc), "Charging Limit: %lu%% (Now: %u%%)", this->configList->values[SysClkConfigValue_ChargingLimitPercentage], this->batteryChargePerc);
this->chargingLimitHeader->setText(chargingLimitBarDesc);
I2cGetInfo(this->i2cInfo);
UpdateInfo(this->infoVals, sizeof(this->infoVals));
}
}

View File

@@ -1,182 +0,0 @@
/* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include "../../ipc.h"
#include "base_menu_gui.h"
#include <inttypes.h>
class StepTrackBarIcon : public tsl::elm::StepTrackBar {
public:
StepTrackBarIcon(const char icon[3], size_t numSteps):
tsl::elm::StepTrackBar(icon, numSteps) { }
const char* getIcon() { return this->m_icon; }
void setIcon(const char* icon) { this->m_icon = icon; }
};
class MiscGui : public BaseMenuGui
{
public:
MiscGui();
~MiscGui();
void listUI() override;
void refresh() override;
protected:
typedef struct {
float batCurrent;
u32 cpuVolt;
u32 gpuVolt;
u32 emcVddq;
u32 memVdd2;
} I2cInfo;
void PsmUpdate(uint32_t dispatchId = 0)
{
psmInitialize();
if (dispatchId)
{
serviceDispatch(psmGetServiceSession(), dispatchId);
svcSleepThread(1000);
}
serviceDispatchOut(psmGetServiceSession(), 17, *(this->chargeInfo));
psmGetBatteryChargePercentage(&(this->batteryChargePerc));
psmExit();
}
void I2cGetInfo(I2cInfo* i2cInfo)
{
i2cInitialize();
float batCurrent = I2c_Max17050_GetBatteryCurrent();
i2cInfo->batCurrent = std::abs(batCurrent) < 10. ? 0. : batCurrent;
if (isMariko) {
i2cInfo->cpuVolt = I2c_BuckConverter_GetMvOut(&I2c_Mariko_CPU);
i2cInfo->gpuVolt = I2c_BuckConverter_GetMvOut(&I2c_Mariko_GPU);
i2cInfo->emcVddq = I2c_BuckConverter_GetMvOut(&I2c_Mariko_DRAM_VDDQ);
i2cInfo->memVdd2 = I2c_BuckConverter_GetMvOut(&I2c_Mariko_DRAM_VDD2);
} else {
i2cInfo->cpuVolt = I2c_BuckConverter_GetMvOut(&I2c_Erista_CPU);
i2cInfo->gpuVolt = I2c_BuckConverter_GetMvOut(&I2c_Erista_GPU);
i2cInfo->emcVddq = I2c_BuckConverter_GetMvOut(&I2c_Erista_DRAM);
i2cInfo->memVdd2 = i2cInfo->emcVddq;
}
I2c_Bq24193_GetFastChargeCurrentLimit(reinterpret_cast<u32 *>(&(chargeInfo->ChargeCurrentLimit)));
i2cExit();
}
void UpdateInfo(char* out, size_t outsize)
{
float chargerVoltLimit = (float)chargeInfo->ChargerVoltageLimit / 1000;
float chargerCurrLimit = (float)chargeInfo->ChargerCurrentLimit / 1000;
float chargerOutWatts = chargerVoltLimit * chargerCurrLimit;
char chargeVoltLimit[20] = "";
if (chargeInfo->ChargeVoltageLimit)
snprintf(chargeVoltLimit, sizeof(chargeVoltLimit), ", %umV", chargeInfo->ChargeVoltageLimit);
char chargWattsInfo[30] = "";
if (chargeInfo->ChargerType)
snprintf(chargWattsInfo, sizeof(chargWattsInfo), " %.1fV/%.1fA (%.1fW)", chargerVoltLimit, chargerCurrLimit, chargerOutWatts);
char batCurInfo[30] = "";
snprintf(batCurInfo, sizeof(batCurInfo), "%+.2fmA (%+.2fW)",
i2cInfo->batCurrent, i2cInfo->batCurrent * (float)chargeInfo->VoltageAvg / 1000'000);
snprintf(out, outsize,
"%s%s\n"
"%.3fV %.2f\u00B0C\n"
"+%umA, -%umA\n"
"+%umA%s\n"
"%.2f%%\n"
"%.2f%%\n"
"%s\n"
"%s\n\n"
"%dmV\n"
"%dmV\n"
"Vddq %dmV, Vdd2 %dmV\n"
,
PsmInfoChargerTypeToStr(chargeInfo->ChargerType), chargWattsInfo,
(float)chargeInfo->VoltageAvg / 1000, (float)chargeInfo->BatteryTemperature / 1000,
chargeInfo->InputCurrentLimit, chargeInfo->VBUSCurrentLimit,
chargeInfo->ChargeCurrentLimit, chargeVoltLimit,
(float)chargeInfo->RawBatteryCharge / 1000,
(float)chargeInfo->BatteryAge / 1000,
PsmPowerRoleToStr(chargeInfo->PowerRole),
batCurInfo,
i2cInfo->cpuVolt,
i2cInfo->gpuVolt,
i2cInfo->emcVddq, i2cInfo->memVdd2
);
}
void PsmChargingToggler(bool* enable)
{
if (!PsmIsChargerConnected(this->chargeInfo))
{
*enable = false;
return;
}
PsmUpdate(*enable ? 2 : 3);
*enable = (PsmIsCharging(this->chargeInfo) == *enable);
}
void LblUpdate(bool shouldSwitch = false)
{
lblInitialize();
lblGetBacklightSwitchStatus(&lblstatus);
if (shouldSwitch)
lblstatus ? lblSwitchBacklightOff(0) : lblSwitchBacklightOn(0);
lblExit();
}
bool isMariko = false;
std::map<SysClkConfigValue, tsl::elm::ToggleListItem*> configToggles;
void addConfigToggle(SysClkConfigValue, const char*);
void updateConfigToggles();
tsl::elm::ToggleListItem *chargingDisabledOverrideToggle, *backlightToggle;
tsl::elm::CategoryHeader *chargingCurrentHeader, *chargingLimitHeader;
StepTrackBarIcon *chargingCurrentBar, *chargingLimitBar;
SysClkConfigValueList* configList;
PsmChargeInfo* chargeInfo;
I2cInfo* i2cInfo;
LblBacklightSwitchStatus lblstatus = LblBacklightSwitchStatus_Disabled;
const char* infoNames =
"Charger:\n"\
"Battery:\n"\
"Current Limit:\n"\
"Charging Limit:\n"\
"Raw Charge:\n"\
"Battery Age:\n"\
"Power Role:\n"\
"Current Flow:\n\n"\
"CPU Volt:\n"\
"GPU Volt:\n"\
"DRAM Volt:";
char infoVals[300] = "";
char chargingLimitBarDesc[40] = "";
char chargingCurrentBarDesc[50] = "";
u32 batteryChargePerc = 0;
u8 frameCounter = 60;
};

View File

@@ -1,20 +0,0 @@
/*
* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
* wrote this file. As long as you retain this notice you can do whatever you
* want with this stuff. If you meet any of us some day, and you think this
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
* --------------------------------------------------------------------------
*/
#pragma once
#include <tesla.hpp>
#define TEXT_COLOR tsl::gfx::Renderer::a(0xFFFF)
#define DESC_COLOR tsl::gfx::Renderer::a({ 0xC, 0xC, 0xC, 0xF })
#define VALUE_COLOR tsl::gfx::Renderer::a({ 0x5, 0xC, 0xA, 0xF })
#define SMALL_TEXT_SIZE 15
#define LABEL_SPACING 7
#define LABEL_FONT_SIZE 15