diff --git a/src/list/src/list.h b/src/list/src/list.h index c0075dd..b3214ad 100644 --- a/src/list/src/list.h +++ b/src/list/src/list.h @@ -120,6 +120,9 @@ list_iterator_new_from_node(list_node_t *node, list_direction_t direction); list_node_t * list_iterator_next(list_iterator_t *self); +list_node_t * +list_iterator_prev(list_iterator_t *self); + void list_iterator_destroy(list_iterator_t *self); diff --git a/src/list/src/list_iterator.c b/src/list/src/list_iterator.c index f1363b2..c0edbc6 100644 --- a/src/list/src/list_iterator.c +++ b/src/list/src/list_iterator.c @@ -51,6 +51,22 @@ list_iterator_next(list_iterator_t *self) { return curr; } +/* + * Return the previous list_node_t or NULL when no more + * nodes remain in the list. + */ + +list_node_t * +list_iterator_prev(list_iterator_t *self) { + list_node_t *curr = self->next; + if (curr) { + self->next = self->direction == LIST_HEAD + ? curr->prev + : curr->next; + } + return curr; +} + /* * Free the list iterator. */ diff --git a/testline.c b/testline.c index f952b28..69d342b 100644 --- a/testline.c +++ b/testline.c @@ -2,6 +2,12 @@ #include #include "src/list/src/list.h" +typedef enum InfoRet { + IR_UNKNOWN = -1, + IR_NORMAL = 0, + IR_UNSUCCESS +} InfoRet; + typedef struct InfoState { char* info; @@ -100,10 +106,9 @@ void initInfoState(InfoState* st, char* text) { st->pos2 = st->pos3 = NULL; } -int initInfoScreen(InfoState* st, char* text) { +InfoRet initInfoScreen(InfoState* st, char* text) { initInfoState(st, text); printf("%d\n", st->wrap->len); - int retn = 0; //lcd.setCursor(0, 0); if ((st->pos2 = list_iterator_next(st->it))) { //printf("hello\n"); @@ -123,12 +128,34 @@ int initInfoScreen(InfoState* st, char* text) { lcd_blank_line(); } } else { - retn = 1; + return IR_UNKNOWN; } - return retn; + return IR_NORMAL; } -int scrollDown(InfoState* st) { +InfoRet scrollDown(InfoState* st) { + if (st->pos2) { + st->pos1 = st->pos2; + } else { + return IR_UNKNOWN; + } + if (st->pos3) { + st->pos2 = st->pos3; + } else { + 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))) { + printf("\n"); + int tmp = lcd_print_between(st->info, (int)st->pos2->val, (int)st->pos3->val); + } else { + printf("\n"); + lcd_blank_line(); + } + return IR_NORMAL; +} + +InfoRet scrollUp(InfoState* st) { } @@ -208,8 +235,25 @@ int main() { list_node_t *node; list_iterator_t *it = list_iterator_new(wrap, LIST_HEAD); + node = list_iterator_next(it); + printf("node val: %d\n", node->val); + node = list_iterator_next(it); + printf("node val: %d\n", node->val); + node = list_iterator_prev(it); + printf("node val: %d\n", node->val); + node = list_iterator_prev(it); + printf("node val: %d\n", node->val); + node = list_iterator_prev(it); + printf("node val: %d\n", node->val); + + InfoRet ret_code; InfoState st; initInfoScreen(&st, cinfo); + for (int i = 0; i < 10; ++i) { + printf("\n"); + ret_code = scrollDown(&st); + printf("\n%d\n", ret_code); + } /* while ((node = list_iterator_next(it))) {