-
Notifications
You must be signed in to change notification settings - Fork 2
/
z21nvs.cpp
86 lines (68 loc) · 2.19 KB
/
z21nvs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
*****************************************************************************
* z21nvs.cpp - library for emulate EEPROM on Non-Volatile Storage
* Copyright (c) 2021 Philipp Gahtow All right reserved.
*
*
*****************************************************************************
* IMPORTANT:
*
* Please contact ROCO Inc. for more details.
*****************************************************************************
*/
// include this library's description file
#include <z21nvs.h>
Preferences store;
// Constructor /////////////////////////////////////////////////////////////////
// Function that handles the creation and setup of instances
z21nvsClass::z21nvsClass()
{
// Open Preferences with my-app namespace. Each application module, library, etc
// has to use a namespace name to prevent key name collisions. We will open storage in
// RW-mode (second parameter has to be false).
// Note: Namespace name is limited to 15 chars.
//store.begin("Z21-app", false);
}
// Public Methods //////////////////////////////////////////////////////////////
// Functions available in Wiring sketches, this library, and other libraries
//*********************************************************************************************
//Daten ermitteln
uint8_t z21nvsClass::read(uint16_t adr)
{
store.begin("Z21-app", true);
//size_t schLen = store.getBytes("Z21EEPROM", NULL, NULL);
char buffer[EESize];
store.getBytes("Z21EEPROM", buffer, EESize);
// Close the Preferences
store.end();
if (adr < EESize)
return buffer[adr];
return 0xFF;
}
bool z21nvsClass::write(uint16_t adr, uint8_t value)
{
store.begin("Z21-app", false);
//size_t schLen = store.getBytes("Z21EEPROM", NULL, NULL);
char buffer[EESize];
store.getBytes("Z21EEPROM", buffer, EESize);
if (adr < EESize) {
buffer[adr] = value;
store.putBytes("Z21EEPROM", buffer, EESize);
// Close the Preferences
store.end();
return true;
}
else {
// Close the Preferences
store.end();
return false;
}
}
bool z21nvsClass::begin(uint16_t size)
{
return true;
}
bool z21nvsClass::commit(void)
{
return true;
}