Pages: [1]   Go Down
Author Topic: PROGMEM in the Arduino 1.0.1 IDE  (Read 1309 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 151
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm utilising the ODBuino project here, http://code.google.com/p/opengauge/source/browse/trunk/obduino32K/obduino32K.pde
To rewrite to use it for a similar but different protocol purpose.

I know the code for that compiles fine on Arduino 0022 as I did have it working there previously.

The compiler in 1.0.1 is throwing a heap of errors mainly due to the PROGMEM prog_char deprecation that's occurred.

I've gone through and modified the lines such as line 759:
prog_char pctd[] PROGMEM="- %d + "; // used in a couple of place

Becomes:
const char pctd[] PROGMEM = "- %d + "; // used in a couple of place

I get problems like this:
prog_char select_no[]  PROGMEM="(NO) YES "; // for config menu
prog_char select_yes[] PROGMEM=" NO (YES)"; // for config menu

Changed to:
const char select_no[]  PROGMEM = "(NO) YES "; // for config menu
const char select_yes[] PROGMEM = " NO (YES)"; // for config menu

Gives an error from function menu_select_yes_no, which is programmed as:
Code:
byte menu_select_yes_no(byte p)
{
  boolean exitMenu = false;

  // set value with left/right and set with middle
  exitMenu = delay_reset_button();  // make sure to clear button

  do
  {
    if(LEFT_BUTTON_PRESSED)
      p=0;
    else if(RIGHT_BUTTON_PRESSED)
      p=1;
    else if(MIDDLE_BUTTON_PRESSED)
      exitMenu = true;

    lcd.setCursor(4,1);
    if(p==0)
      lcd_print_P(select_no);
    else
      lcd_print_P(select_yes);

    exitMenu |= delay_reset_button();
  }
  while(!MIDDLE_BUTTON_PRESSED && !exitMenu);

  return p;
}

The error given is 'invalid conversion from const char* to char*' - this would relate to the lcd_print_P line, which takes the const char "select_yes" and prints to LCD.
Code:
void lcd_print_P(char *string)
{
  char c;
  while( (c = pgm_read_byte(string++)) )
    lcd.write(c);
}

I think the problem is actually the code - lcd_print_P gets a ? pointer? to a string and needs to read it?
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to change both instances of "void lcd_print_P(char *string)" to "void lcd_print_P(const char *string)". Which is how it should have been written in the first place.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

0
Offline Offline
Full Member
***
Karma: 0
Posts: 151
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That fixed the bulk of the errors, there's still some errors hanging around.
'error: cannot convert 'const char*[15]' to 'const char **' for argument to 'byte menu_selection(const char**, byte)'

The function is used to display a menu produced from an array:
Line 3322: byte menu_selection(char ** menu, byte arraySize)

I'm using it as below:
Code:
byte menu_selection(const char ** menu, byte arraySize)
{
  byte selection = 1; // Menu title takes up the first string in the list so skip it
  byte screenChars = 0;  // Characters currently sent to screen
  byte menuItem = 0;     // Menu items past current selection
  boolean exitMenu = false;
  boolean forceExit = false;

  // Note: values are changed with left/right and set with middle
  // Default selection is always the first selection, which should be 'Exit'

  lcd.clear();
  lcd.print((char *)pgm_read_word(&(menu[0])));
  forceExit = delay_reset_button();  // make sure to clear button
 

The array being passed in is as below:
const char displayMenu[6][13] PROGMEM = {"Display menu", "Exit", "Contrast", "Metric", "Fuel/Hour", "Font"};
const char adjustMenu[11][12] PROGMEM = {"Adjust menu", "Exit", "Tank Size", "Fuel Cost", "Fuel %", "Speed %", "Out Wait", "Trip Wait", "Tank Used", "Tank Dist", "Eng Disp"};

They were defined as:
prog_char *adjustMenu[] PROGMEM = {"Adjust menu", "Exit", "Tank Size", "Fuel Cost", "Fuel %", "Speed %", "Out Wait", "Trip Wait", "Tank Used", "Tank Dist", "Eng Disp", };
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The array being passed in is as below:
const char displayMenu[6][13] PROGMEM = {"Display menu", "Exit", "Contrast", "Metric", "Fuel/Hour", "Font"};
const char adjustMenu[11][12] PROGMEM = {"Adjust menu", "Exit", "Tank Size", "Fuel Cost", "Fuel %", "Speed %", "Out Wait", "Trip Wait", "Tank Used", "Tank Dist", "Eng Disp"};

They were defined as:
prog_char *adjustMenu[] PROGMEM = {"Adjust menu", "Exit", "Tank Size", "Fuel Cost", "Fuel %", "Speed %", "Out Wait", "Trip Wait", "Tank Used", "Tank Dist", "Eng Disp", };

You appear to be using a mixture of 2-dimensional char arrays, and arrays of char pointers. These are not the same. The 2D array form wastes space by padding out all the strings to the size of the biggest one. I suggest you use arrays of char pointer throughout. Define them like this:

const char *adjustMenu[] PROGMEM = {"Adjust menu", "Exit", "Tank Size", "Fuel Cost", "Fuel %", "Speed %", "Out Wait", "Trip Wait", "Tank Used", "Tank Dist", "Eng Disp", };

When you declare functions that take them as parameters, declare the parameter type as "const char **" or "const char*[]".

EDIT: even better, use "const char* const adjustMenu[] PROGMEM" and "const char* const*" or "const char* const[]".
« Last Edit: January 06, 2013, 05:59:01 am by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Pages: [1]   Go Up
Jump to: