86 lines
1.4 KiB
C++
86 lines
1.4 KiB
C++
#include "storage.h"
|
|
|
|
bool Storage::isMounted;
|
|
|
|
void Storage::init()
|
|
{
|
|
if (!SPIFFS.begin(true))
|
|
{
|
|
Serial.println("SPIFFS Mount Failed");
|
|
isMounted = false;
|
|
}
|
|
else
|
|
isMounted = true;
|
|
}
|
|
|
|
unsigned int Storage::getSensitivity()
|
|
{
|
|
if (!isMounted)
|
|
return 0xFF;
|
|
|
|
File file = SPIFFS.open("/sensitivity.txt", "r");
|
|
if (!file)
|
|
return 0xFF;
|
|
|
|
String sensitivity = file.readStringUntil('\n');
|
|
file.close();
|
|
|
|
return sensitivity.toInt();
|
|
}
|
|
|
|
void Storage::setSensitivity(unsigned int sensitivity)
|
|
{
|
|
if (!isMounted)
|
|
return;
|
|
|
|
File file = SPIFFS.open("/sensitivity.txt", "w");
|
|
file.println(sensitivity);
|
|
file.close();
|
|
}
|
|
|
|
void Storage::setPID(float kp, float ki, float kd)
|
|
{
|
|
if (!isMounted)
|
|
return;
|
|
|
|
File file = SPIFFS.open("/pid.txt", "w");
|
|
file.println(kp);
|
|
file.println(ki);
|
|
file.println(kd);
|
|
file.close();
|
|
}
|
|
|
|
void Storage::getPID(float &kp, float &ki, float &kd)
|
|
{
|
|
if (!isMounted)
|
|
return;
|
|
|
|
File file = SPIFFS.open("/pid.txt", "r");
|
|
kp = file.readStringUntil('\n').toFloat();
|
|
ki = file.readStringUntil('\n').toFloat();
|
|
kd = file.readStringUntil('\n').toFloat();
|
|
file.close();
|
|
}
|
|
|
|
void Storage::setName(String name)
|
|
{
|
|
if (!isMounted)
|
|
return;
|
|
|
|
File file = SPIFFS.open("/name.txt", "w");
|
|
file.println(name);
|
|
file.close();
|
|
}
|
|
|
|
String Storage::getName()
|
|
{
|
|
if (!isMounted)
|
|
return "";
|
|
|
|
File file = SPIFFS.open("/name.txt", "r");
|
|
String name = file.readStringUntil('\n');
|
|
file.close();
|
|
|
|
return name;
|
|
}
|