mirror of https://github.com/FOME-Tech/fome-fw.git
auto-sync
This commit is contained in:
parent
02942f2f68
commit
4d00c33847
|
@ -29,6 +29,18 @@ void MenuTree::init(MenuItem *first, int linesCount) {
|
||||||
topVisible = first;
|
topVisible = first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuTree::enterSubMenu(void) {
|
||||||
|
if (current->firstChild != NULL) {
|
||||||
|
current = topVisible = current->firstChild;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuTree::back(void) {
|
||||||
|
if (current->parent == root)
|
||||||
|
return; // we are on the top level already
|
||||||
|
current = topVisible = current->parent->topOfTheList;
|
||||||
|
}
|
||||||
|
|
||||||
void MenuTree::nextItem(void) {
|
void MenuTree::nextItem(void) {
|
||||||
if (current->next == NULL) {
|
if (current->next == NULL) {
|
||||||
// todo: go to first element
|
// todo: go to first element
|
||||||
|
@ -42,6 +54,9 @@ void MenuTree::nextItem(void) {
|
||||||
MenuItem::MenuItem(MenuItem * parent, const char *text) {
|
MenuItem::MenuItem(MenuItem * parent, const char *text) {
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
this->text = text;
|
this->text = text;
|
||||||
|
firstChild = NULL;
|
||||||
|
lastChild = NULL;
|
||||||
|
next = NULL;
|
||||||
lcdLine = LL_STRING;
|
lcdLine = LL_STRING;
|
||||||
|
|
||||||
// root element has NULL parent
|
// root element has NULL parent
|
||||||
|
@ -49,14 +64,13 @@ MenuItem::MenuItem(MenuItem * parent, const char *text) {
|
||||||
if (parent->firstChild == NULL) {
|
if (parent->firstChild == NULL) {
|
||||||
parent->firstChild = this;
|
parent->firstChild = this;
|
||||||
index = 0;
|
index = 0;
|
||||||
|
topOfTheList = this;
|
||||||
}
|
}
|
||||||
if (parent->lastChild != NULL) {
|
if (parent->lastChild != NULL) {
|
||||||
index = parent->lastChild->index + 1;
|
index = parent->lastChild->index + 1;
|
||||||
|
topOfTheList = parent->lastChild->topOfTheList;
|
||||||
parent->lastChild->next = this;
|
parent->lastChild->next = this;
|
||||||
}
|
}
|
||||||
parent->lastChild = this;
|
parent->lastChild = this;
|
||||||
} else {
|
|
||||||
firstChild = NULL;
|
|
||||||
lastChild = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ public:
|
||||||
int index;
|
int index;
|
||||||
// that's upper level menu item
|
// that's upper level menu item
|
||||||
MenuItem *parent;
|
MenuItem *parent;
|
||||||
|
MenuItem *topOfTheList;
|
||||||
MenuItem *firstChild;
|
MenuItem *firstChild;
|
||||||
MenuItem *lastChild;
|
MenuItem *lastChild;
|
||||||
MenuItem *next;
|
MenuItem *next;
|
||||||
|
@ -34,6 +35,8 @@ class MenuTree {
|
||||||
public:
|
public:
|
||||||
MenuTree(MenuItem *root);
|
MenuTree(MenuItem *root);
|
||||||
void nextItem(void);
|
void nextItem(void);
|
||||||
|
void back(void);
|
||||||
|
void enterSubMenu(void);
|
||||||
void init(MenuItem *first, int linesCount);
|
void init(MenuItem *first, int linesCount);
|
||||||
MenuItem *root;
|
MenuItem *root;
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,8 @@ int main(void) {
|
||||||
|
|
||||||
testIdleController();
|
testIdleController();
|
||||||
|
|
||||||
|
testMenuTree();
|
||||||
|
|
||||||
// resizeMap();
|
// resizeMap();
|
||||||
printf("Success 20150101\r\n");
|
printf("Success 20150101\r\n");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "nmea.h"
|
#include "nmea.h"
|
||||||
#include "efilib2.h"
|
#include "efilib2.h"
|
||||||
|
#include "lcd_menu_tree.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include "fl_stack.h"
|
#include "fl_stack.h"
|
||||||
#include "io_pins.h"
|
#include "io_pins.h"
|
||||||
|
@ -354,3 +355,58 @@ void testMisc(void) {
|
||||||
assertEquals(true, strEqual("spa3", getPinName(SPARKOUT_3_OUTPUT)));
|
assertEquals(true, strEqual("spa3", getPinName(SPARKOUT_3_OUTPUT)));
|
||||||
assertEquals(SPARKOUT_12_OUTPUT, getPinByName("spa12"));
|
assertEquals(SPARKOUT_12_OUTPUT, getPinByName("spa12"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testMenuTree(void) {
|
||||||
|
print("******************************************* testMenuTree\r\n");
|
||||||
|
|
||||||
|
MenuItem ROOT(NULL, NULL);
|
||||||
|
|
||||||
|
MenuTree tree(&ROOT);
|
||||||
|
|
||||||
|
MenuItem miTopLevel1(tree.root, "top level 1");
|
||||||
|
MenuItem miTopLevel2(tree.root, "top level 2");
|
||||||
|
MenuItem miTopLevel3(tree.root, "top level 3");
|
||||||
|
MenuItem miTopLevel4(tree.root, "top level 4");
|
||||||
|
MenuItem miTopLevel5(tree.root, "top level 5");
|
||||||
|
|
||||||
|
MenuItem miSubMenu1_1(&miTopLevel1, "sub menu 1 1");
|
||||||
|
MenuItem miSubMenu1_2(&miTopLevel1, "sub menu 1 2");
|
||||||
|
|
||||||
|
MenuItem miSubMenu5_1(&miTopLevel5, "sub menu 5 1");
|
||||||
|
MenuItem miSubMenu5_2(&miTopLevel5, "sub menu 5 2");
|
||||||
|
|
||||||
|
assertEquals(0, miTopLevel1.index);
|
||||||
|
assertEquals(1, miTopLevel2.index);
|
||||||
|
assertEquals(4, miTopLevel5.index);
|
||||||
|
|
||||||
|
tree.init(&miTopLevel1, 3);
|
||||||
|
|
||||||
|
tree.nextItem();
|
||||||
|
assertTrue(tree.topVisible == &miTopLevel1);
|
||||||
|
assertTrue(tree.current == &miTopLevel2);
|
||||||
|
|
||||||
|
tree.back();
|
||||||
|
assertTrue(tree.current == &miTopLevel2); // no 'back' since we are on the top level already
|
||||||
|
|
||||||
|
tree.nextItem();
|
||||||
|
assertTrue(tree.topVisible == &miTopLevel1);
|
||||||
|
assertTrue(tree.current == &miTopLevel3);
|
||||||
|
|
||||||
|
tree.nextItem();
|
||||||
|
assertTrue(tree.topVisible == &miTopLevel2);
|
||||||
|
assertTrue(tree.current == &miTopLevel4);
|
||||||
|
|
||||||
|
tree.enterSubMenu();
|
||||||
|
assertTrueM("still same", tree.current == &miTopLevel4); // no children in this one
|
||||||
|
|
||||||
|
tree.nextItem();
|
||||||
|
assertTrue(tree.topVisible == &miTopLevel3);
|
||||||
|
assertTrue(tree.current == &miTopLevel5);
|
||||||
|
|
||||||
|
tree.enterSubMenu();
|
||||||
|
assertTrue(tree.current == &miSubMenu5_1);
|
||||||
|
|
||||||
|
tree.back();
|
||||||
|
assertTrue(tree.current == &miTopLevel1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ void testConsoleLogic(void);
|
||||||
void testGpsParser(void);
|
void testGpsParser(void);
|
||||||
void testFLStack(void);
|
void testFLStack(void);
|
||||||
void testMisc(void);
|
void testMisc(void);
|
||||||
|
void testMenuTree(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue