Fixed scale tare

This commit is contained in:
Martin Bauer
2020-06-05 20:55:01 +02:00
parent 123c2a534b
commit daa2454e71
14 changed files with 622 additions and 44 deletions

View File

@@ -17,4 +17,4 @@ inline String toString(const T & t) {
return String(t);
}
#define assert(EXPRESSION, MSG) ((EXPRESSION) ? (void)0 : _assert(#EXPRESSION, #MSG, __FILE__, __LINE__))
#define assert_msg(EXPRESSION, MSG) ((EXPRESSION) ? (void)0 : _assert(#EXPRESSION, #MSG, __FILE__, __LINE__))

View File

@@ -0,0 +1,181 @@
#pragma once
#ifdef PLATFORM_ESP32
#include "SPIFFS.h"
namespace portablefs
{
using File = ::File;
class Dir
{
public:
Dir() {}
Dir(const String &path)
: root_(SPIFFS.open(path))
{
//next();
}
bool next()
{
file_ = root_.openNextFile();
return file_;
}
bool isFile()
{
return !file_.isDirectory();
}
bool isDirectory()
{
return file_.isDirectory();
}
String fileName() const
{
return file_.name();
}
size_t fileSize() const
{
return file_.size();
}
private:
File root_;
File file_;
};
inline Dir openDir(const String &path)
{
return Dir(path);
}
inline File open(const char *name, const char *mode)
{
return SPIFFS.open(name, mode);
}
inline bool exists(const char *name)
{
return SPIFFS.exists(name);
}
inline bool remove(const char *name)
{
return SPIFFS.remove(name);
}
inline bool mkdir(const char *name)
{
return SPIFFS.mkdir(name);
}
} // namespace portablefs
#endif
#ifdef PLATFORM_ESP8266
#include <FS.h>
namespace portablefs
{
using Dir;
} // namespace portablefs
#endif
#ifdef PLATFORM_NATIVE
#include <string>
#include <fstream>
#include <filesystem>
#include "MockDtypes.h"
namespace fs = std::filesystem;
namespace portablefs
{
const std::string basePath = "./base";
class Dir
{
public:
Dir() {}
Dir(const String &path)
: it_(fs::directory_iterator(path).begin()),
end_(fs::directory_iterator(path).end()),
firstIncremented_(false)
{
}
bool next()
{
if (!firstIncremented_)
firstIncremented_ = true;
else
++it_;
return it_ != end_;
}
bool isFile()
{
return file.is_regular_file();
}
bool isDirectory()
{
return it_.is_directory();
}
String fileName() const
{
return it_.path().filename().string();
}
size_t fileSize() const
{
return it_.file_size();
}
private:
fs::directory_iterator it_;
fs::directory_iterator end_;
bool firstIncremented_;
};
inline Dir openDir(const String &path)
{
return Dir(path);
}
inline File open(const char *name, const char *mode)
{
if(mode == "r")
return fopen()
return SPIFFS.open(name, mode);
}
inline bool exists(const char *name)
{
return SPIFFS.exists(name);
}
inline bool remove(const char *name)
{
return SPIFFS.remove(name);
}
inline bool mkdir(const char *name)
{
return SPIFFS.mkdir(name);
}
} // namespace portablefs
#endif

View File

@@ -7,6 +7,7 @@
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
typedef uint32_t uint_t;
@@ -39,4 +40,7 @@ inline std::string toString(const T & t) {
return stream.str();
}
class String : public std::string
{};
#define assert(EXPRESSION, MSG) ((EXPRESSION) ? (void)0 : _assert(#EXPRESSION, #MSG, __FILE__, __LINE__))