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.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 18 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...