Implement 75% off menu
This commit is contained in:
@@ -1,9 +1,2 @@
|
|||||||
Meine Libs von andren Abhängigkeiten lösen
|
Menu hat manchmal speicher leaks :/
|
||||||
- Die loop funmktions mit eigenem Timer oder ohne Timer
|
|
||||||
- Alle config.h und nicht allgemeinen Header entfernen
|
|
||||||
|
|
||||||
Speedometer:
|
|
||||||
- Mitrechnen durchschnittliche aufrufzeit
|
|
||||||
|
|
||||||
Alle loops Nachgucken ob last_millis aktualisiert wird.
|
|
||||||
Mqtt kram auslagern
|
|
||||||
+71
-9
@@ -10,13 +10,47 @@
|
|||||||
*/
|
*/
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
Menu::Menu(MenuEntry* firstEntry) {
|
Menu::Menu() {
|
||||||
entrys.push_back(firstEntry);
|
|
||||||
this->it = this->entrys.begin();
|
this->it = this->entrys.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Menu::setParentMenu(Menu* menu) {
|
||||||
|
this->parentMenu = menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::addEntry(MenuEntry* entry) {
|
||||||
|
this->entrys.push_back(entry);
|
||||||
|
|
||||||
|
// TODO: Same shit here. Why I get the first element after an increment.
|
||||||
|
static uint8_t inc = 0;
|
||||||
|
inc++;
|
||||||
|
if (inc == 2) {
|
||||||
|
this->it = this->entrys.begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::printMenu() {
|
||||||
|
Serial.println("\n\n");
|
||||||
|
for (std::list<MenuEntry*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
|
||||||
|
MenuEntry* selectedEntry = *(iter);
|
||||||
|
if (this->it == iter)
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.println(selectedEntry->getName());
|
||||||
|
}
|
||||||
|
this->inSubmenu = false;
|
||||||
|
}
|
||||||
|
|
||||||
void Menu::nextEntry() {
|
void Menu::nextEntry() {
|
||||||
if (this->it != this->entrys.end())
|
if (this->inSubmenu) {
|
||||||
|
MenuEntry* selectedEntry = *(this->it);
|
||||||
|
selectedEntry->getMenu()->nextEntry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Why I need the fucking next two lines? here and in the next function
|
||||||
|
std::list<MenuEntry*>::iterator iter = this->it;
|
||||||
|
iter++;
|
||||||
|
if (iter != this->entrys.end())
|
||||||
this->it++;
|
this->it++;
|
||||||
else
|
else
|
||||||
this->it = this->entrys.begin();
|
this->it = this->entrys.begin();
|
||||||
@@ -24,19 +58,47 @@ void Menu::nextEntry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Menu::prevEntry() {
|
void Menu::prevEntry() {
|
||||||
if (this->it != this->entrys.begin())
|
if (this->inSubmenu) {
|
||||||
|
MenuEntry* selectedEntry = *(this->it);
|
||||||
|
selectedEntry->getMenu()->prevEntry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::list<MenuEntry*>::iterator iter = this->entrys.end();
|
||||||
|
iter--;
|
||||||
|
if (this->it != this->entrys.begin()) {
|
||||||
|
Serial.println("--");
|
||||||
this->it--;
|
this->it--;
|
||||||
else
|
}
|
||||||
this->it = this->entrys.end();
|
else {
|
||||||
|
Serial.println("begin");
|
||||||
|
this->it = iter;
|
||||||
|
}
|
||||||
this->printMenu();
|
this->printMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::enterEntry() {
|
void Menu::enterEntry() {
|
||||||
// TODO: find out why i cannot call run directly from the iterator
|
// TODO: find out why i cannot call runAction() directly from the iterator
|
||||||
MenuEntry* selectedEntry = *(this->it);
|
MenuEntry* selectedEntry = *(this->it);
|
||||||
selectedEntry->run();
|
|
||||||
|
if (this->inSubmenu) {
|
||||||
|
selectedEntry->getMenu()->enterEntry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedEntry->getIsMenu()) {
|
||||||
|
this->inSubmenu = true;
|
||||||
|
selectedEntry->getMenu()->setParentMenu(this);
|
||||||
|
}
|
||||||
|
selectedEntry->runAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::enterParentMenu() {
|
void Menu::enterParentMenu() {
|
||||||
this->parentMenu->printMenu();
|
if (this->inSubmenu) {
|
||||||
|
MenuEntry* selectedEntry = *(this->it);
|
||||||
|
selectedEntry->getMenu()->enterParentMenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentMenu)
|
||||||
|
this->parentMenu->printMenu();
|
||||||
}
|
}
|
||||||
+10
-2
@@ -13,12 +13,20 @@
|
|||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
// Only for print in consol
|
||||||
|
// have to be deleted after display installation
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "menuEntry.h"
|
#include "menuEntry.h"
|
||||||
|
|
||||||
|
class MenuEntry;
|
||||||
class Menu {
|
class Menu {
|
||||||
public:
|
public:
|
||||||
Menu(MenuEntry* firstEntry);
|
Menu();
|
||||||
|
|
||||||
|
void setParentMenu(Menu* menu);
|
||||||
|
|
||||||
|
void addEntry(MenuEntry* entry);
|
||||||
void printMenu();
|
void printMenu();
|
||||||
|
|
||||||
void nextEntry();
|
void nextEntry();
|
||||||
@@ -27,7 +35,7 @@ class Menu {
|
|||||||
void enterParentMenu();
|
void enterParentMenu();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool active = false;
|
bool inSubmenu = false;
|
||||||
|
|
||||||
Menu* parentMenu;
|
Menu* parentMenu;
|
||||||
|
|
||||||
|
|||||||
+19
-2
@@ -19,20 +19,37 @@ MenuEntry::MenuEntry(const char* name, void (*function) (), void (*callback) ())
|
|||||||
MenuEntry::MenuEntry(const char* name, void (*function) ()) {
|
MenuEntry::MenuEntry(const char* name, void (*function) ()) {
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->function = function;
|
this->function = function;
|
||||||
|
this->callback = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuEntry::MenuEntry(const char* name, Menu* menu) {
|
MenuEntry::MenuEntry(const char* name, Menu* menu) {
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->menu = menu;
|
this->menu = menu;
|
||||||
this->isMenu = true;
|
this->isMenu = true;
|
||||||
|
this->callback = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuEntry::run() {
|
void MenuEntry::runAction() {
|
||||||
if (isMenu)
|
if (isMenu)
|
||||||
{}
|
this->menu->printMenu();
|
||||||
else
|
else
|
||||||
this->function();
|
this->function();
|
||||||
|
|
||||||
if (this->callback)
|
if (this->callback)
|
||||||
this->callback();
|
this->callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* MenuEntry::getName() {
|
||||||
|
return this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MenuEntry::getIsMenu() {
|
||||||
|
return this->isMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu* MenuEntry::getMenu() {
|
||||||
|
if (isMenu)
|
||||||
|
return this->menu;
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
@@ -13,20 +13,25 @@
|
|||||||
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
|
class Menu;
|
||||||
class MenuEntry {
|
class MenuEntry {
|
||||||
public:
|
public:
|
||||||
MenuEntry(const char* name, void (*function) (), void (*callback) ());
|
MenuEntry(const char* name, void (*function) (), void (*callback) ());
|
||||||
MenuEntry(const char* name, void (*function) ());
|
MenuEntry(const char* name, void (*function) ());
|
||||||
MenuEntry(const char* name, Menu* menu);
|
MenuEntry(const char* name, Menu* menu);
|
||||||
void run();
|
void runAction();
|
||||||
|
|
||||||
|
const char* getName();
|
||||||
|
bool getIsMenu();
|
||||||
|
Menu* getMenu();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* name;
|
const char* name;
|
||||||
|
|
||||||
void (*function) ();
|
void (*function) ();
|
||||||
void (*callback) ();
|
void (*callback) () = nullptr;
|
||||||
|
|
||||||
bool isMenu;
|
bool isMenu = false;
|
||||||
Menu *menu;
|
Menu *menu;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+88
-3
@@ -8,13 +8,23 @@
|
|||||||
#include "driveModi/driveManager.h"
|
#include "driveModi/driveManager.h"
|
||||||
#include "moveControl.h"
|
#include "moveControl.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
#include "menu.h"
|
||||||
|
#include "menuEntry.h"
|
||||||
|
|
||||||
|
// Platzhalter, muss irgendwann weg
|
||||||
|
void dummy(){Serial.println("Dummy in Action");}
|
||||||
|
|
||||||
void callbackControllerAction();
|
void callbackControllerAction();
|
||||||
void callbackControllerConnect();
|
void callbackControllerConnect();
|
||||||
void controllerPrintBattery();
|
void controllerPrintBattery();
|
||||||
|
void p_f();
|
||||||
|
void i_f();
|
||||||
|
void d_f();
|
||||||
|
int32_t displaySelectValue();
|
||||||
|
|
||||||
MoveControl moveController;
|
MoveControl moveController;
|
||||||
DriveManager driveManager(&moveController);
|
DriveManager driveManager(&moveController);
|
||||||
|
Menu* main_m;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
@@ -29,9 +39,40 @@ void setup() {
|
|||||||
Serial.println("\nReady to connect a PS3 Controller... \n");
|
Serial.println("\nReady to connect a PS3 Controller... \n");
|
||||||
Ps3.begin();
|
Ps3.begin();
|
||||||
|
|
||||||
driveManager.changeModus(Modi::ManualControl);
|
|
||||||
|
|
||||||
Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
|
Serial1.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX);
|
||||||
|
|
||||||
|
// Create Menu
|
||||||
|
main_m = new Menu();
|
||||||
|
Menu* mode_m = new Menu();
|
||||||
|
Menu* pid_m = new Menu();
|
||||||
|
|
||||||
|
// Entry for the main menu
|
||||||
|
MenuEntry* mode_e = new MenuEntry("Mode", mode_m);
|
||||||
|
MenuEntry* gps_e = new MenuEntry("GPS", dummy);
|
||||||
|
MenuEntry* pid_e = new MenuEntry("PID", pid_m);
|
||||||
|
main_m->addEntry(mode_e);
|
||||||
|
main_m->addEntry(gps_e);
|
||||||
|
main_m->addEntry(pid_e);
|
||||||
|
|
||||||
|
// Entry for the mode Menu
|
||||||
|
MenuEntry* autopilot_e = new MenuEntry("Autopilot", dummy);
|
||||||
|
MenuEntry* captureRoute_e = new MenuEntry("Capture Route", dummy);
|
||||||
|
MenuEntry* consolControl_e = new MenuEntry("Consol Control", dummy);
|
||||||
|
MenuEntry* manualControl_e = new MenuEntry("Manual Control", dummy);
|
||||||
|
MenuEntry* testMode_e = new MenuEntry("Test Mode", dummy);
|
||||||
|
mode_m->addEntry(autopilot_e);
|
||||||
|
mode_m->addEntry(captureRoute_e);
|
||||||
|
mode_m->addEntry(consolControl_e);
|
||||||
|
mode_m->addEntry(manualControl_e);
|
||||||
|
mode_m->addEntry(testMode_e);
|
||||||
|
|
||||||
|
// Entry for the PID Menu
|
||||||
|
MenuEntry* p_e = new MenuEntry("P", dummy);
|
||||||
|
MenuEntry* i_e = new MenuEntry("I", dummy);
|
||||||
|
MenuEntry* d_e = new MenuEntry("D", dummy);
|
||||||
|
pid_m->addEntry(p_e);
|
||||||
|
pid_m->addEntry(i_e);
|
||||||
|
pid_m->addEntry(d_e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -41,8 +82,36 @@ void loop() {
|
|||||||
Serial.print(Serial1.read());
|
Serial.print(Serial1.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
void callbackControllerAction() {
|
bool isDelayReached() {
|
||||||
|
static uint32_t lastMillis = 0;
|
||||||
|
const uint16_t delay = 200;
|
||||||
|
bool res = false;
|
||||||
|
|
||||||
|
if (millis() - lastMillis > delay) {
|
||||||
|
res = true;
|
||||||
|
lastMillis = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void callbackControllerAction() {
|
||||||
|
// Menu controlling
|
||||||
|
|
||||||
|
if (isDelayReached()) {
|
||||||
|
if (Ps3.data.button.up)
|
||||||
|
main_m->prevEntry();
|
||||||
|
else if (Ps3.data.button.down)
|
||||||
|
main_m->nextEntry();
|
||||||
|
else if (Ps3.data.button.left)
|
||||||
|
main_m->enterParentMenu();
|
||||||
|
else if (Ps3.data.button.right)
|
||||||
|
main_m->enterEntry();
|
||||||
|
else if (Ps3.data.button.select)
|
||||||
|
main_m->printMenu();
|
||||||
|
else if (Ps3.data.button.ps)
|
||||||
|
controllerPrintBattery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void callbackControllerConnect() {
|
void callbackControllerConnect() {
|
||||||
@@ -64,3 +133,19 @@ void controllerPrintBattery() {
|
|||||||
else if( controller_battery == ps3_status_battery_shutdown ) Serial.println("SHUTDOWN");
|
else if( controller_battery == ps3_status_battery_shutdown ) Serial.println("SHUTDOWN");
|
||||||
else Serial.println("UNDEFINED");
|
else Serial.println("UNDEFINED");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p_f() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void i_f() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void d_f() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t displaySelectValue() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user