Skip to content

Community.Hardware.UserSettings

NicolasG3 edited this page Jun 7, 2013 · 1 revision

Community.Hardware.UserSettings allows access to a user config block stored in flash memory.

  • 256 bytes buffer
  • persistent storage in flash memory

Usage
Only one UserSettings exists in the system, it is implemented as a singleton in static member UserSettings.Default Community.System.BitConverter can be used to read and write in the byte buffer.

Sample code

//Get user persistent settings
byte byteValue = UserSettings.Default.Data[0];
byte strLen = UserSettings.Default.Data[1];
String text = null;
if (strLen > 0) 
    text = new String(Encoding.UTF8.GetChars(UserSettings.Default.Data, 2, strLen));
//update values and save
byteValue++;
UserSettings.Default.Data[0] = byteValue;
Byte[] bytes = Encoding.UTF8.GetBytes("Persistent text");
strLen = (byte)bytes.Length;    //assume the string is not larger than the UserSettings buffer
UserSettings.Default.Data[1] = strLen;
bytes.CopyTo(UserSettings.Default.Data, 2);
UserSettings.Default.Save();