forked from arc-bphc/POV-lightsaber
-
Notifications
You must be signed in to change notification settings - Fork 1
/
File.h
49 lines (45 loc) · 1.11 KB
/
File.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include <stdio.h>
#include "esp_spiffs.h"
void initFileSystem()
{
esp_vfs_spiffs_conf_t conf = {
.base_path = "/spiffs",
.partition_label = NULL,
.max_files = 16,
.format_if_mount_failed = true
};
esp_vfs_spiffs_register(&conf);
//esp_spiffs_format(0);
size_t total = 0, used = 0;
esp_spiffs_info(0, &total, &used);
Serial.print("Total space on spiffs ");
Serial.println(total);
Serial.print("Used space ");
Serial.println(used);
}
void deinitFileSystem()
{
//esp_vfs_spiffs_unregister(0);
}
bool readFromFile(const char *fileName, unsigned char *dest, int count)
{
Serial.print("Reading ");
Serial.print(count);
Serial.println(" bytes from file.");
FILE* f = fopen(fileName, "r");
if(!f) return false;
fread(dest, sizeof(unsigned char), count, f);
return true;
}
bool writeToFile(const char *fileName, unsigned char *src, int count)
{
Serial.print("Writing ");
Serial.print(count);
Serial.println(" bytes to file.");
FILE* f = fopen(fileName, "w");
if(!f) return false;
fwrite(src, sizeof(unsigned char), count, f);
fclose(f);
return true;
}