ESP8266_swiss_army_board/src/app/ScreenManager.h

70 lines
2.4 KiB
C++

#ifndef SCREENMANAGER_H
#define SCREENMANAGER_H
#include <Adafruit_SSD1306.h>
#include "definition.h"
#include "SDCardManager.h"
#include "CFGFileParser.h"
#include "CFGDictionary.h"
class ScreenManager
{
friend class SAB;
public:
enum Error {OK, MALLOC_FAILED, VIEW_NOT_FOUND, VIEW_FUNC_UNDEFINED, VIEW_FAILED_TO_EXECUTE, CURRENT_VIEW_UNDEFINED};
boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID);
boolean removeView(const unsigned char UID);
boolean displayView(const int UID = -1);
boolean displayNextView();
boolean applyCfgFromSD();
void invertDisplayColor(const boolean inverted);
void orientDisplay(const Orientation orientation);
void dimDisplay(const boolean dimmed);
void clearDisplay(const boolean bufferOnly = false);
void sleep();
void wakeUp();
void setEnabled(boolean value);
boolean getEnabled();
boolean init();
Error getError() const;
const char* getErrorMessage() const;
boolean isDisplayColorInverted() const;
Orientation getDisplayOrientation() const;
boolean isDisplayDimmed() const;
int getCurrentViewUID() const;
unsigned char getViewCount();
void iterateThroughList();
protected:
ScreenManager(Adafruit_SSD1306 &display, SDCardManager *sdCardManager = NULL);
private:
void *createEmptyList();
boolean addNewLinkAtTheEnd(ViewLinkedList *viewLinkedList, ViewLink viewLink);
boolean removeLinkByUID(ViewLinkedList *viewLinkedList, const unsigned char UID);
ViewLink* getLinkByUID(ViewLinkedList viewLinkedList, const unsigned char UID);
boolean isListEmpty(ViewLinkedList viewLinkedList);
static boolean displayError(Adafruit_SSD1306 &display, void *pData);
void setDefault();
uint8_t orientationTranslator(uint16_t degres);
Adafruit_SSD1306 &_displayRef;
ViewLinkedList _viewLinkedList;
Error _error;
boolean _displayColorInverted;
boolean _displayDimmed;
boolean _enabled;
ViewLink* _currentView;
ViewLink _viewNotFound, _viewFuncUndefined, _currentViewUndefined, _viewFunctionFailedToExecute;
SDCardManager *_sdCardManager;
//This structure contains the error message as well as the UID from the view that caused the error if available.
typedef struct {const __FlashStringHelper* errorMessage; int viewUID;} ErrorInfo;
};
#endif //SCREENMANAGER_H