Skip to content

Commit 2a9d4e2

Browse files
committed
Add system message control
1 parent e0229bf commit 2a9d4e2

File tree

4 files changed

+170
-110
lines changed

4 files changed

+170
-110
lines changed

firmware/OpenLCD/OpenLCD.ino

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313
Select 'SparkFun SerLCD' as the board. We use an ATmega328P running at 11.0592MHz in
1414
order to have error free serial comm.
1515
16+
v11:
17+
Add faster backlight command
18+
Change EEPROM write() to update()
1619
17-
Backlight levels from original datasheet are wrong. Setting of 22 is 76%. See google doc
18-
19-
20-
Todo:
21-
Check how splash screen works on 16 vs 20 width displays
22-
Establish and cut down on boot time
20+
v12:
21+
Add command to disable system messages displayed when settings change (contrast, UART, etc).
2322
*/
2423

2524
//Firmware version. This is sent when requested. Helpful for tech support.
2625
const byte firmwareVersionMajor = 1;
27-
const byte firmwareVersionMinor = 1;
26+
const byte firmwareVersionMinor = 2;
2827

2928
#include <Wire.h> //For I2C functions
3029
#include <SPI.h> //For SPI functions
@@ -80,6 +79,8 @@ void setup()
8079
//for(int x = 0 ; x < 200 ; x++)
8180
// EEPROM.write(x, 0xFF);
8281

82+
setupSystemMessages(); //Load settings, such as displaySystemMessages
83+
8384
setupLCD(); //Initialize the LCD
8485

8586
setupContrast(); //Set contrast
@@ -238,6 +239,11 @@ void updateDisplay()
238239

239240
clearFrameBuffer(); //Get rid of all characters in our buffer
240241
}
242+
//Enable or disable the displaying of system messages
243+
else if (incoming == 46) //. character
244+
{
245+
changeDisplaySystemMessages();
246+
}
241247
//If we get a second special setting character, then write it to the display
242248
//This allows us to print a pipe by escaping it as a double
243249
else if (incoming == 124) //| character

firmware/OpenLCD/Setting_Control.ino

Lines changed: 138 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,52 @@
77
//Toggle the ignore rx setting
88
void changeIgnore()
99
{
10-
byte settingIgnoreRX = EEPROM.read(LOCATION_IGNORE_RX);
10+
settingIgnoreRX = EEPROM.read(LOCATION_IGNORE_RX);
1111

12-
//Display new settings to the user
13-
SerLCD.clear();
14-
SerLCD.setCursor(0, 0);
12+
settingIgnoreRX != settingIgnoreRX; //Toggle setting
1513

16-
SerLCD.print(F("Ignore RX O"));
14+
//Record this new setting
15+
EEPROM.update(LOCATION_IGNORE_RX, settingIgnoreRX);
1716

18-
if (settingIgnoreRX == true)
19-
{
20-
settingIgnoreRX = false;
21-
SerLCD.print(F("FF"));
22-
}
23-
else
17+
if (settingDisplaySystemMessages == true)
2418
{
25-
settingIgnoreRX = true;
26-
SerLCD.print(F("N"));
19+
//Display new settings to the user
20+
SerLCD.clear();
21+
SerLCD.setCursor(0, 0);
22+
23+
SerLCD.print(F("Ignore RX O"));
24+
25+
if (settingIgnoreRX == true)
26+
SerLCD.print(F("FF"));
27+
else
28+
SerLCD.print(F("N"));
29+
30+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
31+
32+
displayFrameBuffer(); //Return the contents of the display
2733
}
28-
//Record this new setting
29-
EEPROM.update(LOCATION_IGNORE_RX, settingIgnoreRX);
34+
}
3035

31-
petSafeDelay(SYSTEM_MESSAGE_DELAY);
36+
//Toggle the 'displaySystemMessages' setting
37+
void changeDisplaySystemMessages()
38+
{
39+
settingDisplaySystemMessages = EEPROM.read(LOCATION_DISPLAY_SYSTEM_MESSAGES);
3240

33-
displayFrameBuffer(); //Return the contents of the display
41+
settingDisplaySystemMessages != settingDisplaySystemMessages; //Toggle the setting
42+
43+
//Record this new setting
44+
EEPROM.update(LOCATION_DISPLAY_SYSTEM_MESSAGES, settingDisplaySystemMessages);
45+
46+
//If user has just enabled messages, then push message to display
47+
if (settingDisplaySystemMessages == true)
48+
{
49+
//Display new setting to the user
50+
SerLCD.clear();
51+
SerLCD.setCursor(0, 0);
52+
SerLCD.print(F("Messages ON"));
53+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
54+
displayFrameBuffer(); //Return the contents of the display
55+
}
3456
}
3557

3658
//Display the current firmware version for a set amount of time
@@ -58,16 +80,19 @@ void changeContrast(byte contrast)
5880
//Go to this new contrast
5981
analogWrite(LCD_CONTRAST, contrast);
6082

61-
//Display the new contrast
62-
SerLCD.clear();
63-
SerLCD.setCursor(0, 0); //First position, 1st row
64-
SerLCD.print("Contrast Set");
65-
SerLCD.setCursor(0, 1); //First position, 2nd row
66-
SerLCD.print(contrast);
83+
if (settingDisplaySystemMessages == true)
84+
{
85+
//Display the new contrast
86+
SerLCD.clear();
87+
SerLCD.setCursor(0, 0); //First position, 1st row
88+
SerLCD.print("Contrast Set");
89+
SerLCD.setCursor(0, 1); //First position, 2nd row
90+
SerLCD.print(contrast);
6791

68-
petSafeDelay(SYSTEM_MESSAGE_DELAY);
92+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
6993

70-
displayFrameBuffer(); //Display what was there before
94+
displayFrameBuffer(); //Display what was there before
95+
}
7196
}
7297

7398
//Change the I2C or TWI address
@@ -78,16 +103,19 @@ void changeTWIAddress(byte newAddress)
78103

79104
setupTWI(); //Leverage the regular startup function
80105

81-
//Display the new TWI address
82-
SerLCD.clear();
83-
SerLCD.setCursor(0, 0); //First position, 1st row
106+
if (settingDisplaySystemMessages == true)
107+
{
108+
//Display the new TWI address
109+
SerLCD.clear();
110+
SerLCD.setCursor(0, 0); //First position, 1st row
84111

85-
SerLCD.print("New TWI: 0x");
86-
SerLCD.print(newAddress, HEX);
112+
SerLCD.print("New TWI: 0x");
113+
SerLCD.print(newAddress, HEX);
87114

88-
petSafeDelay(SYSTEM_MESSAGE_DELAY);
115+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
89116

90-
displayFrameBuffer(); //Display what was there before
117+
displayFrameBuffer(); //Display what was there before
118+
}
91119
}
92120

93121
//Save the current frame buffer to EEPROM as the splash screen
@@ -97,15 +125,18 @@ void changeSplashContent()
97125
for (byte x = 0 ; x < settingLCDlines * settingLCDwidth ; x++)
98126
EEPROM.update(LOCATION_SPLASH_CONTENT + x, currentFrame[x]);
99127

100-
//Display the backlight setting
101-
SerLCD.clear();
102-
SerLCD.setCursor(0, 0); //First position, 1st row
128+
if (settingDisplaySystemMessages == true)
129+
{
130+
//Display the backlight setting
131+
SerLCD.clear();
132+
SerLCD.setCursor(0, 0); //First position, 1st row
103133

104-
SerLCD.print("Splash Recorded");
134+
SerLCD.print("Splash Recorded");
105135

106-
petSafeDelay(SYSTEM_MESSAGE_DELAY);
136+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
107137

108-
displayFrameBuffer(); //Display what was there before
138+
displayFrameBuffer(); //Display what was there before
139+
}
109140
}
110141

111142
//Changes the brightness of a given pin and updates the EEPROM location with that value
@@ -129,25 +160,28 @@ void changeBLBrightness(byte color, byte brightness)
129160
SoftPWMSet(BL_B, 255 - brightness); //Controlled by software PWM
130161
}
131162

132-
//Display the backlight setting
133-
SerLCD.clear();
134-
SerLCD.setCursor(0, 0); //First position, 1st row
163+
if (settingDisplaySystemMessages == true)
164+
{
165+
//Display the backlight setting
166+
SerLCD.clear();
167+
SerLCD.setCursor(0, 0); //First position, 1st row
135168

136-
if (color == RED)
137-
SerLCD.print(F("Backlight"));
138-
else if (color == GREEN)
139-
SerLCD.print(F("Green"));
140-
else if (color == BLUE)
141-
SerLCD.print(F("Blue"));
169+
if (color == RED)
170+
SerLCD.print(F("Backlight"));
171+
else if (color == GREEN)
172+
SerLCD.print(F("Green"));
173+
else if (color == BLUE)
174+
SerLCD.print(F("Blue"));
142175

143-
SerLCD.print(F(": "));
176+
SerLCD.print(F(": "));
144177

145-
brightness = map(brightness, 0, 255, 0, 100); //Covert to percentage
146-
SerLCD.print(brightness);
147-
SerLCD.print(F("%"));
148-
petSafeDelay(SYSTEM_MESSAGE_DELAY);
178+
brightness = map(brightness, 0, 255, 0, 100); //Covert to percentage
179+
SerLCD.print(brightness);
180+
SerLCD.print(F("%"));
181+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
149182

150-
displayFrameBuffer(); //Display what was there before
183+
displayFrameBuffer(); //Display what was there before
184+
}
151185
}
152186

153187
//Changes the brightness of all three backlight pins and updates the EEPROM locations
@@ -218,45 +252,48 @@ void changeUARTSpeed(byte setting)
218252
//Record this new buad rate
219253
EEPROM.update(LOCATION_BAUD, settingUARTSpeed);
220254

221-
//Display that we are at this new speed
222-
SerLCD.clear();
223-
SerLCD.setCursor(0, 0); //First position, 1st row
224-
SerLCD.print(F("Baud now:"));
225-
SerLCD.print(lookUpBaudRate(settingUARTSpeed));
226-
petSafeDelay(SYSTEM_MESSAGE_DELAY);
227-
228255
//Go to this new baud rate
229256
Serial.begin(lookUpBaudRate(settingUARTSpeed));
230257

231-
displayFrameBuffer(); //Display what was there before
258+
if (settingDisplaySystemMessages == true)
259+
{
260+
//Display that we are at this new speed
261+
SerLCD.clear();
262+
SerLCD.setCursor(0, 0); //First position, 1st row
263+
SerLCD.print(F("Baud now:"));
264+
SerLCD.print(lookUpBaudRate(settingUARTSpeed));
265+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
266+
267+
displayFrameBuffer(); //Display what was there before
268+
}
232269
}
233270

234271
void changeSplashEnable()
235272
{
236-
byte settingSplashEnable = EEPROM.read(LOCATION_SPLASH_ONOFF);
273+
settingSplashEnable = EEPROM.read(LOCATION_SPLASH_ONOFF);
237274

238-
//Display new settings to the user
239-
SerLCD.clear();
240-
SerLCD.setCursor(0, 0);
275+
settingSplashEnable != settingSplashEnable; //Toggle setting
241276

242-
SerLCD.print(F("Splash O"));
277+
//Record this new setting
278+
EEPROM.update(LOCATION_SPLASH_ONOFF, settingSplashEnable);
243279

244-
if (settingSplashEnable == true)
280+
if (settingDisplaySystemMessages == true)
245281
{
246-
settingSplashEnable = false;
247-
SerLCD.print(F("FF"));
248-
}
249-
else
250-
{
251-
settingSplashEnable = true;
252-
SerLCD.print(F("N"));
253-
}
254-
petSafeDelay(SYSTEM_MESSAGE_DELAY);
282+
//Display new settings to the user
283+
SerLCD.clear();
284+
SerLCD.setCursor(0, 0);
255285

256-
//Record this new setting
257-
EEPROM.update(LOCATION_SPLASH_ONOFF, settingSplashEnable);
286+
SerLCD.print(F("Splash O"));
258287

259-
displayFrameBuffer(); //Return the contents of the display
288+
if (settingSplashEnable == true)
289+
SerLCD.print(F("FF"));
290+
else
291+
SerLCD.print(F("N"));
292+
293+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
294+
295+
displayFrameBuffer(); //Return the contents of the display
296+
}
260297
}
261298

262299
void changeLinesWidths(byte setting)
@@ -290,28 +327,31 @@ void changeLinesWidths(byte setting)
290327
EEPROM.update(LOCATION_WIDTH, settingLCDwidth);
291328
EEPROM.update(LOCATION_LINES, settingLCDlines);
292329

293-
//Display new settings to the user
294-
SerLCD.clear();
295-
SerLCD.setCursor(0, 0);
296-
297-
SerLCD.print(F("Lines:"));
298-
SerLCD.print(settingLCDlines);
299-
300-
//If we have a single line LCD then clear the message after a second and print more
301-
if (settingLCDlines == 1)
330+
if (settingDisplaySystemMessages == true)
302331
{
303-
petSafeDelay(SYSTEM_MESSAGE_DELAY);
332+
//Display new settings to the user
304333
SerLCD.clear();
305334
SerLCD.setCursor(0, 0);
306-
}
307-
else
308-
{
309-
SerLCD.setCursor(0, 1); //We are assuming at least a two line LCD
310-
}
311335

312-
SerLCD.print(F("Width:"));
313-
SerLCD.print(settingLCDwidth);
314-
petSafeDelay(SYSTEM_MESSAGE_DELAY);
336+
SerLCD.print(F("Lines:"));
337+
SerLCD.print(settingLCDlines);
338+
339+
//If we have a single line LCD then clear the message after a second and print more
340+
if (settingLCDlines == 1)
341+
{
342+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
343+
SerLCD.clear();
344+
SerLCD.setCursor(0, 0);
345+
}
346+
else
347+
{
348+
SerLCD.setCursor(0, 1); //We are assuming at least a two line LCD
349+
}
350+
351+
SerLCD.print(F("Width:"));
352+
SerLCD.print(settingLCDwidth);
353+
petSafeDelay(SYSTEM_MESSAGE_DELAY);
315354

316-
displayFrameBuffer(); //Return the contents of the display
355+
displayFrameBuffer(); //Return the contents of the display
356+
}
317357
}

firmware/OpenLCD/System_Functions.ino

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void setupPower()
8787
void setupUART()
8888
{
8989
//Check to see if we are ignoring the RX reset or not
90-
byte settingIgnoreRX = EEPROM.read(LOCATION_IGNORE_RX);
90+
settingIgnoreRX = EEPROM.read(LOCATION_IGNORE_RX);
9191
if (settingIgnoreRX > 1)
9292
{
9393
settingIgnoreRX = false; //Don't ignore
@@ -163,6 +163,18 @@ void setupContrast()
163163
analogWrite(LCD_CONTRAST, settingContrast);
164164
}
165165

166+
//Look up settings like the enabling of system messages
167+
void setupSystemMessages()
168+
{
169+
//Look up if we should display messages or not
170+
settingDisplaySystemMessages = EEPROM.read(LOCATION_DISPLAY_SYSTEM_MESSAGES);
171+
if (settingDisplaySystemMessages > 1) //True = 1, false = 0
172+
{
173+
settingDisplaySystemMessages = DEFAULT_DISPLAY_SYSTEM_MESSAGES;
174+
EEPROM.update(LOCATION_DISPLAY_SYSTEM_MESSAGES, settingDisplaySystemMessages);
175+
}
176+
}
177+
166178
//Look up and initialize the LCD with the lines and width
167179
void setupLCD()
168180
{

0 commit comments

Comments
 (0)