Added screen error messages
This commit is contained in:
parent
8df64cb583
commit
5ff79119c8
@ -1,6 +1,10 @@
|
|||||||
#include "ScreenManager.h"
|
#include "ScreenManager.h"
|
||||||
|
|
||||||
ScreenManager::ScreenManager(Adafruit_SSD1306 &display) : _displayRef(display), _displayColorInverted(false), _displayDimmed(false), _currentView(NULL), _error(0)
|
ScreenManager::ScreenManager(Adafruit_SSD1306 &display) : _displayRef(display), _displayColorInverted(false), _displayDimmed(false), _currentView(NO_CURRENT_VIEW), _error(0)
|
||||||
|
, _viewNotFound{&(displayError), (ErrorInfo *)malloc(sizeof(ErrorInfo)), RESERVED_VIEW_UID, NULL}
|
||||||
|
, _viewFuncUndefined{&(displayError), (ErrorInfo *)malloc(sizeof(ErrorInfo)), RESERVED_VIEW_UID, NULL}
|
||||||
|
, _currentViewUndefined{&(displayError), (ErrorInfo *)malloc(sizeof(ErrorInfo)), RESERVED_VIEW_UID, NULL}
|
||||||
|
, _viewFunctionFailedToExecute{&(displayError), (ErrorInfo *)malloc(sizeof(ErrorInfo)), RESERVED_VIEW_UID, NULL}
|
||||||
{
|
{
|
||||||
_viewLinkedList = (ViewLinkedList) createEmptyList();
|
_viewLinkedList = (ViewLinkedList) createEmptyList();
|
||||||
_displayRef.setRotation(OR_0);
|
_displayRef.setRotation(OR_0);
|
||||||
@ -131,45 +135,85 @@ ViewLink* ScreenManager::getLinkByUID(ViewLinkedList viewLinkedList, const unsig
|
|||||||
|
|
||||||
boolean ScreenManager::displayView(const int UID)
|
boolean ScreenManager::displayView(const int UID)
|
||||||
{
|
{
|
||||||
boolean result = false;
|
//Reset draw settings:
|
||||||
|
_displayRef.clearDisplay();
|
||||||
|
_displayRef.setCursor(0,0);
|
||||||
|
_displayRef.setTextSize(1);
|
||||||
|
|
||||||
|
|
||||||
if(UID == -1 && _currentView == NO_CURRENT_VIEW)
|
if(UID == -1 && _currentView == NO_CURRENT_VIEW)
|
||||||
{
|
{
|
||||||
//We display an error message on the screen
|
//We display an error message on the screen
|
||||||
|
((ErrorInfo *)_currentViewUndefined.pData)->errorMessage = F("Could not display current view");
|
||||||
|
((ErrorInfo *)_currentViewUndefined.pData)->viewUID = UID;
|
||||||
|
(*_currentViewUndefined.viewLogicFunction)(_displayRef, _currentViewUndefined.pData);
|
||||||
|
_displayRef.display();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(UID == -1)
|
else if(UID == -1)
|
||||||
{
|
{
|
||||||
_displayRef.clearDisplay();
|
if(!(*_currentView->viewLogicFunction)(_displayRef, _currentView->pData))
|
||||||
_displayRef.setCursor(0,0);
|
{
|
||||||
result = (*_currentView->viewLogicFunction)(_displayRef, _currentView->pData);
|
//We display an error message on the screen
|
||||||
_displayRef.display();
|
_displayRef.clearDisplay();
|
||||||
|
((ErrorInfo *)_viewFunctionFailedToExecute.pData)->errorMessage = F("View function failed\nto execute");
|
||||||
|
((ErrorInfo *)_viewFunctionFailedToExecute.pData)->viewUID = UID;
|
||||||
|
(*_viewFunctionFailedToExecute.viewLogicFunction)(_displayRef, _viewFunctionFailedToExecute.pData);
|
||||||
|
_displayRef.display();
|
||||||
|
|
||||||
return result;
|
_currentView = &_viewFunctionFailedToExecute;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_displayRef.display();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewLink *viewLink = getLinkByUID(_viewLinkedList, UID);
|
ViewLink *viewLink = getLinkByUID(_viewLinkedList, UID);
|
||||||
if(viewLink == NULL)
|
if(viewLink == NULL)
|
||||||
{
|
{
|
||||||
//We display an error message on the screen
|
//We display an error message on the screen
|
||||||
|
((ErrorInfo *)_viewNotFound.pData)->errorMessage = F("View does not exist");
|
||||||
|
((ErrorInfo *)_viewNotFound.pData)->viewUID = UID;
|
||||||
|
(*_viewNotFound.viewLogicFunction)(_displayRef, _viewNotFound.pData);
|
||||||
|
_displayRef.display();
|
||||||
|
|
||||||
|
_currentView = &_viewNotFound;
|
||||||
return false;
|
return false;
|
||||||
}else if(viewLink->viewLogicFunction == NULL)
|
}else if(viewLink->viewLogicFunction == NULL)
|
||||||
{
|
{
|
||||||
//We display an error message on the screen
|
//We display an error message on the screen
|
||||||
|
((ErrorInfo *)_viewFuncUndefined.pData)->errorMessage = F("View function is NULL");
|
||||||
|
((ErrorInfo *)_viewFuncUndefined.pData)->viewUID = UID;
|
||||||
|
(*_viewFuncUndefined.viewLogicFunction)(_displayRef, _viewFuncUndefined.pData);
|
||||||
|
_displayRef.display();
|
||||||
|
|
||||||
|
_currentView = &_viewFuncUndefined;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentView = viewLink;
|
|
||||||
|
|
||||||
_displayRef.clearDisplay();
|
if(!(*viewLink->viewLogicFunction)(_displayRef, viewLink->pData))
|
||||||
_displayRef.setCursor(0,0);
|
{
|
||||||
result = (*viewLink->viewLogicFunction)(_displayRef, viewLink->pData);
|
//We display an error message on the screen
|
||||||
|
_displayRef.clearDisplay();
|
||||||
|
((ErrorInfo *)_viewFunctionFailedToExecute.pData)->errorMessage = F("View function failed\nto execute");
|
||||||
|
((ErrorInfo *)_viewFunctionFailedToExecute.pData)->viewUID = UID;
|
||||||
|
(*_viewFunctionFailedToExecute.viewLogicFunction)(_displayRef, _viewFunctionFailedToExecute.pData);
|
||||||
|
_displayRef.display();
|
||||||
|
|
||||||
|
_currentView = &_viewFunctionFailedToExecute;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
_displayRef.display();
|
_displayRef.display();
|
||||||
|
_currentView = viewLink;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
boolean ScreenManager::displayNextView()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenManager::invertDisplayColor(const boolean inverted)
|
void ScreenManager::invertDisplayColor(const boolean inverted)
|
||||||
@ -215,4 +259,46 @@ void ScreenManager::clearDisplay(const boolean bufferOnly)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned char ScreenManager::getViewCount()
|
||||||
|
{
|
||||||
|
unsigned char counter = 0;
|
||||||
|
ViewLinkedList temp = _viewLinkedList;
|
||||||
|
while(!isListEmpty(temp))
|
||||||
|
{
|
||||||
|
counter++;
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScreenManager::getCurrentViewUID() const
|
||||||
|
{
|
||||||
|
if(_currentView == NO_CURRENT_VIEW)
|
||||||
|
return -1;
|
||||||
|
return _currentView->UID < 0 ? -1 : _currentView->UID;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean ScreenManager::displayError(Adafruit_SSD1306 &display, void *pData)
|
||||||
|
{
|
||||||
|
const ErrorInfo *errorInfo = (ErrorInfo *) pData;
|
||||||
|
|
||||||
|
display.setTextSize(3);
|
||||||
|
display.setCursor(19,3);
|
||||||
|
display.drawRect(0,0,display.width(), 27, WHITE);
|
||||||
|
display.print(F("ERROR"));
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(0,29);
|
||||||
|
display.print(errorInfo->errorMessage);
|
||||||
|
//We then display the view UID that caused the probleme
|
||||||
|
|
||||||
|
if(errorInfo->viewUID >= 0)
|
||||||
|
{
|
||||||
|
display.setCursor(0,56);
|
||||||
|
char buff[30] = "";
|
||||||
|
sprintf(buff,"VIEW UID : %d" ,errorInfo->viewUID);
|
||||||
|
display.println(buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ class ScreenManager
|
|||||||
boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID);
|
boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID);
|
||||||
boolean removeView(const unsigned char UID);
|
boolean removeView(const unsigned char UID);
|
||||||
boolean displayView(const int UID = -1);
|
boolean displayView(const int UID = -1);
|
||||||
|
boolean displayNextView();
|
||||||
void invertDisplayColor(const boolean inverted);
|
void invertDisplayColor(const boolean inverted);
|
||||||
void orientDisplay(const Orientation orientation);
|
void orientDisplay(const Orientation orientation);
|
||||||
void dimDisplay(const boolean dimmed);
|
void dimDisplay(const boolean dimmed);
|
||||||
@ -19,7 +20,8 @@ class ScreenManager
|
|||||||
boolean isDisplayColorInverted() const;
|
boolean isDisplayColorInverted() const;
|
||||||
Orientation getDisplayOrientation() const;
|
Orientation getDisplayOrientation() const;
|
||||||
boolean isDisplayDimmed() const;
|
boolean isDisplayDimmed() const;
|
||||||
ViewLink* getCurrentView() const;
|
int getCurrentViewUID() const;
|
||||||
|
unsigned char getViewCount();
|
||||||
|
|
||||||
|
|
||||||
void iterateThroughList();
|
void iterateThroughList();
|
||||||
@ -32,6 +34,7 @@ class ScreenManager
|
|||||||
boolean removeLinkByUID(ViewLinkedList *viewLinkedList, const unsigned char UID);
|
boolean removeLinkByUID(ViewLinkedList *viewLinkedList, const unsigned char UID);
|
||||||
ViewLink* getLinkByUID(ViewLinkedList viewLinkedList, const unsigned char UID);
|
ViewLink* getLinkByUID(ViewLinkedList viewLinkedList, const unsigned char UID);
|
||||||
boolean isListEmpty(ViewLinkedList viewLinkedList);
|
boolean isListEmpty(ViewLinkedList viewLinkedList);
|
||||||
|
static boolean displayError(Adafruit_SSD1306 &display, void *pData);
|
||||||
|
|
||||||
Adafruit_SSD1306 &_displayRef;
|
Adafruit_SSD1306 &_displayRef;
|
||||||
ViewLinkedList _viewLinkedList;
|
ViewLinkedList _viewLinkedList;
|
||||||
@ -39,6 +42,10 @@ class ScreenManager
|
|||||||
boolean _displayColorInverted;
|
boolean _displayColorInverted;
|
||||||
boolean _displayDimmed;
|
boolean _displayDimmed;
|
||||||
ViewLink* _currentView;
|
ViewLink* _currentView;
|
||||||
|
ViewLink _viewNotFound, _viewFuncUndefined, _currentViewUndefined, _viewFunctionFailedToExecute;
|
||||||
|
|
||||||
|
//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
|
#endif //SCREENMANAGER_H
|
||||||
|
Loading…
Reference in New Issue
Block a user