Openfarm Core-AVR Documentation¶
This documentation is for the Openfarm Core Libraries for AVR Development. These libraries are an attempt to make it easier to jump start more serious AVR projects.
core-avr-ds¶
LinkedList¶
- template <class T>
-
class
LinkedList
¶ Basic doubly linked list implementation.
- Template Parameters
T
: Type parameter.
Public Functions
-
~LinkedList
()¶ Destructor.
-
void
clear
()¶ Clears all nodes.
-
int
count
()¶ The total number of elements.
- Return
- The total number of elements.
-
void
add
(T *element)¶ Adds an element to the list. Heap allocates a new node with which to store the element.
- Parameters
element
: The element to add.
-
bool
remove
(T *element)¶ Removes the element and deletes the node the element was stored within.
- Return
- True if successfully removed.
- Parameters
element
: The element to remove.
-
bool
contains
(T *element)¶ Determines if the element is contained within the list.
- Return
- True if the element is contained within the list.
- Parameters
element
: The element to query for.
Iterator¶
- template <class T>
-
class
Iterator
¶ Defines an interface for an iterator.
- Template Parameters
T
: Type parameter.
Subclassed by LinkedListIterator< T >
Public Functions
-
virtual
~Iterator
()¶ Destructor.
-
virtual T *
current
() = 0¶ Element currently pointed to.
- Return
- A pointer to the current element.
-
virtual void
reset
() = 0¶ Resets the iterator to the beginning.
-
virtual bool
moveNext
() = 0¶ Moves the iterator to the next value.
- Return
- True if there is another value, false otherwise.
Tuple¶
core-avr-logging¶
Log¶
-
namespace
Log
¶ Functions
-
void
setFormatter
(LogFormatter *formatter)¶ Sets the formatter for logs.
- Parameters
formatter
: The formatter.
-
void
removeTarget
(LogTarget *target)¶ Removes a target from receiving logs.
- Parameters
target
: The target.
-
void
log
(const char *level, const char *category, const char *message)¶ Log!
- Parameters
level
: The level of the log.category
: The category of the log.message
: The message to log.
-
void
Logger¶
-
class
Logger
¶ Logger instance.
Public Functions
-
Logger
(const char *category)¶ New logger of a specific category.
- Parameters
category
: The category to prefix logs with.
-
void
debug
(const char *message)¶ Logs at a debug level.
- Parameters
message
: The message to log.
-
void
info
(const char *message)¶ Logs at an info level.
- Parameters
message
: The message to log.
-
void
warn
(const char *message)¶ Logs at a warn level.
- Parameters
message
: The message to log.
-
void
error
(const char *message)¶ Logs at an error level.
- Parameters
message
: The message to log.
-
LogTarget¶
-
class
LogTarget
¶ Pure virtual base class that describes the LogTarget interface.
Subclassed by ConsoleLogTarget, DummyLogTarget, FunctionPointerLogTarget, SerialLogTarget
core-avr-io¶
AvrStream¶
-
class
AvrStream
¶ Abstracts the method of reading/writing bytes.
Subclassed by EEPROMStream, MemoryStream
Public Functions
-
virtual char
read
() = 0¶ Reads a single byte from the stream and advances the index.
- Return
- Returns the byte read.
-
virtual int
read
(char *const buffer, const int offset, const int count) = 0¶ Reads a block of bytes into the input buffer.
- Return
- The number of bytes actually read. -1 if there was an error.
- Parameters
buffer
: The buffer to read values into.offset
: The starting index.count
: The maximum number of bytes to read.
-
virtual bool
write
(const char value) = 0¶ Writes a single byte to the stream and advances the index.
- Return
- Returns true if the byte could be successfully written.
- Parameters
value
: The value to write.
-
virtual int
write
(char *const buffer, const int offset, const int count) = 0¶ Writes a block of bytes to the stream.
- Return
- Returns how many bytes were successfully written.
- Parameters
buffer
: The buffer to copy values from.offset
: The starting byte offset.count
: The number of bytes to write from buffer.
-
virtual int
set
(const char value, const int offset, const int count) = 0¶ Sets a block of bytes to a specific value. Effectively, memset.
- Return
- Returns how many bytes were successfully set.
- Parameters
value
: The value to fill with.offset
: The starting byte offset.count
: The number of bytes to set.
-
virtual int
seek
(const int offset, const int origin) = 0¶ Moves the index to a specific place. This is used when reading and writing single values.
- Return
- The current absolute index.
- Parameters
offset
: The offset to count from.origin
: The number of bytes to add to the offset.
-
virtual char
core-avr-database¶
Database¶
-
class
Database
¶ Entry point for adding data to + updating fixed size files.
Public Functions
-
~Database
()¶ Destructor.
-
float
numRecords
()¶ Total number of stored records.
- Return
- Total number of records stored.
-
bool
load
(AvrStream *stream, const int offset)¶ Loads header into memory. This is for Databases that already exist.
- Return
- True if the file was successfully loaded.
- Parameters
stream
: The stream to read/write from.offset
: The byte offset this file starts at.
-
bool
init
(AvrStream *stream, const int offset, const short contentSize, const char valuesPerRecord, const char *uri)¶ Writes header to disk. This is for new Databases.
- Return
- True if the file was successfully written.
- Parameters
stream
: The stream to write to.offset
: The byte offset this file starts at.contentSize
: The size, in bytes, of the file.valuesPerRecord
: The number of values per record.uri
: The uri of the resource.
-
bool
flush
()¶ Flushes any changes to the stream, in case the Database decides to cache.
- Return
- { description_of_the_return_value }
-
bool
add
(const float *value)¶ Adds a set of values to the file. These values are added with a timestamp.
- Return
- Returns true iff the add was successful.
- Parameters
value
: The floats to add to the file.
-
int
dump
(char *buffer, const int recordDffset, const int recordCount)¶ Dumps database data to a buffer. Format is described in more detail in the core-avr-sensor documentation.
This method may modify the buffer and still fail.
- Return
- Returns the number of records copied.
- Parameters
buffer
: Buffer to copy records into.recordOffset
: The starting index of records.recordCount
: The number of records to copy into the buffer.
Public Members
-
DatabaseHeader
header
¶ Header information.
-
Database Manager¶
-
class
DatabaseManager
¶ The DatabaseManager class exposes a fixed-size file manipulation API, based on URI.
Public Functions
-
DatabaseManager
(AvrClock *clock, AvrStream *stream)¶ Constructor.
- Parameters
clock
: The clock implementation to use.stream
: The stream to read/write data with.
-
~DatabaseManager
()¶ Destructor.
-
bool
load
(DatabaseManagerConfig config)¶ Attempts to load existing filesystem.
- Return
- Returns true if everything is good to go.
-
bool
init
(DatabaseManagerConfig config)¶ Initializes a new filesystem.
- Return
- Returns true if everything is good to go.
-
Database *
create
(const char *uri, const int size, const char valuesPerRecord)¶ Creates a Database of a specific size, linked to a URI.
-
Database *
get
(const char *uri)¶ Retrieves a file by uri.
- Return
- If the Database was found, the file. Otherwise, nullptr.
- Parameters
uri
: The uri to retrieve the file with.
-
bool
set
(Database *file)¶ Writes the file. This is the equivalent to calling Database::flush().
- Return
- Returns true if the Database was successfully saved.
- Parameters
file
: The file to write to disk.
-
AvrClock¶
-
class
AvrClock
¶ Abstraction for clock.
Subclassed by ArduinoClock, StandardClock
core-avr-sensor¶
SensorManager¶
-
class
SensorManager
¶ Manages all sensors.
Public Functions
-
SensorManager
(DatabaseManager *data)¶ Constructor.
- Parameters
data
: The database layer.
-
~SensorManager
()¶ Destructor.
-
bool
add
(Sensor *sensor)¶ Adds a sensor.
- Return
- True if the sensor was successfully added.
- Parameters
sensor
: The sensor to add.
-
bool
remove
(Sensor *sensor)¶ Removes a sensor.
- Return
- True if the sensor was successfully removed.
- Parameters
sensor
: The sensor to remove.
-
void
update
(double dt)¶ Updates sensors. This will automatically determine which sensors to poll and write to the database layer.
- Parameters
dt
: The amount of ms that has passed since last update.
-
Sensor¶
-
class
Sensor
¶ Abstract base class for a Sensor.
Subclassed by Dht11Sensor, DummySensor
Public Functions
-
Sensor
()¶ Constructor.
-
virtual
~Sensor
()¶ Destructor.
-
SensorConfig
config
()¶ Retrieves the configuration for this sensor.
- Return
- Config for this object.
-
bool
init
(SensorConfig config)¶ Initializes the sensor.
- Return
- True if sensor initialization was successful.
- Parameters
config
: The configuration for this sensor.
-
virtual bool
poll
(const float *values) = 0¶ Polls the sensor for values.
- Return
- True if the sensor could generate values.
- Parameters
values
: Output values.
-