Skip to content

Commit

Permalink
quirks: add quirks_get_double()
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Jul 11, 2018
1 parent 0021f9e commit 1cc9f44
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/quirks.c
Expand Up @@ -54,6 +54,7 @@ enum property_type {
PT_BOOL,
PT_DIMENSION,
PT_RANGE,
PT_DOUBLE,
};

/**
Expand All @@ -74,6 +75,7 @@ struct property {
char *s;
struct quirk_dimensions dim;
struct quirk_range range;
double d;
} value;
};

Expand Down Expand Up @@ -1434,6 +1436,24 @@ quirks_get_uint32(struct quirks *q, enum quirk which, uint32_t *val)
return true;
}

bool
quirks_get_double(struct quirks *q, enum quirk which, double *val)
{
struct property *p;

if (!q)
return false;

p = quirk_find_prop(q, which);
if (!p)
return false;

assert(p->type == PT_DOUBLE);
*val = p->value.d;

return true;
}

bool
quirks_get_string(struct quirks *q, enum quirk which, char **val)
{
Expand Down
13 changes: 13 additions & 0 deletions src/quirks.h
Expand Up @@ -216,6 +216,19 @@ quirks_get_int32(struct quirks *q,
enum quirk which,
int32_t *val);

/**
* Get the value of the given quirk, as double.
* This function will assert if the quirk type does not match the
* requested type. If the quirk is not set for this device, val is
* unchanged.
*
* @return true if the quirk value is valid, false otherwise.
*/
bool
quirks_get_double(struct quirks *q,
enum quirk which,
double *val);

/**
* Get the value of the given quirk, as string.
* This function will assert if the quirk type does not match the
Expand Down
1 change: 1 addition & 0 deletions tools/shared.c
Expand Up @@ -630,6 +630,7 @@ tools_list_device_quirks(struct quirks_context *ctx,
struct quirk_range r;
uint32_t v;
char *s;
double d;

if (!quirks_has_quirk(quirks, *q))
continue;
Expand Down

0 comments on commit 1cc9f44

Please sign in to comment.