DreherTankController/src/display/display.h

179 lines
5.9 KiB
C++

#ifndef MY_DISPLAY_H_INCLUDED
#define MY_DISPLAY_H_INCLUDED
#include <U8g2lib.h>
#include "../common.h"
//#define _STD_FONT u8g2_font_ncenB10_te
//#define _FIRS_LINE_Y 11
//#define _STD_LINEHEIGHT 12
#define _STD_FONT u8g2_font_fub11_tf
#define _FIRS_LINE_Y 12
#define _STD_LINEHEIGHT 13
#define _SEL_FONT u8g2_font_6x10_tf
#define _FIRS_LINE_Y 12
#define _STD_LINEHEIGHT 13
// Mit der Schriftart u8g2_font_ncenB10_te stellt \xb0 das °-Zeichen dar
#define _BEGIN_FAST_STEPS_DELAY 500
#define _BEGIN_BIG_STEPS_DELAY 3000
#define _FAST_STEP_MS 100
#define _BIG_STEP 10
#define _BACK_TO_HOME_SCREEN 1
#define _MENU_MAIN 1
#define _MENU_SYSTEM 10
#define _MENU_SETTINGS_MODBUS 11
#define _MENU_TEMPERATURE 12
#define _MENU_PRESSURE 13
#define _SELECTION_TEMPERATURE_ENABLED 100
#define _SELECTION_TEMPERATURE_SETPOINT 101
#define _SELECTION_TEMPERATURE_HYSTERESIS 102
#define _SELECTION_PRESSURE_ENABLE_INCREASE 110
#define _SELECTION_PRESSURE_ENABLE_DECREASE 111
#define _SELECTION_PRESSURE_SETPOINT 115
#define _SELECTION_PRESSURE_HYSTERESIS 116
#define _SELECTION_MODBUS_BAUDRATE 150
#define _SELECTION_MODBUS_ADDRESS 151
#define _SELECTION_MODBUS_DELAY 152
#define _SELECTION_P_SENSOR 200
#define _SELECTION_RESET 255
#define _VERIFY_ADMIN 253
#define _ADMIN_CODE 42
#define _POS_TEMPERATURE_MENU 0
#define _POS_TEMPERATURE_ENABLED 0
#define _POS_TEMPERATURE_SETPOINT 1
#define _POS_TEMPERATURE_HYSTERESIS 2
#define _POS_PRESSURE_MENU 1
#define _POS_PRESSURE_ENABLE_INCREASE 0
#define _POS_PRESSURE_ENABLE_DECREASE 1
#define _POS_PRESSURE_SETPOINT 2
#define _POS_PRESSURE_HYSTERESIS 3
#define _POS_SYSTEM 2
#define _POS_MODBUS_MENU 0
#define _POS_MODBUS_ADDRESS 0
#define _POS_MODBUS_BAUDRATE 1
#define _POS_MODBUS_DELAY 2
#define _POS_P_SENSOR_SELECTION 1
#define _POS_P_SMC_1_5V_0_5BAR 0
#define _POS_P_GEMS_0_5V_0_6BAR 1
#define _POS_RESET 3
#define _POS_BAUDRATE_300 0
#define _POS_BAUDRATE_1200 1
#define _POS_BAUDRATE_2400 2
#define _POS_BAUDRATE_4800 3
#define _POS_BAUDRATE_9600 4
#define _POS_BAUDRATE_19200 5
#define _POS_BAUDRATE_38400 6
#define _POS_BAUDRATE_57600 7
#define _POS_BAUDRATE_115200 8
extern "C" uint8_t my_UserInterfaceMessage(u8g2_t *u8g2, const char *title1, const char *title2, const char *title3, const char *buttons, uint8_t cursor);
extern "C" uint8_t my_UserInterfaceSelectionList(u8g2_t *u8g2, const char *title, uint8_t start_pos, const char *sl);
// extern "C" void my_UserInterfaceInputValue(u8g2_t *u8g2, const char *title, const char *pre, uint8_t value, uint8_t digits, const char *post);
extern "C" void my_UserInterfaceInputValueString(u8g2_t *u8g2, const char *title, const char *sub, const char *text);
// extern "C" uint8_t my_read_pin_state(u8x8_t *u8x8);
class Display : public U8G2_ST7920_128X64_F_HW_SPI
{
private:
enum MenuLevel : int8_t {
MenuLevel_1, MenuLevel_2, MenuLevel_3
};
enum Precision : int8_t {
Precision_0, Precision_1, Precision_2
};
uint8_t _bgLightAnalog = 255; // Wie stark die Displaybeleuchtung ist
bool _bgLightBool = true; // Ob die Displaybeleuchtung an ist (egal wie stark)
char _text[50]; // Buffer für Texte
char _text2[30]; // Buffer für Texte
uint8_t _selection; // welche Auswahl gerendert werden soll
uint8_t _cursor; // aktuelle Auswahl-Cursorposition
uint8_t _prevCursor; // letzte Auswahl-Cursorposition
uint8_t _cur_l1; // Cursorposition in Ebene 1
uint8_t _cur_l2; // Cursorposition in Ebene 2
uint8_t _cur_l3; // Cursorposition in Ebene 3
uint8_t _menu_depth; // Im wievielten Untermenü man gerade ist
uint8_t _selCnt; // Anzahl der Auswahlmöglichkeiten
bool _inputValueActive; // Ob gerade ein Wert eingegeben wird
int _val; // Der eingegebene Wert
int _valMin; // Der kleinstmögliche einzugebende Wert
int _valMax; // Der größtmögliche einzugebende Wert
unsigned long _prevT;
bool _enableBigSteps; // Ob große Schritte (_BIG_STEP) durchgeführt werden sollen
unsigned long _checkFastStepTime; // letzte Zeit, zu der ein entsprechender Button NICHT gedrückt war
unsigned long _lastFastStep; // letzte Zeit, zu der ein schneller Schritt ausgeführt wurde
int _stepSize; // Um wieviel der entsprechende Wert auf einmal geändert werden soll
parameters *_params;
values *_vals;
modbusParameters *_modbusParams;
PSensor *_pSensor;
valveStates *_vStates;
void _saveCursorPosForLevel(MenuLevel);
uint8_t _restoreCursor();
void _baudrateCursorPos();
void _setModbusBaudrate();
void _select();
void _select(const uint8_t, const bool restoreCursor=false);
uint8_t _event();
void _nextEvent();
void _prevEvent();
void _home();
void _inputValue(const uint8_t stepSize, const char *title, const char *text=nullptr, const char *val=nullptr);
void _restrictInputValue(int min, int max, Precision p=Precision_0);
public:
const uint8_t btnNext;
const uint8_t btnPrev;
const uint8_t btnSelect;
const uint8_t btnCancel;
const uint8_t bgLed;
Display(uint8_t cs,
uint8_t btnNext,
uint8_t btnPrev,
uint8_t btnSelect,
uint8_t btnCancel,
uint8_t bgLED,
parameters*,
values*,
modbusParameters*,
PSensor*,
valveStates*);
void init();
void process();
void modbusProblem();
void oneWireDevicesDetected(uint8_t count);
void tooMuchOneWireDevicesDetected(uint8_t actual, uint8_t max);
void noOneWireDevicesDetected();
void greeting();
void bgLight(uint8_t);
void bgLight(int val) {bgLight((uint8_t) val);};
void bgLight(bool);
bool bgLightIncrease(uint8_t step=1);
bool bgLightDecrease(uint8_t step=1);
uint8_t bgLightAnalog();
bool bgLightState();
void (*reset)() = 0;
/* Callback-Funktionen */
void(*setParams)(parameters&);
void(*setModbusParams)(const modbusParameters&);
void(*setPSensor)(const PSensor&);
};
#endif // MY_DISPLAY_H_INCLUDED