Looking for some help with code for scrolling up / down through buffer
Don M
Posts: 1,652
Let's say I have a 2048 byte buffer that I dump messages into. Each message would end with an "03" (ETX) byte. Now I want to display them. I know I can do a repeat loop with indexing and an if statement to catch the 03 and stop going forward through. That part I understand.
But let's say I was scrolling forward and now I want to go backward a message at a time. How would that be done?
Any sample code or examples out there?
But let's say I was scrolling forward and now I want to go backward a message at a time. How would that be done?
Any sample code or examples out there?
Comments
There is some sample data in the DAT section. Each line in the DAT section has a start character STX (02), the message, CR / LF and an ETX character (03). The data message in the DAT section is stored into a buffer called "message". I made 2 other buffers that store the charcter index position of each STX and ETX. These are marked in the code.
What I'm trying to simulate is a "window" of 25 lines. By pressing the "f" key you will load the first 25 lines of the message. Each subsequent press of the "f" key will move the lines up one row and then display the newest line on the bottom. If you uncomment one line in the code (marked in the code as to which line) then it will only print 1 line at a time with each press of the "f" key until it gets to the 25th line then it will start at the top and work its way down moving the lines up 1 at a time.
What I'm having a problem understanding is how do I go backward i.e. scroll down until I get to the beginning of the buffer?
Also- is there an easier way to do what I have done here? I feel as though I made this harder than it needs to be but it has helped me learn this so far...
Appreciate any and all help / comments.
The way I would do it is to have a method that just displays 25 lines (or less if the end is hit) starting at a specific index. Then when f or p is pressed increment or decrement the index and call the display method. However that would require rewriting chunks of the above. I came up with an easier to implement solution using your existing code. I just copied the block for the "f" keypress and added a "p" keypress section the only difference between that and the "f" section is that the index is decremented by 2 first. That seemed to do what you want.
Start your 2048 character buffer with ETX as the first character and have each message terminated with an ETX.
Have a single method that scans up or down depending on the parameter it is called with.
Something like: " scan(curr_pos, 1)" to scan forward and "scan(curr_pos, -1) to go backwards.