diff options
author | Marcus Meissner <marcus@jet.franken.de> | 2022-09-28 17:48:10 +0200 |
---|---|---|
committer | Marcus Meissner <marcus@jet.franken.de> | 2022-09-28 17:48:10 +0200 |
commit | e34e69bfa56a5f7aef8bf003c685a3c79fd6d74b (patch) | |
tree | f236204a5628812e1790c7651bce4104f147f9f8 /camlibs | |
parent | 7605d4ab2b65d209bc94b6ae3fd0d26daf14a3f2 (diff) | |
download | libgphoto2-e34e69bfa56a5f7aef8bf003c685a3c79fd6d74b.tar.gz |
some Canons have an enum from 0-3 for the battery level instead of going from 0 to 100.
Detect and handle this case. (fixes https://github.com/gphoto/gphoto2/issues/541)
Diffstat (limited to 'camlibs')
-rw-r--r-- | camlibs/ptp2/config.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/camlibs/ptp2/config.c b/camlibs/ptp2/config.c index d319eaa7d..4ac6b88ab 100644 --- a/camlibs/ptp2/config.c +++ b/camlibs/ptp2/config.c @@ -7075,6 +7075,21 @@ _get_BatteryLevel(CONFIG_GET_ARGS) { return GP_ERROR; gp_widget_new (GP_WIDGET_TEXT, _(menu->label), widget); + if (dpd->FormFlag == PTP_DPFF_Enumeration) { + unsigned int i, highest = 0, factor = 1; + + gp_widget_set_name (*widget, menu->name); + + /* This is for Canon ... they have enums [0,1,2,3] and [0,25,50,75,100] .. For the 0-3 enum, multiply by 33 */ + for (i=0;i<dpd->FORM.Enum.NumberOfValues;i++) { + if (dpd->FORM.Enum.SupportedValue[i].u8 > highest) + highest = dpd->FORM.Enum.SupportedValue[i].u8; + } + if (highest == 3) factor = 33; + + sprintf (buffer, "%d%%", dpd->CurrentValue.u8 * factor); + return gp_widget_set_value(*widget, buffer); + } if (dpd->FormFlag == PTP_DPFF_Range) { gp_widget_set_name (*widget, menu->name); start = dpd->FORM.Range.MinimumValue.u8; |