Arduino Forum

Using Arduino => Programming Questions => Topic started by: daba on May 12, 2018, 06:43 pm

Title: Error compiling
Post by: daba on May 12, 2018, 06:43 pm

I have a uint8_t array in PROGMEM I am trying to read from (byte 8), second line of the code below.

Compiler error is "expected ')' before ';' token".

If I remark out this line, the sketch compiles no problem....

I can't see anything wrong, almost copied from the reference text....

if (! data_valid) {

   colour = pgm_read_byte_near( RemoteXY_CONF[8] );

   get_LED_RGB(colour);
   RemoteXY.valid_r = red;
   RemoteXY.valid_g = grn;
   RemoteXY.valid_b = blu;
   }

Perhaps it just needs a fresh pair of eyes......
Title: Re: Error compiling
Post by: TolpuddleSartre on May 12, 2018, 06:47 pm
Perhaps we need code tags and all your code, and the exact error message.
Title: Re: Error compiling
Post by: daba on May 12, 2018, 07:03 pm
Perhaps we need code tags and all your code, and the exact error message.
I can't post ALL the code, it exceeds the maximum number of characters

"colour" is a global uint8_t, so are red, grn, and blue

the get_LED_RGB function works if I just put a number as the argument to it

It's throwing up a lot of references to the declaration of the RemoteXY_CONF array, which is in RemoteXY.h

Here's all the error messages....


Arduino: 1.8.5 (Windows 7), Board: "Arduino Nano, ATmega328P"

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,

                 from sketch\BaitBoat2.ino.cpp:1:

C:\Users\Dave\Documents\Arduino\BaitBoat2\BaitBoat2.ino: In function 'void loop()':

C:\Users\Dave\Documents\Arduino\libraries\RemoteXY/RemoteXY.h:158:23: error: expected primary-expression before 'const'

 #define RemoteXY_CONF const PROGMEM RemoteXY_CONF_PROGMEM

                       ^

C:\Users\Dave\Documents\Arduino\BaitBoat2\BaitBoat2.ino:557:35: note: in expansion of macro 'RemoteXY_CONF'

       colour = pgm_read_byte_near(RemoteXY_CONF[8]);

                                   ^

C:\Users\Dave\Documents\Arduino\libraries\RemoteXY/RemoteXY.h:158:23: error: expected ')' before 'const'

 #define RemoteXY_CONF const PROGMEM RemoteXY_CONF_PROGMEM

                       ^

C:\Users\Dave\Documents\Arduino\BaitBoat2\BaitBoat2.ino:557:35: note: in expansion of macro 'RemoteXY_CONF'

       colour = pgm_read_byte_near(RemoteXY_CONF[8]);

                                   ^

BaitBoat2:557: error: expected ')' before ';' token

       colour = pgm_read_byte_near(RemoteXY_CONF[8]);

                ^

exit status 1
expected ')' before ';' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Title: Re: Error compiling
Post by: TolpuddleSartre on May 12, 2018, 07:06 pm
See how much easier it is, when you can see the whole picture?

Do the macro expansion manually, and you'll see the problem.
Title: Re: Error compiling
Post by: daba on May 12, 2018, 07:32 pm
See how much easier it is, when you can see the whole picture?

Do the macro expansion manually, and you'll see the problem.
I have no idea what you mean by "Do the macro expansion manually". 

Perhaps if you posted the whole of the details it might get easier, but one-liners are not much help to a novice.

Are you suggesting I have to modify RemoteXY.h ??
Title: Re: Error compiling
Post by: Danois90 on May 12, 2018, 07:47 pm
The macro "RemoteXY_CONF" is invalid, fix it :)
Title: Re: Error compiling
Post by: daba on May 12, 2018, 07:50 pm
Here is the code section that defines the bytes in RemoteXY_CONF

It is in my sketch, not in RemoteXY.h

Code: [Select]

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////


// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__HARDSERIAL

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200


// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,35,0,10,0,13,3,8,178,4,
  131,1,0,57,13,5,1,8,31,77,
  97,105,110,0,129,0,4,1,40,5,
  0,8,66,97,105,116,66,111,97,116,
  32,67,111,110,116,114,111,108,0,131,
  0,36,57,13,5,2,16,8,83,101,
  116,117,112,0,5,32,3,12,42,42,
  1,178,26,31,129,0,45,32,3,4,
  1,8,82,0,129,0,0,31,2,4,
  1,8,76,0,129,0,20,8,9,4,
  1,8,70,87,68,0,4,0,52,10,
  8,47,1,204,26,129,0,52,58,9,
  3,1,24,76,105,103,104,116,115,0,
  129,0,51,5,10,3,1,24,66,97,
  116,116,101,114,121,0,130,0,60,1,
  4,4,1,134,130,0,48,1,12,4,
  1,1,66,131,48,1,16,4,1,30,
  8,65,22,69,0,10,10,1,1,0,
  70,1,8,8,1,246,31,80,0,129,
  0,81,4,7,3,1,24,72,111,111,
  107,0,129,0,79,7,11,3,1,24,
  82,101,108,101,97,115,101,0,65,22,
  90,0,10,10,1,1,0,91,1,8,
  8,1,246,31,83,0,66,1,93,14,
  4,39,1,1,17,4,0,91,10,8,
  47,1,2,26,66,1,72,14,4,39,
  1,1,17,4,0,70,10,8,47,1,
  2,26,129,0,79,58,12,3,1,24,
  72,111,112,112,101,114,115,0,129,0,
  20,55,8,4,1,8,82,69,86,0,
  129,0,46,1,14,5,2,24,83,101,
  116,117,112,0,129,0,2,14,30,3,
  2,8,80,111,114,116,32,72,111,112,
  112,101,114,32,83,101,114,118,111,32,
  37,0,129,0,35,8,12,3,2,8,
  77,105,110,0,7,22,35,12,11,5,
  2,94,26,2,129,0,53,8,6,3,
  2,8,77,97,120,0,7,22,52,12,
  11,5,2,94,26,2,129,0,1,21,
  30,3,2,8,83,116,98,100,32,72,
  111,112,112,101,114,32,83,101,114,118,
  111,32,37,0,7,22,35,19,11,5,
  2,94,26,2,7,22,52,19,11,5,
  2,94,26,2,129,0,9,28,31,3,
  2,8,82,117,100,100,101,114,32,83,
  101,114,118,111,32,37,32,32,32,40,
  45,47,43,41,0,7,22,44,26,11,
  5,2,94,26,2,129,0,11,35,30,
  3,2,8,84,104,114,111,116,116,108,
  101,32,69,83,67,32,37,32,32,32,
  40,45,47,43,41,0,7,22,44,33,
  11,5,2,94,26,2,129,0,16,50,
  15,3,2,8,66,97,116,116,101,114,
  121,32,40,86,41,0,7,14,35,48,
  11,5,2,94,26,2,2,129,0,1,
  43,30,3,2,8,72,111,111,107,32,
  82,101,108,101,97,115,101,32,84,105,
  109,101,32,83,0,7,22,35,41,11,
  5,2,94,26,2,1,2,80,0,20,
  6,2,204,31,82,101,115,101,116,32,
  73,110,100,105,99,97,116,111,114,115,
  0,129,0,84,8,13,3,2,8,68,
  105,114,101,99,116,105,111,110,0,129,
  0,68,22,6,3,2,8,84,114,105,
  109,0,7,22,66,26,11,5,2,94,
  26,2,7,22,66,33,11,5,2,94,
  26,2,65,31,79,51,21,12,2,129,
  0,82,52,14,3,2,178,0,1,2,
  80,54,19,6,2,0,1,83,97,118,
  101,0,129,0,48,13,2,4,2,8,
  60,0,129,0,48,20,2,4,2,8,
  60,0,2,0,81,12,18,5,2,29,
  24,1,136,82,69,86,0,78,79,82,
  0,2,0,81,19,18,5,2,29,24,
  1,136,82,69,86,0,78,79,82,0,
  2,0,81,26,18,5,2,29,24,1,
  136,82,69,86,0,78,79,82,0,2,
  0,81,33,18,5,2,29,24,1,136,
  82,69,86,0,78,79,82,0 };
  
// this structure defines all the variables of your control interface
struct {

    // input variable
  int8_t joystick_1_x; // =-100..100 x-coordinate joystick position
  int8_t joystick_1_y; // =-100..100 y-coordinate joystick position
  int8_t lights; // =0..100 slider position
  uint8_t hkr_p; // =1 if button pressed, else =0
  uint8_t hkr_s; // =1 if button pressed, else =0
  int8_t stbdhopper; // =0..100 slider position
  int8_t porthopper; // =0..100 slider position
  int16_t PHop_Min;  // −32767.. +32767
  int16_t PHop_Max;  // −32767.. +32767
  int16_t SHop_Min;  // −32767.. +32767
  int16_t SHop_Max;  // −32767.. +32767
  int16_t Rud_Rng;  // −32767.. +32767
  int16_t Thr_Rng;  // −32767.. +32767
  float Batt_Volts;
  int16_t Hook_Rel;  // −32767.. +32767
  uint8_t Reset; // =1 if button pressed, else =0
  int16_t Rud_Trim;  // −32767.. +32767
  int16_t Thr_Trim;  // −32767.. +32767
  uint8_t Save_Settings; // =1 if button pressed, else =0
  uint8_t PHop_Rev; // =1 if switch ON and =0 if OFF
  uint8_t SHop_Rev; // =1 if switch ON and =0 if OFF
  uint8_t Rud_Rev; // =1 if switch ON and =0 if OFF
  uint8_t Thr_Rev; // =1 if switch ON and =0 if OFF

    // output variable
  int8_t batt_meter; // =0..100 level position
  uint8_t rel_flag_p_r; // =0..255 LED Red brightness
  uint8_t rel_flag_p_g; // =0..255 LED Green brightness
  uint8_t rel_flag_s_r; // =0..255 LED Red brightness
  uint8_t rel_flag_s_g; // =0..255 LED Green brightness
  int8_t s_max; // =0..100 level position
  int8_t p_max; // =0..100 level position
  uint8_t valid_r; // =0..255 LED Red brightness
  uint8_t valid_g; // =0..255 LED Green brightness
  uint8_t valid_b; // =0..255 LED Blue brightness

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0
  
} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////
Title: Re: Error compiling
Post by: daba on May 12, 2018, 07:58 pm
The macro "RemoteXY_CONF" is invalid, fix it :)
How can it be "wrong" if works...

This array block is pushed to the connected mobile to define the control screens.

So what exactly is stopping me reading from that array ?
Title: Re: Error compiling
Post by: Jobi-Wan on May 12, 2018, 08:02 pm
Just to clarify what TolpuddleSartre wrote...


When you #define something, that's a macro.

#define bla blub

From that point on, the compiler will replace any occurrence of bla with blub. That's called macro expansion. It expands the thing you've #defined to the stuff you've #defined it to be. In this case, it expands bla into blub.

In your case, RemoteXY_CONF is a macro. It occurs in the line you're asking about. That line looks normal if you don't know that RemoteXY_CONF is a macro, but do the macro expansion manually, and you'll see the problem.
Title: Re: Error compiling
Post by: Danois90 on May 12, 2018, 08:08 pm
You are using the macro "#define RemoteXY_CONF const PROGMEM RemoteXY_CONF_PROGMEM" as argument to "pgm_read_byte_near", your code will expand to:

Code: [Select]
pgm_read_byte_near(const PROGMEM RemoteXY_CONF_PROGMEM[8]);

Which is a malformed statement, therefore the macro is not working.
Title: Re: Error compiling
Post by: daba on May 12, 2018, 08:11 pm
Just to clarify what TolpuddleSartre wrote...


When you #define something, that's a macro.

#define bla blub

From that point on, the compiler will replace any occurrence of bla with blub. That's called macro expansion. It expands the thing you've #defined to the stuff you've #defined it to be. In this case, it expands bla into blub.

In your case, RemoteXY_CONF is a macro. It occurs in the line you're asking about. That line looks normal if you don't know that RemoteXY_CONF is a macro, but do the macro expansion manually, and you'll see the problem.

From what I can see RemoteXY_CONF is a uint8_t array, I can't see it #define'd anywhere, it must be in the RemoteXY library....

Does this mean that there is no way to read bytes from RemoteXY_CONF ??

I would not have a clue how to "do the macro expansion manually" with my sketch....

Here's a simpler example with much less "CONF"

Code: [Select]

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3
#define REMOTEXY_SERIAL_SPEED 9600


// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,1,0,0,0,11,0,8,108,0,
  4,0,26,14,10,36,2,26 };
  
// this structure defines all the variables of your control interface
struct {

    // input variable
  int8_t slider_1; // =0..100 slider position

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////
Title: Re: Error compiling
Post by: Jobi-Wan on May 12, 2018, 08:25 pm
From what I can see RemoteXY_CONF is a uint8_t array, I can't see it #define'd anywhere, it must be in the RemoteXY library....

Does this mean that there is no way to read bytes from RemoteXY_CONF ??

I would not have a clue how to "do the macro expansion manually" with my sketch....
In post #2 where you post all messages, you can see where and how it is #defined.
Title: Re: Error compiling
Post by: daba on May 12, 2018, 08:30 pm
In post #2 where you post all messages, you can see where and how it is #defined.

In which case, I'll go no further, I'm not into modifying someone else's library code.... I'll send him a message with a link to this thread, and see if he can "fix it" so we can read bytes from that array.
Title: Re: Error compiling
Post by: Jobi-Wan on May 12, 2018, 08:38 pm
Does the library come with any example sketches that show how it is intended to be used?
Title: Re: Error compiling
Post by: TolpuddleSartre on May 12, 2018, 08:41 pm
In which case, I'll go no further,
How about using the time waiting for a response reading this (https://forum.arduino.cc/index.php?topic=149014.0) ?
Title: Re: Error compiling
Post by: daba on May 12, 2018, 08:51 pm
Does the library come with any example sketches that show how it is intended to be used?
Not really, the "Examples" page just shows some finished (sic) projects.

the web-site is here if you want to look.

I really like RemoteXY, it's simple enough to use, I can modify my screen layout and content in the EDITOR, generate the "source code", and copy/Paste-over the configuration block in my sketch.  When the phone connects, it sends all the _CONF data to the phone to reproduce the design-time.

Not being able to read from that _CONF array isn't a deal-breaker. I'm only using it to get the screen background colour RGB values, I can see the number, so I'll continue just quoting it literally.
Title: Re: Error compiling
Post by: Jobi-Wan on May 12, 2018, 09:09 pm
Does it show the source code for those projects? And do they read from the CONF array?


But let's get back to this macro expansion thing...

You include a header that defines this:
Code: [Select]
#define RemoteXY_CONF const PROGMEM RemoteXY_CONF_PROGMEM

Then you declare an array like this:
Code: [Select]
uint8_t RemoteXY_CONF[] =
 { 255,35,0,10,0,13,3,8,178,4,
 131,1,0,57,13,5,1,8,31,77,


Then you read from that array:
Code: [Select]
colour = pgm_read_byte_near(RemoteXY_CONF[8]);

Note that the macro occurs in both the declaration of the array and in the attempt at reading from it.

Do the macro expansion in the array declaration. In a text editor, not in your head. You will see that it still looks good.

Then do the macro expansion in the colour read part. You should see that it does not look good.

Look at the now macro-expanded array declaration again. You should see what to read from.
Title: Re: Error compiling
Post by: daba on May 12, 2018, 09:13 pm
I may be a new forum member here, but I am in no way unfamiliar with forum etiqutte.

My field is PLC Programming, and was once a technical trainer for Rockwell Automation (you may have heard of them).

I am also a regular contributor to, and moderator for, the PLCs.net community, with over 4,000 posts to date. My user-name there is the same as here.

There is absolutely no way I would have posted replies like some of the earlier ones, being as much use as chocolate teapots. Terse, unhelpful, and slightly condescending. Everyone needs some help, at all levels.

There, I've had my say, and if this post gets me barred from this forum, then so be it.
Title: Re: Error compiling
Post by: TolpuddleSartre on May 12, 2018, 09:20 pm
Let's just examine your technical writer's approach to problem solving, shall we? (you don't have to answer that, it was rhetorical)

First post, incomplete code (not in code tags, so you got the 8) smilie) and an incomplete error message.

Second post, still no code ("it's too long" - you could have attached it), but an error message that points exactly to your problem.

Third post
Quote
Perhaps if you posted the whole of the details it might get easier, but one-liners are not much help to a novice.
So, you can post incomplete snippets, but we have to provide fully crafted answers?


Quote
but I am in no way unfamiliar with forum etiqutte (sic)
Yeah, right.

This isn't about etiquette, it's about common-sense.
Title: Re: Error compiling
Post by: Jobi-Wan on May 12, 2018, 09:30 pm
An embroidery forum? Gardening?
Have you been on those forums?
Some people use a type-B needle for underhand stitching. Savages!
Title: Re: Error compiling
Post by: daba on May 12, 2018, 09:43 pm
@TolpuddleSartre

I believed, at the time, I had given enough information.... I was unaware that what looks like perfectly reasonable and syntactically correct code can fail to work under "circumstances"

If someone had come back and said something like "The line of code looks fine. One case it won't work correctly is if "RemoteXY_CONF" is #defined as a macro.  You may have done this yourself, but it could be in one of your included libraries, in which case you should address the matter to the library contributor"

That sort of reply would have shortened this thread dramatically, and I would have given up earlier, but to receive replies like (not yours, I will add) "The macro "RemoteXY_CONF" is invalid, fix it " doesn't cut it when I can't even see that it is a macro.

Now quit the derogatory remarks, please


Title: Re: Error compiling
Post by: TolpuddleSartre on May 12, 2018, 09:50 pm
Quote
I believed, at the time, I had given enough information.... I was unaware that what looks like perfectly reasonable and syntactically correct code can fail to work under "circumstances"
The code was obviously (really, really obviously) not syntactically correct - had it been so, the compiler would not have so comprehensively up-chucked on it.
We can tell that, even though we still can't see the code itself.

Seriously, how are we supposed to gauge your level of expertise, but by asking questions?
Title: Re: Error compiling
Post by: surbyte on May 12, 2018, 10:35 pm
Focus in post#16 to fix your problem and please edit post#1, #2 using Tags. </>


How to use this forum (https://forum.arduino.cc/index.php?topic=149014.0)

Please, do it!!
Title: Re: Error compiling
Post by: daba on May 13, 2018, 01:23 am
Focus in post#16 to fix your problem and please edit post#1, #2 using Tags. </>


How to use this forum (https://forum.arduino.cc/index.php?topic=149014.0)

Please, do it!!

Fixing my problem in someone else's library doesn't seem right to me.... Sometime in the future that library may get updated, which will invalidate whatever "fix" I made to make this project work. And then, of course, I could publish a project that no-one else can compile....
Title: Re: Error compiling
Post by: ieee488 on May 13, 2018, 01:33 am
Fixing my problem in someone else's library doesn't seem right to me.... Sometime in the future that library may get updated, which will invalidate whatever "fix" I made to make this project work. And then, of course, I could publish a project that no-one else can compile....
What library?

Whose library are you "fixing" ? ? ?



.
Title: Re: Error compiling
Post by: daba on May 13, 2018, 10:19 am
What library?

Whose library are you "fixing" ? ? ?

.
I am not going to be "fixing" library code to make my code work.

The library is "RemoteXY", clearly stated in the code in post #6

Anyway, the issue has been solved, thanks to a user on another forum, and I now know how to read from, and write into, the array in question.
Title: Re: Error compiling
Post by: AWOL on May 13, 2018, 10:23 am
The library is "RemoteXY", clearly stated in the code in post #6
I guess this really is the fabled xy problem :D

Quote
I now know how to read from, and write into, the array
Write into?