added pid settings to menu
This commit is contained in:
+37
-21
@@ -14,11 +14,7 @@ Menu::Menu() {
|
||||
this->it = this->entrys.begin();
|
||||
}
|
||||
|
||||
void Menu::setParentMenu(Menu* menu) {
|
||||
this->parentMenu = menu;
|
||||
}
|
||||
|
||||
void Menu::addEntry(MenuEntry* entry) {
|
||||
void Menu::addEntry(MenuAction* entry) {
|
||||
this->entrys.push_back(entry);
|
||||
|
||||
// TODO: Same shit here. Why I get the first element after an increment.
|
||||
@@ -31,8 +27,8 @@ void Menu::addEntry(MenuEntry* entry) {
|
||||
|
||||
void Menu::printMenu() {
|
||||
Serial.println("\n\n");
|
||||
for (std::list<MenuEntry*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
|
||||
MenuEntry* selectedEntry = *(iter);
|
||||
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
|
||||
MenuAction* selectedEntry = *(iter);
|
||||
if (this->it == iter)
|
||||
Serial.print(" ");
|
||||
Serial.println(selectedEntry->getName());
|
||||
@@ -40,15 +36,15 @@ void Menu::printMenu() {
|
||||
this->inSubmenu = false;
|
||||
}
|
||||
|
||||
void Menu::nextEntry() {
|
||||
void Menu::down() {
|
||||
if (this->inSubmenu) {
|
||||
MenuEntry* selectedEntry = *(this->it);
|
||||
selectedEntry->getMenu()->nextEntry();
|
||||
MenuAction* selectedEntry = *(this->it);
|
||||
selectedEntry->getMenu()->down();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Why I need the fucking next two lines? here and in the next function
|
||||
std::list<MenuEntry*>::iterator iter = this->it;
|
||||
std::list<MenuAction*>::iterator iter = this->it;
|
||||
iter++;
|
||||
if (iter != this->entrys.end())
|
||||
this->it++;
|
||||
@@ -57,13 +53,13 @@ void Menu::nextEntry() {
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void Menu::prevEntry() {
|
||||
void Menu::up() {
|
||||
if (this->inSubmenu) {
|
||||
MenuEntry* selectedEntry = *(this->it);
|
||||
selectedEntry->getMenu()->prevEntry();
|
||||
MenuAction* selectedEntry = *(this->it);
|
||||
selectedEntry->getMenu()->up();
|
||||
return;
|
||||
}
|
||||
std::list<MenuEntry*>::iterator iter = this->entrys.end();
|
||||
std::list<MenuAction*>::iterator iter = this->entrys.end();
|
||||
iter--;
|
||||
if (this->it != this->entrys.begin()) {
|
||||
Serial.println("--");
|
||||
@@ -76,12 +72,12 @@ void Menu::prevEntry() {
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void Menu::enterEntry() {
|
||||
void Menu::right() {
|
||||
// TODO: find out why i cannot call runAction() directly from the iterator
|
||||
MenuEntry* selectedEntry = *(this->it);
|
||||
MenuAction* selectedEntry = *(this->it);
|
||||
|
||||
if (this->inSubmenu) {
|
||||
selectedEntry->getMenu()->enterEntry();
|
||||
selectedEntry->getMenu()->right();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,13 +88,33 @@ void Menu::enterEntry() {
|
||||
selectedEntry->runAction();
|
||||
}
|
||||
|
||||
void Menu::enterParentMenu() {
|
||||
void Menu::left() {
|
||||
if (this->inSubmenu) {
|
||||
MenuEntry* selectedEntry = *(this->it);
|
||||
selectedEntry->getMenu()->enterParentMenu();
|
||||
MenuAction* selectedEntry = *(this->it);
|
||||
selectedEntry->getMenu()->left();
|
||||
return;
|
||||
}
|
||||
|
||||
if (parentMenu)
|
||||
this->parentMenu->printMenu();
|
||||
}
|
||||
|
||||
void Menu::yes() {
|
||||
if (this->inSubmenu) {
|
||||
MenuAction* selectedEntry = *(this->it);
|
||||
selectedEntry->getMenu()->yes();
|
||||
return;
|
||||
}
|
||||
|
||||
this->right();
|
||||
}
|
||||
|
||||
void Menu::no() {
|
||||
if (this->inSubmenu) {
|
||||
MenuAction* selectedEntry = *(this->it);
|
||||
selectedEntry->getMenu()->no();
|
||||
return;
|
||||
}
|
||||
|
||||
this->left();
|
||||
}
|
||||
+13
-14
@@ -17,30 +17,29 @@
|
||||
// have to be deleted after display installation
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "menuEntry.h"
|
||||
#include "menuAction.h"
|
||||
#include "menuControl.h"
|
||||
|
||||
class MenuEntry;
|
||||
class Menu {
|
||||
class MenuAction;
|
||||
class Menu : public MenuControl {
|
||||
public:
|
||||
Menu();
|
||||
|
||||
void setParentMenu(Menu* menu);
|
||||
|
||||
void addEntry(MenuEntry* entry);
|
||||
void addEntry(MenuAction* entry);
|
||||
void printMenu();
|
||||
|
||||
void nextEntry();
|
||||
void prevEntry();
|
||||
void enterEntry();
|
||||
void enterParentMenu();
|
||||
void down();
|
||||
void up();
|
||||
void right();
|
||||
void left();
|
||||
void yes();
|
||||
void no();
|
||||
|
||||
private:
|
||||
bool inSubmenu = false;
|
||||
|
||||
Menu* parentMenu;
|
||||
|
||||
std::list<MenuEntry*> entrys;
|
||||
std::list<MenuEntry*>::iterator it;
|
||||
std::list<MenuAction*> entrys;
|
||||
std::list<MenuAction*>::iterator it;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -8,28 +8,28 @@
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "menuEntry.h"
|
||||
#include "menuAction.h"
|
||||
|
||||
MenuEntry::MenuEntry(const char* name, void (*function) (), void (*callback) ()) {
|
||||
MenuAction::MenuAction(const char* name, void (*function) (), void (*callback) ()) {
|
||||
this->name = name;
|
||||
this->function = function;
|
||||
this->callback = callback;
|
||||
}
|
||||
|
||||
MenuEntry::MenuEntry(const char* name, void (*function) ()) {
|
||||
MenuAction::MenuAction(const char* name, void (*function) ()) {
|
||||
this->name = name;
|
||||
this->function = function;
|
||||
this->callback = nullptr;
|
||||
}
|
||||
|
||||
MenuEntry::MenuEntry(const char* name, Menu* menu) {
|
||||
MenuAction::MenuAction(const char* name, MenuControl* menu) {
|
||||
this->name = name;
|
||||
this->menu = menu;
|
||||
this->isMenu = true;
|
||||
this->callback = nullptr;
|
||||
}
|
||||
|
||||
void MenuEntry::runAction() {
|
||||
void MenuAction::runAction() {
|
||||
if (isMenu)
|
||||
this->menu->printMenu();
|
||||
else
|
||||
@@ -39,15 +39,15 @@ void MenuEntry::runAction() {
|
||||
this->callback();
|
||||
}
|
||||
|
||||
const char* MenuEntry::getName() {
|
||||
const char* MenuAction::getName() {
|
||||
return this->name;
|
||||
}
|
||||
|
||||
bool MenuEntry::getIsMenu() {
|
||||
bool MenuAction::getIsMenu() {
|
||||
return this->isMenu;
|
||||
}
|
||||
|
||||
Menu* MenuEntry::getMenu() {
|
||||
MenuControl* MenuAction::getMenu() {
|
||||
if (isMenu)
|
||||
return this->menu;
|
||||
else
|
||||
@@ -13,17 +13,17 @@
|
||||
|
||||
#include "menu.h"
|
||||
|
||||
class Menu;
|
||||
class MenuEntry {
|
||||
class MenuControl;
|
||||
class MenuAction {
|
||||
public:
|
||||
MenuEntry(const char* name, void (*function) (), void (*callback) ());
|
||||
MenuEntry(const char* name, void (*function) ());
|
||||
MenuEntry(const char* name, Menu* menu);
|
||||
MenuAction(const char* name, void (*function) (), void (*callback) ());
|
||||
MenuAction(const char* name, void (*function) ());
|
||||
MenuAction(const char* name, MenuControl* menu);
|
||||
void runAction();
|
||||
|
||||
const char* getName();
|
||||
bool getIsMenu();
|
||||
Menu* getMenu();
|
||||
MenuControl* getMenu();
|
||||
|
||||
private:
|
||||
const char* name;
|
||||
@@ -32,7 +32,7 @@ class MenuEntry {
|
||||
void (*callback) () = nullptr;
|
||||
|
||||
bool isMenu = false;
|
||||
Menu *menu;
|
||||
MenuControl* menu;
|
||||
};
|
||||
|
||||
#endif // MENU_ENTRY_H
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @file menuControl.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-19
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MENU_CONTROLL_H
|
||||
#define MENU_CONTROLL_H
|
||||
|
||||
class MenuControl {
|
||||
public:
|
||||
|
||||
// Ínputs from the Gamepad
|
||||
virtual void down();
|
||||
virtual void up();
|
||||
virtual void right();
|
||||
virtual void left();
|
||||
virtual void yes();
|
||||
virtual void no();
|
||||
|
||||
virtual void printMenu();
|
||||
void setParentMenu(MenuControl* menu) {this->parentMenu = menu;}
|
||||
|
||||
protected:
|
||||
MenuControl* parentMenu = nullptr;
|
||||
};
|
||||
|
||||
#endif // MENU_CONTROLL_H
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @file pidSettings.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-19
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "menuPidSettings.h"
|
||||
|
||||
MenuPidSettings::MenuPidSettings(PID* pid) {
|
||||
this->pid = pid;
|
||||
this->values[0] = (uint8_t) pid->GetKp();
|
||||
this->values[1] = (uint8_t) pid->GetKi();
|
||||
this->values[2] = (uint8_t) pid->GetKd();
|
||||
}
|
||||
|
||||
void MenuPidSettings::down() {
|
||||
if (values[curPos] > 0)
|
||||
values[curPos]--;
|
||||
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void MenuPidSettings::up() {
|
||||
if (values[curPos] < UINT8_MAX)
|
||||
values[curPos]++;
|
||||
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void MenuPidSettings::right() {
|
||||
if (curPos < NUM_VAL - 1)
|
||||
curPos++;
|
||||
else
|
||||
curPos = 0;
|
||||
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void MenuPidSettings::left() {
|
||||
if (curPos > 0)
|
||||
curPos--;
|
||||
else
|
||||
curPos = NUM_VAL - 1;
|
||||
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void MenuPidSettings::no() {
|
||||
if (parentMenu)
|
||||
this->parentMenu->printMenu();
|
||||
}
|
||||
|
||||
void MenuPidSettings::yes() {
|
||||
this->pid->SetTunings(this->values[0], this->values[1], this->values[2]);
|
||||
if (parentMenu)
|
||||
this->parentMenu->printMenu();
|
||||
}
|
||||
|
||||
void MenuPidSettings::printMenu() {
|
||||
Serial.println(" P I D ");
|
||||
char pos[16];
|
||||
switch (this->curPos) {
|
||||
case 0:
|
||||
sprintf(pos, "_%d.3_ %d.3 %d.3 ", this->values[0], this->values[1], this->values[2]);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
sprintf(pos, " %d.3 _%d.3_ %d.3 ", this->values[0], this->values[1], this->values[2]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
sprintf(pos, " %d.3 %d.3 _%d.3_", this->values[0], this->values[1], this->values[2]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Serial.println(pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file pidSettings.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-01-19
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PID_SETTINGS_H
|
||||
#define PID_SETTINGS_H
|
||||
|
||||
#include "menuControl.h"
|
||||
#include <PID_v1.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// TODO: delete after installtion of display
|
||||
#include <Arduino.h>
|
||||
|
||||
#define NUM_VAL 3
|
||||
|
||||
class MenuPidSettings : public MenuControl {
|
||||
public:
|
||||
MenuPidSettings(PID* pid);
|
||||
|
||||
void down();
|
||||
void up();
|
||||
void right();
|
||||
void left();
|
||||
void no();
|
||||
void yes();
|
||||
|
||||
void printMenu();
|
||||
|
||||
private:
|
||||
PID* pid;
|
||||
uint8_t values[NUM_VAL];
|
||||
uint8_t curPos = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // PID_SETTINGS_H
|
||||
Reference in New Issue
Block a user