This commit is contained in:
Robin Dietzel 2023-01-05 16:32:42 +01:00
parent 13fdacfcec
commit 1441fc49b4
5 changed files with 100 additions and 39 deletions

View File

@ -87,6 +87,7 @@ int main(void) {
InitSequence initializer(display); InitSequence initializer(display);
initializer.runInitSequence(); initializer.runInitSequence();
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET);
using namespace floatpump::menu; using namespace floatpump::menu;
Menu mainmenu(display); Menu mainmenu(display);
@ -112,8 +113,7 @@ int main(void) {
while (1) { while (1) {
mainmenu.updateMenu();
mainmenu.displayMenu();
if(rot_button) { if(rot_button) {
rot_button = false; rot_button = false;
mainmenu.keypress(); mainmenu.keypress();

View File

@ -89,6 +89,7 @@ void HardFault_Handler(void)
/* USER CODE END HardFault_IRQn 0 */ /* USER CODE END HardFault_IRQn 0 */
while (1) while (1)
{ {
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
/* USER CODE BEGIN W1_HardFault_IRQn 0 */ /* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */ /* USER CODE END W1_HardFault_IRQn 0 */
} }

View File

@ -6,6 +6,7 @@
#define FLOATPUMP_MENU_H #define FLOATPUMP_MENU_H
#include <vector> #include <vector>
#include <typeinfo>
#include "Menu_Entry.h" #include "Menu_Entry.h"
#include "LCD_I2C_Driver.h" #include "LCD_I2C_Driver.h"
@ -22,65 +23,91 @@ namespace floatpump {
void addEntry(Menu_Entry entry) { void addEntry(Menu_Entry entry) {
m_entries.push_back(entry); m_entries.push_back(entry);
} }
void updateMenu() {
int page = m_current_index / 4;
int pageindex = m_current_index % 4;
void displayMenu() { for (int i = 0; i < 4; i++) {
int page = m_first_index / 4; m_driver.LCDSetCursor(0, i);
int pageindex = m_first_index % 4;
for(int i = 0; i < 4; i++) { if (pageindex == i) {
m_driver.LCDSetCursor(0,i); m_driver.LCDSendChar(LCD_I2C_Driver::SpecialChars::RightArrow);
if(pageindex == i) {
m_driver.LCDSendChar(LCD_I2C_Driver::SpecialChars::RightArrow);
} else {
m_driver.LCDSendCString(" ");
}
m_driver.LCDSetCursor(1,i);
int entry_index = (page * 4) + i;
if( m_entries.size() > entry_index ) {
std::string dspstring = m_entries[entry_index].printLine();
if(dspstring.length() > 19) {
m_driver.LCDSendCString("-------------------");
} else { } else {
dspstring.append((19 - dspstring.length()), ' '); m_driver.LCDSendCString(" ");
m_driver.LCDSendCString(const_cast<char *>(dspstring.c_str())); }
m_driver.LCDSetCursor(1, i);
int entry_index = (page * 4) + i;
//Display submenus first and then entries
if (entry_index < m_submenus.size()) {
std::string dspstring = "submenu";
m_driver.LCDSendCString("submenu");
//TODO: display submenu contentsnames
//Display entries
} else if (entry_index < (m_entries.size() + m_submenus.size())) {
std::string dspstring = m_entries[entry_index - m_submenus.size()].printLine();
if (dspstring.length() > 19) {
m_driver.LCDSendCString("-------------------");
} else {
dspstring.append((19 - dspstring.length()), ' ');
m_driver.LCDSendCString(const_cast<char *>(dspstring.c_str()));
}
} else { //Show separator at end of menu
//TODO: make this look better
m_driver.LCDSendCString("-");
} }
} else {
m_driver.LCDSendCString("-------------------");
} }
}
} }
void keypress() { void keypress() {
if(m_first_index < m_entries.size()) { //enter submenu
m_entries[m_first_index].action_press(); if (m_current_index < m_submenus.size()) {
//forward press to entry
} else if (m_current_index < (m_entries.size() + m_submenus.size())) {
m_entries[m_current_index - m_submenus.size()].action_press();
} }
} }
void increase() { void increase() {
if(m_entries[m_first_index].isEntered()) { //always increase
m_entries[m_first_index].action_increase(); if (m_current_index < m_submenus.size()) {
} else if(m_first_index < m_entries.size() - 1 && !m_entries[m_first_index].isEntered()) { m_current_index++;
m_first_index++; //increase when not in entry entered state
} else if (m_current_index < (m_submenus.size() + m_entries.size())) {
if (m_entries[m_current_index - m_submenus.size()].isEntered()) {
m_entries[m_current_index - m_submenus.size()].action_increase();
} else if (m_current_index < (m_submenus.size() + m_entries.size() - 1)) {
m_current_index++;
}
} }
} }
void decrease() { void decrease() {
if(m_entries[m_first_index].isEntered()) { if (m_current_index > m_submenus.size()) {
m_entries[m_first_index].action_decrease(); if (m_entries[m_current_index - m_submenus.size()].isEntered()) {
} else if(m_first_index > 0) { m_entries[m_current_index - m_submenus.size()].action_decrease();
m_first_index--; } else {
m_current_index--;
}
} else if (m_current_index > 0) {
m_current_index--;
} }
} }
void addSubmenu(Menu *submenu) {
submenu->m_parent = this;
m_submenus.push_back(submenu);
}
private: private:
LCD_I2C_Driver &m_driver; LCD_I2C_Driver &m_driver;
std::vector<Menu_Entry> m_entries; std::vector<Menu_Entry> m_entries;
std::vector<Menu *> m_submenus;
int m_first_index = 0; Menu *m_parent = nullptr;
int m_current_index = 0;
}; };
} // floatpump } // floatpump

View File

@ -0,0 +1,23 @@
//
// Created by robtor on 05.01.23.
//
#ifndef FLOATPUMP_MENU_CONTROLLER_H
#define FLOATPUMP_MENU_CONTROLLER_H
#include "Menu.h"
namespace floatpump {
namespace menu {
class Menu_Controller {
private:
};
} // floatpump
} // menu
#endif //FLOATPUMP_MENU_CONTROLLER_H

View File

@ -0,0 +1,10 @@
//
// Created by robtor on 05.01.23.
//
#include "Menu_Controller.h"
namespace floatpump {
namespace menu {
} // floatpump
} // menu