Skip to content

Plunger Settings Component

Path: src/PlungerSettings.h

Revision History: Initial documentation

PlungerSettings is a configuration management component for plunger mechanisms. It provides a structured way to define, store, and retrieve operational parameters for plunger controls, including speeds, timeouts, current thresholds, and behavioral settings. The component supports JSON serialization for persistent storage in the filesystem.

  • LittleFS filesystem support for persistent storage
  • JSON processing capabilities (via ArduinoJson)
  • Logging functionality (ArduinoLog)
  • Comprehensive parameter set for plunger operation control
  • Default values based on predefined constants
  • JSON serialization and deserialization
  • Persistent storage in LittleFS
  • Type-safe parameter parsing with error handling
  • Detailed diagnostic logging

PlungerSettings

Arduino

ArduinoJson

LittleFS

ArduinoLog

Plunger

From Constants

From Parameters

Yes

No

Yes

No

Valid

Invalid

Constructor

Default Values

Initialize Settings

Initialize Settings

Load Settings

File Exists?

Parse JSON

Keep Default Values

Parse Success?

Update Settings

Keep Default Values

Save Settings

Serialize to JSON

Write to File

fromJson

Parse Each Setting

Type Validation

Update Setting

Keep Default Value

print

Log All Settings

  • Consider using a static JsonDocument with predefined capacity to avoid dynamic memory allocation
  • Implement selective parameter updates to minimize file writes
  • Add validation ranges for settings to prevent extreme values that might cause hardware issues
  • Consider adding checksums or signatures to detect tampering with settings files
  • Implement access control mechanisms for settings modification
  • Sanitize inputs from external sources before applying to settings
  • Ensure parameter ranges comply with hardware specifications
  • Add parameter validation to prevent unsafe mechanical operations
  • Document any safety-critical parameters and their implications
  • Create a web-based configuration interface for easy parameter adjustment
  • Implement settings profiles for different operational scenarios
  • Add ability to backup/restore settings to/from external storage
  • Consider implementing periodic settings validation to detect drift or corruption

The PlungerSettings component can be used as follows:

// Create settings object with default values
PlungerSettings settings;
// Load saved settings from filesystem
if (settings.load()) {
Log.infoln("Loaded plunger settings from filesystem");
} else {
Log.warningln("Using default plunger settings");
// Save current defaults to create the settings file
settings.save();
}
// Access settings
uint16_t speed = settings.speedMediumHz;
// Update a setting
settings.currentJamThresholdMa = 1200;
// Save updated settings
settings.save();
// Debug output all settings
settings.print();

Documentation for the PlungerSettings class including JSON serialization and deserialization methods, persistent storage capabilities, and configuration parameters for plunger operation control.