mirror of https://github.com/nirenjan/libx52.git
Make libx52_set_clock return 0 only if fields changed
This is used by an application to check if it needs to call libx52_update. If libx52_set_clock returns 0, it can be assumed that the clock did change values that require an update, but any other value indicates that an update is not required.pull/10/head
parent
b0309b1b40
commit
059ec6af1a
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue