arrays, buffers, ring buffers and pointers...

Status
Not open for further replies.

joey120373

Well-known member
Hello, Ive been trying to learn as much as i can about these things, however im finding it all to easy to get confused.
I am not a programmer, but i can usually cobble something up in arduino that works to some degree.
I have started a new project, a tool for work that will basically be a specialized function generator and meter all in one diagnoistic tool.

One of the things I want it to do is read in a serial data, and display it on a TFT. This part is easy, provided the serial data packet is small enough that it
will fit on the available space of the TFT. I'm going to use somewhat arbitrary numbers here, but if i use a reasonable font size, lest say i can get 15 lines of serial data before i run out of space on the screen.

As it stands, i read each byte as a char:

input_byte = Serial.read();

then add that to a string:

if ( input_byte != '\n' ){
data_string += input_byte ;
}

data_string in this case is an array, so that if i don't get a '\n'
the String gets terminated and printed as is.

the data_string is stored in an array.
so i have 2 arrays :

char input_byte [byts]; // byts = say 32
String received_data_string[strgs]; // str = say 32

I think i understand this correctly, but PLEASE correct me if im wrong,

but when i call the command :

tft.println(received_data_string[0]);

I am calling a pointer? i am saying " print the info at location
[0] in the buffer?

So what i would need to do is, once the buffer is full, copy the data
in received_data_string[0] to received_data_string[1], and
received_data_string[1] --> received_data_string[2]

and so on, then put the newest received_data_string
into [0].

I just now found the memcpy function, and im assuming this is the way to accomplish this?
so:

memcpy(received_data_string[0], received_data_string[1], 32); ?

i have not tried this yet, and as i understand it, the last argument (32) is the number of bytes to copy?

i am thinking this approach would allow me to store and then print the info as needed
but I've read that this is not an efficient way of doing things and that a circular buffer with an offset is better, but i can barely wrap my head around what i have already stated, and i probably have that wrong.

So questions are,

Do I have this even remotely right?

and

Is this an "ok" way to do this or are there faster alternatives?

I am using a teensy4, and am nowhere near running out of room, and its plenty speedy,
my main concern is a smooth and responsive user interface, and thus far that part of the project is working great.

I am using an RA8875 ATM, and have posted on another thread about trying to get the harware scroll feature to work, but im thinking, that even if i do get that to work, i still need to implement a ( rolloing ? ) array or buffer to store the data.

thanks
 
Status
Not open for further replies.
Back
Top