diff --git a/libx52/libx52.h b/libx52/libx52.h index 53dc779..806c760 100644 --- a/libx52/libx52.h +++ b/libx52/libx52.h @@ -192,7 +192,8 @@ int libx52_set_led_state(libx52_device *x52, * @param[in] time Time value from \ref time(3) * @param[in] local 0 for GM time, non-zero for localtime * - * @returns 0 on success, -errno on failure + * @returns 0 on success, -EAGAIN if no change from previous time, + * -errno on failure */ int libx52_set_clock(libx52_device *x52, time_t time, int local); diff --git a/libx52/x52_date_time.c b/libx52/x52_date_time.c index aecea54..b90cb2b 100644 --- a/libx52/x52_date_time.c +++ b/libx52/x52_date_time.c @@ -28,6 +28,7 @@ int libx52_set_clock(libx52_device *x52, time_t time, int local) int local_date_year; int local_time_hour; int local_time_minute; + int update_required = 0; if (!x52) { return -EINVAL; @@ -60,6 +61,7 @@ int libx52_set_clock(libx52_device *x52, time_t time, int local) x52->date_month = local_date_month; x52->date_year = local_date_year; set_bit(&x52->update_mask, X52_BIT_MFD_DATE); + update_required = 1; } /* Update the time only if it has changed */ @@ -69,17 +71,19 @@ int libx52_set_clock(libx52_device *x52, time_t time, int local) x52->time_hour = local_time_hour; x52->time_minute = local_time_minute; set_bit(&x52->update_mask, X52_BIT_MFD_TIME); + update_required = 1; } /* Update the offset fields only if the timezone has changed */ if (x52->timezone[LIBX52_CLOCK_1] != local_tz) { set_bit(&x52->update_mask, X52_BIT_MFD_OFFS1); set_bit(&x52->update_mask, X52_BIT_MFD_OFFS2); + update_required = 1; } /* Save the timezone */ x52->timezone[LIBX52_CLOCK_1] = local_tz; - return 0; + return (update_required ? 0 : -EAGAIN); } int libx52_set_clock_timezone(libx52_device *x52, libx52_clock_id clock, int offset)