mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-01 10:32:35 +01:00
Brightness: refactor
This commit is contained in:
@@ -9,4 +9,17 @@ typedef struct FFBrightnessResult {
|
||||
bool builtin;
|
||||
} FFBrightnessResult;
|
||||
|
||||
enum {
|
||||
FF_DDC_EDID_ADDR = 0x50u,
|
||||
FF_DDC_CI_ADDR = 0x37u,
|
||||
FF_DDC_CI_WRITE_ADDR = FF_DDC_CI_ADDR << 1,
|
||||
FF_DDC_CI_READ_ADDR = FF_DDC_CI_WRITE_ADDR | 1,
|
||||
FF_DDC_CI_VCP_COMMAND = 0x51u,
|
||||
FF_DDC_CI_GET_VCP = 0x01u,
|
||||
FF_DDC_CI_SET_VCP = 0x03u,
|
||||
FF_DDC_CI_COMMAND_PACKET = 0x80u,
|
||||
FF_DDC_CI_LUMINANCE_OPCODE = 0x10u,
|
||||
};
|
||||
#define FF_DDC_CI_MAKE_HEADER(len) (FF_DDC_CI_COMMAND_PACKET | ((len) & 0x7F))
|
||||
|
||||
const char* ffDetectBrightness(FFBrightnessOptions* options, FFlist* result); // list of FFBrightnessResult
|
||||
|
||||
@@ -85,17 +85,17 @@ static const char* detectWithDdcci(FF_A_UNUSED const FFDisplayServerResult* disp
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t i2cIn[4] = { 0x82, 0x01, 0x10 /* luminance */ };
|
||||
i2cIn[3] = 0x6e ^ i2cIn[0] ^ i2cIn[1] ^ i2cIn[2];
|
||||
uint8_t i2cIn[4] = { FF_DDC_CI_MAKE_HEADER(2), FF_DDC_CI_GET_VCP, FF_DDC_CI_LUMINANCE_OPCODE };
|
||||
i2cIn[3] = FF_DDC_CI_WRITE_ADDR ^ i2cIn[0] ^ i2cIn[1] ^ i2cIn[2];
|
||||
|
||||
for (uint32_t i = 0; i < 2; ++i) {
|
||||
IOAVServiceWriteI2C(service, 0x37, 0x51, i2cIn, ARRAY_SIZE(i2cIn));
|
||||
usleep(options->ddcciSleep * 1000);
|
||||
IOAVServiceWriteI2C(service, FF_DDC_CI_ADDR, FF_DDC_CI_VCP_COMMAND, i2cIn, ARRAY_SIZE(i2cIn));
|
||||
ffTimeSleep(options->ddcciSleep);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t i2cOut[12] = {};
|
||||
if (IOAVServiceReadI2C(service, 0x37, 0x51, i2cOut, ARRAY_SIZE(i2cOut)) == KERN_SUCCESS) {
|
||||
if (IOAVServiceReadI2C(service, FF_DDC_CI_ADDR, FF_DDC_CI_VCP_COMMAND, i2cOut, ARRAY_SIZE(i2cOut)) == KERN_SUCCESS) {
|
||||
if (i2cOut[2] != 0x02 || i2cOut[3] != 0x00) {
|
||||
continue;
|
||||
}
|
||||
@@ -185,18 +185,18 @@ static const char* detectWithDdcci(const FFDisplayServerResult* displayServer, F
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t i2cIn[] = { 0x51, 0x82, 0x01, 0x10 /* luminance */, 0 };
|
||||
i2cIn[4] = 0x6E ^ i2cIn[0] ^ i2cIn[1] ^ i2cIn[2] ^ i2cIn[3];
|
||||
uint8_t i2cIn[] = { FF_DDC_CI_VCP_COMMAND, FF_DDC_CI_MAKE_HEADER(2), FF_DDC_CI_GET_VCP, FF_DDC_CI_LUMINANCE_OPCODE, 0 };
|
||||
i2cIn[4] = FF_DDC_CI_WRITE_ADDR ^ i2cIn[0] ^ i2cIn[1] ^ i2cIn[2] ^ i2cIn[3];
|
||||
|
||||
IOI2CRequest request = {
|
||||
.commFlags = kNilOptions,
|
||||
.sendAddress = 0x6e,
|
||||
.sendAddress = FF_DDC_CI_WRITE_ADDR,
|
||||
.sendTransactionType = kIOI2CSimpleTransactionType,
|
||||
.sendBuffer = (vm_address_t) i2cIn,
|
||||
.sendBytes = ARRAY_SIZE(i2cIn),
|
||||
.minReplyDelay = options->ddcciSleep * 1000ULL,
|
||||
.replyAddress = 0x6F,
|
||||
.replySubAddress = 0x51,
|
||||
.replyAddress = FF_DDC_CI_READ_ADDR,
|
||||
.replySubAddress = FF_DDC_CI_VCP_COMMAND,
|
||||
.replyTransactionType = transactionType,
|
||||
.replyBytes = ARRAY_SIZE(i2cOut),
|
||||
.replyBuffer = (vm_address_t) i2cOut,
|
||||
|
||||
@@ -31,12 +31,12 @@ const char* detectWithDdcci(FF_A_UNUSED FFBrightnessOptions* options, FFlist* re
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t i2cIn[] = { 0x51, 0x82, 0x01, 0x10 /* luminance */, 0 };
|
||||
i2cIn[4] = 0x6E ^ i2cIn[0] ^ i2cIn[1] ^ i2cIn[2] ^ i2cIn[3];
|
||||
uint8_t i2cIn[] = { FF_DDC_CI_VCP_COMMAND, FF_DDC_CI_MAKE_HEADER(2), FF_DDC_CI_GET_VCP, FF_DDC_CI_LUMINANCE_OPCODE, 0 };
|
||||
i2cIn[4] = FF_DDC_CI_WRITE_ADDR ^ i2cIn[0] ^ i2cIn[1] ^ i2cIn[2] ^ i2cIn[3];
|
||||
|
||||
int ret = ioctl(fd, I2CRDWR, &(struct iic_rdwr_data) {
|
||||
.msgs = &(struct iic_msg) {
|
||||
.slave = 0x6E,
|
||||
.slave = FF_DDC_CI_WRITE_ADDR,
|
||||
.flags = IIC_M_WR,
|
||||
.len = ARRAY_SIZE(i2cIn),
|
||||
.buf = i2cIn
|
||||
@@ -49,11 +49,11 @@ const char* detectWithDdcci(FF_A_UNUSED FFBrightnessOptions* options, FFlist* re
|
||||
}
|
||||
|
||||
ffTimeSleep(options->ddcciSleep);
|
||||
|
||||
|
||||
uint8_t i2cOut[12] = {};
|
||||
ret = ioctl(fd, I2CRDWR, &(struct iic_rdwr_data) {
|
||||
.msgs = &(struct iic_msg) {
|
||||
.slave = 0x6F,
|
||||
.slave = FF_DDC_CI_READ_ADDR, // LSB will be overridden by kernel to set read bit
|
||||
.flags = IIC_M_RD,
|
||||
.len = ARRAY_SIZE(i2cOut),
|
||||
.buf = i2cOut
|
||||
|
||||
@@ -159,7 +159,7 @@ static const char* detectWithDdcci(const FFDisplayServerResult* displayServer, F
|
||||
NTSTATUS monitorStatus = ffGetPhysicalMonitors(&deviceName, 1, &monitorCount, &physicalMonitor);
|
||||
if (NT_SUCCESS(monitorStatus) && monitorCount >= 1) {
|
||||
DWORD curr = 0, max = 0;
|
||||
if (NT_SUCCESS(ffDDCCIGetVCPFeature(physicalMonitor, 0x10 /* luminance */, NULL, &curr, &max))) {
|
||||
if (NT_SUCCESS(ffDDCCIGetVCPFeature(physicalMonitor, FF_DDC_CI_LUMINANCE_OPCODE, NULL, &curr, &max))) {
|
||||
FFBrightnessResult* brightness = FF_LIST_ADD(FFBrightnessResult, *result);
|
||||
if (display->name.length > 0) {
|
||||
ffStrbufInitCopy(&brightness->name, &display->name);
|
||||
|
||||
Reference in New Issue
Block a user