Go Down

Topic: Pointers to Flash objects? (Read 436 times) previous topic - next topic

Professor Chaos

I'm stuck on a problem using Mikal Hart's Flash library.

I have a bunch of flash tables, storing data associated with multiple possible objects:
Code: [Select]
FLASH_TABLE(byte, dataforobject1, <lots of data>);
FLASH_TABLE(byte, dataforobject2, <lots of data>);

etc.


what I would like to do is have a class which contains a pointer to a flash table with the appropriate data:
Code: [Select]
class foo {
public:
<pointer to a flash table>
};


I was hoping to dynamically create an instance of foo, then set the pointer to the appropriate flash table.  Then be able to access the data in fooinstance's flash table through that pointer.

Is that possible?  I can't include a flash table in the class itself of course, but I can't figure out how to describe a pointer that will let me get at the flash table's data.

Coding Badly


Give this a try...

Code: [Select]
#include <Flash.h>

FLASH_TABLE(byte, dataforobject1, 1, 2, 3, 4 );
FLASH_TABLE(byte, dataforobject2, 5, 6, 7, 8, 9, 10 );

class foo
{
public:

  void setData( _FLASH_TABLE<byte> * data )
  {
    pdfo = data;
  }

  byte first( void )
  {
    return( (*pdfo)[0][0] );
  }
 
private:

  _FLASH_TABLE<byte> * pdfo;
};

foo bar;

void setup( void )
{
  Serial.begin( 115200 );

  bar.setData( &dataforobject1 );
  Serial.println( bar.first() );

  bar.setData( &dataforobject2 );
  Serial.println( bar.first() );
}

void loop( void )
{
}

Professor Chaos

Many thanks Coding Badly - that worked!  What I was really missing was the parentheses around the pointer name.

[Though for anyone else looking here, I think the code as written is really for a one-dimensional array, not a table.  And you would need DEC formatters in the prints to get the results you expect.]

Go Up