sysclk: fix config value reset bug
This commit is contained in:
@@ -55,12 +55,15 @@ void MiscGui::addConfigToggle(SysClkConfigValue configVal, const char* altName)
|
||||
this->configToggles[configVal] = toggle;
|
||||
}
|
||||
|
||||
|
||||
void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
const char* altName,
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
const ValueThresholds* thresholds,
|
||||
const std::map<uint32_t, std::string>& labels)
|
||||
const std::map<uint32_t, std::string>& labels,
|
||||
const std::vector<NamedValue>& namedValues,
|
||||
bool showDefaultValue)
|
||||
{
|
||||
const char* configName = altName ? altName : sysclkFormatConfigValue(configVal, true);
|
||||
|
||||
@@ -83,7 +86,7 @@ void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
ValueThresholds thresholdsCopy = (thresholds ? *thresholds : ValueThresholds{});
|
||||
|
||||
listItem->setClickListener(
|
||||
[this, configVal, range, categoryName, thresholdsCopy, labels](u64 keys)
|
||||
[this, configVal, range, categoryName, thresholdsCopy, labels, namedValues, showDefaultValue](u64 keys)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == 0)
|
||||
return false;
|
||||
@@ -108,7 +111,9 @@ void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
},
|
||||
thresholdsCopy,
|
||||
true,
|
||||
labels // <── NEW
|
||||
labels,
|
||||
namedValues,
|
||||
showDefaultValue
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -128,7 +133,9 @@ void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
},
|
||||
ValueThresholds(),
|
||||
false,
|
||||
labels // <── NEW
|
||||
labels,
|
||||
namedValues,
|
||||
showDefaultValue
|
||||
);
|
||||
}
|
||||
|
||||
@@ -137,7 +144,15 @@ void MiscGui::addConfigButton(SysClkConfigValue configVal,
|
||||
|
||||
this->listElement->addItem(listItem);
|
||||
this->configButtons[configVal] = listItem;
|
||||
this->configRanges[configVal] = range;
|
||||
this->configRanges[configVal] = range;
|
||||
this->configNamedValues[configVal] = namedValues;
|
||||
}
|
||||
|
||||
void MiscGui::updateConfigToggles() {
|
||||
for (const auto& [value, toggle] : this->configToggles) {
|
||||
if (toggle != nullptr)
|
||||
toggle->setState(this->configList->values[value]);
|
||||
}
|
||||
}
|
||||
|
||||
void MiscGui::addFreqButton(SysClkConfigValue configVal,
|
||||
@@ -203,15 +218,11 @@ void MiscGui::addFreqButton(SysClkConfigValue configVal,
|
||||
this->configRanges[configVal] = ValueRange(0, 0, 0, "MHz", 1);
|
||||
}
|
||||
|
||||
void MiscGui::updateConfigToggles() {
|
||||
for (const auto& [value, toggle] : this->configToggles) {
|
||||
if (toggle != nullptr)
|
||||
toggle->setState(this->configList->values[value]);
|
||||
}
|
||||
}
|
||||
|
||||
void MiscGui::listUI()
|
||||
{
|
||||
ValueThresholds thresholdsDisabled(0, 0);
|
||||
std::vector<NamedValue> noNamedValues = {};
|
||||
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader("Settings"));
|
||||
addConfigToggle(HocClkConfigValue_UncappedClocks, nullptr);
|
||||
addConfigToggle(HocClkConfigValue_OverwriteBoostMode, nullptr);
|
||||
@@ -315,10 +326,6 @@ void MiscGui::listUI()
|
||||
{320000000, "Absolute Max"},
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(IsMariko()) {
|
||||
addFreqButton(HocClkConfigValue_MarikoMaxCpuClock, nullptr, SysClkModule_CPU, cpu_freq_label_m);
|
||||
addFreqButton(HocClkConfigValue_MarikoMaxGpuClock, nullptr, SysClkModule_GPU, gpu_freq_label_m);
|
||||
@@ -331,24 +338,347 @@ void MiscGui::listUI()
|
||||
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader("KIP"));
|
||||
|
||||
std::vector<NamedValue> autoAdjOptions = {
|
||||
NamedValue("AUTO_ADJ", 0),
|
||||
NamedValue("AUTO_ADJ_BL", 1)
|
||||
};
|
||||
|
||||
addConfigButton(
|
||||
KipConfigValue_mtcConf,
|
||||
"MTC Configuration",
|
||||
ValueRange(0, 1, 1, "", 1),
|
||||
"MTC Configuration",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
autoAdjOptions,
|
||||
false
|
||||
);
|
||||
|
||||
addConfigToggle(KipConfigValue_hpMode, "HP Mode");
|
||||
|
||||
std::map<uint32_t, std::string> emc_voltage_label = {
|
||||
{1100000, "Default (Mariko)"},
|
||||
{1125000, "Default (Erista)"},
|
||||
{1175000, "Rating"},
|
||||
{1212500, "Safe Max"},
|
||||
};
|
||||
|
||||
|
||||
|
||||
ValueThresholds vdd2Thresholds(1212500, 1250000);
|
||||
addConfigButton(
|
||||
KipConfigValue_commonEmcMemVolt,
|
||||
"EMC VDD2 Voltage",
|
||||
ValueRange(912500, 1350000, 12500, "mV", 1000),
|
||||
"Voltage",
|
||||
&vdd2Thresholds
|
||||
&vdd2Thresholds,
|
||||
emc_voltage_label,
|
||||
noNamedValues,
|
||||
false
|
||||
);
|
||||
|
||||
std::vector<NamedValue> marikoMaxEmcClock = {
|
||||
NamedValue("1600MHz", 1600000),
|
||||
NamedValue("1633MHz", 1633000),
|
||||
NamedValue("1666MHz", 1666000),
|
||||
NamedValue("1700MHz", 1700000),
|
||||
NamedValue("1733MHz", 1733000),
|
||||
NamedValue("1766MHz", 1766000),
|
||||
NamedValue("1800MHz", 1800000),
|
||||
NamedValue("1833MHz", 1833000),
|
||||
NamedValue("1866MHz", 1866000),
|
||||
NamedValue("1900MHz", 1900000),
|
||||
NamedValue("1933MHz", 1933000),
|
||||
NamedValue("1966MHz", 1966000),
|
||||
NamedValue("2000MHz", 2000000),
|
||||
NamedValue("2033MHz", 2033000),
|
||||
NamedValue("2066MHz", 2066000),
|
||||
NamedValue("2100MHz", 2100000),
|
||||
NamedValue("2133MHz", 2133000),
|
||||
NamedValue("2166MHz", 2166000),
|
||||
NamedValue("2200MHz", 2200000),
|
||||
NamedValue("2233MHz", 2233000),
|
||||
NamedValue("2266MHz", 2266000),
|
||||
NamedValue("2300MHz", 2300000),
|
||||
NamedValue("2333MHz", 2333000),
|
||||
NamedValue("2366MHz", 2366000),
|
||||
NamedValue("2400MHz", 2400000),
|
||||
NamedValue("2433MHz", 2433000),
|
||||
NamedValue("2466MHz", 2466000),
|
||||
NamedValue("2500MHz", 2500000),
|
||||
NamedValue("2533MHz", 2533000),
|
||||
NamedValue("2566MHz", 2566000),
|
||||
NamedValue("2600MHz", 2600000),
|
||||
NamedValue("2633MHz", 2633000),
|
||||
NamedValue("2666MHz", 2666000),
|
||||
NamedValue("2700MHz", 2700000),
|
||||
NamedValue("2733MHz", 2733000),
|
||||
NamedValue("2766MHz", 2766000),
|
||||
NamedValue("2800MHz", 2800000),
|
||||
NamedValue("2833MHz", 2833000),
|
||||
NamedValue("2866MHz", 2866000),
|
||||
NamedValue("2900MHz", 2900000),
|
||||
NamedValue("2933MHz", 2933000),
|
||||
NamedValue("2966MHz", 2966000),
|
||||
NamedValue("3000MHz", 3000000),
|
||||
NamedValue("3033MHz", 3033000),
|
||||
NamedValue("3066MHz", 3066000),
|
||||
NamedValue("3100MHz", 3100000),
|
||||
NamedValue("3133MHz", 3133000),
|
||||
NamedValue("3166MHz", 3166000),
|
||||
NamedValue("3200MHz", 3200000),
|
||||
};
|
||||
|
||||
std::vector<NamedValue> eristaMaxEmcClock = {
|
||||
NamedValue("1600MHz", 1600000),
|
||||
NamedValue("1633MHz", 1633000),
|
||||
NamedValue("1666MHz", 1666000),
|
||||
NamedValue("1700MHz", 1700000),
|
||||
NamedValue("1733MHz", 1733000),
|
||||
NamedValue("1766MHz", 1766000),
|
||||
NamedValue("1800MHz", 1800000),
|
||||
NamedValue("1833MHz", 1833000),
|
||||
NamedValue("1866MHz", 1866000),
|
||||
NamedValue("1900MHz", 1900000),
|
||||
NamedValue("1933MHz", 1933000),
|
||||
NamedValue("1966MHz", 1966000),
|
||||
NamedValue("2000MHz", 2000000),
|
||||
NamedValue("2033MHz", 2033000),
|
||||
NamedValue("2066MHz", 2066000),
|
||||
NamedValue("2100MHz", 2100000),
|
||||
NamedValue("2133MHz", 2133000),
|
||||
NamedValue("2166MHz", 2166000),
|
||||
NamedValue("2200MHz", 2200000),
|
||||
NamedValue("2233MHz", 2233000),
|
||||
NamedValue("2266MHz", 2266000),
|
||||
NamedValue("2300MHz", 2300000),
|
||||
NamedValue("2333MHz", 2333000),
|
||||
NamedValue("2366MHz", 2366000),
|
||||
NamedValue("2400MHz", 2400000),
|
||||
};
|
||||
if(IsErista()) {
|
||||
addConfigButton(
|
||||
KipConfigValue_eristaEmcMaxClock,
|
||||
"EMC Max Clock",
|
||||
ValueRange(0, 1, 1, "", 1),
|
||||
"EMC Max Clock",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
eristaMaxEmcClock,
|
||||
false
|
||||
);
|
||||
} else {
|
||||
addConfigButton(
|
||||
KipConfigValue_marikoEmcMaxClock,
|
||||
"EMC Max Clock",
|
||||
ValueRange(0, 1, 1, "", 1),
|
||||
"EMC Max Clock",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
marikoMaxEmcClock,
|
||||
false
|
||||
);
|
||||
addConfigButton(
|
||||
KipConfigValue_marikoEmcVddqVolt,
|
||||
"EMC VDDQ Voltage",
|
||||
ValueRange(550000, 700000, 5000, "mV", 1000),
|
||||
"EMC VDDQ Voltage",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
addConfigButton(
|
||||
KipConfigValue_t1_tRCD,
|
||||
"t1 tRCD",
|
||||
ValueRange(0, 8, 1, "", 1),
|
||||
"tRCD",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
addConfigButton(
|
||||
KipConfigValue_t2_tRP,
|
||||
"t2 tRP",
|
||||
ValueRange(0, 8, 1, "", 1),
|
||||
"tRP",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
addConfigButton(
|
||||
KipConfigValue_t3_tRAS,
|
||||
"t3 tRAS",
|
||||
ValueRange(0, 10, 1, "", 1),
|
||||
"tRAS",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
addConfigButton(
|
||||
KipConfigValue_t4_tRRD,
|
||||
"t4 tRRD",
|
||||
ValueRange(0, 7, 1, "", 1),
|
||||
"tRRD",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
addConfigButton(
|
||||
KipConfigValue_t5_tRFC,
|
||||
"t5 tRFC",
|
||||
ValueRange(0, 11, 1, "", 1),
|
||||
"tRFC",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
|
||||
addConfigButton(
|
||||
KipConfigValue_t6_tRTW,
|
||||
"t6 tRTW",
|
||||
ValueRange(0, 10, 1, "", 1),
|
||||
"tRTW",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
|
||||
addConfigButton(
|
||||
KipConfigValue_t7_tWTR,
|
||||
"t7 tWTR",
|
||||
ValueRange(0, 10, 1, "", 1),
|
||||
"tWTR",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
|
||||
addConfigButton(
|
||||
KipConfigValue_t8_tREFI,
|
||||
"t8 tREFI",
|
||||
ValueRange(0, 6, 1, "", 1),
|
||||
"tREFI",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
|
||||
std::vector<NamedValue> rlLabels = {
|
||||
NamedValue("1600BL", 0),
|
||||
NamedValue("1866BL", 4),
|
||||
NamedValue("2133BL", 8)
|
||||
};
|
||||
|
||||
std::vector<NamedValue> wlLabels = {
|
||||
NamedValue("1600BL", 0),
|
||||
NamedValue("1866BL", 2),
|
||||
NamedValue("2133BL", 4)
|
||||
};
|
||||
|
||||
addConfigButton(
|
||||
KipConfigValue_mem_burst_read_latency,
|
||||
"Read Latency",
|
||||
ValueRange(0, 6, 1, "", 0),
|
||||
"Read Latency",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
rlLabels,
|
||||
false
|
||||
);
|
||||
|
||||
addConfigButton(
|
||||
KipConfigValue_mem_burst_write_latency,
|
||||
"Write Latency",
|
||||
ValueRange(0, 6, 1, "", 0),
|
||||
"Write Latency",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
wlLabels,
|
||||
false
|
||||
);
|
||||
|
||||
std::vector<NamedValue> marikoTableConf = {
|
||||
NamedValue("Auto", 0),
|
||||
NamedValue("Default", 1),
|
||||
NamedValue("1581MHz Tbreak", 2),
|
||||
NamedValue("1683MHz Tbreak", 3),
|
||||
NamedValue("HELIOS Table", 4)
|
||||
};
|
||||
|
||||
ValueThresholds mCpuVoltThresholds(1160, 1180);
|
||||
|
||||
if(IsErista()) {
|
||||
addConfigButton(
|
||||
KipConfigValue_eristaCpuUV,
|
||||
"CPU UV",
|
||||
ValueRange(0, 5, 1, "", 1),
|
||||
"CPU UV",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
true
|
||||
);
|
||||
addConfigButton(
|
||||
KipConfigValue_eristaCpuMaxVolt,
|
||||
"CPU Max Voltage",
|
||||
ValueRange(1120, 1235, 5, "mV", 1),
|
||||
"CPU Max Voltage",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
} else {
|
||||
addConfigButton(
|
||||
KipConfigValue_tableConf,
|
||||
"CPU UV Table",
|
||||
ValueRange(0, 12, 1, "", 0),
|
||||
"CPU UV Table",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
marikoTableConf,
|
||||
false
|
||||
);
|
||||
addConfigButton(
|
||||
KipConfigValue_marikoCpuUVLow,
|
||||
"CPU Low UV",
|
||||
ValueRange(0, 8, 1, "", 1),
|
||||
"CPU Low UV",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
addConfigButton(
|
||||
KipConfigValue_marikoCpuUVHigh,
|
||||
"CPU High UV",
|
||||
ValueRange(0, 12, 1, "", 1),
|
||||
"CPU High UV",
|
||||
&thresholdsDisabled,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
addConfigButton(
|
||||
KipConfigValue_marikoCpuMaxVolt,
|
||||
"CPU Max Voltage",
|
||||
ValueRange(1000, 1235, 5, "mV", 1),
|
||||
"CPU Max Voltage",
|
||||
&mCpuVoltThresholds,
|
||||
{},
|
||||
{},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* saveBtn = new tsl::elm::ListItem("Save KIP Settings");
|
||||
saveBtn->setClickListener([](u64 keys) {
|
||||
if (keys & HidNpadButton_A) {
|
||||
@@ -364,6 +694,31 @@ void MiscGui::listUI()
|
||||
this->listElement->addItem(saveBtn);
|
||||
}
|
||||
|
||||
static std::string getValueDisplayText(uint64_t currentValue,
|
||||
const ValueRange& range,
|
||||
const std::vector<NamedValue>& namedValues)
|
||||
{
|
||||
char valueText[32];
|
||||
|
||||
for (const auto& namedValue : namedValues) {
|
||||
if (currentValue == namedValue.value) {
|
||||
return namedValue.name;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentValue == 0) {
|
||||
snprintf(valueText, sizeof(valueText), "%s", VALUE_DEFAULT_TEXT);
|
||||
} else {
|
||||
uint64_t displayValue = currentValue / range.divisor;
|
||||
if (!range.suffix.empty()) {
|
||||
snprintf(valueText, sizeof(valueText), "%lu %s", displayValue, range.suffix.c_str());
|
||||
} else {
|
||||
snprintf(valueText, sizeof(valueText), "%lu", displayValue);
|
||||
}
|
||||
}
|
||||
return std::string(valueText);
|
||||
}
|
||||
|
||||
void MiscGui::refresh() {
|
||||
BaseMenuGui::refresh();
|
||||
|
||||
@@ -377,11 +732,24 @@ void MiscGui::refresh() {
|
||||
for (const auto& [configVal, button] : this->configButtons) {
|
||||
uint64_t currentValue = this->configList->values[configVal];
|
||||
const ValueRange& range = this->configRanges[configVal];
|
||||
|
||||
|
||||
auto namedValuesIt = this->configNamedValues.find(configVal);
|
||||
const std::vector<NamedValue>& namedValues = (namedValuesIt != this->configNamedValues.end())
|
||||
? namedValuesIt->second
|
||||
: std::vector<NamedValue>();
|
||||
|
||||
char valueText[32];
|
||||
if (currentValue == 0) {
|
||||
snprintf(valueText, sizeof(valueText), "%s", VALUE_DEFAULT_TEXT);
|
||||
} else {
|
||||
|
||||
bool foundNamedValue = false;
|
||||
for (const auto& namedValue : namedValues) {
|
||||
if (currentValue == namedValue.value) {
|
||||
snprintf(valueText, sizeof(valueText), "%s", namedValue.name.c_str());
|
||||
foundNamedValue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundNamedValue) {
|
||||
uint64_t displayValue = currentValue / range.divisor;
|
||||
if (!range.suffix.empty()) {
|
||||
snprintf(valueText, sizeof(valueText), "%lu %s", displayValue, range.suffix.c_str());
|
||||
@@ -389,6 +757,7 @@ void MiscGui::refresh() {
|
||||
snprintf(valueText, sizeof(valueText), "%lu", displayValue);
|
||||
}
|
||||
}
|
||||
|
||||
button->setValue(valueText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
protected:
|
||||
std::map<SysClkConfigValue, tsl::elm::ListItem*> configButtons;
|
||||
std::map<SysClkConfigValue, ValueRange> configRanges; // Store ranges for refresh
|
||||
std::map<SysClkConfigValue, std::vector<NamedValue>> configNamedValues; // NEW — Store named values for refresh
|
||||
SysClkConfigValueList* configList;
|
||||
std::map<SysClkConfigValue, tsl::elm::ToggleListItem*> configToggles;
|
||||
std::map<SysClkConfigValue, std::tuple<tsl::elm::TrackBar*, tsl::elm::ListItem*, std::vector<uint64_t>>> configTrackbars;
|
||||
@@ -28,11 +29,14 @@ protected:
|
||||
const ValueRange& range,
|
||||
const std::string& categoryName,
|
||||
const ValueThresholds* thresholds,
|
||||
const std::map<uint32_t, std::string>& labels = {});
|
||||
const std::map<uint32_t, std::string>& labels = {},
|
||||
const std::vector<NamedValue>& namedValues = {},
|
||||
bool showDefaultValue = true);
|
||||
void addFreqButton(SysClkConfigValue configVal,
|
||||
const char* altName,
|
||||
SysClkModule module,
|
||||
const std::map<uint32_t, std::string>& labels = {}); void updateConfigToggles();
|
||||
const std::map<uint32_t, std::string>& labels = {});
|
||||
void updateConfigToggles();
|
||||
|
||||
tsl::elm::ToggleListItem* enabledToggle;
|
||||
u8 frameCounter = 60;
|
||||
|
||||
@@ -10,14 +10,18 @@ ValueChoiceGui::ValueChoiceGui(std::uint32_t selectedValue,
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds,
|
||||
bool enableThresholds,
|
||||
std::map<std::uint32_t, std::string> labels)
|
||||
std::map<std::uint32_t, std::string> labels,
|
||||
std::vector<NamedValue> namedValues,
|
||||
bool showDefaultValue)
|
||||
: selectedValue(selectedValue),
|
||||
range(range),
|
||||
categoryName(categoryName),
|
||||
listener(listener),
|
||||
thresholds(thresholds),
|
||||
enableThresholds(enableThresholds),
|
||||
labels(labels)
|
||||
labels(labels),
|
||||
namedValues(namedValues),
|
||||
showDefaultValue(showDefaultValue)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -28,15 +32,13 @@ ValueChoiceGui::~ValueChoiceGui()
|
||||
std::string ValueChoiceGui::formatValue(std::uint32_t value)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
if (value == 0) {
|
||||
return VALUE_DEFAULT_TEXT;
|
||||
if(showDefaultValue) {
|
||||
if (value == 0) {
|
||||
return VALUE_DEFAULT_TEXT;
|
||||
}
|
||||
}
|
||||
|
||||
double displayValue = static_cast<double>(value) / static_cast<double>(range.divisor);
|
||||
|
||||
oss << std::fixed << std::setprecision(range.decimalPlaces) << displayValue;
|
||||
|
||||
if (!range.suffix.empty()) {
|
||||
oss << " " << range.suffix;
|
||||
}
|
||||
@@ -45,6 +47,10 @@ std::string ValueChoiceGui::formatValue(std::uint32_t value)
|
||||
|
||||
int ValueChoiceGui::getSafetyLevel(std::uint32_t value)
|
||||
{
|
||||
if(thresholds.warning == 0 && thresholds.danger == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (value > thresholds.danger) {
|
||||
return 2;
|
||||
}
|
||||
@@ -60,15 +66,12 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
|
||||
if (selected) {
|
||||
text += " \uE14B";
|
||||
}
|
||||
|
||||
std::string rightText = "";
|
||||
auto it = labels.find(value);
|
||||
if (it != labels.end()) {
|
||||
rightText = it->second;
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(text, rightText, false);
|
||||
|
||||
switch (safety)
|
||||
{
|
||||
case 0:
|
||||
@@ -84,10 +87,8 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
}
|
||||
|
||||
if (!rightText.empty())
|
||||
listItem->setValueColor(tsl::Color(180, 180, 180, 255));
|
||||
|
||||
listItem->setClickListener([this, value](u64 keys)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
|
||||
@@ -98,7 +99,45 @@ tsl::elm::ListItem* ValueChoiceGui::createValueListItem(std::uint32_t value, boo
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return listItem;
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* ValueChoiceGui::createNamedValueListItem(const NamedValue& namedValue, bool selected, int safety)
|
||||
{
|
||||
std::string text = namedValue.name;
|
||||
if (selected) {
|
||||
text += " \uE14B";
|
||||
}
|
||||
|
||||
tsl::elm::ListItem* listItem = new tsl::elm::ListItem(text, namedValue.rightText, false);
|
||||
switch (safety)
|
||||
{
|
||||
case 0:
|
||||
listItem->setTextColor(tsl::Color(255, 255, 255, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 255, 255, 255));
|
||||
break;
|
||||
case 1:
|
||||
listItem->setTextColor(tsl::Color(255, 165, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 165, 0, 255));
|
||||
break;
|
||||
case 2:
|
||||
listItem->setTextColor(tsl::Color(255, 0, 0, 255));
|
||||
listItem->setValueColor(tsl::Color(255, 0, 0, 255));
|
||||
break;
|
||||
}
|
||||
if (!namedValue.rightText.empty())
|
||||
listItem->setValueColor(tsl::Color(180, 180, 180, 255));
|
||||
|
||||
listItem->setClickListener([this, value = namedValue.value](u64 keys)
|
||||
{
|
||||
if ((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) {
|
||||
if (this->listener(value)) {
|
||||
tsl::goBack();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return listItem;
|
||||
}
|
||||
|
||||
@@ -107,15 +146,25 @@ void ValueChoiceGui::listUI()
|
||||
if (!categoryName.empty()) {
|
||||
this->listElement->addItem(new tsl::elm::CategoryHeader(categoryName));
|
||||
}
|
||||
|
||||
this->listElement->addItem(this->createValueListItem(0, this->selectedValue == 0, 0));
|
||||
|
||||
for (std::uint32_t value = range.min; value <= range.max; value += range.step)
|
||||
{
|
||||
int safety = getSafetyLevel(value);
|
||||
bool selected = (value == this->selectedValue);
|
||||
this->listElement->addItem(this->createValueListItem(value, selected, safety));
|
||||
|
||||
for (const auto& namedValue : namedValues) {
|
||||
int safety = enableThresholds ? getSafetyLevel(namedValue.value) : 0;
|
||||
bool selected = (namedValue.value == this->selectedValue);
|
||||
this->listElement->addItem(this->createNamedValueListItem(namedValue, selected, safety));
|
||||
}
|
||||
|
||||
|
||||
if (showDefaultValue) {
|
||||
this->listElement->addItem(this->createValueListItem(0, this->selectedValue == 0, 0));
|
||||
}
|
||||
|
||||
if (namedValues.empty()) {
|
||||
for (std::uint32_t value = range.min; value <= range.max; value += range.step)
|
||||
{
|
||||
int safety = getSafetyLevel(value);
|
||||
bool selected = (value == this->selectedValue);
|
||||
this->listElement->addItem(this->createValueListItem(value, selected, safety));
|
||||
}
|
||||
}
|
||||
|
||||
this->listElement->jumpToItem("", "\uE14B");
|
||||
}
|
||||
@@ -1,40 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "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 <functional>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "base_menu_gui.h"
|
||||
|
||||
using ValueChoiceListener = std::function<bool(std::uint32_t value)>;
|
||||
|
||||
#define VALUE_DEFAULT_TEXT "Default"
|
||||
|
||||
struct ValueRange {
|
||||
@@ -44,10 +16,8 @@ struct ValueRange {
|
||||
std::string suffix;
|
||||
std::uint32_t divisor;
|
||||
int decimalPlaces;
|
||||
|
||||
ValueRange()
|
||||
: min(0), max(0), step(1), suffix(""), divisor(1), decimalPlaces(0) {}
|
||||
|
||||
ValueRange(std::uint32_t min, std::uint32_t max, std::uint32_t step,
|
||||
const std::string& suffix = "", std::uint32_t divisor = 1, int decimalPlaces = 0)
|
||||
: min(min), max(max), step(step), suffix(suffix),
|
||||
@@ -57,11 +27,19 @@ struct ValueRange {
|
||||
struct ValueThresholds {
|
||||
std::uint32_t warning;
|
||||
std::uint32_t danger;
|
||||
|
||||
ValueThresholds(std::uint32_t warning = 0, std::uint32_t danger = 0)
|
||||
: warning(warning), danger(danger) {}
|
||||
};
|
||||
|
||||
struct NamedValue {
|
||||
std::string name;
|
||||
std::uint32_t value;
|
||||
std::string rightText;
|
||||
|
||||
NamedValue(const std::string& name, std::uint32_t value, const std::string& rightText = "")
|
||||
: name(name), value(value), rightText(rightText) {}
|
||||
};
|
||||
|
||||
class ValueChoiceGui : public BaseMenuGui
|
||||
{
|
||||
protected:
|
||||
@@ -71,14 +49,16 @@ protected:
|
||||
ValueChoiceListener listener;
|
||||
ValueThresholds thresholds;
|
||||
bool enableThresholds;
|
||||
|
||||
// NEW — map of value → right-side text (like version numbers)
|
||||
std::map<std::uint32_t, std::string> labels;
|
||||
|
||||
|
||||
std::vector<NamedValue> namedValues;
|
||||
bool showDefaultValue = true;
|
||||
|
||||
tsl::elm::ListItem* createValueListItem(std::uint32_t value, bool selected, int safety);
|
||||
tsl::elm::ListItem* createNamedValueListItem(const NamedValue& namedValue, bool selected, int safety);
|
||||
std::string formatValue(std::uint32_t value);
|
||||
int getSafetyLevel(std::uint32_t value);
|
||||
|
||||
|
||||
public:
|
||||
ValueChoiceGui(std::uint32_t selectedValue,
|
||||
const ValueRange& range,
|
||||
@@ -86,8 +66,30 @@ public:
|
||||
ValueChoiceListener listener,
|
||||
const ValueThresholds& thresholds = ValueThresholds(),
|
||||
bool enableThresholds = false,
|
||||
std::map<std::uint32_t, std::string> labels = {});
|
||||
std::map<std::uint32_t, std::string> labels = {},
|
||||
std::vector<NamedValue> namedValues = {},
|
||||
bool showDefaultValue = true);
|
||||
~ValueChoiceGui();
|
||||
|
||||
|
||||
void addNamedValue(const std::string& name, std::uint32_t value, const std::string& rightText = "")
|
||||
{
|
||||
namedValues.emplace_back(name, value, rightText);
|
||||
}
|
||||
|
||||
void addNamedValues(const std::vector<NamedValue>& values)
|
||||
{
|
||||
namedValues.insert(namedValues.end(), values.begin(), values.end());
|
||||
}
|
||||
|
||||
void clearNamedValues()
|
||||
{
|
||||
namedValues.clear();
|
||||
}
|
||||
|
||||
void setShowDefaultValue(bool show)
|
||||
{
|
||||
showDefaultValue = show;
|
||||
}
|
||||
|
||||
void listUI() override;
|
||||
};
|
||||
@@ -599,7 +599,7 @@ void ClockManager::GetKipData() {
|
||||
}
|
||||
|
||||
SysClkConfigValueList configValues;
|
||||
memset(&configValues, 0, sizeof(configValues));
|
||||
this->config->GetConfigValues(&configValues);
|
||||
|
||||
configValues.values[KipConfigValue_custRev] = cust_get_cust_rev(&table);
|
||||
configValues.values[KipConfigValue_mtcConf] = cust_get_mtc_conf(&table);
|
||||
|
||||
Reference in New Issue
Block a user