/Feature-Variables

Persistent event driven variables aimed at making complex designs much simpler

Primary LanguageC++MIT LicenseMIT

Features-Variables

GitHub release arduino-library-badge PlatformIO Build Status Arduino Build Status GitHub License

Features are persistent event driven variables specifically for use with the popular Arduino boards and Espressif series micro controllers. They simplify everything from loading and saving variable data into flash for persistance over reboots, to firing multiple events when the value of a variable has changed, to simplifying data passing when using ArduinoJSON, all in a few lines of easy to understand code.

The library and examples are supported in the Arduino IDE and platformIO for building. Check out the library.properties or platfomio.ini file for idea on how to build the library in the Arduino IDE or on pio. Included are a heap of examples on how to use each of the advantages of Features in your application fully compatible with both build methods.

If you would like to reach out, this project is open to comments, improvements, or general feedback, so feel free to open an issue or create a pull request with any ideas!

Quick Start

Starting or migrating a project to Features is easy. Just see this short example of how to create a very basic Feature application storing the value of millis() every second:

#include <Effortless_SPIFFS.h> // Optional
#include <FeatureVariables.h>

// Create a Global Feature - opens value from flash automatically when using Effortless_SPIFFS!
Feature<unsigned long> current_millis;

// Create a callback
void string_callback(unsigned long _current_millis) {
  Serial.printf("my_string has changed to: \"%u\"\n", _current_millis);
}

void setup() {
  // Start Serial
  Serial.begin(115200);
  Serial.println();

  // Add callback to Feature
  current_millis.addEventCallback(string_callback);
}

void loop() {
  // Assign millis() to Feature every second - saves value automatically when using Effortless_SPIFFS!
  current_millis = millis();
  delay(1000);
}

Examples

For a comprehensive understanding of the API and how to use Features check out the examples folder. In there you can find several examples showing:

Contributing

Contributions of any type are most welcome. Feel free to open an issues with feedback, questions, ideas, or anything else regarding Features or a pull request for new any ideas on code style or implementation.