Skip to content

Commit b557e8a

Browse files
committed
🎨 Removed define usage in CPP file
1 parent 07a5102 commit b557e8a

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=KeyDB
2-
version=1.0.0
2+
version=1.1.0
33
author=Andreas <andreas@zapsterstudios.com>
44
maintainer=Andreas <andreas@zapsterstudios.com>
55
sentence=Wrapper around EEPROM as a key storing database.

src/KeyDB.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void KeyDB::loadKeys() {
2828
int position = 1;
2929
for (int i = 0; i < count; i++) {
3030
// Loop through the key char length.
31-
for(int k = 0; k < DB_KEY_LENGTH; k++) {
31+
for(int k = 0; k < this->keyLength; k++) {
3232
// Add read char to key string.
3333
char readChar = char(EEPROM.read(position));
3434
this->keys[i].concat(readChar);
@@ -46,13 +46,13 @@ void KeyDB::saveKeys() {
4646
// Loop through the key list.
4747
int keys = 0;
4848
int position = 1;
49-
for (int i = 0; i < DB_KEY_MAX; i++) {
49+
for (int i = 0; i < this->keyMax; i++) {
5050
// Break out of array if empty.
5151
if (this->keys[i] == "")
5252
break;
5353

5454
// Loop through the key char length.
55-
for(int k = 0; k < DB_KEY_LENGTH; k++) {
55+
for(int k = 0; k < this->keyLength; k++) {
5656
// Write key char to storage.
5757
EEPROM.update(position, this->keys[i][k]);
5858

@@ -82,10 +82,10 @@ void KeyDB::addKey(String key) {
8282
this->keys[keys] = key;
8383

8484
// Find position for next input.
85-
int position = (keys * DB_KEY_LENGTH) + 1;
85+
int position = (keys * this->keyLength) + 1;
8686

8787
// Loop through the key char length.
88-
for(int k = 0; k < DB_KEY_LENGTH; k++) {
88+
for(int k = 0; k < this->keyLength; k++) {
8989
// Write key char to storage.
9090
EEPROM.update(position, this->keys[keys][k]);
9191

@@ -108,7 +108,7 @@ void KeyDB::removeKey(String key) {
108108

109109
// Loop through keys.
110110
int shifting = 0;
111-
for (int i = 0; i < DB_KEY_MAX; i++) {
111+
for (int i = 0; i < this->keyMax; i++) {
112112
// Shift indexes if shifting.
113113
if (shifting)
114114
this->keys[i - 1] = this->keys[i];
@@ -137,7 +137,7 @@ bool KeyDB::keyExists(String key) {
137137
key = this->keyLengthen(key);
138138

139139
// Loop through keys.
140-
for (int i = 0; i < DB_KEY_MAX; i++) {
140+
for (int i = 0; i < this->keyMax; i++) {
141141
// Return out of array if empty.
142142
if (this->keys[i] == "")
143143
return false;
@@ -157,7 +157,7 @@ bool KeyDB::keyExists(String key) {
157157
*/
158158
String KeyDB::keyLengthen(String key) {
159159
// Add zeros untill correct char length.
160-
while (key.length() < DB_KEY_LENGTH) {
160+
while (key.length() < this->keyLength) {
161161
key = '0' + key;
162162
}
163163

src/KeyDB.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class KeyDB {
2525

2626
String keyLengthen(String key);
2727
String keys[DB_KEY_MAX] = {""};
28+
29+
private:
30+
int keyMax = DB_KEY_MAX;
31+
int keyLength = DB_KEY_LENGTH;
2832
};
2933

3034
#endif

0 commit comments

Comments
 (0)