@@ -233,9 +233,9 @@ Like so:
233
233
234
234
.. code-block :: arduino
235
235
236
- String myString = myPreferences.getString("myStringKey ");
236
+ float myFloat = myPreferences.getFloat("pi ");
237
237
238
- This will retrieve the String value from the namespace key ``"myStringKey " `` and assign it to the String type variable ``myString ``.
238
+ This will retrieve the float value from the namespace key ``"pi " `` and assign it to the float type variable ``myFloat ``.
239
239
240
240
241
241
Summary
@@ -277,9 +277,10 @@ When started, the system has no way of knowing which of the above conditions is
277
277
// not the complete setup(), but in setup(), include this...
278
278
279
279
stcPrefs.begin("STCPrefs", RO_MODE); // Open our namespace (or create it
280
- // if it doesn't exist) in in RO mode.
280
+ // if it doesn't exist) in RO mode.
281
281
282
- bool tpInit = stcPrefs.isKey("nvsInit"); // Test for the existence of the "already initialized" key.
282
+ bool tpInit = stcPrefs.isKey("nvsInit"); // Test for the existence
283
+ // of the "already initialized" key.
283
284
284
285
if (tpInit == false) {
285
286
// If tpInit is 'false', the key "nvsInit" does not yet exist therefore this
@@ -289,13 +290,15 @@ When started, the system has no way of knowing which of the above conditions is
289
290
290
291
291
292
// The .begin() method created the "STCPrefs" namespace and since this is our
292
- // first-time run we will create our keys and store the initial "factory default" values.
293
+ // first-time run we will create
294
+ // our keys and store the initial "factory default" values.
293
295
stcPrefs.putUChar("curBright", 10);
294
296
stcPrefs.putString("talChan", "one");
295
297
stcPrefs.putLong("talMax", -220226);
296
298
stcPrefs.putBool("ctMde", true);
297
299
298
- stcPrefs.putBool("nvsInit", true); // Create the "already initialized" key and store a value.
300
+ stcPrefs.putBool("nvsInit", true); // Create the "already initialized"
301
+ // key and store a value.
299
302
300
303
// The "factory defaults" are created and stored so...
301
304
stcPrefs.end(); // Close the namespace in RW mode and...
@@ -456,10 +459,12 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s
456
459
Serial.begin(115200);
457
460
delay(250);
458
461
459
- mySketchPrefs.begin("myPrefs", RW_MODE); // open (or create) the namespace "myPrefs" in RW mode
462
+ mySketchPrefs.begin("myPrefs", RW_MODE); // open (or create) the namespace
463
+ // "myPrefs" in RW mode
460
464
mySketchPrefs.clear(); // delete any previous keys in this namespace
461
465
462
- // Create an array of test values. We're using hex numbers throughout to better show how the bytes move around.
466
+ // Create an array of test values. We're using hex numbers
467
+ // throughout to better show how the bytes move around.
463
468
int16_t myArray[] = { 0x1112, 0x2122, 0x3132, 0x4142, 0x5152, 0x6162, 0x7172 };
464
469
465
470
Serial.println("Printing myArray...");
@@ -468,22 +473,28 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s
468
473
}
469
474
Serial.println("\r\n");
470
475
471
- // In the next statement, the second sizeof() needs to match the data type of the elements of myArray
472
- Serial.print("The number of elements in myArray is: "); Serial.println( sizeof(myArray) / sizeof(int16_t) );
473
- Serial.print("But the size of myArray in bytes is: "); Serial.println( sizeof(myArray) );
476
+ // In the next statement, the second sizeof() needs
477
+ // to match the data type of the elements of myArray
478
+ Serial.print("The number of elements in myArray is: ");
479
+ Serial.println( sizeof(myArray) / sizeof(int16_t) );
480
+ Serial.print("But the size of myArray in bytes is: ");
481
+ Serial.println( sizeof(myArray) );
474
482
Serial.println("");
475
483
476
- Serial.println("Storing myArray into the Preferences namespace \"myPrefs\" against the key \"myPrefsBytes\".");
484
+ Serial.println(
485
+ "Storing myArray into the Preferences namespace \"myPrefs\" against the key \"myPrefsBytes\".");
477
486
// Note: in the next statement, to store the entire array, we must use the
478
487
// size of the arrray in bytes, not the number of elements in the array.
479
488
mySketchPrefs.putBytes( "myPrefsBytes", myArray, sizeof(myArray) );
480
- Serial.print("The size of \"myPrefsBytes\" is (in bytes): "); Serial.println( mySketchPrefs.getBytesLength("myPrefsBytes") );
489
+ Serial.print("The size of \"myPrefsBytes\" is (in bytes): ");
490
+ Serial.println( mySketchPrefs.getBytesLength("myPrefsBytes") );
481
491
Serial.println("");
482
492
483
- int16_t myIntBuffer[20] = {}; // No magic about 20. Just making a buffer (array) big enough.
493
+ int16_t myIntBuffer[20] = {}; // No magic about 20. Just making a buffer (array) big enough.
484
494
Serial.println("Retrieving the value of myPrefsBytes into myIntBuffer.");
485
495
Serial.println(" - Note the data type of myIntBuffer matches that of myArray");
486
- mySketchPrefs.getBytes( "myPrefsBytes", myIntBuffer, mySketchPrefs.getBytesLength("myPrefsBytes") );
496
+ mySketchPrefs.getBytes("myPrefsBytes", myIntBuffer,
497
+ mySketchPrefs.getBytesLength("myPrefsBytes"));
487
498
488
499
Serial.println("Printing myIntBuffer...");
489
500
// In the next statement, sizeof() needs to match the data type of the elements of myArray
@@ -492,9 +503,11 @@ This is best explained with an example. Here the ``Bytes`` methods are used to s
492
503
}
493
504
Serial.println("\r\n");
494
505
495
- Serial.println("We can see how the data from myArray is actually stored in the namespace as follows.");
496
- uint8_t myByteBuffer[40] = {}; // No magic about 40. Just making a buffer (array) big enough.
497
- mySketchPrefs.getBytes( "myPrefsBytes", myByteBuffer, mySketchPrefs.getBytesLength("myPrefsBytes") );
506
+ Serial.println(
507
+ "We can see how the data from myArray is actually stored in the namespace as follows.");
508
+ uint8_t myByteBuffer[40] = {}; // No magic about 40. Just making a buffer (array) big enough.
509
+ mySketchPrefs.getBytes("myPrefsBytes", myByteBuffer,
510
+ mySketchPrefs.getBytesLength("myPrefsBytes"));
498
511
499
512
Serial.println("Printing myByteBuffer...");
500
513
for (int i = 0; i < mySketchPrefs.getBytesLength("myPrefsBytes"); i++) {
0 commit comments