Skip to content

Commit e550673

Browse files
committed
Ability to show important messages on the display
Implemented for the Nokia 5110 display. 4bit display needs to be implemented and tested. Due to the lack of hardware I can't do it.
1 parent bd7cd88 commit e550673

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

Arduino_Pedelec_Controller/display.cpp

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ static byte glyph1[] = {0x0b, 0xfc, 0x4e, 0xac, 0x0b}; //symbol for wh/km part 1
3333
static byte glyph2[] = {0xc8, 0x2f, 0x6a, 0x2e, 0xc8}; //symbol for wh/km part 2
3434
static byte glyph3[] = {0x44, 0x28, 0xfe, 0x6c, 0x28}; //bluetooth-symbol check this out: http://www.carlos-rodrigues.com/projects/pcd8544/
3535

36+
unsigned long show_important_info_until = 0;
37+
void display_show_important_info(const char *str, int duration_secs)
38+
{
39+
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
40+
unsigned long seconds = 2;
41+
if (duration_secs)
42+
seconds = duration_secs;
43+
44+
show_important_info_until = millis() + (seconds*1000);
45+
46+
#ifdef SUPPORT_DISPLAY_BACKLIGHT
47+
enable_backlight();
48+
#endif
49+
50+
// TODO: Implement and test 4bit display mode
51+
lcd.clear();
52+
lcd.setCursor(0, 2);
53+
lcd.print(str);
54+
#endif
55+
}
56+
3657
static void display_nokia_setup() //first time setup of nokia display
3758
{
3859
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
@@ -56,6 +77,37 @@ static void display_nokia_setup() //first time setup of nokia display
5677
#endif
5778
}
5879

80+
static void display_4bit_setup()
81+
{
82+
#if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_LCD_4BIT)
83+
lcd.begin(16, 2);
84+
#endif
85+
}
86+
87+
// Check if we should show an important info to the user
88+
static bool handle_important_info_expire()
89+
{
90+
if (show_important_info_until)
91+
{
92+
if (millis() < show_important_info_until)
93+
{
94+
// Important info still active
95+
return true;
96+
}
97+
98+
// Important info expired
99+
show_important_info_until = 0;
100+
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
101+
display_nokia_setup();
102+
#elif (DISPLAY_TYPE & DISPLAY_TYPE_16X2_LCD_4BIT)
103+
display_4bit_setup();
104+
#endif
105+
}
106+
107+
// No important info shown
108+
return false;
109+
}
110+
59111
static void display_4bit_update()
60112
{
61113
#if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_LCD_4BIT)
@@ -75,6 +127,9 @@ static void display_4bit_update()
75127
static void display_nokia_update()
76128
{
77129
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
130+
if (handle_important_info_expire())
131+
return;
132+
78133
lcd.setCursor(0,0);
79134
lcd.print(voltage_display,1);
80135

@@ -165,21 +220,19 @@ void display_init()
165220
pinMode(13,OUTPUT);
166221
digitalWrite(13,LOW);
167222
#endif
223+
168224
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
169225
display_nokia_setup();
170-
#endif
171-
172-
#if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_LCD_4BIT)
173-
lcd.begin(16, 2);
226+
#elif (DISPLAY_TYPE & DISPLAY_TYPE_16X2_LCD_4BIT)
227+
display_4bit_setup();
174228
#endif
175229
}
176230

177231
void display_update()
178232
{
179233
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
180234
display_nokia_update();
181-
#endif
182-
#if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_LCD_4BIT)
235+
#elif (DISPLAY_TYPE & DISPLAY_TYPE_16X2_LCD_4BIT)
183236
display_4bit_update();
184237
#endif
185238
}

Arduino_Pedelec_Controller/display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2121

2222
void display_init();
2323
void display_update();
24+
void display_show_important_info(const char *str, int duration_secs);
2425

2526
// Global defines from main program.
2627
// This list will be replaced by a proper defined interface between

0 commit comments

Comments
 (0)