112 lines
2.8 KiB
C++
112 lines
2.8 KiB
C++
#ifndef CUI_H
|
|
#define CUI_H
|
|
|
|
#include "SSD1306.h"
|
|
|
|
#define WIDTH SCREEN_WIDTH
|
|
#define HEIGHT SCREEN_HEIGHT
|
|
#define DISPLAY_PAGE_COUNT (SCREEN_HEIGHT / 8)
|
|
|
|
enum ITEM_MODE {
|
|
MODE_NORMAL,
|
|
MODE_SET,
|
|
MODE_CONFIG,
|
|
};
|
|
|
|
enum MESSAGE_MODE {
|
|
MODE_NONE,
|
|
MODE_NO_WIFI,
|
|
MODE_AC,
|
|
MODE_LOAD
|
|
};
|
|
|
|
typedef struct box_struct {
|
|
int16_t x, y;
|
|
uint16_t w, h;
|
|
} BOX_TYPE;
|
|
|
|
class CUI : public SSD1306 {
|
|
public:
|
|
// Constructor
|
|
//CUI(Adafruit_SSD1306 &display);
|
|
CUI();
|
|
void setup();
|
|
void start();
|
|
void updateDisplay(unsigned long tick);
|
|
void updateDisplayTop(unsigned long tick);
|
|
void updateDisplayBottom(unsigned long tick);
|
|
void message(uint8_t lineNo, char *szMessage);
|
|
void progress(uint8_t lineNo, uint8_t progress);
|
|
void loopButton(unsigned long tickMillis);
|
|
inline void setItemMode(uint16_t mode) { m_nItemMode = mode; };
|
|
|
|
// Shared variables with ISR
|
|
volatile bool bButtonSetChanged;
|
|
volatile bool bButtonUpChanged;
|
|
volatile bool bButtonDownChanged;
|
|
volatile unsigned long buttonSetChangeTime; // Time when button was pressed
|
|
volatile unsigned long buttonUpChangeTime; // Time when button was pressed
|
|
volatile unsigned long buttonDownChangeTime; // Time when button was pressed
|
|
|
|
private:
|
|
uint16_t m_nMessageMode, lastMessageMode;
|
|
uint16_t m_nMainMode, lastMainMode; // Temp, Humid, Clock
|
|
uint16_t m_nItemMode, lastItemMode; // Normal, Set, Config
|
|
uint16_t m_nItem, lastItem; // Temp, Hum, Heat ...
|
|
int16_t m_nValue, lastValue;
|
|
uint8_t *m_pUnit, *lastUnit;
|
|
uint16_t m_nD0, lastD0;
|
|
uint16_t m_nD1, lastD1;
|
|
uint16_t m_nD2, lastD2;
|
|
uint16_t m_nD3, lastD3;
|
|
uint8_t *m_pDUnit, *lastpDUnit;
|
|
BOX_TYPE boxMode, boxTitle, boxValue, boxUnit, boxD0, boxD1, boxD2, boxDot, boxD3, boxDUnit;
|
|
|
|
bool bDot;
|
|
bool bButtonChanged;
|
|
|
|
|
|
|
|
// Helper function to update digits
|
|
bool displayTop();
|
|
bool displayBottom();
|
|
//bool displayTemperature();
|
|
//bool displayHumidity();
|
|
//void displayClock() {};
|
|
void getBoundaries();
|
|
|
|
// Buttons
|
|
unsigned long buttonSetDownTime;
|
|
unsigned long buttonUpDownTime;
|
|
unsigned long buttonDownDownTime;
|
|
|
|
unsigned int buttonSetDownDuration;
|
|
unsigned int buttonUpDownDuration;
|
|
unsigned int buttonDownDownDuration;
|
|
|
|
bool bButtonSetUp; // Flag for menu button
|
|
bool bButtonSetDown; // Flag for menu button
|
|
|
|
bool bButtonUpUp; // Flag for up button
|
|
bool bButtonUpDown; // Flag for down button
|
|
|
|
|
|
bool bButtonDownUp; // Flag for up button
|
|
bool bButtonDownDown; // Flag for down button
|
|
|
|
void initButtonState();
|
|
void checkButtonStates(unsigned long tickMillis);
|
|
|
|
};
|
|
|
|
//
|
|
// Button ISR's
|
|
//
|
|
void IRAM_ATTR buttonSetISR(void *);
|
|
void IRAM_ATTR buttonUpISR(void *);
|
|
void IRAM_ATTR buttonDownISR(void *);
|
|
|
|
extern CUI ui;
|
|
#endif
|
|
|