I’m trying to create a class property for managing application settings in non-volatile memory (e.g. user-adjustable settings remembered between runs, like Settings.Volume, and elegant code like “if (Settings.AccelerometerSupported) then… ). I just can’t make the compiler happy and fear this language may not even support the concept.
I haven’t worked in C++ in decades (am accustomed to higher-level languages), so I may be missing something obvious. Hours googling and attempting dozens of combinations of braces and semicolons have only yielded not-so-helpful compiler errors.
I know I can write public get_this and set_this methods/functions, but I’m trying to be more elegant about it. Can this be done, and if so, can someone help with the syntax? Thanks!
.h:
//Configuration/settings support
#ifndef SettingsManager_h
#define SettingsManager_h
#include "Arduino.h"
class SettingsManager
{
public:
//Instantiate
SettingsManager(int NVRAMOffset=0);
//Properties
byte AutoLockDelay {get_AutoLockDelay,set_AutoLockDelay}; //PROBLEM HERE, numerous attempts at combinations of {}; chars not shown
private:
int _NVRAMOffset;
void set_AutoLockDelay(byte value);
byte get_AutoLockDelay();
};
#endif
cpp:
//Configuration support
#include <Arduino.h>"
#include <EEPROM.h>
#include "SettingsManager.h"
//Offsets into NVRAM
#define NVRixAutoLockDelaySecs 0
//Instantiate
SettingsManager::SettingsManager(int NVRAMOffset)
{
_NVRAMOffset=NVRAMOffset;
}
//AutoLockDelay property
void SettingsManager::setAutoLockDelay(byte value)
{
EEPROM.write(_NVRAMOffset+NVRixAutoLockDelaySecs,value);
}
byte SettingsManager::getAutoLockDelay()
{
return(EEPROM.read(_NVRAMOffset+NVRixAutoLockDelaySecs));
}