Advertisement
FlyFar

Settings.cpp

Jul 17th, 2023
997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | Cybersecurity | 0 0
  1. #include "Settings.h"
  2.  
  3. Settings::Settings(){
  4.  
  5. }
  6.  
  7. void Settings::load() {
  8.     if(debug) Serial.println("\nLoad Settings");
  9.  
  10.     ssidLen = EEPROM.read(ssidLenAdr);
  11.     if(ssidLen < 0 || ssidLen > 32) {
  12.         Settings::reset();
  13.         return;
  14.     }
  15.     passwordLen = EEPROM.read(passwordLenAdr);
  16.     if(passwordLen < 0 || passwordLen > 32) {
  17.         Settings::reset();
  18.         return;
  19.     }
  20.     autostartLen = EEPROM.read(autostartLenAdr);
  21.     if(autostartLen < 1 || autostartLen > 32) {
  22.         Settings::reset();
  23.         return;
  24.     }
  25.     channel = EEPROM.read(channelAdr);
  26.     if(channel < 1 || channel > 14) {
  27.         Settings::reset();
  28.         return;
  29.     }
  30.     hidden = (bool)EEPROM.read(hiddenAdr);
  31.     autoExec = (bool)EEPROM.read(autoExecAdr);
  32.    
  33.     for(int i = 0; i < ssidLen; i++) ssid[i] = EEPROM.read(ssidAdr + i);
  34.     for(int i = 0; i < passwordLen; i++) password[i] = EEPROM.read(passwordAdr + i);
  35.     for(int i = 0; i < autostartLen; i++) autostart[i] = EEPROM.read(autostartAdr + i);
  36. }
  37.  
  38. void Settings::save() {
  39.     if(debug) Serial.println("Save Settings");
  40.  
  41.     EEPROM.write(ssidLenAdr, ssidLen);
  42.     for(int i = 0; i < ssidLen; i++) {
  43.         EEPROM.write(ssidAdr + i, ssid[i]);
  44.     }
  45.     EEPROM.write(passwordLenAdr, passwordLen);
  46.     for(int i = 0; i < passwordLen; i++) {
  47.         EEPROM.write(passwordAdr + i, password[i]);
  48.     }
  49.     EEPROM.write(autostartLenAdr, autostartLen);
  50.     for(int i = 0; i < autostartLen; i++) {
  51.         EEPROM.write(autostartAdr + i, autostart[i]);
  52.     }
  53.     EEPROM.write(channelAdr, channel);
  54.     EEPROM.write(hiddenAdr, hidden);
  55.     EEPROM.write(autoExecAdr, autoExec);
  56.  
  57.     EEPROM.commit();
  58. }
  59.  
  60. void Settings::reset() {
  61.     if(debug) Serial.println("Reset Settings");
  62.  
  63.     String _ssid = "WiFi Duck";
  64.     _ssid.toCharArray(ssid, 32);
  65.     ssidLen = _ssid.length();
  66.  
  67.     String _pswd = "quackquack";
  68.     _pswd.toCharArray(password, 32);
  69.     passwordLen = _pswd.length();
  70.  
  71.     String _autostart = "autostart.txt";
  72.     _autostart.toCharArray(autostart, 32);
  73.     autostartLen = _autostart.length();
  74.  
  75.     channel = 1;
  76.     hidden = false;
  77.     autoExec = false;
  78.  
  79.     save();
  80. }
  81.  
  82. void Settings::print() {
  83.     Serial.println("\nSettings:");
  84.     Serial.println("SSID = "+(String)ssid);
  85.     Serial.println("Password = " + (String)password);
  86.     Serial.println("Channel = " + (String)channel);
  87.     Serial.println("Hidden SSID = " + (String)hidden);
  88.     Serial.println("auto. Execute = " + (String)autoExec);
  89.     Serial.println("Autoscript = '" + (String)autostart + "'");
  90. }
Tags: cpp Settings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement