scrollUp done; use a pointer instead of the iterator
This commit is contained in:
parent
6d9a191be1
commit
28e06e13ea
2 changed files with 52 additions and 10 deletions
60
testline.c
60
testline.c
|
@ -13,7 +13,7 @@ typedef struct InfoState {
|
||||||
char* info;
|
char* info;
|
||||||
list_node_t *pos1, *pos2, *pos3;
|
list_node_t *pos1, *pos2, *pos3;
|
||||||
list_t *wrap;
|
list_t *wrap;
|
||||||
list_iterator_t *it;
|
//list_iterator_t *it;
|
||||||
//list_node_t *node;
|
//list_node_t *node;
|
||||||
} InfoState;
|
} InfoState;
|
||||||
|
|
||||||
|
@ -101,22 +101,26 @@ void initInfoState(InfoState* st, char* text) {
|
||||||
//st->pos3 = text;
|
//st->pos3 = text;
|
||||||
st->wrap = list_new();
|
st->wrap = list_new();
|
||||||
st->wrap = aux_gen_wrap_list(st->wrap, st->info);
|
st->wrap = aux_gen_wrap_list(st->wrap, st->info);
|
||||||
st->it = list_iterator_new(st->wrap, LIST_HEAD);
|
//st->it = list_iterator_new(st->wrap, LIST_HEAD);
|
||||||
st->pos1 = list_iterator_next(st->it);
|
//st->pos1 = list_iterator_next(st->it);
|
||||||
|
st->pos1 = list_at(st->wrap, 0);
|
||||||
st->pos2 = st->pos3 = NULL;
|
st->pos2 = st->pos3 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoRet initInfoScreen(InfoState* st, char* text) {
|
InfoRet initInfoScreen(InfoState* st, char* text) {
|
||||||
initInfoState(st, text);
|
initInfoState(st, text);
|
||||||
printf("%d\n", st->wrap->len);
|
printf("%d\n", st->wrap->len);
|
||||||
|
if (st->pos1 == NULL) {
|
||||||
|
return IR_UNKNOWN;
|
||||||
|
}
|
||||||
//lcd.setCursor(0, 0);
|
//lcd.setCursor(0, 0);
|
||||||
if ((st->pos2 = list_iterator_next(st->it))) {
|
if ((st->pos2 = st->pos1->next)) {
|
||||||
//printf("hello\n");
|
//printf("hello\n");
|
||||||
//printf("%d\n", st->pos2->val);
|
//printf("%d\n", st->pos2->val);
|
||||||
int tmp = lcd_print_between(st->info, 0, (int)st->pos2->val);
|
int tmp = lcd_print_between(st->info, 0, (int)st->pos2->val);
|
||||||
//printf("%d\n", tmp);
|
//printf("%d\n", tmp);
|
||||||
//printf("%d\n", st->wrap->len);
|
//printf("%d\n", st->wrap->len);
|
||||||
if ((st->pos3 = list_iterator_next(st->it))) {
|
if ((st->pos3 = st->pos2->next)) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
//printf("%d\n", st->pos2->val);
|
//printf("%d\n", st->pos2->val);
|
||||||
//printf("%d\n", st->pos3->val);
|
//printf("%d\n", st->pos3->val);
|
||||||
|
@ -145,7 +149,7 @@ InfoRet scrollDown(InfoState* st) {
|
||||||
return IR_UNSUCCESS;
|
return IR_UNSUCCESS;
|
||||||
}
|
}
|
||||||
int tmp = lcd_print_between(st->info, (int)st->pos1->val, (int)st->pos2->val);
|
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");
|
printf("\n");
|
||||||
int tmp = lcd_print_between(st->info, (int)st->pos2->val, (int)st->pos3->val);
|
int tmp = lcd_print_between(st->info, (int)st->pos2->val, (int)st->pos3->val);
|
||||||
} else {
|
} else {
|
||||||
|
@ -156,7 +160,34 @@ InfoRet scrollDown(InfoState* st) {
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoRet scrollUp(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);
|
wrap = aux_gen_wrap_list(wrap, cinfo);
|
||||||
|
|
||||||
list_node_t *node;
|
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 val: %d\n", node->val);
|
||||||
|
printf("node prev: %p\n", node->prev);
|
||||||
|
/*
|
||||||
node = list_iterator_next(it);
|
node = list_iterator_next(it);
|
||||||
printf("node val: %d\n", node->val);
|
printf("node val: %d\n", node->val);
|
||||||
node = list_iterator_prev(it);
|
node = list_iterator_prev(it);
|
||||||
|
@ -245,6 +279,7 @@ int main() {
|
||||||
printf("node val: %d\n", node->val);
|
printf("node val: %d\n", node->val);
|
||||||
node = list_iterator_prev(it);
|
node = list_iterator_prev(it);
|
||||||
printf("node val: %d\n", node->val);
|
printf("node val: %d\n", node->val);
|
||||||
|
*/
|
||||||
|
|
||||||
InfoRet ret_code;
|
InfoRet ret_code;
|
||||||
InfoState st;
|
InfoState st;
|
||||||
|
@ -255,6 +290,12 @@ int main() {
|
||||||
printf("\n%d\n", ret_code);
|
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))) {
|
while ((node = list_iterator_next(it))) {
|
||||||
printf("%d\n", (unsigned int)(node->val));
|
printf("%d\n", (unsigned int)(node->val));
|
||||||
|
@ -302,7 +343,8 @@ int main() {
|
||||||
printf("%d\n%s\n", pos-cinfo, line);
|
printf("%d\n%s\n", pos-cinfo, line);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
list_iterator_destroy(it);
|
//list_iterator_destroy(it);
|
||||||
list_destroy(wrap);
|
list_destroy(wrap);
|
||||||
|
destoryInfoState(&st);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in a new issue