2017-11-26 19:22:15 +00:00
|
|
|
#ifndef __ScreenManager
|
|
|
|
#define __ScreenManager
|
|
|
|
|
|
|
|
#include <LiquidCrystal.h>
|
|
|
|
|
|
|
|
|
|
|
|
class ScreenManager;
|
|
|
|
|
|
|
|
|
|
|
|
class BaseScreen
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
ScreenManager* mScreenManager;
|
|
|
|
|
|
|
|
protected:
|
2017-11-27 14:51:32 +00:00
|
|
|
ScreenManager* getScreenManager();
|
2017-11-26 19:22:15 +00:00
|
|
|
unsigned long getCurrentTime();
|
|
|
|
LiquidCrystal* getDisplay();
|
|
|
|
|
|
|
|
|
|
|
|
void printTime(int value);
|
2017-11-27 14:51:32 +00:00
|
|
|
|
2017-11-26 19:22:15 +00:00
|
|
|
public:
|
|
|
|
BaseScreen(ScreenManager* screenManager)
|
|
|
|
{
|
|
|
|
mScreenManager = screenManager;
|
|
|
|
}
|
|
|
|
|
2017-11-27 14:51:32 +00:00
|
|
|
virtual ~BaseScreen() {}
|
|
|
|
|
2017-11-26 19:22:15 +00:00
|
|
|
virtual void onShow() = 0;
|
|
|
|
virtual void onHide() = 0;
|
2017-11-27 14:51:32 +00:00
|
|
|
|
2017-11-26 19:22:15 +00:00
|
|
|
virtual void onButton() = 0;
|
|
|
|
virtual void onEncoder(long lastPosition, long newPosition) = 0;
|
|
|
|
virtual void onTick() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ScreenManager
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
LiquidCrystal* mDisplay;
|
|
|
|
unsigned long* mCurrentTime;
|
2017-11-27 14:51:32 +00:00
|
|
|
|
2017-11-26 19:22:15 +00:00
|
|
|
BaseScreen* mCurrent = NULL;
|
2017-11-27 14:51:32 +00:00
|
|
|
|
2017-11-26 19:22:15 +00:00
|
|
|
public:
|
|
|
|
ScreenManager(LiquidCrystal* display, unsigned long* currentTime)
|
|
|
|
{
|
|
|
|
mDisplay = display;
|
|
|
|
mCurrentTime = currentTime;
|
|
|
|
}
|
2017-11-27 14:51:32 +00:00
|
|
|
|
|
|
|
|
2017-11-26 19:22:15 +00:00
|
|
|
inline BaseScreen* getCurrent()
|
|
|
|
{
|
|
|
|
return mCurrent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline unsigned long getCurrentTime()
|
|
|
|
{
|
|
|
|
return *mCurrentTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline LiquidCrystal* getDisplay()
|
|
|
|
{
|
|
|
|
return mDisplay;
|
2017-11-27 14:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> void show()
|
2017-11-26 19:22:15 +00:00
|
|
|
{
|
|
|
|
if (mCurrent != NULL)
|
|
|
|
{
|
|
|
|
mCurrent->onHide();
|
|
|
|
delete(mCurrent);
|
|
|
|
}
|
2017-11-27 14:51:32 +00:00
|
|
|
|
2017-11-26 19:22:15 +00:00
|
|
|
mCurrent = new T(this);
|
|
|
|
mCurrent->onShow();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|