-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorage.ino
More file actions
82 lines (76 loc) · 2.7 KB
/
Storage.ino
File metadata and controls
82 lines (76 loc) · 2.7 KB
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
void InitializeData(){
while (!eeprom_is_ready());
SendMode = EEPROM.read(EEPROM_SendMode);
MinIntegerPlaces = (uint16_t)eepromReadInt(EEPROM_MinIntegerPlaces);
MaxIntegerPlaces = (uint16_t)eepromReadInt(EEPROM_MaxIntegerPlaces);
MinDecimalPlaces = (uint16_t)eepromReadInt(EEPROM_MinDecimalPlaces);
MaxDecimalPlaces = (uint16_t)eepromReadInt(EEPROM_MaxDecimalPlaces);
StartEndChar = EEPROM.read(EEPROM_StartEndChar);
LineEnd = EEPROM.read(EEPROM_LineEnd);
Delimiter = EEPROM.read(EEPROM_Delimiter);
ComPortBaudRate = eepromReadInt(EEPROM_ComPortBaudRate);
ComPortSetup = EEPROM.read(EEPROM_ComPortSetup);
PartialSendingMaxDelay = EEPROM.read(EEPROM_PartialSendingMaxDelay);
CurrentWeightNo = eepromReadInt(EEPROM_CurrentWeightNo);
}
void StoreData(){
while (!eeprom_is_ready());
EEPROM.update(EEPROM_SendMode, SendMode);
eepromWriteInt(EEPROM_MinIntegerPlaces, MinIntegerPlaces);
eepromWriteInt(EEPROM_MaxIntegerPlaces, MaxIntegerPlaces);
eepromWriteInt(EEPROM_MinDecimalPlaces, MinDecimalPlaces);
eepromWriteInt(EEPROM_MaxDecimalPlaces, MaxDecimalPlaces);
EEPROM.update(EEPROM_StartEndChar, StartEndChar);
EEPROM.update(EEPROM_LineEnd, LineEnd);
EEPROM.update(EEPROM_Delimiter, Delimiter);
eepromWriteInt(EEPROM_ComPortBaudRate, ComPortBaudRate);
EEPROM.update(EEPROM_ComPortSetup, ComPortSetup);
EEPROM.update(EEPROM_PartialSendingMaxDelay, PartialSendingMaxDelay);
eepromWriteInt(EEPROM_CurrentWeightNo, CurrentWeightNo);
#if DEBUG
Serial.println("Stored!");
PrintStorage();
#endif
}
void eepromWriteInt(int adr, int value) {
byte low, high;
low=value&0xFF;
high=(value>>8)&0xFF;
EEPROM.update(adr, low);
EEPROM.update(++adr, high);
return;
}
int eepromReadInt(int adr) {
byte low, high;
low=EEPROM.read(adr);
high=EEPROM.read(++adr);
return low + ((high << 8)&0xFF00);
}
void PrintStorage(){
#if DEBUG
Serial.print("SendMode: ");
Serial.println(SendMode);
Serial.print("Int: ");
Serial.print(MinIntegerPlaces);
Serial.print(" - ");
Serial.println(MaxIntegerPlaces);
Serial.print("Dec: ");
Serial.print(MinDecimalPlaces);
Serial.print(" - ");
Serial.println(MaxDecimalPlaces);
Serial.print("StartEndChar: ");
Serial.println(StartEndChar);
Serial.print("LineEnd: ");
Serial.println(LineEnd);
Serial.print("Delimiter: ");
Serial.println(Delimiter);
Serial.print("ComPortBaudRate: ");
Serial.println(ComPortBaudRate);
Serial.print("ComPortSetup: ");
Serial.println(ComPortSetup);
Serial.print("Byte sending delay: ");
Serial.println(PartialSendingMaxDelay);
Serial.print("Current Weight No: ");
Serial.println(CurrentWeightNo);
#endif
}