Jump to content
Sign in to follow this  
IRobertI

Poking around in the firmware and I'm stuck.

Recommended Posts

Posted · Poking around in the firmware and I'm stuck.

Tried StackOverflow (good luck getting noticed in that avalanche of questions...) and another forum without luck so now I'm here.

Basically I'm trying to modify lcd_lib_draw_stringP and since I've never touched Arduino code before I'm flailing around in the dark even more than usual. The problem is that a variable doesn't seem to hold the value I'm expecting even though printing it out on the screen suggests it does... :)

The array I'm trying to get data from:

 


static const uint16_t f_04b036ptDescriptors[95][3] PROGMEM =
{
{2, 7, 0}, //
{1, 7, 2}, // !
{3, 7, 3}, // "
etc

Snippet of the function:

 


void lcd_lib_draw_small_stringP(uint8_t x, uint8_t y, const char* pstr)
{
uint16_t offset;
uint8_t index;
for(char c = pgm_read_byte(pstr); c; c = pgm_read_byte(++pstr))
{
index = c - ' ';
offset = f_04b036ptDescriptors[index][2];

How I'm calling it:

 


lcd_lib_draw_small_stringP(15, 10, PSTR("M"));

Now, the trouble I'm having is with the c variable. If I print it out on the screen using the helper function int_to_string I get the expected result (77 for 'M'). index also shows the expected value after subtracting ' ' if I print it out (45). However, I can't seem to use index to get the correct item from the array into offset. I get back "weird" values like -8467 instead of the expected 1-300 range.

If I set index = 45 and/or set c = 'M' manually inside the function everything works just fine.

What am I missing?

 

Share this post


Link to post
Share on other sites
Posted · Poking around in the firmware and I'm stuck.

 


offset = f_04b036ptDescriptors[index][2];

That's not valid for accessing program memory. You have to use the pgm_read_word() function like this:

 


offset = (uint16_t)pgm_read_word(&f_04b036ptDescriptors[index][2]);

Or alternatively you should be able to do (but above syntax better and I may have the ptr math all wrong here):

 


offset = (uint16_t)pgm_read_word(f_04b036ptDescriptors+index*3+2);

 

Share this post


Link to post
Share on other sites
Posted · Poking around in the firmware and I'm stuck.

Yay! Now it's working, thanks George :) Now all I have to do is the rest of it hehe.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Our picks

    • Ultimaker Cura 4.0 | Stable available!
      Ultimaker Cura 4.0 is mainly focused on the improved user interface and cloud integration.
      As always, we want to collect your user feedback for this release. If there are any improvements you can think of, feel free to mention it here and help us to shape the next release.
      • 87 replies
×
×
  • Create New...

Important Information

Welcome to the Ultimaker Community of 3D printing experts. Visit the following links to read more about our Terms of Use or our Privacy Policy. Thank you!