Lookup Tables

01 Jan 2010

Hi,

Whats wrong with the below lookup table?

unsigned char codeTypes[21] { CODE_TYPE_FLOAT | F_CODE_INDEX, // F
                              CODE_TYPE_INT | G_CODE_INDEX, // G
                              NULL_CODE_CODE, // H
                              CODE_TYPE_FLOAT | I_CODE_INDEX, // I
                              CODE_TYPE_FLOAT | J_CODE_INDEX, // J
                              NULL_CODE_CODE, // K
                              NULL_CODE_CODE, // L
                              CODE_TYPE_INT | M_CODE_INDEX, // M
                              NULL_CODE_CODE, // N
                              NULL_CODE_CODE, // O
                              CODE_TYPE_FLOAT | P_CODE_INDEX, // P
                              CODE_TYPE_FLOAT | Q_CODE_INDEX, // Q
                              CODE_TYPE_FLOAT | R_CODE_INDEX, // R
                              CODE_TYPE_FLOAT | S_CODE_INDEX, // S
                              NULL_CODE_CODE, // T
                              NULL_CODE_CODE, // U
                              NULL_CODE_CODE, // V
                              NULL_CODE_CODE, // W
                              CODE_TYPE_FLOAT | X_CODE_INDEX, // X
                              CODE_TYPE_FLOAT | Y_CODE_INDEX, // Y
                              CODE_TYPE_FLOAT | Z_CODE_INDEX, // Z
                            }

The compiler moans it wants a ";" after "unsigned char codeTypes[21]". The code is a snippet from a GCODE interpreter designed to run a 3 axis CNC machine I am trying (but failing) to port from the Arduino!

Thanks in advance.

Michael.

01 Jan 2010

I believe you need a ; after the closing brace and an assignment operator for the array.

 

unsigned char codeTypes[21] = { CODE_TYPE_FLOAT | F_CODE_INDEX, // F
                              CODE_TYPE_INT | G_CODE_INDEX, // G
                              NULL_CODE_CODE, // H
                              CODE_TYPE_FLOAT | I_CODE_INDEX, // I
                              CODE_TYPE_FLOAT | J_CODE_INDEX, // J
                              NULL_CODE_CODE, // K
                              NULL_CODE_CODE, // L
                              CODE_TYPE_INT | M_CODE_INDEX, // M
                              NULL_CODE_CODE, // N
                              NULL_CODE_CODE, // O
                              CODE_TYPE_FLOAT | P_CODE_INDEX, // P
                              CODE_TYPE_FLOAT | Q_CODE_INDEX, // Q
                              CODE_TYPE_FLOAT | R_CODE_INDEX, // R
                              CODE_TYPE_FLOAT | S_CODE_INDEX, // S
                              NULL_CODE_CODE, // T
                              NULL_CODE_CODE, // U
                              NULL_CODE_CODE, // V
                              NULL_CODE_CODE, // W
                              CODE_TYPE_FLOAT | X_CODE_INDEX, // X
                              CODE_TYPE_FLOAT | Y_CODE_INDEX, // Y
                              CODE_TYPE_FLOAT | Z_CODE_INDEX, // Z
                            };
01 Jan 2010 . Edited: 01 Jan 2010

Hi Michael,

Just need an "=" and a ";" as the way to define the initialisation for the array:

unsigned char codeTypes[21] = { CODE_TYPE_FLOAT | F_CODE_INDEX, // F
                                :
                                CODE_TYPE_FLOAT | Z_CODE_INDEX, // Z
                              };

Also, if codeTypes never changes, you may want to define it as "const unsigned char" (edit: i wrote 'static' first, by mistake) so the compiler knows it can allocate it in FLASH rather than RAM.

Simon

01 Jan 2010

Thanks guys the  "=" and a ";" seem to do the trick,

It seems to be an up hill battle porting code from the Arduino to the Mbed, I thought a lot of users of the Mbed would of come from an Arduino background simply seeking more power! Shame there is no Arduino compatible libarys for the Mbed as the Arduino documentation, code examples and reference is second to none.

Must say I'm really struggling with the Mbed's due to a lack of reference, even defining what functions within this particular subset of C are supported and basic examples of how they can be implemented. I know I'm just a novice and thats why i'm struggling, but then I think its fair to say that alot of people turning to the mBed are in the same boat so to speak.

I should also point out that the forum based support for the Mbed has been excellent. Me being naive thought I could simply dump my Arduino sketches into the Mbed IDE and bobs your uncle!!! (moan over!).

Thanks chaps for the help. 

05 Jan 2010

What "subset of C"? I'm not familiar with what Arduino uses but mbed's online IDE uses a fully standard C/C++ compiler. All standard C (and C++) headers and functions should be supported. Are you missing anything in particular?

05 Jan 2010

Its a super-set really not sub, basically in Arduino there are a load of standard functions created for the system, it uses the standard ATMega GCC compiler, with an IDE and standardised libraries.

There are 2 options open to you,

1. Port Arduino libraries to the Keil compiler on here  (they're open source)

2. Port the source of your program to mbed.

21 May 2010

Hi Michael:

I'm not able to offer you any help but I would like you to know that you are not alone in trying to migrate from the Arduino.  I am in exactly the same boat with exactly the same observations regarding documentation and examples.

I would also like to add that I too find the support on this forum excellent.

I have to wonder if I could help port the libraries to the Keil compiler.  I know little about it, but have experience on the Arduino side.

Just and offer if anyone wants to nibble at it.

Tim