mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Initial Commit
This commit is contained in:
38
CYD-Klipper-Display/src/conf/global_config.cpp
Normal file
38
CYD-Klipper-Display/src/conf/global_config.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <Preferences.h>
|
||||
#include "global_config.h"
|
||||
|
||||
GLOBAL_CONFIG global_config = {0};
|
||||
|
||||
void WriteGlobalConfig() {
|
||||
Preferences preferences;
|
||||
preferences.begin("global_config", false);
|
||||
preferences.putBytes("global_config", &global_config, sizeof(global_config));
|
||||
preferences.end();
|
||||
}
|
||||
|
||||
void VerifyVersion(){
|
||||
Preferences preferences;
|
||||
if (!preferences.begin("global_config", false))
|
||||
return;
|
||||
|
||||
GLOBAL_CONFIG config = {0};
|
||||
preferences.getBytes("global_config", &config, sizeof(config));
|
||||
Serial.printf("Config version: %d\n", config.version);
|
||||
if (config.version != CONFIG_VERSION) {
|
||||
Serial.println("Clearing Global Config");
|
||||
preferences.clear();
|
||||
}
|
||||
|
||||
preferences.end();
|
||||
}
|
||||
|
||||
void LoadGlobalConfig() {
|
||||
global_config.version = CONFIG_VERSION;
|
||||
VerifyVersion();
|
||||
Preferences preferences;
|
||||
preferences.begin("global_config", true);
|
||||
preferences.getBytes("global_config", &global_config, sizeof(global_config));
|
||||
preferences.end();
|
||||
|
||||
Serial.printf("Touch: %d\n", global_config.screenCalibrated);
|
||||
}
|
||||
Reference in New Issue
Block a user