| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <functional> | ||
| 4 | #include <string> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "DisplayDriver.h" | ||
| 8 | |||
| 9 | class OLEDPage { | ||
| 10 | public: | ||
| 11 | static bool InitializeDisplay(int type); | ||
| 12 | |||
| 13 | enum class OLEDType { | ||
| 14 | NONE, | ||
| 15 | SMALL, | ||
| 16 | SINGLE_COLOR, | ||
| 17 | TWO_COLOR, | ||
| 18 | TEXT_ONLY | ||
| 19 | }; | ||
| 20 | |||
| 21 | static void SetOLEDType(OLEDType tp); | ||
| 22 | ✗ | static OLEDType GetOLEDType() { return oledType; } | |
| 23 | 12 | static void SetHas4DirectionControls(bool b = true) { has4DirectionControls = b; } | |
| 24 | 17 | static bool Has4DirectionControls() { return has4DirectionControls; } | |
| 25 | ✗ | static void SetOLEDOrientationFlipped(bool b) { oledFlipped = b; } | |
| 26 | ✗ | static bool GetOLEDOrientationFlipped() { return oledFlipped; } | |
| 27 | 130 | static OLEDPage* GetCurrentPage() { return currentPage; } | |
| 28 | static void SetCurrentPage(OLEDPage* p); | ||
| 29 | ✗ | static void SetForcedOff(bool b) { oledForcedOff = b; }; | |
| 30 | 182 | static bool IsForcedOff() { return oledForcedOff; } | |
| 31 | static int GetLEDDisplayWidth(); | ||
| 32 | static int GetLEDDisplayHeight(); | ||
| 33 | static int GetI2CBus(); | ||
| 34 | |||
| 35 | OLEDPage(); | ||
| 36 | ✗ | virtual ~OLEDPage() {} | |
| 37 | |||
| 38 | OLEDPage(const OLEDPage&) = delete; | ||
| 39 | void operator=(OLEDPage const&) = delete; | ||
| 40 | |||
| 41 | ✗ | virtual void displaying() {} | |
| 42 | 5 | virtual void hiding() {} | |
| 43 | ✗ | virtual void display() {} | |
| 44 | |||
| 45 | 14 | virtual bool doIteration(bool& displayOn) { return false; } | |
| 46 | virtual bool doAction(const std::string& action) = 0; | ||
| 47 | |||
| 48 | ✗ | OLEDPage& autoDelete() { | |
| 49 | ✗ | autoDeleteOnHide = true; | |
| 50 | ✗ | return *this; | |
| 51 | } | ||
| 52 | |||
| 53 | static void printString(int x, int y, const std::string& str, bool white = true); | ||
| 54 | static void printStringCentered(int y, const std::string& str, bool white = true); | ||
| 55 | static void fillTriangle(short x0, short y0, short x1, short y1, short x2, short y2, bool white = true); | ||
| 56 | static void drawLine(short x0, short y0, short x1, short y1, bool white = true); | ||
| 57 | static void drawBitmap(short x, short y, const unsigned char bitmap[], short w, short h, bool white = true); | ||
| 58 | static void drawRect(short x0, short y0, short x1, short y1, bool white = true); | ||
| 59 | static void fillRect(short x0, short y0, short x1, short y1, bool white = true); | ||
| 60 | static void flushDisplay(); | ||
| 61 | static void clearDisplay(); | ||
| 62 | static void displayOff(); | ||
| 63 | |||
| 64 | static int getMinimumRefresh(); | ||
| 65 | static void displayBootingNotice(const std::string& msg = ""); | ||
| 66 | |||
| 67 | protected: | ||
| 68 | static void readCapeImage(); | ||
| 69 | |||
| 70 | static OLEDType oledType; | ||
| 71 | static bool oledFlipped; | ||
| 72 | static OLEDPage* currentPage; | ||
| 73 | static bool oledForcedOff; | ||
| 74 | static bool has4DirectionControls; | ||
| 75 | |||
| 76 | static int _capeImageWidth; | ||
| 77 | static int _capeImageHeight; | ||
| 78 | static std::vector<uint8_t> _capeImage; | ||
| 79 | |||
| 80 | bool autoDeleteOnHide; | ||
| 81 | }; | ||
| 82 | |||
| 83 | class TitledOLEDPage : public OLEDPage { | ||
| 84 | public: | ||
| 85 | TitledOLEDPage(const std::string& title); | ||
| 86 | ✗ | virtual ~TitledOLEDPage() {} | |
| 87 | |||
| 88 | protected: | ||
| 89 | virtual int displayTitle(); | ||
| 90 | std::string title; | ||
| 91 | int numRows; | ||
| 92 | }; | ||
| 93 | |||
| 94 | class PromptOLEDPage : public TitledOLEDPage { | ||
| 95 | public: | ||
| 96 | PromptOLEDPage(const std::string& title, const std::string& msg1, const std::string& msg2, | ||
| 97 | const std::vector<std::string>& items); | ||
| 98 | PromptOLEDPage(const std::string& title, const std::string& msg1, const std::string& msg2, | ||
| 99 | const std::vector<std::string>& items, | ||
| 100 | const std::function<void(const std::string&)>& itemSelectedCallback); | ||
| 101 | ✗ | virtual ~PromptOLEDPage() {} | |
| 102 | |||
| 103 | virtual void displaying() override; | ||
| 104 | virtual bool doAction(const std::string& action) override; | ||
| 105 | virtual void ItemSelected(const std::string& item); | ||
| 106 | |||
| 107 | virtual void display() override; | ||
| 108 | |||
| 109 | protected: | ||
| 110 | std::string msg1; | ||
| 111 | std::string msg2; | ||
| 112 | std::vector<std::string> items; | ||
| 113 | int curSelected; | ||
| 114 | std::function<void(const std::string&)> itemSelectedCallback; | ||
| 115 | }; | ||
| 116 | |||
| 117 | class ListOLEDPage : public TitledOLEDPage { | ||
| 118 | public: | ||
| 119 | ListOLEDPage(const std::string& title, const std::vector<std::string>& items, OLEDPage* parent = nullptr); | ||
| 120 | ✗ | virtual ~ListOLEDPage() {} | |
| 121 | |||
| 122 | virtual void displaying() override; | ||
| 123 | virtual bool doAction(const std::string& action) override; | ||
| 124 | |||
| 125 | virtual void display() override; | ||
| 126 | |||
| 127 | protected: | ||
| 128 | virtual void displayScrollArrows(int startY); | ||
| 129 | |||
| 130 | std::vector<std::string> items; | ||
| 131 | int curTop; | ||
| 132 | OLEDPage* parent; | ||
| 133 | }; | ||
| 134 | |||
| 135 | class MenuOLEDPage : public ListOLEDPage { | ||
| 136 | public: | ||
| 137 | MenuOLEDPage(const std::string& title, const std::vector<std::string>& items, OLEDPage* parent = nullptr); | ||
| 138 | MenuOLEDPage(const std::string& title, const std::vector<std::string>& items, | ||
| 139 | const std::function<void(const std::string&)>& itemSelectedCallback, | ||
| 140 | OLEDPage* parent = nullptr); | ||
| 141 | ✗ | virtual ~MenuOLEDPage() {} | |
| 142 | |||
| 143 | virtual void displaying() override; | ||
| 144 | virtual bool doAction(const std::string& action) override; | ||
| 145 | |||
| 146 | virtual void itemSelected(const std::string& item); | ||
| 147 | |||
| 148 | virtual void display() override; | ||
| 149 | |||
| 150 | protected: | ||
| 151 | int curSelected; | ||
| 152 | std::function<void(const std::string&)> itemSelectedCallback; | ||
| 153 | }; | ||
| 154 |