Skip to content

janscience/MicroConfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arduino-lint

MicroConfig

Configuration menus for microcontrollers.

Developed for Teensy and Arduino, but should run on many more micro controllers, since it is mostly plain C++ code.

Features

  • Interactive configuration and execution via serial streams.
  • Read and write YAML configuration file on SD card.
  • Configures key-value pairs, with values being strings, enums, booleans, integer types, or floats.
  • Numerical types with units and unit conversion.
  • Object-oriented and templated interface.
  • Stores pointers to arbitarily sized action names (no memory consuming copies).
  • Predefined menu for reporting, saving, loading and erasing configuration file.
  • Predefined menu for uploading firmware, based on FlasherX.

ToDo

  • Make the serialmonitor.py and the general aspects of the logger configuration GUI a proper python package.
  • In unit conversion do not only check the prefix but also the unit itself.
  • Support transfer of configuration to another micro controller via a serial stream.
  • Store and retrieve configuration to EEPROM in a compact way.

Usage

This is a brief teaser, for details see the user guide.

Define a menu with a number of submenus and configurable parameters:

#include <SD.h>
#include <MicroConfig.h>

Config config("micro.cfg", &SD);               // main menu and configuration file
Menu settings(config, "Settings");             // settings sub menu
StringParameter<32> path(settings, "Path", "recordings/");
char filename[64] = "recording.wav";
StringPointerParameter<64> file_name(settings, "Recording", &filename);
NumberParameter<float> file_time(settings, "FileTime", 30.0, 1.0, 8640.0, "%.0f", "s");

Menu aisettings(config, "Analog input");       // analog input sub menu
NumberParameter<uint32_t> rate(aisettings, "SamplingRate", 48000, 1, 1000000, "%.1f", "Hz", "kHz");

// sub menu for reporting, saving, loading and removing configuration file:
ConfigurationMenu configuration_menu(config, SD);
HelpAction help_act(config, "Help");

Load the configuration file and execute the menu like this:

void setup() {
  Serial.begin(9600);
  while (!Serial && millis() < 2000) {};
  SD.begin(BUILTIN_SDCARD);              // initialize SD card
  config.load();                         // load configuration file from SD card
  if (Serial)
    config.execute(Serial, 10000);       // execute the main menu, 10s timeout
}

Then you get:

Configuration file "micro.cfg" not found or empty.

Menu:
  1) Settings ...
  2) Analog input ...
  3) Configuration ...
  4) Help
  Select: 

The first two sub menus allow you to change the values of the parameters defined above.

Hit '3' followed by return to enter the configuration menu, where you can choose to view the current configuration:

Settings:
  Path:     recordings/
  FileTime: 300s
Analog input:
  SamplingRate: 48.0kHz

The configuration file, that you can also save from this menu, looks exactly like this as well. The format is compatible with YAML files and can be easily edited.

The configuration values can be accessed by the .value() member functions. The value of the file name parameter is directly stored in the provided variable. The following code

  Serial.printf("path: %s\n", path.value());
  Serial.printf("file name: %s\n", filename);
  Serial.printf("file time: %g\n", file_time.value());
  Serial.printf("sampling rate: %u\n", rate.value());

prints

path: recordings/
file name: recording.wav
file time: 30
sampling rate: 48000

Note that for the file name we do not need to retrieve the value from the parameter. Instead we just use the variable that has been automagically set by the StringPointerParameter.

Nice and easy, isn't it?

Interface

Basic menu structure

  • Action: Base class for executable or configurable menu entries.
  • Parameter: Actions with configurable name-value pairs of various types.
  • Menu: A menu of actions and parameters.
  • Config: Menu with configuration file.

Help and configuration menu

Menu for firmware updates

Examples

In examples/ you find sketches demonstrating the use of the MicroConfig libraries.

  • menu: Example demonstrating most features of the MicroConfig library.

Utilities

In utils/ you find useful python scripts:

  • serialmonitor: serial monitor for the console that automatically detects Teensys connected to USB.

Applications of the MicroConfig libraries

MicroConfig is used in:

About

Configuration menus for microcontrollers

Resources

License

Stars

Watchers

Forks

Packages

No packages published