Add timezone config item

This commit is contained in:
Camden Dixie O'Brien 2023-05-15 17:25:25 +01:00
parent be666164f4
commit 8be7ec1e28
3 changed files with 59 additions and 7 deletions

View File

@ -21,6 +21,7 @@ typedef enum {
HOSTNAME, HOSTNAME,
SSID, SSID,
PSK, PSK,
TIMEZONE,
ITEM_COUNT, ITEM_COUNT,
} ItemIndex; } ItemIndex;
@ -47,6 +48,10 @@ static Item state[ITEM_COUNT] = {
.id = "psk", .id = "psk",
.default_value = CONFIG_DEFAULT_PSK, .default_value = CONFIG_DEFAULT_PSK,
}, },
[TIMEZONE] = {
.id = "timezone",
.default_value = CONFIG_DEFAULT_TIMEZONE,
},
}; };
static bool load(ItemIndex item) static bool load(ItemIndex item)
@ -225,3 +230,18 @@ void config_add_psk_callback(ConfigCallback callback)
{ {
add_callback(PSK, callback); add_callback(PSK, callback);
} }
void config_set_timezone(const char *timezone)
{
set(TIMEZONE, timezone);
}
size_t config_get_timezone(char *buffer, size_t buffer_size)
{
return get(TIMEZONE, buffer, buffer_size);
}
void config_add_timezone_callback(ConfigCallback callback)
{
add_callback(TIMEZONE, callback);
}

View File

@ -44,7 +44,7 @@ size_t config_get_hostname(char *buffer, size_t buffer_size);
/** /**
* Add a callback for hostname updates. * Add a callback for hostname updates.
* *
* The function specified in the argument will be invoked whenever a * The function specified in the argument will be invoked whenever
* the hostname is updated, with the new value as its argument. The * the hostname is updated, with the new value as its argument. The
* lifetime of the passed argument will be static, but the value may * lifetime of the passed argument will be static, but the value may
* be modified once the callback returns. * be modified once the callback returns.
@ -72,8 +72,8 @@ size_t config_get_ssid(char *buffer, size_t buffer_size);
/** /**
* Add a callback for SSID updates. * Add a callback for SSID updates.
* *
* The function specified in the argument will be invoked whenever a * The function specified in the argument will be invoked whenever
* the ssid is updated, with the new value as its argument. The * the SSID is updated, with the new value as its argument. The
* lifetime of the passed argument will be static, but the value may * lifetime of the passed argument will be static, but the value may
* be modified once the callback returns. * be modified once the callback returns.
*/ */
@ -100,11 +100,40 @@ size_t config_get_psk(char *buffer, size_t buffer_size);
/** /**
* Add a callback for PSK updates. * Add a callback for PSK updates.
* *
* The function specified in the argument will be invoked whenever a * The function specified in the argument will be invoked whenever the
* the psk is updated, with the new value as its argument. The * PSK is updated, with the new value as its argument. The lifetime of
* lifetime of the passed argument will be static, but the value may * the passed argument will be static, but the value may be modified
* be modified once the callback returns. * once the callback returns.
*/ */
void config_add_psk_callback(ConfigCallback callback); void config_add_psk_callback(ConfigCallback callback);
/**
* Set the timezone.
*
* The argument should be a null-terminated string, containing a
* timezone spec in the format expected by tzset(). If the maximum
* length is exceeded, the value will still be used, but will be
* truncated.
*/
void config_set_timezone(const char *psk);
/**
* Write the timezone into the given buffer.
*
* The length of the timezone is returned. If the value's size exceeds
* the size of the buffer, nothing will be written to the buffer but
* the length is still returned.
*/
size_t config_get_timezone(char *buffer, size_t buffer_size);
/**
* Add a callback for timezone updates.
*
* The function specified in the argument will be invoked whenever the
* timezone is updated, with the new value as its argument. The
* lifetime of the passed argument will be static, but the value may
* be modified once the callback returns.
*/
void config_add_timezone_callback(ConfigCallback callback);
#endif #endif

View File

@ -8,4 +8,7 @@ menu "Bedside clock settings"
config DEFAULT_PSK config DEFAULT_PSK
string "PSK for default WiFi network" string "PSK for default WiFi network"
default "" default ""
config DEFAULT_TIMEZONE
string "Default timezone"
default "Europe/London"
endmenu endmenu