Перевод на C++, исправление ошибок, драйвер СО2

This commit is contained in:
kkira
2026-06-18 19:45:49 +03:00
parent 7efb06407f
commit b8e49e2911
9 changed files with 137 additions and 266 deletions

View File

@@ -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;
}

View File

@@ -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;
};