2023-08-09 16:31:24 +08:00
|
|
|
#include "monitor.h"
|
2023-08-08 20:23:26 +08:00
|
|
|
|
|
|
|
|
#include "common/io/io.h"
|
|
|
|
|
#include "util/edidHelper.h"
|
|
|
|
|
#include "util/stringUtils.h"
|
|
|
|
|
|
|
|
|
|
#include <dirent.h>
|
2023-08-12 00:27:05 +08:00
|
|
|
#include <sys/stat.h>
|
2023-08-08 20:23:26 +08:00
|
|
|
|
2023-08-09 16:31:24 +08:00
|
|
|
const char* ffDetectMonitor(FFlist* results)
|
2023-08-08 20:23:26 +08:00
|
|
|
{
|
|
|
|
|
const char* drmDirPath = "/sys/class/drm/";
|
|
|
|
|
|
|
|
|
|
DIR* dirp = opendir(drmDirPath);
|
|
|
|
|
if(dirp == NULL)
|
|
|
|
|
return "opendir(drmDirPath) == NULL";
|
|
|
|
|
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY drmDir = ffStrbufCreateA(64);
|
|
|
|
|
ffStrbufAppendS(&drmDir, drmDirPath);
|
|
|
|
|
|
|
|
|
|
uint32_t drmDirLength = drmDir.length;
|
|
|
|
|
|
|
|
|
|
struct dirent* entry;
|
|
|
|
|
while((entry = readdir(dirp)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if(ffStrEquals(entry->d_name, ".") || ffStrEquals(entry->d_name, ".."))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(&drmDir, entry->d_name);
|
|
|
|
|
ffStrbufAppendS(&drmDir, "/edid");
|
|
|
|
|
|
2023-08-15 19:19:26 +08:00
|
|
|
uint8_t edidData[512];
|
|
|
|
|
ssize_t edidLength = ffReadFileData(drmDir.chars, sizeof(edidData), edidData);
|
|
|
|
|
if(edidLength <= 0 || edidLength % 128 != 0)
|
2023-08-08 20:23:26 +08:00
|
|
|
{
|
|
|
|
|
ffStrbufSubstrBefore(&drmDir, drmDirLength);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t width, height;
|
2023-08-09 13:25:22 +08:00
|
|
|
ffEdidGetPhysicalResolution(edidData, &width, &height);
|
2023-08-08 20:23:26 +08:00
|
|
|
if (width != 0 && height != 0)
|
|
|
|
|
{
|
2023-08-09 16:31:24 +08:00
|
|
|
FFMonitorResult* display = (FFMonitorResult*) ffListAdd(results);
|
2023-08-08 20:23:26 +08:00
|
|
|
display->width = width;
|
|
|
|
|
display->height = height;
|
2023-08-10 10:15:02 +08:00
|
|
|
ffStrbufInit(&display->name);
|
|
|
|
|
ffEdidGetName(edidData, &display->name);
|
2023-08-09 13:25:22 +08:00
|
|
|
ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight);
|
2023-08-15 19:19:26 +08:00
|
|
|
display->hdrCompatible = ffEdidGetHdrCompatible(edidData, (uint32_t) edidLength);
|
2023-08-08 20:23:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufSubstrBefore(&drmDir, drmDirLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir(dirp);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|