Add raw time and date APIs to libx52

The raw time and date APIs bypass the timezone calculation and update
the internal data structures with the requested time in hh:mm and date
in dd/mm/yy formats.

This is unlikely to be used often, but it is useful during testing.
feature/test-new-mem-api
nirenjan 2017-08-18 07:23:49 -07:00
parent 6b89a9d7f9
commit 52abd335ab
3 changed files with 60 additions and 8 deletions

View File

@ -5,7 +5,7 @@ lib_LTLIBRARIES = libx52.la
# Core libx52 library
# This library handles the USB communication between the host and the X52
libx52_la_SOURCES = x52_control.c x52_core.c x52_date_time.c x52_mfd_led.c
libx52_la_LDFLAGS = -version-info 2:1:1 -lusb-1.0
libx52_la_LDFLAGS = -version-info 3:0:2 -lusb-1.0
# Header files that need to be copied
x52includedir = $(includedir)/x52pro

View File

@ -285,6 +285,36 @@ int libx52_set_clock_format(libx52_device *x52,
libx52_clock_id clock,
libx52_clock_format format);
/**
* @brief Set the hour and minute on clock 1
*
* This is a raw API which can be used for manual control if the user
* so desires, however, it will not update the timezone or the date
* values.
*
* @param[in] x52 Pointer to the device
* @param[in] hour Hour to display
* @param[in] minute Minute to display
*
* @returns 0 on success, \c -EINVAL if \p x52 is not valid
*/
int libx52_set_time(libx52_device *x52, uint8_t hour, uint8_t minute);
/**
* @brief Set the date
*
* This is a raw API which can be used for manual control if the user
* so desires, however, it will not update the timezone or the time values.
*
* @param[in] x52 Pointer to the device
* @param[in] dd Day to display
* @param[in] mm Month to display
* @param[in] yy Year to display
*
* @returns 0 on success, \c -EINVAL if \p x52 is not valid
*/
int libx52_set_date(libx52_device *x52, uint8_t dd, uint8_t mm, uint8_t yy);
/**
* @brief Set the date format for the MFD date display
*

View File

@ -57,10 +57,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) {
x52->date_day = local_date_day;
x52->date_month = local_date_month;
x52->date_year = local_date_year;
set_bit(&x52->update_mask, X52_BIT_MFD_DATE);
libx52_set_date(x52, local_date_day, local_date_month, local_date_year);
update_required = 1;
}
@ -68,9 +65,7 @@ int libx52_set_clock(libx52_device *x52, time_t time, int local)
if (x52->time_hour != local_time_hour ||
x52->time_minute != local_time_minute) {
x52->time_hour = local_time_hour;
x52->time_minute = local_time_minute;
set_bit(&x52->update_mask, X52_BIT_MFD_TIME);
libx52_set_time(x52, local_time_hour, local_time_minute);
update_required = 1;
}
@ -86,6 +81,33 @@ int libx52_set_clock(libx52_device *x52, time_t time, int local)
return (update_required ? 0 : -EAGAIN);
}
int libx52_set_time(libx52_device *x52, uint8_t hour, uint8_t minute)
{
if (!x52) {
return -EINVAL;
}
x52->time_hour = hour;
x52->time_minute = minute;
set_bit(&x52->update_mask, X52_BIT_MFD_TIME);
return 0;
}
int libx52_set_date(libx52_device *x52, uint8_t dd, uint8_t mm, uint8_t yy)
{
if (!x52) {
return -EINVAL;
}
x52->date_day = dd;
x52->date_month = mm;
x52->date_year = yy;
set_bit(&x52->update_mask, X52_BIT_MFD_DATE);
return 0;
}
int libx52_set_clock_timezone(libx52_device *x52, libx52_clock_id clock, int offset)
{
if (!x52) {