Jump to content

Poking around in the firmware and I'm stuck.


IRobertI

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?

 

  • 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);

     

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • UltiMaker Cura 5.8 beta released
        Another Cura release has arrived and in this 5.8 beta release, the focus is on improving Z seams, as well as completing support for the full Method series of printers by introducing a profile for the UltiMaker Method.
          • Like
        • 1 reply
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Thanks
          • Like
        • 3 replies
    ×
    ×
    • Create New...