Brightness (macOS): code refactor

This commit is contained in:
李通洲 2023-08-09 09:00:29 +08:00
parent 7598e57704
commit 3acbe84570
No known key found for this signature in database
GPG Key ID: 269AD4F5325A22A3
3 changed files with 26 additions and 23 deletions

View File

@ -1,6 +1,7 @@
#include "brightness.h"
#include "detection/displayserver/displayserver.h"
#include "util/apple/cf_helpers.h"
#include "util/edidHelper.h"
#include <CoreGraphics/CoreGraphics.h>
@ -34,26 +35,6 @@ static const char* detectWithDisplayServices(const FFDisplayServerResult* displa
return NULL;
}
static void getNameFromEdid(uint8_t edid[128], FFstrbuf* name)
{
// https://github.com/jinksong/read_edid/blob/master/parse-edid/parse-edid.c
for (uint32_t i = 0x36; i < 0x7E; i += 0x12)
{ // read through descriptor blocks...
if (edid[i] == 0x00)
{ // not a timing descriptor
if (edid[i+3] == 0xfc)
{ // Model Name tag
for (uint32_t j = 0; j < 13; j++)
{
if (edid[i + 5 + j] == 0x0a)
return;
ffStrbufAppendC(name, (char) edid[i + 5 + j]);
}
}
}
}
}
// https://github.com/waydabber/m1ddc
// Works for Apple Silicon and USB-C adapter connection ( but not HTMI )
static const char* detectWithDdcci(FFlist* result)
@ -120,7 +101,7 @@ static const char* detectWithDdcci(FFlist* result)
uint8_t edid[128] = {};
if (IOAVServiceReadI2C(service, 0x50, 0x00, edid, sizeof(edid)) == KERN_SUCCESS)
getNameFromEdid(edid, &brightness->name);
ffEdidGetName(edid, &brightness->name);
}
}

View File

@ -1,8 +1,28 @@
#include "edidHelper.h"
void ffEdidGetNativeResolution(uint8_t edid[128], uint32_t* width, uint32_t* height)
void ffEdidGetPhycialDisplay(uint8_t edid[128], uint32_t* width, uint32_t* height)
{
const int dtd = 54;
*width = (((uint32_t) edid[dtd + 4] >> 4) << 8) | edid[dtd + 2];
*height = (((uint32_t) edid[dtd + 7] >> 4) << 8) | edid[dtd + 5];
}
void ffEdidGetName(uint8_t edid[128], FFstrbuf* name)
{
// https://github.com/jinksong/read_edid/blob/master/parse-edid/parse-edid.c
for (uint32_t i = 0x36; i < 0x7E; i += 0x12)
{ // read through descriptor blocks...
if (edid[i] == 0x00)
{ // not a timing descriptor
if (edid[i+3] == 0xfc)
{ // Model Name tag
for (uint32_t j = 0; j < 13; j++)
{
if (edid[i + 5 + j] == 0x0a)
return;
ffStrbufAppendC(name, (char) edid[i + 5 + j]);
}
}
}
}
}

View File

@ -4,7 +4,9 @@
#define FF_INCLUDED_EDID_HELPER_H
#include <stdint.h>
#include "util/FFstrbuf.h"
void ffEdidGetNativeResolution(uint8_t edid[128], uint32_t* width, uint32_t* height);
void ffEdidGetPhycialDisplay(uint8_t edid[128], uint32_t* width, uint32_t* height);
void ffEdidGetName(uint8_t edid[128], FFstrbuf* name);
#endif