backlight + ddc - fix and improve several small things

1. use max valu in the get and store it once a get has been done so it
will get backlight level right on unsuaul monitors that do not use
0->100
2. detect as an error dinfing 2 screesn with the same edid and log it
3. use ddca_enable_sleep_suppression() to try speed up things a bit to
sleep less inside ddcutil
This commit is contained in:
Carsten Haitzler 2020-11-26 00:38:01 +00:00
parent f190df472a
commit c4e76ed593
2 changed files with 27 additions and 7 deletions

View File

@ -9,6 +9,7 @@ typedef struct
double from_val, to_val;
Ecore_Animator *anim;
Ecore_Timer *retry_timer;
int ddc_max;
int retries;
} Backlight_Device;
@ -81,17 +82,18 @@ static void
_backlight_system_ddc_get_cb(void *data, const char *params)
{
char edid[257];
int id = -1, val = -1;
int id = -1, val = -1, max = -1;
double fval;
Backlight_Device *bd = data;
if (!params) return;
if (sscanf(params, "%256s %i %i", edid, &id, &val) != 3) return;
if (sscanf(params, "%256s %i %i %i", edid, &id, &val, &max) != 4) return;
if (!bd->edid) return;
if (!!strncmp(bd->edid, edid, strlen(edid))) return;
e_system_handler_del("ddc-val-get", _backlight_system_ddc_get_cb, bd);
if (val < 0) fval = -1.0;
else fval = (double)val / 100.0;
bd->ddc_max = max;
if ((fabs(fval - bd->val) >= DBL_EPSILON) || (val == -1))
{
bd->val = fval;
@ -243,8 +245,12 @@ _backlight_devices_device_set(Backlight_Device *bd, double val)
#endif
if (!strncmp(bd->dev, "ddc:", 4))
{
double fval;
fprintf(stderr, "BL: ddc bklight %1.3f @ %1.3f\n", bd->val, ecore_time_get());
e_system_send("ddc-val-set", "%s %i %i", bd->dev + 4, 0x10, (int)(bd->val * 100.0)); // backlight val in e_system_ddc.c
if (bd->ddc_max) fval = bd->val * (double)bd->ddc_max;
else fval = bd->val * 100.0;
e_system_send("ddc-val-set", "%s %i %i", bd->dev + 4, 0x10, (int)(fval)); // backlight val in e_system_ddc.c
ecore_event_add(E_EVENT_BACKLIGHT_CHANGE, NULL, NULL, NULL);
}
else
@ -520,7 +526,9 @@ _backlight_system_ddc_list_cb(void *data EINA_UNUSED, const char *params)
{
const char *p = params;
char dev[257], buf[343];
Eina_Hash *tmphash;
tmphash = eina_hash_string_superfast_new(NULL);
e_system_handler_del("ddc-list", _backlight_system_ddc_list_cb, NULL);
while ((p) && (*p))
{
@ -531,10 +539,14 @@ _backlight_system_ddc_list_cb(void *data EINA_UNUSED, const char *params)
bl_devs = eina_list_append
(bl_devs, eina_stringshare_add(buf));
_backlight_devices_edid_register(buf, dev);
if (eina_hash_find(tmphash, dev))
printf("BL: DDC ERROR: You have multiple DDC screens with the same EDID [%s] - this will lead to weirdness.\n", dev);
eina_hash_add(tmphash, dev, dev);
if (*p != ' ') break;
}
else break;
}
eina_hash_free(tmphash);
_backlight_devices_pending_done();
}

View File

@ -198,6 +198,8 @@ struct {
(DDCA_Display_Handle ddca_dh);
void (*ddca_set_global_sleep_multiplier)
(double multiplier);
bool (*ddca_enable_sleep_suppression)
(bool newval);
} ddc_func;
static DDCA_Display_Info_List *ddc_dlist = NULL;
@ -325,6 +327,7 @@ _ddc_init(void)
ddc_func._x = dlsym(ddc_lib, #_x); \
} while (0)
SYM_OPT(ddca_set_global_sleep_multiplier);
SYM_OPT(ddca_enable_sleep_suppression);
// brute force modprobe this as it likely is needed - probe will fail
// if this doesn't work or find devices anyway
@ -333,6 +336,10 @@ _ddc_init(void)
if (!_ddc_probe()) return EINA_FALSE;
// try improve performance by limiting sleeps in ddcutil
if (ddc_func.ddca_enable_sleep_suppression)
ddc_func.ddca_enable_sleep_suppression(true);
return EINA_TRUE;
}
@ -484,7 +491,7 @@ _do_val_get(Ecore_Thread *th, const char *edid, int id)
{
Dev *d;
Req *r;
int screen, val;
int screen, val, max;
char buf[512];
DDCA_Non_Table_Vcp_Value valrec;
@ -505,15 +512,16 @@ _do_val_get(Ecore_Thread *th, const char *edid, int id)
if (ddc_func.ddca_get_non_table_vcp_value
(ddc_dh[screen], id, &valrec) == 0)
{
max = valrec.ml | valrec.mh << 8;
val = valrec.sl | (valrec.sh << 8);
fprintf(stderr, "DDC: get ok %s 0x%02x = %i\n", edid, id, val);
snprintf(buf, sizeof(buf), "%s %i %i", edid, id, val);
fprintf(stderr, "DDC: get ok %s 0x%02x val=%i max=%i\n", edid, id, val, max);
snprintf(buf, sizeof(buf), "%s %i %i %i", edid, id, val, max);
}
else
{
fprintf(stderr, "DDC: get fail %s 0x%02x\n", edid, id);
err:
snprintf(buf, sizeof(buf), "%s %i -1", edid, id);
snprintf(buf, sizeof(buf), "%s %i -1 -1", edid, id);
}
r = _req_alloc("ddc-val-get", buf);
if (r) ecore_thread_feedback(th, r);