summaryrefslogtreecommitdiffstats
path: root/movement/filesystem.h
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2022-05-09 12:14:42 -0400
committerJoey Castillo <joeycastillo@utexas.edu>2022-05-09 12:14:42 -0400
commit21ee056e26c3e158cf56f8577169f86b8d577a65 (patch)
tree12d2841a2d2ccd33eb1fbb73f7f1ad990d1cd140 /movement/filesystem.h
parent91b436237aaf39e2328b9380042aa40e06faa4cb (diff)
downloadSensor-Watch-21ee056e26c3e158cf56f8577169f86b8d577a65.tar.gz
Sensor-Watch-21ee056e26c3e158cf56f8577169f86b8d577a65.tar.bz2
Sensor-Watch-21ee056e26c3e158cf56f8577169f86b8d577a65.zip
first pass at filesystem in movement
Diffstat (limited to 'movement/filesystem.h')
-rw-r--r--movement/filesystem.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/movement/filesystem.h b/movement/filesystem.h
new file mode 100644
index 00000000..c9a5804c
--- /dev/null
+++ b/movement/filesystem.h
@@ -0,0 +1,79 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Joey Castillo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef FILESYSTEM_H_
+#define FILESYSTEM_H_
+#include <stdio.h>
+#include <stdbool.h>
+#include "watch.h"
+
+/** @brief Initializes and mounts the tiny 8kb filesystem, formatting it if need be.
+ * @return true if the filesystem was mounted successfully.
+ */
+bool filesystem_init(void);
+
+/** @brief Gets the space available on the filesystem.
+ * @return the free space in bytes
+ */
+int filesystem_get_free_space(void);
+
+/** @brief Checks for the existence of a file on the filesystem.
+ * @param filename the file you wish to check
+ * @return true if the file exists; false otherwise
+ */
+bool filesystem_file_exists(char *filename);
+
+/** @brief Removes a file on the filesystem.
+ * @param filename the file you wish to remove
+ * @return true if the file was deleted successfully; false otherwise
+ */
+bool filesystem_rm(char *filename);
+
+/** @brief Reads a file from the filesystem into a buffer
+ * @param filename the file you wish to read
+ * @param buf A buffer of at least length bytes; the file will be read into this buffer
+ * @param length The number of bytes to read
+ * @return true if the read was successful; false otherwise
+ * @note This function will set buf to zero and read all bytes of the file into the buffer.
+ * If you are reading a raw value (say you wrote a uint32 to a file), you can read back
+ * the value by passing in the file's length for length. If you wish to treat the buffer
+ * as a null-terminated string, allocate a buffer one byte longer than the file's length,
+ * and the last byte will be guaranteed to be 0.
+ */
+bool filesystem_read_file(char *filename, char *buf, int32_t length);
+
+/** @brief Writes file to the filesystem
+ * @param filename the file you wish to write
+ * @param text The contents of the file
+ * @param length The number of bytes to write
+ * @return true if the write was successful; false otherwise
+ */
+bool filesystem_write_file(char *filename, char *text, int32_t length);
+
+/** @brief Handles the interactive file browser when Movement is plugged in to USB.
+ * @param line The command that the user typed into the serial console.
+ */
+void filesystem_process_command(char *line);
+
+#endif // FILESYSTEM_H_