mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-07-21 22:19:12 -04:00
Converge File object with std::fstream. Simplify LogFile.
LogFile no longer watches SD card presence and tries to open/close files dynamically.
This commit is contained in:
parent
4d6fccd8ea
commit
0d6103916d
11 changed files with 59 additions and 88 deletions
|
@ -23,28 +23,14 @@
|
|||
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
LogFile::LogFile(
|
||||
const std::string& file_path
|
||||
) : file_path { file_path }
|
||||
) : file { file_path, File::openmode::out | File::openmode::ate }
|
||||
{
|
||||
file.open_for_append(file_path);
|
||||
|
||||
sd_card_status_signal_token = sd_card::status_signal += [this](const sd_card::Status status) {
|
||||
this->on_sd_card_status(status);
|
||||
};
|
||||
}
|
||||
|
||||
LogFile::~LogFile() {
|
||||
sd_card::status_signal -= sd_card_status_signal_token;
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
bool LogFile::is_ready() {
|
||||
return file.is_ready();
|
||||
bool LogFile::is_open() const {
|
||||
return file.is_open();
|
||||
}
|
||||
|
||||
bool LogFile::write_entry(const rtc::RTC& datetime, const std::string& entry) {
|
||||
|
@ -55,11 +41,3 @@ bool LogFile::write_entry(const rtc::RTC& datetime, const std::string& entry) {
|
|||
bool LogFile::write(const std::string& message) {
|
||||
return file.puts(message) && file.sync();
|
||||
}
|
||||
|
||||
void LogFile::on_sd_card_status(const sd_card::Status status) {
|
||||
if( status == sd_card::Status::Mounted ) {
|
||||
file.open_for_append(file_path);
|
||||
} else {
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue