scrollUp done; use a pointer instead of the iterator

This commit is contained in:
maxchen32 2024-01-14 11:11:26 +08:00
parent 6d9a191be1
commit 28e06e13ea
2 changed files with 52 additions and 10 deletions

View File

@ -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.

View File

@ -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;
}