Merge pull request #12 from ytrikoz/platformio

FileUtils, some typos fixes
This commit is contained in:
Yuri Trikoz
2020-06-20 17:16:16 +03:00
committed by GitHub
12 changed files with 354 additions and 210 deletions

66
include/Errors.h Normal file
View File

@@ -0,0 +1,66 @@
#pragma once
#include <Arduino.h>
enum ErrorType_t {
ET_NONE,
ET_FUNCTION,
ET_MODULE,
ET_SYSTEM
};
enum ErrorLevel_t {
EL_NONE,
EL_INFO,
EL_WARNING,
EL_ERROR
};
String getErrorLevelStr(ErrorLevel_t level);
class Error : public Printable {
public:
static Error OK() {
return Error();
}
static Error InfoMessage(const char *message) {
return Error(EL_INFO, message);
}
static Error ErrorMessage(const char *message) {
return Error(EL_ERROR, message);
}
public:
Error() : _type{ET_NONE}, _level{EL_NONE} {};
Error(const ErrorLevel_t level, const char *message) : Error(ET_FUNCTION, level, message){};
Error(const ErrorType_t type, const ErrorLevel_t level, const char *message) : _type{type}, _level{level} {
strncpy(_message, message, sizeof(_message));
};
const ErrorLevel_t level() const { return _level; }
const ErrorType_t type() const { return _type; }
const char *message() const { return _message; }
operator bool() const { return _level != EL_NONE; }
const String toString() const {
char buf[128];
sprintf(buf, "[%s] %s", getErrorLevelStr(_level).c_str(), _message);
return String(buf);
}
virtual size_t printTo(Print &p) const {
return p.println(toString().c_str());
}
private:
char _message[128];
ErrorType_t _type;
ErrorLevel_t _level;
};

View File

@@ -13,8 +13,10 @@
#include "Consts.h"
#include "ESP32_Spec.h"
#include "ESP8266_Spec.h"
#include "Errors.h"
#include "GyverFilters.h"
#include "UptimeInterval.h"
#include "Utils\FileUtils.h"
#include "Utils\JsonUtils.h"
#include "Utils\StringUtils.h"
#include "Utils\TimeUtils.h"
@@ -189,15 +191,9 @@ extern void getMemoryLoad(String text);
extern void saveConfig();
extern String getURL(const String &urls);
extern String writeFile(String fileName, String strings);
extern String readFile(String fileName, size_t len);
extern String addFile(String fileName, String strings);
extern void servo_();
extern boolean isDigitStr(String str);
extern String jsonWriteStr(String &json, String name, String volume);
extern void led_blink(String satus);
extern int count(String str, String found);
// Mqtt
extern void MQTT_init();
@@ -208,7 +204,6 @@ extern void sendSTATUS(String topik, String state);
extern void sendCONTROL(String id, String topik, String state);
extern void do_mqtt_connection();
extern void handleMQTT();
extern String selectFromMarkerToMarker(String str, String found, int number);
// WiFiUtils
extern void WIFI_init();

30
include/Utils/FileUtils.h Normal file
View File

@@ -0,0 +1,30 @@
#pragma once
#include <Arduino.h>
#include <FS.h>
/*
* Чтение строки из файла
* возвращает стоку из файла в которой есть искомое слово found
*/
String readFileString(const String& filename, const String& str_to_found);
/*
* Добовление строки в файл
*/
String addFile(const String& fileName, const String& str);
/*
* Запись строки в файл
*/
String writeFile(const String& fileName, const String& str);
/*
* Чтение файла в строку
*/
String readFile(const String& fileName, size_t len);
/*
* Размер файла
*/
String sizeFile(const String& fileName);

View File

@@ -16,4 +16,8 @@ String deleteBeforeDelimiter(String str, String found);
String deleteBeforeDelimiterTo(String str, String found);
String selectFromMarkerToMarker(String str, String found, int number);
String selectFromMarkerToMarker(String str, String found, int number);
size_t itemsCount(String str, const String& separator);
boolean isDigitStr(const String&);

View File

@@ -11,9 +11,17 @@ void reconfigTime();
/*
* Получение текущего времени
*/
String GetTime();
String getTime();
/*
* Получаем время в формате linux gmt
*/
String getTimeUnix();
String GetTimeUnix();
/*
* Параметр время
* Результат выполнения
*/
boolean getUnixTimeStr(String&);
String GetTimeWOsec();