diff --git a/Core/Inc/git_rev.h b/Core/Inc/git_rev.h index 1d45030..c088182 100644 --- a/Core/Inc/git_rev.h +++ b/Core/Inc/git_rev.h @@ -7,6 +7,6 @@ // Auto generated header file containing the last git revision -#define GIT_HASH "29dd3f3" +#define GIT_HASH "27146c9" #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H \ No newline at end of file diff --git a/Core/Src/main.cpp b/Core/Src/main.cpp index c3f7e02..2800793 100644 --- a/Core/Src/main.cpp +++ b/Core/Src/main.cpp @@ -8,6 +8,7 @@ #include "button_input.h" #include "Menu.h" #include "Menu_Entry_Type_Checkable.h" +#include "Menu_Entry_Type_Numeric.h" #define SLAVE_ADDRESS_LCD 0x4e @@ -94,6 +95,9 @@ int main(void) { mainmenu.addEntry(entry3); mainmenu.addEntry(entry3); + Menu_Entry integer(new Menu_Entry_Type_Numeric, "Val"); + mainmenu.addEntry(integer); + static int old_pos = 0; while (1) { diff --git a/Middlewares/floatpump/Inc/Menu.h b/Middlewares/floatpump/Inc/Menu.h index 2729310..20a5dee 100644 --- a/Middlewares/floatpump/Inc/Menu.h +++ b/Middlewares/floatpump/Inc/Menu.h @@ -38,11 +38,15 @@ namespace floatpump { m_driver.LCDSetCursor(1,i); int entry_index = (page * 4) + i; - if( m_entries.size() > entry_index) { - + if( m_entries.size() > entry_index ) { std::string dspstring = m_entries[entry_index].printLine(); - dspstring.append((19 - dspstring.length()), ' '); - m_driver.LCDSendCString(const_cast(dspstring.c_str())); + + if(dspstring.length() > 19) { + m_driver.LCDSendCString("-------------------"); + } else { + dspstring.append((19 - dspstring.length()), ' '); + m_driver.LCDSendCString(const_cast(dspstring.c_str())); + } } else { m_driver.LCDSendCString("-------------------"); } @@ -57,13 +61,20 @@ namespace floatpump { } void increase() { - if(m_first_index < m_entries.size() - 1) + 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++; + } } void decrease() { - if(m_first_index > 0) + if(m_entries[m_first_index].isEntered()) { + m_entries[m_first_index].action_decrease(); + } else if(m_first_index > 0) { m_first_index--; + } + } private: LCD_I2C_Driver &m_driver; diff --git a/Middlewares/floatpump/Inc/Menu_Entry.h b/Middlewares/floatpump/Inc/Menu_Entry.h index 3cd3bb3..54becf0 100644 --- a/Middlewares/floatpump/Inc/Menu_Entry.h +++ b/Middlewares/floatpump/Inc/Menu_Entry.h @@ -18,7 +18,10 @@ namespace floatpump { Menu_Entry(Menu_Entry_Type_Delegate *type, std::string name) : m_type(type), m_name(name) {}; std::string printLine() { - return m_name + ": " + m_type->toString(); + int spaces = 19 - (m_name.length() + m_type->toString().length()); + std::string spacer; + spacer.append(spaces, ' '); + return m_name + spacer + m_type->toString(); } void action_press() { @@ -33,6 +36,10 @@ namespace floatpump { m_type->u_decrease(1); } + bool isEntered() { + return m_type->isEntered(); + } + private: std::string m_name; }; diff --git a/Middlewares/floatpump/Inc/Menu_Entry_Type_Checkable.h b/Middlewares/floatpump/Inc/Menu_Entry_Type_Checkable.h index 2ed2edd..40248b2 100644 --- a/Middlewares/floatpump/Inc/Menu_Entry_Type_Checkable.h +++ b/Middlewares/floatpump/Inc/Menu_Entry_Type_Checkable.h @@ -13,7 +13,7 @@ namespace floatpump { class Menu_Entry_Type_Checkable : public Menu_Entry_Type_Delegate { public: std::string toString() override { - return std::string((m_state) ? "True" : "false"); + return std::string((m_state) ? "ON " : "OFF"); } void u_press() override { @@ -28,7 +28,9 @@ namespace floatpump { } - bool enterable = false; + bool isEntered() override { + return false; + } private: bool m_state = false; diff --git a/Middlewares/floatpump/Inc/Menu_Entry_Type_Delegate.h b/Middlewares/floatpump/Inc/Menu_Entry_Type_Delegate.h index 65cad4c..e1ae09f 100644 --- a/Middlewares/floatpump/Inc/Menu_Entry_Type_Delegate.h +++ b/Middlewares/floatpump/Inc/Menu_Entry_Type_Delegate.h @@ -17,8 +17,7 @@ namespace floatpump { virtual void u_press() = 0; virtual void u_increase(uint16_t steps = 1) = 0; virtual void u_decrease(uint16_t steps = 1) = 0; - - bool enterable = true; + virtual bool isEntered() = 0; }; } // floatpump diff --git a/Middlewares/floatpump/Inc/Menu_Entry_Type_Numeric.h b/Middlewares/floatpump/Inc/Menu_Entry_Type_Numeric.h new file mode 100644 index 0000000..7576e2e --- /dev/null +++ b/Middlewares/floatpump/Inc/Menu_Entry_Type_Numeric.h @@ -0,0 +1,34 @@ +// +// Created by robtor on 04.01.23. +// + +#ifndef FLOATPUMP_MENU_ENTRY_TYPE_NUMERIC_H +#define FLOATPUMP_MENU_ENTRY_TYPE_NUMERIC_H + +#include +#include "Menu_Entry_Type_Delegate.h" + +namespace floatpump { + namespace menu { + + class Menu_Entry_Type_Numeric : public Menu_Entry_Type_Delegate { + public: + std::string toString() override; + + void u_press() override; + + void u_increase(uint16_t steps) override; + + void u_decrease(uint16_t steps) override; + + bool isEntered() override; + + private: + uint16_t m_value = 0; + bool m_entered = false; + }; + + } // floatpump +} // menu + +#endif //FLOATPUMP_MENU_ENTRY_TYPE_NUMERIC_H diff --git a/Middlewares/floatpump/Src/Menu_Entry_Type_Numeric.cpp b/Middlewares/floatpump/Src/Menu_Entry_Type_Numeric.cpp new file mode 100644 index 0000000..d4c53e8 --- /dev/null +++ b/Middlewares/floatpump/Src/Menu_Entry_Type_Numeric.cpp @@ -0,0 +1,33 @@ +// +// Created by robtor on 04.01.23. +// + +#include "Menu_Entry_Type_Numeric.h" + +namespace floatpump { + namespace menu { + std::string Menu_Entry_Type_Numeric::toString() { + if(m_entered) { + return "#" + std::to_string(m_value); + } else { + return " " + std::to_string(m_value); + } + } + + void Menu_Entry_Type_Numeric::u_press() { + m_entered = !m_entered; + } + + void Menu_Entry_Type_Numeric::u_increase(uint16_t steps) { + m_value++; + } + + void Menu_Entry_Type_Numeric::u_decrease(uint16_t steps) { + m_value--; + } + + bool Menu_Entry_Type_Numeric::isEntered() { + return m_entered; + } + } // floatpump +} // menu \ No newline at end of file