diff --git a/Core/Src/main.cpp b/Core/Src/main.cpp index a82733f..59c68b3 100644 --- a/Core/Src/main.cpp +++ b/Core/Src/main.cpp @@ -87,6 +87,7 @@ int main(void) { InitSequence initializer(display); initializer.runInitSequence(); + HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET); using namespace floatpump::menu; Menu mainmenu(display); @@ -112,8 +113,7 @@ int main(void) { while (1) { - - mainmenu.displayMenu(); + mainmenu.updateMenu(); if(rot_button) { rot_button = false; mainmenu.keypress(); diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index bccd857..cf96daa 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -89,6 +89,7 @@ void HardFault_Handler(void) /* USER CODE END HardFault_IRQn 0 */ while (1) { + HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); /* USER CODE BEGIN W1_HardFault_IRQn 0 */ /* USER CODE END W1_HardFault_IRQn 0 */ } diff --git a/Middlewares/floatpump/Inc/Menu.h b/Middlewares/floatpump/Inc/Menu.h index 20a5dee..3295578 100644 --- a/Middlewares/floatpump/Inc/Menu.h +++ b/Middlewares/floatpump/Inc/Menu.h @@ -6,6 +6,7 @@ #define FLOATPUMP_MENU_H #include +#include #include "Menu_Entry.h" #include "LCD_I2C_Driver.h" @@ -22,65 +23,91 @@ namespace floatpump { void addEntry(Menu_Entry entry) { m_entries.push_back(entry); } + void updateMenu() { + int page = m_current_index / 4; + int pageindex = m_current_index % 4; - void displayMenu() { - int page = m_first_index / 4; - int pageindex = m_first_index % 4; + for (int i = 0; i < 4; i++) { + m_driver.LCDSetCursor(0, i); - for(int i = 0; i < 4; i++) { - m_driver.LCDSetCursor(0,i); - - 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("-------------------"); + if (pageindex == i) { + m_driver.LCDSendChar(LCD_I2C_Driver::SpecialChars::RightArrow); } else { - dspstring.append((19 - dspstring.length()), ' '); - m_driver.LCDSendCString(const_cast(dspstring.c_str())); + m_driver.LCDSendCString(" "); + } + + 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(dspstring.c_str())); + } + } else { //Show separator at end of menu + //TODO: make this look better + m_driver.LCDSendCString("-"); } - } else { - m_driver.LCDSendCString("-------------------"); } - } } void keypress() { - if(m_first_index < m_entries.size()) { - m_entries[m_first_index].action_press(); + //enter submenu + 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() { - if(m_entries[m_first_index].isEntered()) { - m_entries[m_first_index].action_increase(); - } else if(m_first_index < m_entries.size() - 1 && !m_entries[m_first_index].isEntered()) { - m_first_index++; + //always increase + if (m_current_index < m_submenus.size()) { + m_current_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() { - if(m_entries[m_first_index].isEntered()) { - m_entries[m_first_index].action_decrease(); - } else if(m_first_index > 0) { - m_first_index--; + if (m_current_index > m_submenus.size()) { + if (m_entries[m_current_index - m_submenus.size()].isEntered()) { + m_entries[m_current_index - m_submenus.size()].action_decrease(); + } 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: LCD_I2C_Driver &m_driver; std::vector m_entries; - - int m_first_index = 0; + std::vector m_submenus; + Menu *m_parent = nullptr; + int m_current_index = 0; }; } // floatpump diff --git a/Middlewares/floatpump/Inc/Menu_Controller.h b/Middlewares/floatpump/Inc/Menu_Controller.h new file mode 100644 index 0000000..69b2a1d --- /dev/null +++ b/Middlewares/floatpump/Inc/Menu_Controller.h @@ -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 diff --git a/Middlewares/floatpump/Src/Menu_Controller.cpp b/Middlewares/floatpump/Src/Menu_Controller.cpp new file mode 100644 index 0000000..3ff4f46 --- /dev/null +++ b/Middlewares/floatpump/Src/Menu_Controller.cpp @@ -0,0 +1,10 @@ +// +// Created by robtor on 05.01.23. +// + +#include "Menu_Controller.h" + +namespace floatpump { + namespace menu { + } // floatpump +} // menu \ No newline at end of file