mirror of https://github.com/nirenjan/libx52.git
Add support for clock and date format
parent
499cad666f
commit
0fa638fa16
|
@ -30,6 +30,23 @@ Secondary=UTC
|
||||||
# timezone name as defined by the Olson time database.
|
# timezone name as defined by the Olson time database.
|
||||||
Tertiary=UTC
|
Tertiary=UTC
|
||||||
|
|
||||||
|
# PrimaryFormat controls the clock format of the primary clock. This is
|
||||||
|
# either 12hr or 24hr, and can be abbreviated to 12 or 24
|
||||||
|
PrimaryFormat=12hr
|
||||||
|
|
||||||
|
# SecondaryFormat controls the clock format of the secondary clock. This is
|
||||||
|
# either 12hr or 24hr, and can be abbreviated to 12 or 24
|
||||||
|
SecondaryFormat=12hr
|
||||||
|
|
||||||
|
# TertiaryFormat controls the clock format of the tertiary clock. This is
|
||||||
|
# either 12hr or 24hr, and can be abbreviated to 12 or 24
|
||||||
|
TertiaryFormat=12hr
|
||||||
|
|
||||||
|
# DateFormat controls the format of the date display. This can be one of
|
||||||
|
# ddmmyy, mmddyy or yymmdd. Alternate representations of these are
|
||||||
|
# dd-mm-yy, mm-dd-yy or yy-mm-dd respectively.
|
||||||
|
DateFormat=ddmmyy
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# LED Settings - only applicable to X52Pro
|
# LED Settings - only applicable to X52Pro
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
@ -118,6 +118,39 @@ void x52d_cfg_set_Clock_Tertiary(char* param)
|
||||||
x52d_dev_set_clock_timezone(LIBX52_CLOCK_3, get_tz_offset(param));
|
x52d_dev_set_clock_timezone(LIBX52_CLOCK_3, get_tz_offset(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_clock_format(const char *name, libx52_clock_id id, libx52_clock_format fmt)
|
||||||
|
{
|
||||||
|
PINELOG_TRACE("Setting %s clock format to %s", name,
|
||||||
|
fmt == LIBX52_CLOCK_FORMAT_12HR ? "12 hour" : "24 hour");
|
||||||
|
x52d_dev_set_clock_format(id, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void x52d_cfg_set_Clock_FormatPrimary(libx52_clock_format fmt)
|
||||||
|
{
|
||||||
|
set_clock_format("primary", LIBX52_CLOCK_1, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void x52d_cfg_set_Clock_FormatSecondary(libx52_clock_format fmt)
|
||||||
|
{
|
||||||
|
set_clock_format("secondary", LIBX52_CLOCK_2, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void x52d_cfg_set_Clock_FormatTertiary(libx52_clock_format fmt)
|
||||||
|
{
|
||||||
|
set_clock_format("tertiary", LIBX52_CLOCK_3, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void x52d_cfg_set_Clock_DateFormat(libx52_date_format fmt)
|
||||||
|
{
|
||||||
|
static const char *formats[] = {
|
||||||
|
"dd-mm-yy",
|
||||||
|
"mm-dd-yy",
|
||||||
|
"yy-mm-dd"
|
||||||
|
};
|
||||||
|
PINELOG_TRACE("Setting date format to %s", formats[fmt]);
|
||||||
|
x52d_dev_set_date_format(fmt);
|
||||||
|
}
|
||||||
|
|
||||||
static pthread_t clock_thr;
|
static pthread_t clock_thr;
|
||||||
|
|
||||||
static void * x52_clock_thr(void *param)
|
static void * x52_clock_thr(void *param)
|
||||||
|
|
|
@ -30,6 +30,18 @@ CFG(Clock, Secondary, clock_2_tz, string_parser, UTC)
|
||||||
// timezone name as defined by the Olson time database.
|
// timezone name as defined by the Olson time database.
|
||||||
CFG(Clock, Tertiary, clock_3_tz, string_parser, UTC)
|
CFG(Clock, Tertiary, clock_3_tz, string_parser, UTC)
|
||||||
|
|
||||||
|
// Clock format for the primary clock
|
||||||
|
CFG(Clock, FormatPrimary, clock_format[LIBX52_CLOCK_1], clock_format_parser, 12hr)
|
||||||
|
|
||||||
|
// Clock format for the secondary clock
|
||||||
|
CFG(Clock, FormatSecondary, clock_format[LIBX52_CLOCK_2], clock_format_parser, 12hr)
|
||||||
|
|
||||||
|
// Clock format for the tertiary clock
|
||||||
|
CFG(Clock, FormatTertiary, clock_format[LIBX52_CLOCK_3], clock_format_parser, 12hr)
|
||||||
|
|
||||||
|
// Date format for the date display
|
||||||
|
CFG(Clock, DateFormat, date_format, date_format_parser, ddmmyy)
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* LED Settings - only applicable to X52Pro
|
* LED Settings - only applicable to X52Pro
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
|
@ -22,6 +22,12 @@
|
||||||
struct x52d_config {
|
struct x52d_config {
|
||||||
bool clock_enabled;
|
bool clock_enabled;
|
||||||
bool primary_clock_local;
|
bool primary_clock_local;
|
||||||
|
|
||||||
|
// Since we don't have a _MAX identifier for libx52_clock_id, use
|
||||||
|
// the maximum clock ID + 1 as the length
|
||||||
|
libx52_clock_format clock_format[LIBX52_CLOCK_3 + 1];
|
||||||
|
libx52_date_format date_format;
|
||||||
|
|
||||||
char clock_2_tz[NAME_MAX];
|
char clock_2_tz[NAME_MAX];
|
||||||
char clock_3_tz[NAME_MAX];
|
char clock_3_tz[NAME_MAX];
|
||||||
|
|
||||||
|
@ -43,6 +49,10 @@ void x52d_cfg_set_Clock_Enabled(bool param);
|
||||||
void x52d_cfg_set_Clock_PrimaryIsLocal(bool param);
|
void x52d_cfg_set_Clock_PrimaryIsLocal(bool param);
|
||||||
void x52d_cfg_set_Clock_Secondary(char* param);
|
void x52d_cfg_set_Clock_Secondary(char* param);
|
||||||
void x52d_cfg_set_Clock_Tertiary(char* param);
|
void x52d_cfg_set_Clock_Tertiary(char* param);
|
||||||
|
void x52d_cfg_set_Clock_FormatPrimary(libx52_clock_format param);
|
||||||
|
void x52d_cfg_set_Clock_FormatSecondary(libx52_clock_format param);
|
||||||
|
void x52d_cfg_set_Clock_FormatTertiary(libx52_clock_format param);
|
||||||
|
void x52d_cfg_set_Clock_DateFormat(libx52_date_format param);
|
||||||
void x52d_cfg_set_LED_Fire(libx52_led_state param);
|
void x52d_cfg_set_LED_Fire(libx52_led_state param);
|
||||||
void x52d_cfg_set_LED_Throttle(libx52_led_state param);
|
void x52d_cfg_set_LED_Throttle(libx52_led_state param);
|
||||||
void x52d_cfg_set_LED_A(libx52_led_state param);
|
void x52d_cfg_set_LED_A(libx52_led_state param);
|
||||||
|
|
|
@ -92,6 +92,40 @@ static int led_parser(struct x52d_config *cfg, size_t offset, const char *value)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int clock_format_parser(struct x52d_config *cfg, size_t offset, const char *value)
|
||||||
|
{
|
||||||
|
CONFIG_PTR(libx52_clock_format *, config);
|
||||||
|
CHECK_PARAMS();
|
||||||
|
|
||||||
|
if (!strcasecmp(value, "12hr") || !strcasecmp(value, "12")) {
|
||||||
|
*config = LIBX52_CLOCK_FORMAT_12HR;
|
||||||
|
} else if (!strcasecmp(value, "24hr") || !strcasecmp(value, "24")) {
|
||||||
|
*config = LIBX52_CLOCK_FORMAT_24HR;
|
||||||
|
} else {
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int date_format_parser(struct x52d_config *cfg, size_t offset, const char *value)
|
||||||
|
{
|
||||||
|
CONFIG_PTR(libx52_date_format *, config);
|
||||||
|
CHECK_PARAMS();
|
||||||
|
|
||||||
|
if (!strcasecmp(value, "ddmmyy") || !strcasecmp(value, "dd-mm-yy")) {
|
||||||
|
*config = LIBX52_DATE_FORMAT_DDMMYY;
|
||||||
|
} else if (!strcasecmp(value, "mmddyy") || !strcasecmp(value, "mm-dd-yy")) {
|
||||||
|
*config = LIBX52_DATE_FORMAT_MMDDYY;
|
||||||
|
} else if (!strcasecmp(value, "yymmdd") || !strcasecmp(value, "yy-mm-dd")) {
|
||||||
|
*config = LIBX52_DATE_FORMAT_YYMMDD;
|
||||||
|
} else {
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Map for config->param */
|
/* Map for config->param */
|
||||||
#define CFG(section, key, name, parser, def) {#section, #key, parser, offsetof(struct x52d_config, name)},
|
#define CFG(section, key, name, parser, def) {#section, #key, parser, offsetof(struct x52d_config, name)},
|
||||||
const struct config_map {
|
const struct config_map {
|
||||||
|
|
Loading…
Reference in New Issue