FEATURE: Added more menu entry types
This commit is contained in:
parent
c1f7cbc865
commit
5c60217399
@ -9,6 +9,10 @@
|
||||
#include "Menu.h"
|
||||
#include "Menu_Entry_Type_Checkable.h"
|
||||
#include "Menu_Entry_Type_Numeric.h"
|
||||
#include "Menu_Entry_Type_Percent.h"
|
||||
#include "Menu_Entry_Type_Time.h"
|
||||
#include "Config_Entry_Type.h"
|
||||
|
||||
|
||||
#define SLAVE_ADDRESS_LCD 0x4e
|
||||
|
||||
@ -83,20 +87,19 @@ int main(void) {
|
||||
using namespace floatpump::menu;
|
||||
|
||||
Menu mainmenu(display);
|
||||
Menu_Entry entry(new Menu_Entry_Type_Checkable(), "test");
|
||||
Menu_Entry entry2(new Menu_Entry_Type_Checkable(), "test2bl");
|
||||
Menu_Entry_Type_Checkable entry1bool(true);
|
||||
Menu_Entry entry(&entry1bool, "test");
|
||||
|
||||
Menu_Entry_Type_Percent entry1perc(15);
|
||||
Menu_Entry entry2(&entry1perc, "Prozent");
|
||||
|
||||
Menu_Entry_Type_Time entry1time(23,44,12);
|
||||
Menu_Entry entry3(&entry1time, "Uhrzeit");
|
||||
|
||||
mainmenu.addEntry(entry);
|
||||
mainmenu.addEntry(entry2);
|
||||
mainmenu.addEntry(entry);
|
||||
mainmenu.addEntry(entry2);
|
||||
|
||||
Menu_Entry entry3(new Menu_Entry_Type_Checkable(), "Page2");
|
||||
mainmenu.addEntry(entry3);
|
||||
mainmenu.addEntry(entry3);
|
||||
mainmenu.addEntry(entry3);
|
||||
|
||||
Menu_Entry integer(new Menu_Entry_Type_Numeric, "Val");
|
||||
mainmenu.addEntry(integer);
|
||||
|
||||
static int old_pos = 0;
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define FLOATPUMP_MENU_ENTRY_H
|
||||
|
||||
#include <Menu_Entry_Type_Delegate.h>
|
||||
#include <Config_Entry_Delegate.h>
|
||||
|
||||
|
||||
namespace floatpump {
|
||||
@ -13,7 +14,8 @@ namespace floatpump {
|
||||
|
||||
class Menu_Entry {
|
||||
public:
|
||||
Menu_Entry_Type_Delegate *m_type;
|
||||
menu::Menu_Entry_Type_Delegate *m_type;
|
||||
config::Config_Entry_Delegate *m_config;
|
||||
|
||||
Menu_Entry(Menu_Entry_Type_Delegate *type, std::string name) : m_type(type), m_name(name) {};
|
||||
|
||||
|
@ -6,12 +6,16 @@
|
||||
#define FLOATPUMP_MENU_ENTRY_TYPE_CHECKABLE_H
|
||||
|
||||
#include "Menu_Entry_Type_Delegate.h"
|
||||
#include "Config_Entry_Type.h"
|
||||
|
||||
namespace floatpump {
|
||||
namespace menu {
|
||||
|
||||
class Menu_Entry_Type_Checkable : public Menu_Entry_Type_Delegate {
|
||||
public:
|
||||
Menu_Entry_Type_Checkable(bool mState)
|
||||
: m_state(mState) {}
|
||||
|
||||
std::string toString() override {
|
||||
return std::string((m_state) ? "ON " : "OFF");
|
||||
}
|
||||
@ -34,7 +38,6 @@ namespace floatpump {
|
||||
|
||||
private:
|
||||
bool m_state = false;
|
||||
|
||||
};
|
||||
|
||||
} // floatpump
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define FLOATPUMP_MENU_ENTRY_DELEGATE_H
|
||||
|
||||
#include <string>
|
||||
#include "Config_Entry_Delegate.h"
|
||||
|
||||
namespace floatpump {
|
||||
namespace menu {
|
||||
|
39
Middlewares/floatpump/Inc/Menu_Entry_Type_Percent.h
Normal file
39
Middlewares/floatpump/Inc/Menu_Entry_Type_Percent.h
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// Created by robtor on 05.01.23.
|
||||
//
|
||||
|
||||
#ifndef FLOATPUMP_MENU_ENTRY_TYPE_PERCENT_H
|
||||
#define FLOATPUMP_MENU_ENTRY_TYPE_PERCENT_H
|
||||
|
||||
#include "Menu_Entry_Type_Delegate.h"
|
||||
|
||||
namespace floatpump {
|
||||
namespace menu {
|
||||
|
||||
|
||||
class Menu_Entry_Type_Percent : public floatpump::menu::Menu_Entry_Type_Delegate{
|
||||
public:
|
||||
Menu_Entry_Type_Percent(uint8_t val) : m_value(val) {};
|
||||
|
||||
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:
|
||||
uint8_t m_value = 0;
|
||||
bool m_entered = false;
|
||||
};
|
||||
|
||||
} //menu
|
||||
} //floatpump
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //FLOATPUMP_MENU_ENTRY_TYPE_PERCENT_H
|
61
Middlewares/floatpump/Inc/Menu_Entry_Type_Time.cpp
Normal file
61
Middlewares/floatpump/Inc/Menu_Entry_Type_Time.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
//
|
||||
// Created by robtor on 05.01.23.
|
||||
//
|
||||
|
||||
#include "Menu_Entry_Type_Time.h"
|
||||
|
||||
namespace floatpump {
|
||||
namespace menu {
|
||||
std::string Menu_Entry_Type_Time::toString() {
|
||||
switch(m_entered) {
|
||||
case 0:
|
||||
return std::string(" " + std::to_string(m_hour) + ":" + std::to_string(m_minute) + ":" + std::to_string(m_second)); break;
|
||||
case 1:
|
||||
return std::string("#" + std::to_string(m_hour) + ":" + std::to_string(m_minute) + ":" + std::to_string(m_second)); break;
|
||||
case 2:
|
||||
return std::string(" " + std::to_string(m_hour) + "#" + std::to_string(m_minute) + ":" + std::to_string(m_second)); break;
|
||||
case 3:
|
||||
return std::string(" " + std::to_string(m_hour) + ":" + std::to_string(m_minute) + "#" + std::to_string(m_second)); break;
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void Menu_Entry_Type_Time::u_press() {
|
||||
if(m_entered < 3) {
|
||||
m_entered++;
|
||||
} else {
|
||||
m_entered = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Menu_Entry_Type_Time::u_increase(uint16_t steps) {
|
||||
switch(m_entered) {
|
||||
case 1:
|
||||
(m_hour < 23) ? m_hour++ : m_hour = 0; break;
|
||||
case 2:
|
||||
(m_minute < 59) ? m_minute++ : m_minute = 0; break;
|
||||
case 3:
|
||||
(m_second < 59) ? m_second++ : m_second = 0; break;
|
||||
}
|
||||
}
|
||||
|
||||
void Menu_Entry_Type_Time::u_decrease(uint16_t steps) {
|
||||
switch(m_entered) {
|
||||
case 1:
|
||||
(m_hour > 0) ? m_hour-- : m_hour = 23; break;
|
||||
case 2:
|
||||
(m_minute > 0) ? m_minute-- : m_minute = 59; break;
|
||||
case 3:
|
||||
(m_second > 0) ? m_second-- : m_second = 59; break;
|
||||
}
|
||||
}
|
||||
|
||||
bool Menu_Entry_Type_Time::isEntered() {
|
||||
if(m_entered > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // floatpump
|
||||
} // menu
|
35
Middlewares/floatpump/Inc/Menu_Entry_Type_Time.h
Normal file
35
Middlewares/floatpump/Inc/Menu_Entry_Type_Time.h
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// Created by robtor on 05.01.23.
|
||||
//
|
||||
|
||||
#ifndef FLOATPUMP_MENU_ENTRY_TYPE_TIME_H
|
||||
#define FLOATPUMP_MENU_ENTRY_TYPE_TIME_H
|
||||
|
||||
#include "Menu_Entry_Type_Delegate.h"
|
||||
|
||||
namespace floatpump {
|
||||
namespace menu {
|
||||
|
||||
class Menu_Entry_Type_Time : public Menu_Entry_Type_Delegate{
|
||||
public:
|
||||
Menu_Entry_Type_Time(uint8_t hour, uint8_t minute, uint8_t second) : m_hour(hour), m_minute(minute), m_second(second) {};
|
||||
|
||||
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:
|
||||
uint8_t m_entered = 0;
|
||||
uint8_t m_hour, m_minute, m_second;
|
||||
};
|
||||
|
||||
} // floatpump
|
||||
} // menu
|
||||
|
||||
#endif //FLOATPUMP_MENU_ENTRY_TYPE_TIME_H
|
@ -7,5 +7,6 @@
|
||||
namespace floatpump {
|
||||
namespace menu {
|
||||
|
||||
|
||||
} // floatpump
|
||||
} // menu
|
@ -8,9 +8,9 @@ namespace floatpump {
|
||||
namespace menu {
|
||||
std::string Menu_Entry_Type_Numeric::toString() {
|
||||
if(m_entered) {
|
||||
return "#" + std::to_string(m_value);
|
||||
return "# " + std::to_string(m_value);
|
||||
} else {
|
||||
return " " + std::to_string(m_value);
|
||||
return " " + std::to_string(m_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
32
Middlewares/floatpump/Src/Menu_Entry_Type_Percent.cpp
Normal file
32
Middlewares/floatpump/Src/Menu_Entry_Type_Percent.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by robtor on 05.01.23.
|
||||
//
|
||||
|
||||
#include "Menu_Entry_Type_Percent.h"
|
||||
|
||||
std::string floatpump::menu::Menu_Entry_Type_Percent::toString() {
|
||||
if(m_entered) {
|
||||
return std::string("# " + std::to_string(m_value) + "%");
|
||||
} else {
|
||||
return std::string(" " + std::to_string(m_value) + "%");
|
||||
}
|
||||
}
|
||||
|
||||
void floatpump::menu::Menu_Entry_Type_Percent::u_press() {
|
||||
m_entered = !m_entered;
|
||||
}
|
||||
|
||||
void floatpump::menu::Menu_Entry_Type_Percent::u_increase(uint16_t steps) {
|
||||
if(m_value < 100)
|
||||
m_value++;
|
||||
}
|
||||
|
||||
void floatpump::menu::Menu_Entry_Type_Percent::u_decrease(uint16_t steps) {
|
||||
if(m_value > 0) {
|
||||
m_value--;
|
||||
}
|
||||
}
|
||||
|
||||
bool floatpump::menu::Menu_Entry_Type_Percent::isEntered() {
|
||||
return m_entered;
|
||||
}
|
Loading…
Reference in New Issue
Block a user