Skip to content

Commit 5287e59

Browse files
authored
Merge pull request #18 from makinako/patch/eeprom-update
Updated all references of EEPROM.write to EEPROM.update
2 parents 928cf44 + 3baeb2d commit 5287e59

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

firmware/OpenLCD/OpenLCD.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void updateDisplay()
392392

393393
//Record this custom char to EEPROM
394394
for (byte charSpot = 0 ; charSpot < 8 ; charSpot++)
395-
EEPROM.write(LOCATION_CUSTOM_CHARACTERS + (customCharNumber * 8) + charSpot, customCharData[charSpot]); //addr, val
395+
EEPROM.update(LOCATION_CUSTOM_CHARACTERS + (customCharNumber * 8) + charSpot, customCharData[charSpot]); //addr, val
396396

397397
//For some reason you need to re-init the LCD after a custom char is created
398398
SerLCD.begin(settingLCDwidth, settingLCDlines);
@@ -444,4 +444,4 @@ void displayFrameBuffer(void)
444444

445445
//Return the cursor to its original position
446446
SerLCD.setCursor(characterCount % settingLCDwidth, characterCount / settingLCDwidth);
447-
}
447+
}

firmware/OpenLCD/Setting_Control.ino

+14-14
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void changeIgnore()
2626
SerLCD.print(F("N"));
2727
}
2828
//Record this new setting
29-
EEPROM.write(LOCATION_IGNORE_RX, settingIgnoreRX);
29+
EEPROM.update(LOCATION_IGNORE_RX, settingIgnoreRX);
3030

3131
petSafeDelay(SYSTEM_MESSAGE_DELAY);
3232

@@ -53,7 +53,7 @@ void displayFirmwareVersion()
5353
//Press a or z to adjust, x to exit
5454
void changeContrast(byte contrast)
5555
{
56-
EEPROM.write(LOCATION_CONTRAST, contrast); //Store this new contrast
56+
EEPROM.update(LOCATION_CONTRAST, contrast); //Store this new contrast
5757

5858
//Go to this new contrast
5959
analogWrite(LCD_CONTRAST, contrast);
@@ -74,7 +74,7 @@ void changeContrast(byte contrast)
7474
void changeTWIAddress(byte newAddress)
7575
{
7676
//Record the new address
77-
EEPROM.write(LOCATION_TWI_ADDRESS, newAddress);
77+
EEPROM.update(LOCATION_TWI_ADDRESS, newAddress);
7878

7979
setupTWI(); //Leverage the regular startup function
8080

@@ -95,7 +95,7 @@ void changeSplashContent()
9595
{
9696
//Record the current frame to EEPROM
9797
for (byte x = 0 ; x < settingLCDlines * settingLCDwidth ; x++)
98-
EEPROM.write(LOCATION_SPLASH_CONTENT + x, currentFrame[x]);
98+
EEPROM.update(LOCATION_SPLASH_CONTENT + x, currentFrame[x]);
9999

100100
//Display the backlight setting
101101
SerLCD.clear();
@@ -114,17 +114,17 @@ void changeBLBrightness(byte color, byte brightness)
114114
{
115115
if (color == RED)
116116
{
117-
EEPROM.write(LOCATION_RED_BRIGHTNESS, brightness); //Record new setting
117+
EEPROM.update(LOCATION_RED_BRIGHTNESS, brightness); //Record new setting
118118
analogWrite(BL_RW, 255 - brightness); //Controlled by PNP so reverse the brightness value
119119
}
120120
else if (color == GREEN)
121121
{
122-
EEPROM.write(LOCATION_GREEN_BRIGHTNESS, brightness); //Record new setting
122+
EEPROM.update(LOCATION_GREEN_BRIGHTNESS, brightness); //Record new setting
123123
analogWrite(BL_G, 255 - brightness); //Controlled by PNP so reverse the brightness value
124124
}
125125
else if (color == BLUE)
126126
{
127-
EEPROM.write(LOCATION_BLUE_BRIGHTNESS, brightness); //Record new setting
127+
EEPROM.update(LOCATION_BLUE_BRIGHTNESS, brightness); //Record new setting
128128
//analogWrite(BL_B, 255 - brightness); //Controlled by PNP so reverse the brightness value
129129
SoftPWMSet(BL_B, 255 - brightness); //Controlled by software PWM
130130
}
@@ -154,15 +154,15 @@ void changeBLBrightness(byte color, byte brightness)
154154
//with their rgb values to eliminate flicker. Incoming brightness values should be 0 to 255
155155
void changeBacklightRGB(byte red, byte green, byte blue) {
156156
//update red
157-
EEPROM.write(LOCATION_RED_BRIGHTNESS, red); //Record new setting
157+
EEPROM.update(LOCATION_RED_BRIGHTNESS, red); //Record new setting
158158
analogWrite(BL_RW, 255 - red); //Controlled by PNP so reverse the brightness value
159159

160160
//update green
161-
EEPROM.write(LOCATION_GREEN_BRIGHTNESS, green); //Record new setting
161+
EEPROM.update(LOCATION_GREEN_BRIGHTNESS, green); //Record new setting
162162
analogWrite(BL_G, 255 - green); //Controlled by PNP so reverse the brightness value
163163

164164
//update blue (SoftPWM)
165-
EEPROM.write(LOCATION_BLUE_BRIGHTNESS, blue); //Record new setting
165+
EEPROM.update(LOCATION_BLUE_BRIGHTNESS, blue); //Record new setting
166166
//analogWrite(BL_B, 255 - brightness); //Controlled by PNP so reverse the brightness value
167167
SoftPWMSet(BL_B, 255 - blue); //Controlled by software PWM
168168
}
@@ -216,7 +216,7 @@ void changeUARTSpeed(byte setting)
216216
}
217217

218218
//Record this new buad rate
219-
EEPROM.write(LOCATION_BAUD, settingUARTSpeed);
219+
EEPROM.update(LOCATION_BAUD, settingUARTSpeed);
220220

221221
//Display that we are at this new speed
222222
SerLCD.clear();
@@ -254,7 +254,7 @@ void changeSplashEnable()
254254
petSafeDelay(SYSTEM_MESSAGE_DELAY);
255255

256256
//Record this new setting
257-
EEPROM.write(LOCATION_SPLASH_ONOFF, settingSplashEnable);
257+
EEPROM.update(LOCATION_SPLASH_ONOFF, settingSplashEnable);
258258

259259
displayFrameBuffer(); //Return the contents of the display
260260
}
@@ -287,8 +287,8 @@ void changeLinesWidths(byte setting)
287287
clearFrameBuffer();
288288

289289
//Record this new setting
290-
EEPROM.write(LOCATION_WIDTH, settingLCDwidth);
291-
EEPROM.write(LOCATION_LINES, settingLCDlines);
290+
EEPROM.update(LOCATION_WIDTH, settingLCDwidth);
291+
EEPROM.update(LOCATION_LINES, settingLCDlines);
292292

293293
//Display new settings to the user
294294
SerLCD.clear();

firmware/OpenLCD/System_Functions.ino

+10-12
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void setupUART()
9191
if (settingIgnoreRX > 1)
9292
{
9393
settingIgnoreRX = false; //Don't ignore
94-
EEPROM.write(LOCATION_IGNORE_RX, settingIgnoreRX);
94+
EEPROM.update(LOCATION_IGNORE_RX, settingIgnoreRX);
9595
}
9696

9797
if (settingIgnoreRX == false) //If we are NOT ignoring RX, then
@@ -103,7 +103,7 @@ void setupUART()
103103
if (settingUARTSpeed > BAUD_1000000) //Check to see if the baud rate has ever been set
104104
{
105105
settingUARTSpeed = DEFAULT_BAUD; //Reset UART to 9600 if there is no baud rate stored
106-
EEPROM.write(LOCATION_BAUD, settingUARTSpeed);
106+
EEPROM.update(LOCATION_BAUD, settingUARTSpeed);
107107
}
108108

109109
//Initialize the UART
@@ -139,7 +139,7 @@ void setupTWI()
139139
if ((twiAddress == 0) || (twiAddress > 0x7F))
140140
{ // If the TWI address is invalid, use a default address
141141
twiAddress = DEFAULT_TWI_ADDRESS;
142-
EEPROM.write(LOCATION_TWI_ADDRESS, DEFAULT_TWI_ADDRESS);
142+
EEPROM.update(LOCATION_TWI_ADDRESS, DEFAULT_TWI_ADDRESS);
143143
}
144144

145145
Wire.begin(twiAddress); //Initialize Wire library as slave at twiAddress address
@@ -154,7 +154,7 @@ void setupContrast()
154154
if (settingContrast == 255) //Check to see if the contrast has ever been set
155155
{
156156
settingContrast = DEFAULT_CONTRAST_LCD; //Default
157-
EEPROM.write(LOCATION_CONTRAST, settingContrast);
157+
EEPROM.update(LOCATION_CONTRAST, settingContrast);
158158
}
159159

160160
//Change contrast without notification message
@@ -171,14 +171,14 @@ void setupLCD()
171171
if (settingLCDlines > 4)
172172
{
173173
settingLCDlines = DEFAULT_LINES;
174-
EEPROM.write(LOCATION_LINES, settingLCDlines);
174+
EEPROM.update(LOCATION_LINES, settingLCDlines);
175175
}
176176

177177
settingLCDwidth = EEPROM.read(LOCATION_WIDTH);
178178
if (settingLCDwidth > 20)
179179
{
180180
settingLCDwidth = DEFAULT_WIDTH;
181-
EEPROM.write(LOCATION_WIDTH, settingLCDwidth);
181+
EEPROM.update(LOCATION_WIDTH, settingLCDwidth);
182182
}
183183

184184
//Check the display jumper
@@ -222,7 +222,7 @@ void setupSplash()
222222
if (settingSplashEnable > 1)
223223
{
224224
settingSplashEnable = DEFAULT_SPLASH;
225-
EEPROM.write(LOCATION_SPLASH_ONOFF, settingSplashEnable);
225+
EEPROM.update(LOCATION_SPLASH_ONOFF, settingSplashEnable);
226226
}
227227

228228
if (settingSplashEnable)
@@ -246,7 +246,7 @@ void setupSplash()
246246
if (settingUARTSpeed > BAUD_1000000) //Check to see if the baud rate has ever been set
247247
{
248248
settingUARTSpeed = DEFAULT_BAUD; //Reset UART to 9600 if there is no baud rate stored
249-
EEPROM.write(LOCATION_BAUD, settingUARTSpeed);
249+
EEPROM.update(LOCATION_BAUD, settingUARTSpeed);
250250
}
251251

252252
SerLCD.print(lookUpBaudRate(settingUARTSpeed));
@@ -284,7 +284,7 @@ void setupSplash()
284284

285285
SerLCD.print("Baud Reset");
286286

287-
EEPROM.write(LOCATION_BAUD, BAUD_9600);
287+
EEPROM.update(LOCATION_BAUD, BAUD_9600);
288288

289289
petSafeDelay(SYSTEM_MESSAGE_DELAY);
290290

@@ -352,9 +352,7 @@ void checkEmergencyReset(void)
352352

353353
//If we make it here, then RX pin stayed low the whole time
354354
//Reset all EEPROM locations to factory defaults.
355-
for (int x = 0 ; x < 200 ; x++)
356-
EEPROM.write(x, 0xFF);
357-
355+
for (int x = 0 ; x < 200 ; x++) EEPROM.update(x, 0xFF);
358356

359357
//Change contrast without notification message
360358
analogWrite(LCD_CONTRAST, 40); //Set contrast to default

0 commit comments

Comments
 (0)