From 28e06e13ea4c34ab6b8ed21b95c38fe148df43fe Mon Sep 17 00:00:00 2001 From: maxchen32 Date: Sun, 14 Jan 2024 11:11:26 +0800 Subject: [PATCH] scrollUp done; use a pointer instead of the iterator --- src/list/Readme.md | 2 +- testline.c | 60 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/list/Readme.md b/src/list/Readme.md index 4eeab16..6207880 100644 --- a/src/list/Readme.md +++ b/src/list/Readme.md @@ -182,4 +182,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/testline.c b/testline.c index 69d342b..23c145a 100644 --- a/testline.c +++ b/testline.c @@ -13,7 +13,7 @@ typedef struct InfoState { char* info; list_node_t *pos1, *pos2, *pos3; list_t *wrap; - list_iterator_t *it; + //list_iterator_t *it; //list_node_t *node; } InfoState; @@ -101,22 +101,26 @@ void initInfoState(InfoState* st, char* text) { //st->pos3 = text; st->wrap = list_new(); st->wrap = aux_gen_wrap_list(st->wrap, st->info); - st->it = list_iterator_new(st->wrap, LIST_HEAD); - st->pos1 = list_iterator_next(st->it); + //st->it = list_iterator_new(st->wrap, LIST_HEAD); + //st->pos1 = list_iterator_next(st->it); + st->pos1 = list_at(st->wrap, 0); st->pos2 = st->pos3 = NULL; } InfoRet initInfoScreen(InfoState* st, char* text) { initInfoState(st, text); printf("%d\n", st->wrap->len); + if (st->pos1 == NULL) { + return IR_UNKNOWN; + } //lcd.setCursor(0, 0); - if ((st->pos2 = list_iterator_next(st->it))) { + if ((st->pos2 = st->pos1->next)) { //printf("hello\n"); //printf("%d\n", st->pos2->val); int tmp = lcd_print_between(st->info, 0, (int)st->pos2->val); //printf("%d\n", tmp); //printf("%d\n", st->wrap->len); - if ((st->pos3 = list_iterator_next(st->it))) { + if ((st->pos3 = st->pos2->next)) { printf("\n"); //printf("%d\n", st->pos2->val); //printf("%d\n", st->pos3->val); @@ -145,7 +149,7 @@ InfoRet scrollDown(InfoState* st) { return IR_UNSUCCESS; } int tmp = lcd_print_between(st->info, (int)st->pos1->val, (int)st->pos2->val); - if ((st->pos3 = list_iterator_next(st->it))) { + if ((st->pos3 = st->pos3->next)) { printf("\n"); int tmp = lcd_print_between(st->info, (int)st->pos2->val, (int)st->pos3->val); } else { @@ -156,7 +160,34 @@ InfoRet scrollDown(InfoState* st) { } InfoRet scrollUp(InfoState* st) { + if (st->pos2) { + st->pos3 = st->pos2; + } else { + return IR_UNKNOWN; + } + if (st->pos1 == NULL) { + return IR_UNKNOWN; + } else if ((int)st->pos1->val == -1) { + return IR_UNSUCCESS; + } else { + st->pos2 = st->pos1; + } + + if ((st->pos1 = st->pos1->prev)) { + int tmp = lcd_print_between(st->info, (int)st->pos1->val, (int)st->pos2->val); + } else { + return IR_UNKNOWN; + } + printf("\n"); + int tmp = lcd_print_between(st->info, (int)st->pos2->val, (int)st->pos3->val); + return IR_NORMAL; +} + +void destoryInfoState(InfoState* st) { + st->pos1 = st->pos2 = st->pos3 = NULL; + list_destroy(st->wrap); + st->info = NULL; } /* @@ -233,10 +264,13 @@ int main() { wrap = aux_gen_wrap_list(wrap, cinfo); list_node_t *node; - list_iterator_t *it = list_iterator_new(wrap, LIST_HEAD); + //list_iterator_t *it = list_iterator_new(wrap, LIST_HEAD); - node = list_iterator_next(it); + //node = list_iterator_next(it); + node = list_at(wrap, 0); printf("node val: %d\n", node->val); + printf("node prev: %p\n", node->prev); + /* node = list_iterator_next(it); printf("node val: %d\n", node->val); node = list_iterator_prev(it); @@ -245,6 +279,7 @@ int main() { printf("node val: %d\n", node->val); node = list_iterator_prev(it); printf("node val: %d\n", node->val); + */ InfoRet ret_code; InfoState st; @@ -255,6 +290,12 @@ int main() { printf("\n%d\n", ret_code); } + for (int i = 0; i < 10; ++i) { + printf("\n"); + ret_code = scrollUp(&st); + printf("\n%d\n", ret_code); + } + /* while ((node = list_iterator_next(it))) { printf("%d\n", (unsigned int)(node->val)); @@ -302,7 +343,8 @@ int main() { printf("%d\n%s\n", pos-cinfo, line); } */ - list_iterator_destroy(it); + //list_iterator_destroy(it); list_destroy(wrap); + destoryInfoState(&st); return 0; } \ No newline at end of file