Add SSID and PSK config items
This commit is contained in:
parent
81dfa7fe1c
commit
87c9ca3c81
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HOSTNAME,
|
HOSTNAME,
|
||||||
|
SSID,
|
||||||
|
PSK,
|
||||||
ITEM_COUNT,
|
ITEM_COUNT,
|
||||||
} ItemIndex;
|
} ItemIndex;
|
||||||
|
|
||||||
@ -37,6 +39,14 @@ static Item state[ITEM_COUNT] = {
|
|||||||
.id = "hostname",
|
.id = "hostname",
|
||||||
.default_value = CONFIG_DEFAULT_HOSTNAME,
|
.default_value = CONFIG_DEFAULT_HOSTNAME,
|
||||||
},
|
},
|
||||||
|
[SSID] = {
|
||||||
|
.id = "ssid",
|
||||||
|
.default_value = CONFIG_DEFAULT_SSID,
|
||||||
|
},
|
||||||
|
[PSK] = {
|
||||||
|
.id = "psk",
|
||||||
|
.default_value = CONFIG_DEFAULT_PSK,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool load(ItemIndex item)
|
static bool load(ItemIndex item)
|
||||||
@ -185,3 +195,33 @@ void config_add_hostname_callback(ConfigCallback callback)
|
|||||||
{
|
{
|
||||||
add_callback(HOSTNAME, callback);
|
add_callback(HOSTNAME, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void config_set_ssid(const char *ssid)
|
||||||
|
{
|
||||||
|
set(SSID, ssid);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t config_get_ssid(char *buffer, size_t buffer_size)
|
||||||
|
{
|
||||||
|
return get(SSID, buffer, buffer_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void config_add_ssid_callback(ConfigCallback callback)
|
||||||
|
{
|
||||||
|
add_callback(SSID, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void config_set_psk(const char *psk)
|
||||||
|
{
|
||||||
|
set(PSK, psk);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t config_get_psk(char *buffer, size_t buffer_size)
|
||||||
|
{
|
||||||
|
return get(PSK, buffer, buffer_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void config_add_psk_callback(ConfigCallback callback)
|
||||||
|
{
|
||||||
|
add_callback(PSK, callback);
|
||||||
|
}
|
||||||
|
@ -51,4 +51,60 @@ size_t config_get_hostname(char *buffer, size_t buffer_size);
|
|||||||
*/
|
*/
|
||||||
void config_add_hostname_callback(ConfigCallback callback);
|
void config_add_hostname_callback(ConfigCallback callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the SSID of the WiFi network.
|
||||||
|
*
|
||||||
|
* The argument should be a null-terminated string. If the maximum
|
||||||
|
* length is exceeded, the value will still be used, but will be
|
||||||
|
* truncated.
|
||||||
|
*/
|
||||||
|
void config_set_ssid(const char *ssid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the SSID of the WiFi network into the given buffer.
|
||||||
|
*
|
||||||
|
* The length of the SSID 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_ssid(char *buffer, size_t buffer_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a callback for SSID updates.
|
||||||
|
*
|
||||||
|
* The function specified in the argument will be invoked whenever a
|
||||||
|
* the ssid 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_ssid_callback(ConfigCallback callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the PSK for the WiFi network.
|
||||||
|
*
|
||||||
|
* The argument should be a null-terminated string. If the maximum
|
||||||
|
* length is exceeded, the value will still be used, but will be
|
||||||
|
* truncated.
|
||||||
|
*/
|
||||||
|
void config_set_psk(const char *psk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the PSK for the WiFi network into the given buffer.
|
||||||
|
*
|
||||||
|
* The length of the psk 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_psk(char *buffer, size_t buffer_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a callback for PSK updates.
|
||||||
|
*
|
||||||
|
* The function specified in the argument will be invoked whenever a
|
||||||
|
* the psk 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_psk_callback(ConfigCallback callback);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
menu "Bedside clock settings"
|
menu "Bedside clock settings"
|
||||||
config DEFAULT_HOSTNAME
|
config DEFAULT_HOSTNAME
|
||||||
string "The default hostname for the device"
|
string "Default hostname"
|
||||||
default "bedside-clock"
|
default "bedside-clock"
|
||||||
prompt "Default hostname"
|
config DEFAULT_SSID
|
||||||
|
string "SSID of default WiFi network"
|
||||||
|
default ""
|
||||||
|
config DEFAULT_PSK
|
||||||
|
string "PSK for default WiFi network"
|
||||||
|
default ""
|
||||||
endmenu
|
endmenu
|
||||||
|
Loading…
x
Reference in New Issue
Block a user