Jump to content
Ultimaker Community of 3D Printing Experts

Poking around in the firmware and I'm stuck.


IRobertI
 Share

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
     Share

    • Our picks

      • New here? Get ahead with a free onboarding course
        Hi,
         
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 11 replies
    ×
    ×
    • Create New...