From 21ee056e26c3e158cf56f8577169f86b8d577a65 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Mon, 9 May 2022 12:14:42 -0400 Subject: first pass at filesystem in movement --- movement/filesystem.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 movement/filesystem.h (limited to 'movement/filesystem.h') 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 +#include +#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_ -- cgit v1.2.3