diff --git a/watering_system_mini_project/MenuItem.cpp b/watering_system_mini_project/MenuItem.cpp index 7a06a5d..8660490 100644 --- a/watering_system_mini_project/MenuItem.cpp +++ b/watering_system_mini_project/MenuItem.cpp @@ -24,7 +24,7 @@ } String MenuItem::display() { - return MenuItem::name; + return "t " + String(MenuItem::name); } @@ -41,6 +41,7 @@ return String(BranchMenuItem::name) + " ->"; } + IntValueItem::IntValueItem(char const* name, int initial) { IntValueItem::name = name; IntValueItem::value = initial; @@ -54,6 +55,7 @@ return String(IntValueItem::name) + ": " + String(IntValueItem::value); } + BoolValueItem::BoolValueItem(char const* name, bool initial) { BoolValueItem::name = name; BoolValueItem::value = initial; diff --git a/watering_system_mini_project/MenuItem.h b/watering_system_mini_project/MenuItem.h index 11dc8b1..1effc80 100644 --- a/watering_system_mini_project/MenuItem.h +++ b/watering_system_mini_project/MenuItem.h @@ -12,21 +12,16 @@ MenuItem* next; MenuItem* goBack(); MenuItem* goDown(); - MenuItem* goRight(); - String display(); -// void addChild(MenuItem* c) { -// if (!child) child = c; -// c->parent = this; -// } + virtual MenuItem* goRight(); + virtual String display(); }; class BranchMenuItem: public MenuItem { public: - using MenuItem::MenuItem; BranchMenuItem(const char* name, const MenuItem* child); MenuItem* child; - MenuItem* goRight(); - String display(); + MenuItem* goRight() override; + String display() override; }; class IntValueItem: public MenuItem { @@ -41,8 +36,8 @@ public: BoolValueItem(const char* name, const bool initialValue); bool value; - MenuItem* BoolValueItem::goRight(); - String BoolValueItem::display(); + MenuItem* BoolValueItem::goRight() override; + String BoolValueItem::display() override; }; #endif \ No newline at end of file diff --git a/watering_system_mini_project/watering_system_mini_project.ino b/watering_system_mini_project/watering_system_mini_project.ino index f2eb0e1..e539fe7 100644 --- a/watering_system_mini_project/watering_system_mini_project.ino +++ b/watering_system_mini_project/watering_system_mini_project.ino @@ -1,10 +1,10 @@ # include "MenuItem.h" - MenuItem top = MenuItem("Main menu"); - MenuItem* current = ⊤ - MenuItem toggle = BoolValueItem("A switch", false); - MenuItem sub = BranchMenuItem("Sub menu", &toggle); - MenuItem next = IntValueItem("Power", 1); + MenuItem* top = new MenuItem("Main menu"); + MenuItem* current = top; + MenuItem* toggle = new BoolValueItem("A switch", false); + MenuItem* sub = new BranchMenuItem("Sub menu", toggle); + MenuItem* next = new IntValueItem("Power", 1); void displayMenu() { Serial.println("---- MENU ----"); @@ -15,8 +15,9 @@ void setup() { Serial.begin(9600); - top.next = ⊂ - sub.next = ⊤ + top->next = sub; + sub->next = toggle; + toggle->next = top; displayMenu(); }