Skip to content

Commit

Permalink
Add pre-commit config (#15)
Browse files Browse the repository at this point in the history
Fix linting checks
  • Loading branch information
charlesbaynham authored Sep 27, 2021
1 parent 5851f5b commit c7a7d5d
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ vendor

# C++ stuff
*.bin
*.bin.dSYM
*.bin.dSYM
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1 # Use the ref you want to point at
hooks:
- id: trailing-whitespace
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- id: check-added-large-files
args: ['--maxkb=123']

# Disabled clang formatting since it requires clang to be installed
# separately which isn't compatible with pre-commit cloud
#
# - repo: https://github.com/pocc/pre-commit-hooks
# rev: v1.3.4
# hooks:
# - id: clang-format
# args: [--style=Google]
# - id: clang-tidy
# - id: oclint
# - id: uncrustify
# - id: cppcheck
# - id: cpplint
# - id: include-what-you-use
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: ruby
script:
- bundle install
- bundle exec arduino_ci_remote.rb
- bundle exec arduino_ci_remote.rb
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source 'https://rubygems.org'
gem 'arduino_ci'
gem 'arduino_ci'
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Overly Simplified File System (OSFS)
====================================

Provides an extremely basic, low footprint file system for EEPROM access in
an Arduino or other AVR microprocessor. Could be ported to other architectures very easily.
an Arduino or other AVR microprocessor. Could be ported to other architectures very easily.

Note
----
Expand All @@ -19,12 +19,12 @@ and `writeNBytes` functions to interface the library with your storage medium.
Usage
-----

The user must define interface functions to read / write from the memory in use.
This means that OSFS can be used for arbitrary storage media, including external
hardware interfaced by e.g. SPI.
The user must define interface functions to read / write from the memory in use.
This means that OSFS can be used for arbitrary storage media, including external
hardware interfaced by e.g. SPI.

To use OSFS with the Arduino EEPROM, copy the function definitions from the examples
into your program header.
To use OSFS with the Arduino EEPROM, copy the function definitions from the examples
into your program header.

Datatypes can be stored using the command `newFile`, e.g.

Expand All @@ -44,9 +44,9 @@ OSFS will refuse to deal with your ROM unless it has first been `format()`ed:

OSFS::format();

All OSFS functions return an `enum class result` which will give you more information
if they fail. E.g.
All OSFS functions return an `enum class result` which will give you more information
if they fail. E.g.

using namespace OSFS;

r = getFile("testInt", testInt);
Expand All @@ -56,13 +56,13 @@ if they fail. E.g.
else if (r == result::NO_ERROR)
// File found
else {
// Another error occurred.
// Another error occurred.
// See OSFS.h for a full list of error codes
int errCode = (int) r;
}

The OSFS functions `newFile` and `getFile` use templates to accept any data type, including
custom classes or structs. See the example `writeTest.ino` for details.
custom classes or structs. See the example `writeTest.ino` for details.

Alternatively, `newFile` can write a given number of bytes into storage, starting at a given
location. This is particularly useful for storing strings, e.g.:
Expand Down Expand Up @@ -106,13 +106,13 @@ Each file has a header of n bytes:
`Size of file` and `pointer to next` are both present because a file may not
necessarily fill all the available space, e.g. if it has been overwritten
with a smaller file. As of v1.2, overwriting with a larger file is supported if
there is a sufficiently large continuous space available to place it in.
there is a sufficiently large continuous space available to place it in.

The first 4 bytes of EEPROM are reserved for information about this library:
Bytes 1 to 4 = "OSFS" Bytes 5 to 6 = uint16_t containing version info.

Unless these 6 bytes match their expected values, this library will consider
the EEPROM to be unformatted and will refuse to work with it until format() is called.
the EEPROM to be unformatted and will refuse to work with it until format() is called.

Interface functions
-------------------
Expand All @@ -124,37 +124,37 @@ backwards compatibility), these can be used to access any type of storage
medium, not just EEPROM. The example files show how this can be done for
accessing the built-in EEPROM on an AVR device. The tests show how to point
them at a chunk of RAM instead (slightly pointless in real life, since the
contents would be lost on power-off).
contents would be lost on power-off).

To define your own interface, copy the following definitions into your code:

```
// Here we define the four pieces of information that OSFS needs to make a filesystem:
//
//
// 1) and 2) How large is the storage medium?
uint16_t OSFS::startOfEEPROM = 1;
uint16_t OSFS::endOfEEPROM = 1024;
// 3) How do I read from the medium?
void OSFS::readNBytes(uint16_t address, unsigned int num, byte* output) {
... code that copies `num` bytes from your storage medium
... code that copies `num` bytes from your storage medium
at `address` into the waiting array `output` ...
}
// 4) How to I write to the medium?
void OSFS::writeNBytes(uint16_t address, unsigned int num, const byte* input) {
... code that copies `num` bytes from the array `input`
... code that copies `num` bytes from the array `input`
into `address` on your storage medium ...
}
```

You don't need to include checks for overflowing your memory bounds in `readNBytes` and `writeNBytes` since OSFS will check `address` and `num` against the `startOfEEPROM` and `endOfEEPROM` constants you provide.
You don't need to include checks for overflowing your memory bounds in `readNBytes` and `writeNBytes` since OSFS will check `address` and `num` against the `startOfEEPROM` and `endOfEEPROM` constants you provide.

Once these four components are defined, OSFS will now manage that chunk of
your storage medium. Call `OSFS::format()` to get going and follow the
examples for tips. Note that you don't have to provide OSFS with the whole
thing: it's just as happy managing a small piece of your memory as it is
managing all of it.
managing all of it.



Expand Down
6 changes: 3 additions & 3 deletions examples/readTest/readTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void setup() {
////////////////////////////

Serial.println(F("Looking for testInt..."));

int testInt;
r = OSFS::getFile("testInt", testInt);

Expand All @@ -67,7 +67,7 @@ void setup() {
////////////////////////////

Serial.println(F("Looking for testStr..."));

char testStr[15];
uint16_t filePtr, fileSize;
r = OSFS::getFileInfo("testStr", filePtr, fileSize);
Expand Down Expand Up @@ -95,7 +95,7 @@ void setup() {
};

complexType testCplx;

r = OSFS::getFile("testCplx", testCplx);

if (r == notfound)
Expand Down
4 changes: 2 additions & 2 deletions examples/writeTest/writeTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

// Here we define the four pieces of information that OSFS needs to make a filesystem:
//
//
// 1) and 2) How large is the storage medium?
uint16_t OSFS::startOfEEPROM = 1;
uint16_t OSFS::endOfEEPROM = 1024;
Expand All @@ -38,7 +38,7 @@ void OSFS::writeNBytes(uint16_t address, unsigned int num, const byte* input) {
}


// The rest is your program as normal.
// The rest is your program as normal.
void setup() {

Serial.begin(57600);
Expand Down
2 changes: 1 addition & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ isDeletedFile KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
#######################################
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ version=1.2.2
author=Charles Baynham <[email protected]>
maintainer=Charles Baynham <[email protected]>
sentence=An Overly Simplified FileSystem for storing things, e.g. in the Arduino's EEPROM
paragraph=Provides an extremely basic, low footprint file system for storage access in an Arduino or other AVR microprocessor. Could be ported to other architectures very easily. The examples provided show how to use OSFS with the Arduino's EEPROM, but it can be used with any sequentially addressed form of storage.
paragraph=Provides an extremely basic, low footprint file system for storage access in an Arduino or other AVR microprocessor. Could be ported to other architectures very easily. The examples provided show how to use OSFS with the Arduino's EEPROM, but it can be used with any sequentially addressed form of storage.
category=Data Storage
url=https://github.com/charlesbaynham/OSFS
architectures=avr
includes=OSFS.h
includes=OSFS.h
36 changes: 17 additions & 19 deletions src/OSFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace OSFS {
char paddedFilename[FILE_NAME_LENGTH];
padFilename(filename, paddedFilename);

// Loop through checking the file header until
// Loop through checking the file header until
// a) we reach a NULL pointer,
// b) we find a deleted file that can be overwritten
// c) we get an OOL pointer somehow
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace OSFS {

// If there's no next file
if (workingHeader.nextFile == 0) {

return result::FILE_NOT_FOUND;
}

Expand All @@ -73,7 +73,7 @@ namespace OSFS {

// Header for new file
fileHeader newHeader;

// Store padded filename in newHeader
padFilename(filename, newHeader.fileID);

Expand Down Expand Up @@ -108,7 +108,7 @@ namespace OSFS {
uint16_t workingAddress = startOfEEPROM + sizeof(FSInfo);
uint16_t writeAddress;

// Loop through checking the file header until
// Loop through checking the file header until
// a) we reach a NULL pointer (i.e. the end of the current files)
// b) we find a deleted file that can be overwritten
// c) we run out of space
Expand All @@ -121,11 +121,11 @@ namespace OSFS {
if (r != result::NO_ERROR)
return r;


// If there's no next file, calculate the start of the spare space and break the loop
// Note that we might find a file header with fileSize == 0 if there are no files on
// the filesystem at all. In this case, overwrite this "dummy header".
if (workingHeader.nextFile == 0) {
// Note that we might find a file header with fileSize == 0 if there are no files on
// the filesystem at all. In this case, overwrite this "dummy header".
if (workingHeader.nextFile == 0) {
if (workingHeader.fileSize != 0)
writeAddress = workingAddress + sizeof(workingHeader) + workingHeader.fileSize;
else
Expand All @@ -149,19 +149,19 @@ namespace OSFS {
workingAddress = workingHeader.nextFile;
}

// See if there's enough space in the EEPROM to fit our file in
// See if there's enough space in the EEPROM to fit our file in
if (writeAddress + sizeRequired - 1 > endOfEEPROM)
return result::INSUFFICIENT_SPACE;

// We have a pointer to an address that has sufficient space to store our
// data, in writeAddress.
//
// data, in writeAddress.
//
// We have a pointer to the previous header in workingAddress
//
//
// We have a copy of the previous header in workingHeader
//
// First, constuct a header for this file:

newHeader.fileSize = size;
if (workingHeader.nextFile == 0)
newHeader.nextFile = 0;
Expand All @@ -179,7 +179,7 @@ namespace OSFS {
}

result deleteFile(const char * filename) {

// Confirm that the EEPROM is managed by this version of OSFS
result r = checkLibVersion();

Expand All @@ -194,7 +194,7 @@ namespace OSFS {
fileHeader workingHeader;
uint16_t workingAddress = startOfEEPROM + sizeof(FSInfo);

// Loop through checking the file header until
// Loop through checking the file header until
// a) we reach a NULL pointer,
// b) we find our file and it's not deleted
// c) we get an OOL pointer somehow
Expand All @@ -209,10 +209,9 @@ namespace OSFS {

// Delete the file if it has the same name and isn't already deleted
if (!isDeletedFile(workingHeader) && 0 == strncmp(workingHeader.fileID, filenamePadded, FILE_NAME_LENGTH)) {

workingHeader.flags = workingHeader.flags | 1<<DELBIT;
r = writeNBytesChk(workingAddress, sizeof(fileHeader), &workingHeader);

if (r != result::NO_ERROR)
return r;

Expand Down Expand Up @@ -289,7 +288,7 @@ namespace OSFS {
}

result readNBytesChk(uint16_t address, unsigned int num, void* output) {

if (address < startOfEEPROM || address > endOfEEPROM) return result::UNCAUGHT_OOR;
if (address + num < startOfEEPROM || address + num > endOfEEPROM) return result::UNCAUGHT_OOR;

Expand All @@ -303,7 +302,6 @@ namespace OSFS {
// Pad filename to FILE_NAME_LENGTH chars
bool ended = false;
for (int i = 0; i<FILE_NAME_LENGTH; i++) {

char inChar;
if (!ended)
inChar = *(filenameIn+i);
Expand Down
Loading

0 comments on commit c7a7d5d

Please sign in to comment.