Skip to content

Commit f9ba8e9

Browse files
arcaome-no-dev
authored andcommitted
Refactoring EPS32NVS library to Preferences library (espressif#199)
* Refactoring EPS32NVS library to Preferences library * Renaming all set* functions to put * Added functions for float, double and bool * Small redesign of Preferences API * added type to put* function names * for (u)int64_t used functions name with *(U)Long64 * added functions for long and unsigned long (same like int a unsigned int)
1 parent 4a90aee commit f9ba8e9

File tree

7 files changed

+218
-152
lines changed

7 files changed

+218
-152
lines changed

Diff for: libraries/ESP32NVS/examples/StartCounter/StartCounter.ino

-56
This file was deleted.

Diff for: libraries/ESP32NVS/keywords.txt

-41
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
ESP32 start counter example with Preferences library
3+
4+
This simple example demonstrate using Preferences library to store how many times
5+
was ESP32 module started. Preferences library is wrapper around Non-volatile
6+
storage on ESP32 processor.
7+
8+
created for arduino-esp32 09 Feb 2017
9+
by Martin Sloup (Arcao)
10+
*/
11+
12+
#include <Preferences.h>
13+
14+
Preferences preferences;
15+
16+
void setup() {
17+
Serial.begin(115200);
18+
Serial.println();
19+
20+
// Open Preferences with my-app namespace. Each application module, library, etc.
21+
// has to use namespace name to prevent key name collisions. We will open storage in
22+
// RW-mode (second parameter has to be false).
23+
// Note: Namespace name is limited to 15 chars
24+
preferences.begin("my-app", false);
25+
26+
// Remove all preferences under opened namespace
27+
//preferences.clear();
28+
29+
// Or remove the counter key only
30+
//preferences.remove("counter");
31+
32+
// Get a counter value, if key is not exist return default value 0
33+
// Note: Key name is limited to 15 chars too
34+
unsigned int counter = preferences.getUInt("counter", 0);
35+
36+
// Increase counter
37+
counter++;
38+
39+
// Print counter to a Serial
40+
Serial.printf("Current counter value: %u\n", counter);
41+
42+
// Store counter to the Preferences
43+
preferences.putUInt("counter", counter);
44+
45+
// Close the Preferences
46+
preferences.end();
47+
48+
// Wait 10 seconds
49+
Serial.println("Restarting in 10 seconds...");
50+
delay(10000);
51+
52+
// Restart ESP
53+
ESP.restart();
54+
}
55+
56+
void loop() {}

Diff for: libraries/Preferences/keywords.txt

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#######################################
2+
# Syntax Coloring Map NVS
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
Preferences KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
begin KEYWORD2
15+
end KEYWORD2
16+
17+
clear KEYWORD2
18+
delete KEYWORD2
19+
20+
putChar KEYWORD2
21+
putUChar KEYWORD2
22+
putShort KEYWORD2
23+
putUShort KEYWORD2
24+
putInt KEYWORD2
25+
putUInt KEYWORD2
26+
putLong KEYWORD2
27+
putULong KEYWORD2
28+
putLong64 KEYWORD2
29+
putULong64 KEYWORD2
30+
putFloat KEYWORD2
31+
putDouble KEYWORD2
32+
putBool KEYWORD2
33+
putString KEYWORD2
34+
putBytes KEYWORD2
35+
36+
getChar KEYWORD2
37+
getUChar KEYWORD2
38+
getShort KEYWORD2
39+
getUShort KEYWORD2
40+
getInt KEYWORD2
41+
getUInt KEYWORD2
42+
getLong KEYWORD2
43+
getULong KEYWORD2
44+
getLong64 KEYWORD2
45+
getULong64 KEYWORD2
46+
getFloat KEYWORD2
47+
getDouble KEYWORD2
48+
getBool KEYWORD2
49+
getString KEYWORD2
50+
getBytes KEYWORD2
51+
52+
#######################################
53+
# Constants (LITERAL1)
54+
#######################################

Diff for: libraries/ESP32NVS/library.properties renamed to libraries/Preferences/library.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name=ESP32NVS
1+
name=Preferences
22
version=1.0
33
author=Hristo Gochkov
44
maintainer=Hristo Gochkov <hristo@espressif.com>
5-
sentence=Provides frendly access to ESP32's Non-Volatile Storage
5+
sentence=Provides friendly access to ESP32's Non-Volatile Storage
66
paragraph=
77
category=Data Storage
88
url=

0 commit comments

Comments
 (0)