Перевод на C++, исправление ошибок, драйвер СО2
This commit is contained in:
@@ -1,27 +1,18 @@
|
||||
#include "sd_task.hpp"
|
||||
|
||||
#include "queues.hpp"
|
||||
#include "co2_data.hpp"
|
||||
#include "sdcard.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
static SDCard sd;
|
||||
|
||||
void SDTask_Run()
|
||||
{
|
||||
sd.Init();
|
||||
|
||||
CO2Data data;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (xQueueReceive(
|
||||
g_sdQueue,
|
||||
&data,
|
||||
portMAX_DELAY))
|
||||
{
|
||||
sd.AppendCO2(
|
||||
data.timestamp,
|
||||
data.ppm);
|
||||
}
|
||||
}
|
||||
bool SDCardLogger::init() {
|
||||
return (f_mount(&fs, "", 1) == FR_OK);
|
||||
}
|
||||
|
||||
bool SDCardLogger::write(const std::string &line) {
|
||||
if (f_open(&file, "co2_log.txt", FA_OPEN_APPEND | FA_WRITE) != FR_OK)
|
||||
return false;
|
||||
|
||||
UINT bw;
|
||||
f_write(&file, line.c_str(), line.size(), &bw);
|
||||
f_write(&file, "\r\n", 2, &bw);
|
||||
f_close(&file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
#pragma once
|
||||
#include "fatfs.h"
|
||||
#include <string>
|
||||
|
||||
void SDTask_Run();
|
||||
class SDCardLogger {
|
||||
public:
|
||||
bool init();
|
||||
bool write(const std::string &line);
|
||||
|
||||
private:
|
||||
FIL file;
|
||||
FATFS fs;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user