Skip to content

Commit eb7b978

Browse files
committed
Load Nokia display info messages from flash
config.h change: Convert msg_XXX variables to new format: const char msg_XXXXXXX[] PROGMEM = "foobar";
1 parent b64ba4b commit eb7b978

File tree

7 files changed

+34
-15
lines changed

7 files changed

+34
-15
lines changed

Arduino_Pedelec_Controller/Arduino_Pedelec_Controller.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ void loop()
440440
km=variable.kilometers;
441441
mah=variable.mah;
442442
} else
443-
display_show_important_info(msg_battery_charged, 5);
443+
display_show_important_info(FROM_FLASH(msg_battery_charged), 5);
444444
#endif
445445
if (voltage<6.0) //do not write new data to eeprom when on USB Power
446446
{variables_saved=true;}
@@ -650,7 +650,7 @@ void loop()
650650
++idle_shutdown_count;
651651
if (idle_shutdown_count > idle_shutdown_secs)
652652
{
653-
display_show_important_info("Idle shutdown. Good night.", 60);
653+
display_show_important_info(MY_F("Idle shutdown. Good night."), 60);
654654
save_eeprom();
655655
digitalWrite(fet_out,HIGH);
656656
}
@@ -662,7 +662,7 @@ void loop()
662662
if (voltage < vemergency_shutdown && voltage_display < vemergency_shutdown
663663
&& voltage > 6.0)
664664
{
665-
display_show_important_info("Battery undervoltage detected. Emergency shutdown.", 60);
665+
display_show_important_info(MY_F("Battery undervoltage detected. Emergency shutdown."), 60);
666666
delay(1000);
667667
save_eeprom();
668668
digitalWrite(fet_out,HIGH);

Arduino_Pedelec_Controller/config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ const float current_offset = 0.0; // for Rev 1.3 ONLY! set this valu
148148
const float current_amplitude_R11 = 0.0296; // for Rev 1.1 - 1.2 set this value according to your own current-calibration. Default: 0.0296
149149
const float current_amplitude_R13 = 0.0741; // for Rev 1.3 set this value according to your own current-calibration. Default: 0.0741
150150

151-
const char* const msg_welcome = "Welcome";
152-
const char* const msg_shutdown = "Live long and prosper.";
153-
const char* const msg_battery_charged = "Batt. charged! Resetting counters";
151+
const char msg_welcome[] PROGMEM = "Welcome";
152+
const char msg_shutdown[] PROGMEM = "Live long and prosper.";
153+
const char msg_battery_charged[] PROGMEM = "Batt. charged! Resetting counters";
154154

155155
#endif

Arduino_Pedelec_Controller/display.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ static const PROGMEM byte glyph2[] = {0xc8, 0x2f, 0x6a, 0x2e, 0xc8}; //symbol fo
6565
static const PROGMEM byte glyph3[] = {0x44, 0x28, 0xfe, 0x6c, 0x28}; //bluetooth-symbol check this out: http://www.carlos-rodrigues.com/projects/pcd8544/
6666

6767
unsigned long show_important_info_until = 0;
68-
void display_show_important_info(const char *str, int duration_secs)
69-
{
7068
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
69+
static void prepare_important_info(int duration_secs)
70+
{
7171
unsigned long seconds = 2;
7272
if (duration_secs)
7373
seconds = duration_secs;
@@ -81,10 +81,26 @@ void display_show_important_info(const char *str, int duration_secs)
8181
// TODO: Implement and test 4bit display mode
8282
lcd.clear();
8383
lcd.setCursor(0, 2);
84+
}
85+
#endif
86+
87+
void display_show_important_info(const char *str, int duration_secs)
88+
{
89+
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
90+
prepare_important_info(duration_secs);
91+
lcd.print(str);
92+
#endif
93+
}
94+
95+
void display_show_important_info(const __FlashStringHelper *str, int duration_secs)
96+
{
97+
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
98+
prepare_important_info(duration_secs);
8499
lcd.print(str);
85100
#endif
86101
}
87102

103+
88104
// Calculate length of number.
89105
// Don't use sprintf() here is it sucks up 1.5kb of code space.
90106
static byte calc_number_length(const unsigned long x)
@@ -106,7 +122,7 @@ static byte calc_number_length(const unsigned long x)
106122

107123
void display_show_welcome_msg()
108124
{
109-
display_show_important_info(msg_welcome, 5);
125+
display_show_important_info(FROM_FLASH(msg_welcome), 5);
110126

111127
#if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)
112128
lcd.setCursor(0, 5);
@@ -266,7 +282,7 @@ static void display_nokia_menu()
266282
else
267283
lcd.print(MY_F(" "));
268284

269-
lcd.print(reinterpret_cast<const __FlashStringHelper *>(item->get_name()));
285+
lcd.print(FROM_FLASH((item->get_name())));
270286

271287
++current_lcd_row;
272288
if (current_lcd_row == nokia_screen_rows)

Arduino_Pedelec_Controller/display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2424
void display_init();
2525
void display_update();
2626
void display_show_important_info(const char *str, int duration_secs);
27+
void display_show_important_info(const __FlashStringHelper *str, int duration_secs);
2728

2829
void display_show_welcome_msg();
2930
void display_show_welcome_msg_temp();

Arduino_Pedelec_Controller/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,6 @@ extern void activate_new_profile();
7373
// This is the version as in Arduino 1.5 and newer.
7474
#define MY_F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
7575

76+
#define FROM_FLASH(str) (reinterpret_cast<const __FlashStringHelper *>(str))
77+
7678
#endif

Arduino_Pedelec_Controller/menu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ static void handle_profile(MenuItem* p_menu_item)
188188
static void show_new_state(const boolean is_on)
189189
{
190190
if (is_on)
191-
display_show_important_info("Aktiviert", 1);
191+
display_show_important_info(MY_F("Aktiviert"), 1);
192192
else
193-
display_show_important_info("Deaktiviert", 1);
193+
display_show_important_info(MY_F("Deaktiviert"), 1);
194194

195195
menu_active = false;
196196
}

Arduino_Pedelec_Controller/switches.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void action_set_soft_poti(int new_throttle_stat)
7979
#endif
8080
poti_stat = new_throttle_stat;
8181
if (poti_stat == 0)
82-
display_show_important_info("Tempomat reset", 0);
82+
display_show_important_info(MY_F("Tempomat reset"), 0);
8383
else
8484

8585
{
@@ -136,7 +136,7 @@ static void action_shutdown_system()
136136
{
137137
// Shut down system
138138
#if HARDWARE_REV >=2
139-
display_show_important_info(msg_shutdown, 60);
139+
display_show_important_info(FROM_FLASH(msg_shutdown), 60);
140140
save_eeprom();
141141
digitalWrite(fet_out,HIGH);
142142
#endif
@@ -234,7 +234,7 @@ static void execute_action(const sw_action action)
234234
break;
235235
#endif
236236
default:
237-
display_show_important_info("Unknown action!", 2);
237+
display_show_important_info(MY_F("Unknown action!"), 2);
238238
break;
239239
}
240240
}

0 commit comments

Comments
 (0)