FEATURE: New numeric menu type
This commit is contained in:
parent
029f2745d1
commit
c1f7cbc865
@ -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
|
@ -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) {
|
||||
|
@ -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<char *>(dspstring.c_str()));
|
||||
|
||||
if(dspstring.length() > 19) {
|
||||
m_driver.LCDSendCString("-------------------");
|
||||
} else {
|
||||
dspstring.append((19 - dspstring.length()), ' ');
|
||||
m_driver.LCDSendCString(const_cast<char *>(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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
34
Middlewares/floatpump/Inc/Menu_Entry_Type_Numeric.h
Normal file
34
Middlewares/floatpump/Inc/Menu_Entry_Type_Numeric.h
Normal file
@ -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 <string>
|
||||
#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
|
33
Middlewares/floatpump/Src/Menu_Entry_Type_Numeric.cpp
Normal file
33
Middlewares/floatpump/Src/Menu_Entry_Type_Numeric.cpp
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user