forked from microsoft/microbit-robot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage.cpp
More file actions
33 lines (29 loc) · 803 Bytes
/
storage.cpp
File metadata and controls
33 lines (29 loc) · 803 Bytes
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
#include "pxt.h"
#define CALIBRATION_KEY "robot"
namespace robot {
struct Calibration {
int radioGroup;
int drift;
};
//%
void writeCalibration(int radioGroup, int drift) {
Calibration cal;
cal.radioGroup = radioGroup;
cal.drift = drift;
uBit.storage.put(CALIBRATION_KEY, (uint8_t *)&cal, sizeof(Calibration));
}
//%
int readCalibration(int field) {
KeyValuePair* kv = uBit.storage.get(CALIBRATION_KEY);
int value = 0;
if (NULL != kv) {
Calibration cal;
memcpy(&cal, kv->value, sizeof(Calibration));
if (field == 0)
value = cal.radioGroup;
else if (field == 1)
value = cal.drift;
}
return value;
}
}