Correcting grammar in my previous post:
gfvalvo:
Looks likeyouryou're stuck. I thought maybe you had a whole lot of calls to make at the same time and could blast them out using array / loop.Better get typing.
Correcting grammar in my previous post:
gfvalvo:
Looks likeyouryou're stuck. I thought maybe you had a whole lot of calls to make at the same time and could blast them out using array / loop.Better get typing.
I'm not sure why you seem so set on putting your bytes into an array, when your send() function just takes them out again...
If send() is under your control, perhaps polymorphism is something you should look into:
byte LCD::send(byte b) {
// send one byte
Serial1.write(b);
while(Serial1.available() == 0);
return Serial1.read();
}
byte LCD::send(byte b1, byte b2) {
// Send two bytes
Serial1.write(b1);
Serial1.write(b2);
while(Serial1.available() == 0);
return Serial1.read();
}
byte LCD::send(byte b1, byte b2, byte b3) {
// send three bytes (existing code)
Serial1.write(b1);
Serial1.write(b2);
Serial1.write(b3);
while(Serial1.available() == 0);
return Serial1.read();
}
byte LCD::send(byte *b, int bytes) {
// send any number of bytes
for(int i = 0; i < bytes; i++)
{
Serial1.write(*b);
b++;
}
while(Serial1.available() == 0);
return Serial1.read();
}
You need to be more explicit about the initialiser type; so a cast like this works:
#include <stdio.h>
/*
unsigned char* send(const unsigned char b[], int bytes) {
printf("%#hhx %#hhx %d\n", b[0], b[1], bytes);
}
int main() {
send((const unsigned char[]){ 0x45, 0x56 }, 2);
}
*/
typedef const unsigned char send_array_t[];
unsigned char* send(send_array_t b, int bytes) {
printf("%#hhx %#hhx %d\n", b[0], b[1], bytes);
}
int main() {
send((send_array_t){ 0x45, 0x56 }, 2);
}
0x45 0x56 2
westfw:
I'm not sure why you seem so set on putting your bytes into an array, when your send() function just takes them out again...
With an array, I can have one single send function, so if I need to upgrade or change it later, I can do so a single place. And the MCU has instruction cycles spare, so why not use that to make my life easier. If I need to optimize for speed at a later time, I'll know how many morphs to make. And your suggestion will be very valueable at such a time, so thank you. ![]()
arduarn:
You need to be more explicit about the initialiser type; so a cast like this works:#include <stdio.h>
/*
unsigned char* send(const unsigned char b[], int bytes) {
printf("%#hhx %#hhx %d\n", b[0], b[1], bytes);
}
int main() {
send((const unsigned char[]){ 0x45, 0x56 }, 2);
}
*/
typedef const unsigned char send_array_t[];
unsigned char* send(send_array_t b, int bytes) {
printf("%#hhx %#hhx %d\n", b[0], b[1], bytes);
}
int main() {
send((send_array_t){ 0x45, 0x56 }, 2);
}
0x45 0x56 2
I will test this later today. It's seems to be as close as possible to what I'm asking. I assume I could also include stuff like String arguments, possibly bu using %s... Which means I can use that solution in more cases than originally anticipated.
Thank you.
westfw:
If send() is under your control, perhaps polymorphism is something you should look into:
Overloading is not polymorphism.
One of the key features of class inheritance is that a pointer to a derived class is type-compatible with a pointer to its base class. Polymorphism is the art of taking advantage of this simple but powerful and versatile feature.
Zefugi:
I assume I could also include stuff like String arguments, possibly bu using %s... Which means I can use that solution in more cases than originally anticipated.
Starting to regret switching from asm to c++ ![]()