Skip to content

Commit

Permalink
Get latest values for enabled DDC/CI features
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderfrangos committed Dec 17, 2023
1 parent 2787566 commit 6dad0ca
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/Monitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ getAllMonitors = async (ddcciMethod = "default") => {
const brightness = await checkVCP(id, parseInt(brightnessType))
if(brightness) {
ddcciInfo.brightnessValues = brightness
features[brightnessType] = brightness
}

ddcciInfo.brightnessRaw = ddcciInfo.brightnessValues[0]
Expand Down Expand Up @@ -501,33 +502,28 @@ checkMonitorFeatures = async (monitor, skipCache = false) => {
} catch(e) {
console.log("Couldn't get capabilities report for monitor " + monitor)
}

// This part is flaky, so we'll do it slowly
// Capabilities report allows us to skip this, thankfully
features["0x10"] = await checkVCPIfEnabled(monitor, 0x10, "luminance", skipCache)
features["0x13"] = await checkVCPIfEnabled(monitor, 0x13, "brightness", skipCache)
features["0x12"] = await checkVCPIfEnabled(monitor, 0x12, "contrast", skipCache)
features["0xD6"] = await checkVCPIfEnabled(monitor, 0xD6, "powerState", skipCache)
features["0x62"] = await checkVCPIfEnabled(monitor, 0x62, "volume", skipCache)

// Get alternative brightness VCP per monitor
if(ddcBrightnessVCPs[hwid[1]]) {
features[ddcBrightnessVCPs[hwid[1]]] = await checkVCPIfEnabled(monitor, parseInt(ddcBrightnessVCPs[hwid[1]]), "altBrightness", skipCache)
}

// Get custom DDC/CI features
const settingsFeatures = settings?.monitorFeatures?.[hwid[1]]
if(settingsFeatures) {
for(const vcp in settingsFeatures) {
if(vcp == "0x10" || vcp == "0x12" || vcp == "0x13" || vcp == "0x62" || vcp == "0xD6") {
continue; // Skip if built-in feature
if(ddcBrightnessVCPs[hwid[1]] && vcp == ddcBrightnessVCPs[hwid[1]]) {
continue; // Skip if custom brightness
}
if(settingsFeatures[vcp]) {
features[vcp] = await checkVCPIfEnabled(monitor, parseInt(vcp), vcp, skipCache)
features[vcp] = await checkVCPIfEnabled(monitor, parseInt(vcp), vcp, true)
}
}
}

// This part is flaky, so we'll do it slowly
// Capabilities report allows us to skip this, thankfully
features["0x10"] = await checkVCPIfEnabled(monitor, 0x10, "luminance", skipCache)
features["0x13"] = await checkVCPIfEnabled(monitor, 0x13, "brightness", skipCache)
features["0x12"] = await checkVCPIfEnabled(monitor, 0x12, "contrast", skipCache)
features["0xD6"] = await checkVCPIfEnabled(monitor, 0xD6, "powerState", skipCache)
features["0x62"] = await checkVCPIfEnabled(monitor, 0x62, "volume", skipCache)

} catch (e) {
console.log(e)
}
Expand Down Expand Up @@ -618,6 +614,20 @@ getBrightnessDDC = (monitorObj) => {
monitor = applyRemap(monitor)
// Unnormalize brightness
monitor.brightness = normalizeBrightness(monitor.brightness, true, monitor.min, monitor.max)

// Get custom DDC/CI features
const settingsFeatures = settings?.monitorFeatures?.[monitor.hwid[1]]
if(settingsFeatures) {
for(const vcp in settingsFeatures) {
if(vcp == monitor.brightnessType) {
continue; // Skip brightness
}
if(settingsFeatures[vcp]) {
monitor.features[vcp] = await checkVCP(monitor.id, parseInt(vcp))
}
}
}

clearTimeout(timeout)
resolve(monitor)

Expand Down Expand Up @@ -684,9 +694,9 @@ async function checkVCPIfEnabled(monitor, code, setting, skipCache = false) {
const hwid = monitor.split("#")
const userEnabledFeature = settings?.monitorFeatures?.[hwid[1]]?.[vcpString]
const isInReport = monitorReports[monitor]?.[vcpString] ? true : false
const hasReport = monitorReports[monitor] ? true : false
const hasReport = monitorReports[monitor] && Object.keys(monitorReports[monitor])?.length > 0 ? true : false

if (!skipCache && hasReport && !isInReport) return false;
if (hasReport && !isInReport) return false;

// If we previously saw that a feature was supported, we shouldn't have to check again.
if ((!skipCache || !userEnabledFeature) && vcpCache[monitor] && vcpCache[monitor]["vcp_" + vcpString]) return vcpCache[monitor]["vcp_" + vcpString];
Expand Down

0 comments on commit 6dad0ca

Please sign in to comment.