Merged the loadPreferences and setDefaultPreferences functions

This commit is contained in:
Dionysus 2024-06-04 12:15:09 -04:00
parent 885c0f57c1
commit 12a437ff69
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE

View File

@ -135,7 +135,6 @@ void setup() {
displayXBM(); displayXBM();
// Initialize the preferences // Initialize the preferences
setDefaultPreferences();
loadPreferences(); loadPreferences();
// Connect to WiFi if credentials are stored, otherwise scan for networks // Connect to WiFi if credentials are stored, otherwise scan for networks
@ -226,60 +225,49 @@ void loop() {
} }
void setDefaultPreferences() { void loadPreferences() {
preferences.begin("config", false); preferences.begin("config", false);
// IRC preferences // IRC preferences
if (!preferences.isKey("irc_nickname")) if (!preferences.isKey("irc_nickname"))
preferences.putString("irc_nickname", "ACID_" + String(random(1000, 10000))); preferences.putString("irc_nickname", "ACID_" + String(random(1000, 10000)));
irc_nickname = preferences.getString("irc_nickname");
if (!preferences.isKey("irc_username")) if (!preferences.isKey("irc_username"))
preferences.putString("irc_username", "tdeck"); preferences.putString("irc_username", "tdeck");
irc_username = preferences.getString("irc_username");
if (!preferences.isKey("irc_realname")) if (!preferences.isKey("irc_realname"))
preferences.putString("irc_realname", "ACID DROP Firmware"); preferences.putString("irc_realname", "ACID DROP Firmware");
irc_realname = preferences.getString("irc_realname");
if (!preferences.isKey("irc_server")) if (!preferences.isKey("irc_server"))
preferences.putString("irc_server", "irc.supernets.org"); preferences.putString("irc_server", "irc.supernets.org");
irc_server = preferences.getString("irc_server");
if (!preferences.isKey("irc_port")) if (!preferences.isKey("irc_port"))
preferences.putInt("irc_port", 6667); preferences.putInt("irc_port", 6667);
irc_port = preferences.getInt("irc_port");
if (!preferences.isKey("irc_tls")) if (!preferences.isKey("irc_tls"))
preferences.putBool("irc_tls", false); preferences.putBool("irc_tls", false);
irc_tls = preferences.getBool("irc_tls");
if (!preferences.isKey("irc_channel")) if (!preferences.isKey("irc_channel"))
preferences.putString("irc_channel", "#comms"); preferences.putString("irc_channel", "#comms");
irc_channel = preferences.getString("irc_channel");
if (!preferences.isKey("irc_nickserv")) if (!preferences.isKey("irc_nickserv"))
preferences.putString("irc_nickserv", ""); preferences.putString("irc_nickserv", "");
irc_nickserv = preferences.getString("irc_nickserv");
// WiFi preferences // WiFi preferences
if (!preferences.isKey("wifi_ssid")) if (!preferences.isKey("wifi_ssid"))
preferences.putString("wifi_ssid", ""); preferences.putString("wifi_ssid", "");
wifi_ssid = preferences.getString("wifi_ssid");
if (!preferences.isKey("wifi_password")) if (!preferences.isKey("wifi_password"))
preferences.putString("wifi_password", ""); preferences.putString("wifi_password", "");
preferences.end();
}
void loadPreferences() {
preferences.begin("config", true);
// IRC preferences
irc_nickname = preferences.getString("irc_nickname");
irc_username = preferences.getString("irc_username");
irc_realname = preferences.getString("irc_realname");
irc_server = preferences.getString("irc_server");
irc_port = preferences.getInt("irc_port");
irc_tls = preferences.getBool("irc_tls");
irc_channel = preferences.getString("irc_channel");
irc_nickserv = preferences.getString("irc_nickserv");
// WiFi preferences
wifi_ssid = preferences.getString("wifi_ssid");
wifi_password = preferences.getString("wifi_password"); wifi_password = preferences.getString("wifi_password");
preferences.end(); preferences.end();