A basic graphics package for the LPC4088 Display Module.
Dependents: lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI lpc4088_displaymodule_fs_aid ... more
Fork of DMBasicGUI by
SlideShow/SlideShow.h@5:f4de114c31c3, 2014-12-21 (annotated)
- Committer:
- embeddedartists
- Date:
- Sun Dec 21 13:53:07 2014 +0100
- Revision:
- 5:f4de114c31c3
- Child:
- 13:bff2288c2c61
- Added support for RAW images
- Added SlideShow + App for it
- Moved App-specific stuff out from the AppLauncher and into main
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 5:f4de114c31c3 | 1 | |
embeddedartists | 5:f4de114c31c3 | 2 | #ifndef SLIDESHOW_H |
embeddedartists | 5:f4de114c31c3 | 3 | #define SLIDESHOW_H |
embeddedartists | 5:f4de114c31c3 | 4 | |
embeddedartists | 5:f4de114c31c3 | 5 | #include "mbed.h" |
embeddedartists | 5:f4de114c31c3 | 6 | #include "rtos.h" |
embeddedartists | 5:f4de114c31c3 | 7 | //#include "LcdController.h" |
embeddedartists | 5:f4de114c31c3 | 8 | #include "Image.h" |
embeddedartists | 5:f4de114c31c3 | 9 | #include "Renderer.h" |
embeddedartists | 5:f4de114c31c3 | 10 | |
embeddedartists | 5:f4de114c31c3 | 11 | /** |
embeddedartists | 5:f4de114c31c3 | 12 | */ |
embeddedartists | 5:f4de114c31c3 | 13 | class SlideShow { |
embeddedartists | 5:f4de114c31c3 | 14 | public: |
embeddedartists | 5:f4de114c31c3 | 15 | |
embeddedartists | 5:f4de114c31c3 | 16 | enum SlideShowError { |
embeddedartists | 5:f4de114c31c3 | 17 | Ok, |
embeddedartists | 5:f4de114c31c3 | 18 | InvalidScript, |
embeddedartists | 5:f4de114c31c3 | 19 | RuntimeError, |
embeddedartists | 5:f4de114c31c3 | 20 | UserAbort, |
embeddedartists | 5:f4de114c31c3 | 21 | ScriptEnd, |
embeddedartists | 5:f4de114c31c3 | 22 | OutOfMemory, |
embeddedartists | 5:f4de114c31c3 | 23 | FileError, |
embeddedartists | 5:f4de114c31c3 | 24 | }; |
embeddedartists | 5:f4de114c31c3 | 25 | |
embeddedartists | 5:f4de114c31c3 | 26 | typedef SlideShowError (*calloutFunc)(int calloutId, SlideShow* ss, int identifier); |
embeddedartists | 5:f4de114c31c3 | 27 | |
embeddedartists | 5:f4de114c31c3 | 28 | SlideShow(Renderer* r, /*LcdController::Config* screen,*/ const char* pathPrefix=NULL, uint8_t* bkg=NULL, int xoff=0, int yoff=0, int layer=0, Mutex* fileMutex=NULL); |
embeddedartists | 5:f4de114c31c3 | 29 | ~SlideShow(); |
embeddedartists | 5:f4de114c31c3 | 30 | SlideShowError prepare(const char* scriptFile); |
embeddedartists | 5:f4de114c31c3 | 31 | SlideShowError run(); |
embeddedartists | 5:f4de114c31c3 | 32 | void setCalloutHandler(calloutFunc func, int calloutId); |
embeddedartists | 5:f4de114c31c3 | 33 | void releaseScreen(void); |
embeddedartists | 5:f4de114c31c3 | 34 | void stop() { abortBeforeNextStep = true; } |
embeddedartists | 5:f4de114c31c3 | 35 | |
embeddedartists | 5:f4de114c31c3 | 36 | private: |
embeddedartists | 5:f4de114c31c3 | 37 | |
embeddedartists | 5:f4de114c31c3 | 38 | typedef uint16_t* image_t; |
embeddedartists | 5:f4de114c31c3 | 39 | |
embeddedartists | 5:f4de114c31c3 | 40 | class Transition { |
embeddedartists | 5:f4de114c31c3 | 41 | public: |
embeddedartists | 5:f4de114c31c3 | 42 | typedef enum |
embeddedartists | 5:f4de114c31c3 | 43 | { |
embeddedartists | 5:f4de114c31c3 | 44 | None, |
embeddedartists | 5:f4de114c31c3 | 45 | LeftRight, |
embeddedartists | 5:f4de114c31c3 | 46 | DownUp, |
embeddedartists | 5:f4de114c31c3 | 47 | TopDown, |
embeddedartists | 5:f4de114c31c3 | 48 | Blinds, |
embeddedartists | 5:f4de114c31c3 | 49 | Fade, |
embeddedartists | 5:f4de114c31c3 | 50 | Unknown, |
embeddedartists | 5:f4de114c31c3 | 51 | } Type; |
embeddedartists | 5:f4de114c31c3 | 52 | |
embeddedartists | 5:f4de114c31c3 | 53 | Transition(const char* typeStr) { |
embeddedartists | 5:f4de114c31c3 | 54 | if (typeStr == NULL) { |
embeddedartists | 5:f4de114c31c3 | 55 | t = Unknown; |
embeddedartists | 5:f4de114c31c3 | 56 | } else if (strcmp("none", typeStr) == 0) { |
embeddedartists | 5:f4de114c31c3 | 57 | t = None; |
embeddedartists | 5:f4de114c31c3 | 58 | } else if (strcmp("left-right", typeStr) == 0) { |
embeddedartists | 5:f4de114c31c3 | 59 | t = LeftRight; |
embeddedartists | 5:f4de114c31c3 | 60 | } else if (strcmp("down-up", typeStr) == 0) { |
embeddedartists | 5:f4de114c31c3 | 61 | t = DownUp; |
embeddedartists | 5:f4de114c31c3 | 62 | } else if (strcmp("top-down", typeStr) == 0) { |
embeddedartists | 5:f4de114c31c3 | 63 | t = TopDown; |
embeddedartists | 5:f4de114c31c3 | 64 | } else if (strcmp("blinds", typeStr) == 0) { |
embeddedartists | 5:f4de114c31c3 | 65 | t = Blinds; |
embeddedartists | 5:f4de114c31c3 | 66 | } else if (strcmp("fade", typeStr) == 0) { |
embeddedartists | 5:f4de114c31c3 | 67 | t = Fade; |
embeddedartists | 5:f4de114c31c3 | 68 | } else { |
embeddedartists | 5:f4de114c31c3 | 69 | t = Unknown; |
embeddedartists | 5:f4de114c31c3 | 70 | } |
embeddedartists | 5:f4de114c31c3 | 71 | }; |
embeddedartists | 5:f4de114c31c3 | 72 | ~Transition(); |
embeddedartists | 5:f4de114c31c3 | 73 | SlideShowError execute(SlideShow* ss, Image::ImageData_t* CurrentImage, Image::ImageData_t* NewImage); |
embeddedartists | 5:f4de114c31c3 | 74 | Type type() { return this->t; } |
embeddedartists | 5:f4de114c31c3 | 75 | const char* typeString() { |
embeddedartists | 5:f4de114c31c3 | 76 | switch(t) { |
embeddedartists | 5:f4de114c31c3 | 77 | case None: return "No"; |
embeddedartists | 5:f4de114c31c3 | 78 | case LeftRight: return "Left to Right"; |
embeddedartists | 5:f4de114c31c3 | 79 | case TopDown: return "Top to Bottom"; |
embeddedartists | 5:f4de114c31c3 | 80 | case Blinds: return "Blinds"; |
embeddedartists | 5:f4de114c31c3 | 81 | case Unknown: |
embeddedartists | 5:f4de114c31c3 | 82 | default: |
embeddedartists | 5:f4de114c31c3 | 83 | return "Unknown"; |
embeddedartists | 5:f4de114c31c3 | 84 | } |
embeddedartists | 5:f4de114c31c3 | 85 | }; |
embeddedartists | 5:f4de114c31c3 | 86 | |
embeddedartists | 5:f4de114c31c3 | 87 | private: |
embeddedartists | 5:f4de114c31c3 | 88 | Type t; |
embeddedartists | 5:f4de114c31c3 | 89 | |
embeddedartists | 5:f4de114c31c3 | 90 | enum Constants { |
embeddedartists | 5:f4de114c31c3 | 91 | LeftRight_DelayMs = 100, |
embeddedartists | 5:f4de114c31c3 | 92 | LeftRight_PixelsToSkip = 20, |
embeddedartists | 5:f4de114c31c3 | 93 | DownUp_DelayMs = 100, |
embeddedartists | 5:f4de114c31c3 | 94 | DownUp_LineSkip = 20, |
embeddedartists | 5:f4de114c31c3 | 95 | TopDown_DelayMs = 100, |
embeddedartists | 5:f4de114c31c3 | 96 | TopDown_LineSkip = 20, |
embeddedartists | 5:f4de114c31c3 | 97 | Blinds_LinesPerBlock = 8, |
embeddedartists | 5:f4de114c31c3 | 98 | Blinds_DelayMs = 20, |
embeddedartists | 5:f4de114c31c3 | 99 | Blinds_BeamColor = 0xffff, |
embeddedartists | 5:f4de114c31c3 | 100 | Blinds_BackColor = 0x0000, |
embeddedartists | 5:f4de114c31c3 | 101 | Fade_DelayMs = 80, |
embeddedartists | 5:f4de114c31c3 | 102 | }; |
embeddedartists | 5:f4de114c31c3 | 103 | }; |
embeddedartists | 5:f4de114c31c3 | 104 | |
embeddedartists | 5:f4de114c31c3 | 105 | class Command { |
embeddedartists | 5:f4de114c31c3 | 106 | public: |
embeddedartists | 5:f4de114c31c3 | 107 | typedef enum |
embeddedartists | 5:f4de114c31c3 | 108 | { |
embeddedartists | 5:f4de114c31c3 | 109 | Clear, |
embeddedartists | 5:f4de114c31c3 | 110 | Goto, |
embeddedartists | 5:f4de114c31c3 | 111 | LoadImage, |
embeddedartists | 5:f4de114c31c3 | 112 | Show, |
embeddedartists | 5:f4de114c31c3 | 113 | Wait, |
embeddedartists | 5:f4de114c31c3 | 114 | Callout, |
embeddedartists | 5:f4de114c31c3 | 115 | } Type; |
embeddedartists | 5:f4de114c31c3 | 116 | |
embeddedartists | 5:f4de114c31c3 | 117 | Command(Type cmd, int info=0, Transition* t=NULL, const char* filename=NULL, const char* prefix=NULL) { |
embeddedartists | 5:f4de114c31c3 | 118 | type = cmd; |
embeddedartists | 5:f4de114c31c3 | 119 | information = info; |
embeddedartists | 5:f4de114c31c3 | 120 | transition = t; |
embeddedartists | 5:f4de114c31c3 | 121 | if (filename == NULL) { |
embeddedartists | 5:f4de114c31c3 | 122 | fname = NULL; |
embeddedartists | 5:f4de114c31c3 | 123 | } else { |
embeddedartists | 5:f4de114c31c3 | 124 | fname = (char*)malloc(strlen(filename) + strlen(prefix) + 1); //+1 for null termination |
embeddedartists | 5:f4de114c31c3 | 125 | if (fname != NULL) { |
embeddedartists | 5:f4de114c31c3 | 126 | fname[0] = '\0'; |
embeddedartists | 5:f4de114c31c3 | 127 | strcat(fname, prefix); |
embeddedartists | 5:f4de114c31c3 | 128 | strcat(fname, filename); |
embeddedartists | 5:f4de114c31c3 | 129 | } |
embeddedartists | 5:f4de114c31c3 | 130 | } |
embeddedartists | 5:f4de114c31c3 | 131 | }; |
embeddedartists | 5:f4de114c31c3 | 132 | ~Command() { |
embeddedartists | 5:f4de114c31c3 | 133 | if (fname != NULL) { |
embeddedartists | 5:f4de114c31c3 | 134 | free(fname); |
embeddedartists | 5:f4de114c31c3 | 135 | fname = NULL; |
embeddedartists | 5:f4de114c31c3 | 136 | } |
embeddedartists | 5:f4de114c31c3 | 137 | }; |
embeddedartists | 5:f4de114c31c3 | 138 | void updateInfo(int newInfo) { information = newInfo; } |
embeddedartists | 5:f4de114c31c3 | 139 | int info() { return information; } |
embeddedartists | 5:f4de114c31c3 | 140 | void print(); |
embeddedartists | 5:f4de114c31c3 | 141 | SlideShowError handle(SlideShow* ss, int* seqIdx, int* lastTime); |
embeddedartists | 5:f4de114c31c3 | 142 | private: |
embeddedartists | 5:f4de114c31c3 | 143 | Type type; |
embeddedartists | 5:f4de114c31c3 | 144 | Transition* transition; |
embeddedartists | 5:f4de114c31c3 | 145 | int information; |
embeddedartists | 5:f4de114c31c3 | 146 | char* fname; |
embeddedartists | 5:f4de114c31c3 | 147 | }; |
embeddedartists | 5:f4de114c31c3 | 148 | |
embeddedartists | 5:f4de114c31c3 | 149 | |
embeddedartists | 5:f4de114c31c3 | 150 | typedef enum |
embeddedartists | 5:f4de114c31c3 | 151 | { |
embeddedartists | 5:f4de114c31c3 | 152 | Bmp, |
embeddedartists | 5:f4de114c31c3 | 153 | Raw |
embeddedartists | 5:f4de114c31c3 | 154 | } FileFormat; |
embeddedartists | 5:f4de114c31c3 | 155 | |
embeddedartists | 5:f4de114c31c3 | 156 | typedef struct |
embeddedartists | 5:f4de114c31c3 | 157 | { |
embeddedartists | 5:f4de114c31c3 | 158 | const char* pLabel; |
embeddedartists | 5:f4de114c31c3 | 159 | int index; |
embeddedartists | 5:f4de114c31c3 | 160 | } LabelInfo; |
embeddedartists | 5:f4de114c31c3 | 161 | |
embeddedartists | 5:f4de114c31c3 | 162 | enum { |
embeddedartists | 5:f4de114c31c3 | 163 | MaxNumPreparedImages = 100, |
embeddedartists | 5:f4de114c31c3 | 164 | } Constants; |
embeddedartists | 5:f4de114c31c3 | 165 | |
embeddedartists | 5:f4de114c31c3 | 166 | int screenWidth; |
embeddedartists | 5:f4de114c31c3 | 167 | int screenHeight; |
embeddedartists | 5:f4de114c31c3 | 168 | int screenPixels; |
embeddedartists | 5:f4de114c31c3 | 169 | int screenBytes; |
embeddedartists | 5:f4de114c31c3 | 170 | int drawXoff; |
embeddedartists | 5:f4de114c31c3 | 171 | int drawYoff; |
embeddedartists | 5:f4de114c31c3 | 172 | |
embeddedartists | 5:f4de114c31c3 | 173 | image_t ImageBackBuffer; |
embeddedartists | 5:f4de114c31c3 | 174 | Command** Sequence; |
embeddedartists | 5:f4de114c31c3 | 175 | int allocatedSequenceItems; |
embeddedartists | 5:f4de114c31c3 | 176 | int usedSequenceItems; |
embeddedartists | 5:f4de114c31c3 | 177 | |
embeddedartists | 5:f4de114c31c3 | 178 | const char* pathPrefix; |
embeddedartists | 5:f4de114c31c3 | 179 | |
embeddedartists | 5:f4de114c31c3 | 180 | int CurrentSlot; |
embeddedartists | 5:f4de114c31c3 | 181 | Image::ImageData_t PreparedImages[MaxNumPreparedImages]; |
embeddedartists | 5:f4de114c31c3 | 182 | |
embeddedartists | 5:f4de114c31c3 | 183 | Mutex* fileMutex; |
embeddedartists | 5:f4de114c31c3 | 184 | |
embeddedartists | 5:f4de114c31c3 | 185 | Renderer* rend; |
embeddedartists | 5:f4de114c31c3 | 186 | uint32_t rendHnd; |
embeddedartists | 5:f4de114c31c3 | 187 | int layer; |
embeddedartists | 5:f4de114c31c3 | 188 | |
embeddedartists | 5:f4de114c31c3 | 189 | calloutFunc callout; |
embeddedartists | 5:f4de114c31c3 | 190 | int calloutId; |
embeddedartists | 5:f4de114c31c3 | 191 | |
embeddedartists | 5:f4de114c31c3 | 192 | bool abortBeforeNextStep; |
embeddedartists | 5:f4de114c31c3 | 193 | |
embeddedartists | 5:f4de114c31c3 | 194 | // Utilities |
embeddedartists | 5:f4de114c31c3 | 195 | SlideShowError loadFile(const char* path, uint8_t** pData, uint32_t* pSize); |
embeddedartists | 5:f4de114c31c3 | 196 | |
embeddedartists | 5:f4de114c31c3 | 197 | // Parsing functions |
embeddedartists | 5:f4de114c31c3 | 198 | int getNextLine(char* pBuf, int* pOffset, char** ppLine); |
embeddedartists | 5:f4de114c31c3 | 199 | int splitLine(char* pLine, char** ppPart1, char** ppPart2, char** ppPart3); |
embeddedartists | 5:f4de114c31c3 | 200 | int findLabel(LabelInfo* pLabels, int numLabels, const char* pLabel); |
embeddedartists | 5:f4de114c31c3 | 201 | void freeSequence(void); |
embeddedartists | 5:f4de114c31c3 | 202 | SlideShowError expandSequence(); |
embeddedartists | 5:f4de114c31c3 | 203 | SlideShowError parseScript(char* pBuf); |
embeddedartists | 5:f4de114c31c3 | 204 | |
embeddedartists | 5:f4de114c31c3 | 205 | // Command related functions |
embeddedartists | 5:f4de114c31c3 | 206 | SlideShowError loadImage(const char* pFileName, int slot); |
embeddedartists | 5:f4de114c31c3 | 207 | void delay(int lastTime, int millis); |
embeddedartists | 5:f4de114c31c3 | 208 | SlideShowError runScript(); |
embeddedartists | 5:f4de114c31c3 | 209 | |
embeddedartists | 5:f4de114c31c3 | 210 | }; |
embeddedartists | 5:f4de114c31c3 | 211 | |
embeddedartists | 5:f4de114c31c3 | 212 | #endif |