Added existance check for alarm.json and dev.json
This commit is contained in:
@@ -35,30 +35,29 @@ void startLittleFS()
|
|||||||
void loadDevSettings()
|
void loadDevSettings()
|
||||||
{
|
{
|
||||||
Serial.println("loadSettings");
|
Serial.println("loadSettings");
|
||||||
File file = LittleFS.open("/dev.json", "r");
|
if (LittleFS.exists("/dev.json"))
|
||||||
if (!file)
|
|
||||||
{
|
{
|
||||||
return;
|
File file = LittleFS.open("/dev.json", "r");
|
||||||
}
|
DynamicJsonDocument doc(128);
|
||||||
DynamicJsonDocument doc(128);
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
DeserializationError error = deserializeJson(doc, file);
|
if (error)
|
||||||
if (error)
|
{
|
||||||
{
|
Serial.println(F("Failed to read dev settings"));
|
||||||
Serial.println(F("Failed to read dev settings"));
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (doc.containsKey("bootsound"))
|
if (doc.containsKey("bootsound"))
|
||||||
{
|
{
|
||||||
BOOT_SOUND = doc["bootsound"].as<String>();
|
BOOT_SOUND = doc["bootsound"].as<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc.containsKey("bootsound"))
|
if (doc.containsKey("bootsound"))
|
||||||
{
|
{
|
||||||
UPPERCASE_LETTERS = doc["uppercase"].as<bool>();
|
UPPERCASE_LETTERS = doc["uppercase"].as<bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadSettings()
|
void loadSettings()
|
||||||
|
|||||||
@@ -329,63 +329,61 @@ time_t lastAlarmTime = 0;
|
|||||||
|
|
||||||
void PeripheryManager_::checkAlarms()
|
void PeripheryManager_::checkAlarms()
|
||||||
{
|
{
|
||||||
File file = LittleFS.open("/alarms.json", "r");
|
if (LittleFS.exists("/alarms.json"))
|
||||||
if (!file)
|
|
||||||
{
|
{
|
||||||
return;
|
File file = LittleFS.open("/alarms.json", "r");
|
||||||
}
|
DynamicJsonDocument doc(file.size() * 1.33);
|
||||||
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
DynamicJsonDocument doc(file.size() * 1.33);
|
if (error)
|
||||||
DeserializationError error = deserializeJson(doc, file);
|
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
Serial.println(F("Failed to read Alarm file"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JsonArray alarms = doc["alarms"];
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
time_t now1 = time(nullptr);
|
|
||||||
struct tm *timeInfo;
|
|
||||||
timeInfo = localtime(&now1);
|
|
||||||
int currentHour = timeInfo->tm_hour;
|
|
||||||
int currentMinute = timeInfo->tm_min;
|
|
||||||
int currentDay = timeInfo->tm_wday - 1;
|
|
||||||
|
|
||||||
for (JsonObject alarm : alarms)
|
|
||||||
{
|
|
||||||
int alarmHour = alarm["hour"];
|
|
||||||
int alarmMinute = alarm["minute"];
|
|
||||||
String alarmDays = alarm["days"];
|
|
||||||
|
|
||||||
if (currentHour == alarmHour && currentMinute == alarmMinute && alarmDays.indexOf(String(currentDay)) != -1)
|
|
||||||
{
|
{
|
||||||
if (difftime(now1, lastAlarmTime) < MIN_ALARM_INTERVAL)
|
Serial.println(F("Failed to read Alarm file"));
|
||||||
{
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALARM_ACTIVE = true;
|
|
||||||
lastAlarmTime = now1;
|
|
||||||
|
|
||||||
if (alarm.containsKey("sound"))
|
|
||||||
{
|
|
||||||
ALARM_SOUND = alarm["sound"].as<String>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ALARM_SOUND = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alarm.containsKey("snooze"))
|
|
||||||
{
|
|
||||||
SNOOZE_TIME = alarm["snooze"].as<uint8_t>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SNOOZE_TIME = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
JsonArray alarms = doc["alarms"];
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
time_t now1 = time(nullptr);
|
||||||
|
struct tm *timeInfo;
|
||||||
|
timeInfo = localtime(&now1);
|
||||||
|
int currentHour = timeInfo->tm_hour;
|
||||||
|
int currentMinute = timeInfo->tm_min;
|
||||||
|
int currentDay = timeInfo->tm_wday - 1;
|
||||||
|
|
||||||
|
for (JsonObject alarm : alarms)
|
||||||
|
{
|
||||||
|
int alarmHour = alarm["hour"];
|
||||||
|
int alarmMinute = alarm["minute"];
|
||||||
|
String alarmDays = alarm["days"];
|
||||||
|
|
||||||
|
if (currentHour == alarmHour && currentMinute == alarmMinute && alarmDays.indexOf(String(currentDay)) != -1)
|
||||||
|
{
|
||||||
|
if (difftime(now1, lastAlarmTime) < MIN_ALARM_INTERVAL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ALARM_ACTIVE = true;
|
||||||
|
lastAlarmTime = now1;
|
||||||
|
|
||||||
|
if (alarm.containsKey("sound"))
|
||||||
|
{
|
||||||
|
ALARM_SOUND = alarm["sound"].as<String>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ALARM_SOUND = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alarm.containsKey("snooze"))
|
||||||
|
{
|
||||||
|
SNOOZE_TIME = alarm["snooze"].as<uint8_t>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SNOOZE_TIME = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user