From e34e69bfa56a5f7aef8bf003c685a3c79fd6d74b Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Wed, 28 Sep 2022 17:48:10 +0200 Subject: 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) --- camlibs/ptp2/config.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'camlibs') 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;iFORM.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; -- cgit v1.2.1