Since the send() function specifies a 'byte *' as its first parameter, the compiler would probably be unhappy if you tried use a 'const byte *'. It's trying to prevent you from shooting yourself in the foot.
Is there a way to do this if I re-write the function? I don't really care what part of the source I have to change, if it saves me time in the long run.
This is the function atm:
byte LCD::send(byte *b, int bytes)
{
for(int i = 0; i < bytes; i++)
{
Serial1.write(*b);
b++;
}
while(Serial1.available() == 0);
return Serial1.read();
}
Rather than pointlessly redeclaring variables every time, save yourself some of that unbelievably arduous typing by using predeclared variables. You can even give the data chunks understandable names, for future debugging.
byte result;
byte command1_2[]={0x45, 0x15};
...
result = host.send(command1_2,2);
Rather than pointlessly redeclaring variables every time, save yourself some of that unbelievably arduous typing by using predeclared variables. You can even give the data chunks understandable names, for future debugging.
byte result;
byte command1_2[]={0x45, 0x15};
...
result = host.send(command1_2,2);
This is example code, written for forum readability. Also: I do not optimize while experimenting.
Why? Because it's faster to write and I have to write around a metric bazillion .send calls
the problem seems to be how you're using it. Post an example of the bazillions of calls you have to make. As I implied the solution could be an array (perhaps 2-dimensional) and a loop.
The send() function wants a 'byte *'. So I'm thinking that sending it the address of a c-string literal will make the compiler unhappy without casting. With casting, the send() function will be capable of changing that literal via the pointer. Bad form.
jremington:
I see, you made up a fake problem, to which you want an answer.
I have re-written the question, using actual runtime code, just for you as this is quite real. I do think this makes for a less readable question, but if you prefere it, then why not:
I have a function that sends some bytes to a remote host:
byte LCD::send(byte *b, int bytes)
I actually call this with:
byte buffer[] = { 0x51, baudRateID };
return send(buffer, 2);
This works.
My question is this; is there a way to combine the two lines required to call this function? Something like:
return send({0x51, baudRateID });