1
- // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
1
+ // Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
5
5
// You may obtain a copy of the License at
6
+
6
7
// http://www.apache.org/licenses/LICENSE-2.0
7
8
//
8
9
// Unless required by applicable law or agreed to in writing, software
@@ -43,7 +44,7 @@ bool Preferences::begin(const char * name, bool readOnly, const char* partition_
43
44
}
44
45
err = nvs_open_from_partition (partition_label, name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
45
46
} else {
46
- err = nvs_open (name, readOnly? NVS_READONLY: NVS_READWRITE, &_handle);
47
+ err = nvs_open (name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
47
48
}
48
49
if (err){
49
50
log_e (" nvs_open failed: %s" , nvs_error (err));
@@ -53,14 +54,10 @@ bool Preferences::begin(const char * name, bool readOnly, const char* partition_
53
54
return true ;
54
55
}
55
56
56
- void Preferences::end (){ // modified to add an nvs_commit()
57
+ void Preferences::end (){
57
58
if (!_started){
58
59
return ;
59
60
}
60
- esp_err_t err = nvs_commit (_handle); // to undo changes: delete the lines from here...
61
- if (err){
62
- log_e (" nvs_commit fail: %s %s" , key, nvs_error (err));
63
- } // ... to here.
64
61
nvs_close (_handle);
65
62
_started = false ;
66
63
}
@@ -69,7 +66,7 @@ void Preferences::end(){ // modified to
69
66
* Clear all keys in opened preferences
70
67
* */
71
68
72
- bool Preferences::clear (){ // modified to add an nvs_commit()
69
+ bool Preferences::clear (){
73
70
if (!_started || _readOnly){
74
71
return false ;
75
72
}
@@ -78,20 +75,19 @@ bool Preferences::clear(){ // modified to add a
78
75
log_e (" nvs_erase_all fail: %s" , nvs_error (err));
79
76
return false ;
80
77
}
81
- // return true; // to undo changes: uncomment this line and...
82
- err = nvs_commit (_handle); // ... delete the lines from from here...
78
+ err = nvs_commit (_handle);
83
79
if (err){
84
80
log_e (" nvs_commit fail: %s" , nvs_error (err));
85
81
return false ;
86
82
}
87
- return true ; // ... to here.
83
+ return true ;
88
84
}
89
85
90
86
/*
91
87
* Remove a key
92
88
* */
93
89
94
- bool Preferences::remove (const char * key){ // modified to add an nvs_commit()
90
+ bool Preferences::remove (const char * key){
95
91
if (!_started || !key || _readOnly){
96
92
return false ;
97
93
}
@@ -100,13 +96,12 @@ bool Preferences::remove(const char * key){ // modified to add a
100
96
log_e (" nvs_erase_key fail: %s %s" , key, nvs_error (err));
101
97
return false ;
102
98
}
103
- // return true; // to undo changes: uncomment this line and...
104
- err = nvs_commit (_handle); // ... delete the lines from from here...
99
+ err = nvs_commit (_handle);
105
100
if (err){
106
101
log_e (" nvs_commit fail: %s %s" , key, nvs_error (err));
107
102
return false ;
108
103
}
109
- return true ; // ... to here.
104
+ return true ;
110
105
}
111
106
112
107
/*
0 commit comments