acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Storage.cpp (3578B)
1 #include "Storage.h" 2 3 4 Preferences preferences; 5 6 // Config variables 7 String irc_nickname; 8 String irc_username; 9 String irc_realname; 10 String irc_server; 11 int irc_port; 12 bool irc_tls; 13 String irc_channel; 14 String irc_nickserv; 15 String wifi_ssid; 16 String wifi_password; 17 18 19 void loadPreferences() { 20 preferences.begin("config", false); 21 22 // IRC preferences 23 if (!preferences.isKey("irc_nickname")) 24 preferences.putString("irc_nickname", "ACID_" + String(random(1000, 10000))); 25 irc_nickname = preferences.getString("irc_nickname"); 26 27 if (!preferences.isKey("irc_username")) 28 preferences.putString("irc_username", "tdeck"); 29 irc_username = preferences.getString("irc_username"); 30 31 if (!preferences.isKey("irc_realname")) 32 preferences.putString("irc_realname", "ACID DROP Firmware"); 33 irc_realname = preferences.getString("irc_realname"); 34 35 if (!preferences.isKey("irc_server")) 36 preferences.putString("irc_server", "irc.supernets.org"); 37 irc_server = preferences.getString("irc_server"); 38 39 if (!preferences.isKey("irc_port")) 40 preferences.putInt("irc_port", 6667); 41 irc_port = preferences.getInt("irc_port"); 42 43 if (!preferences.isKey("irc_tls")) 44 preferences.putBool("irc_tls", false); 45 irc_tls = preferences.getBool("irc_tls"); 46 47 if (!preferences.isKey("irc_channel")) 48 preferences.putString("irc_channel", "#comms"); 49 irc_channel = preferences.getString("irc_channel"); 50 51 if (!preferences.isKey("irc_nickserv")) 52 preferences.putString("irc_nickserv", ""); 53 irc_nickserv = preferences.getString("irc_nickserv"); 54 55 // WiFi preferences 56 if (!preferences.isKey("wifi_ssid")) 57 preferences.putString("wifi_ssid", ""); 58 wifi_ssid = preferences.getString("wifi_ssid"); 59 60 if (!preferences.isKey("wifi_password")) 61 preferences.putString("wifi_password", ""); 62 wifi_password = preferences.getString("wifi_password"); 63 64 preferences.end(); 65 } 66 67 68 bool mountSD() { 69 if (SD.begin(BOARD_SDCARD_CS, SPI, 800000U)) { 70 uint8_t cardType = SD.cardType(); 71 72 if (cardType == CARD_NONE) { 73 Serial.println("No SD card attached"); 74 return false; 75 } else { 76 Serial.print("SD Card Type: "); 77 if (cardType == CARD_MMC) 78 Serial.println("MMC"); 79 else if (cardType == CARD_SD) 80 Serial.println("SDSC"); 81 else if (cardType == CARD_SDHC) 82 Serial.println("SDHC"); 83 else 84 Serial.println("UNKNOWN"); 85 86 uint32_t cardSize = SD.cardSize() / (1024 * 1024); 87 uint32_t cardTotal = SD.totalBytes() / (1024 * 1024); 88 uint32_t cardUsed = SD.usedBytes() / (1024 * 1024); 89 Serial.printf("SD Card Size: %lu MB\n", cardSize); 90 Serial.printf("Total space: %lu MB\n", cardTotal); 91 Serial.printf("Used space: %lu MB\n", cardUsed); 92 93 return true; 94 } 95 } 96 97 return false; 98 } 99 100 101 void setupSD() { 102 pinMode(BOARD_SDCARD_CS, OUTPUT); 103 digitalWrite(BOARD_SDCARD_CS, HIGH); 104 pinMode(BOARD_SPI_MISO, INPUT_PULLUP); 105 SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); 106 } 107 108 109 void wipeNVS() { 110 esp_err_t err = nvs_flash_erase(); 111 if (err == ESP_OK) 112 Serial.println("NVS flash erase successful."); 113 else 114 Serial.println("Error erasing NVS flash!"); 115 116 err = nvs_flash_init(); 117 if (err == ESP_OK) 118 Serial.println("NVS flash init successful."); 119 else 120 Serial.println("Error initializing NVS flash!"); 121 }