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 EmbeddedArtists AB

Committer:
embeddedartists
Date:
Mon Nov 04 14:31:50 2019 +0000
Revision:
22:f0d00f29bfeb
Parent:
16:feb669462368
More updates related to mbed OS 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 13:bff2288c2c61 1 /*
embeddedartists 13:bff2288c2c61 2 * Copyright 2014 Embedded Artists AB
embeddedartists 13:bff2288c2c61 3 *
embeddedartists 13:bff2288c2c61 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 13:bff2288c2c61 5 * you may not use this file except in compliance with the License.
embeddedartists 13:bff2288c2c61 6 * You may obtain a copy of the License at
embeddedartists 13:bff2288c2c61 7 *
embeddedartists 13:bff2288c2c61 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 13:bff2288c2c61 9 *
embeddedartists 13:bff2288c2c61 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 13:bff2288c2c61 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 13:bff2288c2c61 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 13:bff2288c2c61 13 * See the License for the specific language governing permissions and
embeddedartists 13:bff2288c2c61 14 * limitations under the License.
embeddedartists 13:bff2288c2c61 15 */
embeddedartists 5:f4de114c31c3 16
embeddedartists 5:f4de114c31c3 17 #ifndef SLIDESHOW_H
embeddedartists 5:f4de114c31c3 18 #define SLIDESHOW_H
embeddedartists 5:f4de114c31c3 19
embeddedartists 5:f4de114c31c3 20 #include "mbed.h"
embeddedartists 5:f4de114c31c3 21 #include "rtos.h"
embeddedartists 5:f4de114c31c3 22 #include "Image.h"
embeddedartists 5:f4de114c31c3 23 #include "Renderer.h"
embeddedartists 5:f4de114c31c3 24
embeddedartists 5:f4de114c31c3 25 /**
embeddedartists 14:647b1896ed84 26 * SlideShow engine.
embeddedartists 13:bff2288c2c61 27 *
embeddedartists 13:bff2288c2c61 28 * For information on how to use the SlideShow and some examples see
embeddedartists 13:bff2288c2c61 29 * https://developer.mbed.org/teams/Embedded-Artists/wiki/LPC4088DM-Using-the-SlideShow-Engine
embeddedartists 13:bff2288c2c61 30 *
embeddedartists 13:bff2288c2c61 31 * @code
embeddedartists 13:bff2288c2c61 32 * #include "mbed.h"
embeddedartists 13:bff2288c2c61 33 * #include "SlideShow.h"
embeddedartists 13:bff2288c2c61 34 * #include "Renderer.h"
embeddedartists 13:bff2288c2c61 35 *
embeddedartists 13:bff2288c2c61 36 * static void tRender(void const *args)
embeddedartists 13:bff2288c2c61 37 * {
embeddedartists 13:bff2288c2c61 38 * Renderer* s = (Renderer*)args;
embeddedartists 13:bff2288c2c61 39 * s->render();
embeddedartists 13:bff2288c2c61 40 * }
embeddedartists 13:bff2288c2c61 41 *
embeddedartists 13:bff2288c2c61 42 * int main(void) {
embeddedartists 13:bff2288c2c61 43 * // initialize the display
embeddedartists 13:bff2288c2c61 44 * ...
embeddedartists 13:bff2288c2c61 45 *
embeddedartists 13:bff2288c2c61 46 * // create the renderer that will handle the display
embeddedartists 13:bff2288c2c61 47 * Renderer r;
embeddedartists 13:bff2288c2c61 48 *
embeddedartists 13:bff2288c2c61 49 * // create the slideshow
embeddedartists 13:bff2288c2c61 50 * SlideShow s(&r);
embeddedartists 13:bff2288c2c61 51 *
embeddedartists 13:bff2288c2c61 52 * // parse and validate the script
embeddedartists 13:bff2288c2c61 53 * SlideShow::SlideShowError err = s.prepare("/mci/myscript.txt");
embeddedartists 13:bff2288c2c61 54 * if (err != SlideShow::Ok) {
embeddedartists 13:bff2288c2c61 55 * // handle error here
embeddedartists 13:bff2288c2c61 56 * }
embeddedartists 13:bff2288c2c61 57 *
embeddedartists 13:bff2288c2c61 58 * // Create the thread to handle the display
embeddedartists 13:bff2288c2c61 59 * Thread tr(tRender, &r, osPriorityHigh);
embeddedartists 13:bff2288c2c61 60 *
embeddedartists 13:bff2288c2c61 61 * // Run the slideshow
embeddedartists 13:bff2288c2c61 62 * s.run();
embeddedartists 13:bff2288c2c61 63 * }
embeddedartists 13:bff2288c2c61 64 * @endcode
embeddedartists 5:f4de114c31c3 65 */
embeddedartists 5:f4de114c31c3 66 class SlideShow {
embeddedartists 5:f4de114c31c3 67 public:
embeddedartists 5:f4de114c31c3 68
embeddedartists 5:f4de114c31c3 69 enum SlideShowError {
embeddedartists 5:f4de114c31c3 70 Ok,
embeddedartists 5:f4de114c31c3 71 InvalidScript,
embeddedartists 5:f4de114c31c3 72 RuntimeError,
embeddedartists 5:f4de114c31c3 73 UserAbort,
embeddedartists 5:f4de114c31c3 74 ScriptEnd,
embeddedartists 5:f4de114c31c3 75 OutOfMemory,
embeddedartists 5:f4de114c31c3 76 FileError,
embeddedartists 5:f4de114c31c3 77 };
embeddedartists 5:f4de114c31c3 78
embeddedartists 13:bff2288c2c61 79 /** A function that the script can call during execution
embeddedartists 13:bff2288c2c61 80 *
embeddedartists 13:bff2288c2c61 81 * @param calloutId identifier given in setCalloutHandler()
embeddedartists 13:bff2288c2c61 82 * @param ss the slideshow instance
embeddedartists 13:bff2288c2c61 83 * @param identifier parameter to the "callout" tag in the script
embeddedartists 13:bff2288c2c61 84 *
embeddedartists 13:bff2288c2c61 85 * @returns
embeddedartists 13:bff2288c2c61 86 * Ok on success
embeddedartists 13:bff2288c2c61 87 * One of the SlideShowError error codes on failure
embeddedartists 13:bff2288c2c61 88 */
embeddedartists 5:f4de114c31c3 89 typedef SlideShowError (*calloutFunc)(int calloutId, SlideShow* ss, int identifier);
embeddedartists 5:f4de114c31c3 90
embeddedartists 13:bff2288c2c61 91 /** Create a new slideshow
embeddedartists 13:bff2288c2c61 92 *
embeddedartists 13:bff2288c2c61 93 * @param r the renderer
embeddedartists 13:bff2288c2c61 94 * @param pathPrefix optional path to prepend to all paths in the script file
embeddedartists 13:bff2288c2c61 95 * @param xoff optional x coordinate to draw the slideshow at, default is 0
embeddedartists 13:bff2288c2c61 96 * @param yoff optional y coordinate to draw the slideshow at, default is 0
embeddedartists 13:bff2288c2c61 97 * @param layer optional z-order, higher layers are drawn on top of lower layers
embeddedartists 13:bff2288c2c61 98 * @param fileMutex optional mutex to prevent simultaneous access of the file system
embeddedartists 13:bff2288c2c61 99 */
embeddedartists 13:bff2288c2c61 100 SlideShow(Renderer* r, const char* pathPrefix=NULL, int xoff=0, int yoff=0, int layer=0, Mutex* fileMutex=NULL);
embeddedartists 5:f4de114c31c3 101 ~SlideShow();
alindvall 16:feb669462368 102
embeddedartists 13:bff2288c2c61 103 /** Parses the script file and prepares internal structures
embeddedartists 13:bff2288c2c61 104 *
embeddedartists 13:bff2288c2c61 105 * @param scriptFile the script with the slideshow
embeddedartists 13:bff2288c2c61 106 *
embeddedartists 13:bff2288c2c61 107 * @returns
embeddedartists 13:bff2288c2c61 108 * Ok on success
embeddedartists 13:bff2288c2c61 109 * One of the SlideShowError error codes on failure
embeddedartists 13:bff2288c2c61 110 */
embeddedartists 5:f4de114c31c3 111 SlideShowError prepare(const char* scriptFile);
embeddedartists 13:bff2288c2c61 112
embeddedartists 13:bff2288c2c61 113 /** Run the slideshow
embeddedartists 13:bff2288c2c61 114 *
embeddedartists 13:bff2288c2c61 115 * This function will run until the script ends. If the script has
embeddedartists 13:bff2288c2c61 116 * an eternal loop then this function will never return.
embeddedartists 13:bff2288c2c61 117 *
embeddedartists 13:bff2288c2c61 118 * @returns
embeddedartists 13:bff2288c2c61 119 * Ok on success
embeddedartists 13:bff2288c2c61 120 * One of the SlideShowError error codes on failure
embeddedartists 13:bff2288c2c61 121 */
embeddedartists 5:f4de114c31c3 122 SlideShowError run();
embeddedartists 13:bff2288c2c61 123
embeddedartists 13:bff2288c2c61 124 /** Register a function that the script can call.
embeddedartists 13:bff2288c2c61 125 *
embeddedartists 13:bff2288c2c61 126 * A callout function allows the use of the "callout" tag in a
embeddedartists 13:bff2288c2c61 127 * slideshow script to e.g. notify the system or to trigger
embeddedartists 13:bff2288c2c61 128 * something.
embeddedartists 13:bff2288c2c61 129 *
embeddedartists 13:bff2288c2c61 130 * There can only be one callout function.
embeddedartists 13:bff2288c2c61 131 */
embeddedartists 5:f4de114c31c3 132 void setCalloutHandler(calloutFunc func, int calloutId);
embeddedartists 13:bff2288c2c61 133
embeddedartists 13:bff2288c2c61 134 /** Decouples this SlideShow from the Renderer
embeddedartists 13:bff2288c2c61 135 */
embeddedartists 5:f4de114c31c3 136 void releaseScreen(void);
embeddedartists 13:bff2288c2c61 137
embeddedartists 13:bff2288c2c61 138 /** Stops the SlideShow.
embeddedartists 13:bff2288c2c61 139 *
embeddedartists 13:bff2288c2c61 140 * The SlideShow will be stopped at the next suitable time,
embeddedartists 13:bff2288c2c61 141 * typically before processing the next step in the script.
embeddedartists 13:bff2288c2c61 142 *
embeddedartists 13:bff2288c2c61 143 * This function is typically called upon an external trigger
embeddedartists 13:bff2288c2c61 144 * like the user pressing a button to end the slideshow.
embeddedartists 13:bff2288c2c61 145 */
embeddedartists 5:f4de114c31c3 146 void stop() { abortBeforeNextStep = true; }
embeddedartists 5:f4de114c31c3 147
embeddedartists 5:f4de114c31c3 148 private:
embeddedartists 5:f4de114c31c3 149
embeddedartists 5:f4de114c31c3 150 typedef uint16_t* image_t;
embeddedartists 5:f4de114c31c3 151
embeddedartists 5:f4de114c31c3 152 class Transition {
embeddedartists 5:f4de114c31c3 153 public:
embeddedartists 5:f4de114c31c3 154 typedef enum
embeddedartists 5:f4de114c31c3 155 {
embeddedartists 5:f4de114c31c3 156 None,
embeddedartists 5:f4de114c31c3 157 LeftRight,
embeddedartists 5:f4de114c31c3 158 DownUp,
embeddedartists 5:f4de114c31c3 159 TopDown,
embeddedartists 5:f4de114c31c3 160 Blinds,
embeddedartists 5:f4de114c31c3 161 Fade,
embeddedartists 5:f4de114c31c3 162 Unknown,
embeddedartists 5:f4de114c31c3 163 } Type;
embeddedartists 5:f4de114c31c3 164
embeddedartists 5:f4de114c31c3 165 Transition(const char* typeStr) {
embeddedartists 5:f4de114c31c3 166 if (typeStr == NULL) {
embeddedartists 5:f4de114c31c3 167 t = Unknown;
embeddedartists 5:f4de114c31c3 168 } else if (strcmp("none", typeStr) == 0) {
embeddedartists 5:f4de114c31c3 169 t = None;
embeddedartists 5:f4de114c31c3 170 } else if (strcmp("left-right", typeStr) == 0) {
embeddedartists 5:f4de114c31c3 171 t = LeftRight;
embeddedartists 5:f4de114c31c3 172 } else if (strcmp("down-up", typeStr) == 0) {
embeddedartists 5:f4de114c31c3 173 t = DownUp;
embeddedartists 5:f4de114c31c3 174 } else if (strcmp("top-down", typeStr) == 0) {
embeddedartists 5:f4de114c31c3 175 t = TopDown;
embeddedartists 5:f4de114c31c3 176 } else if (strcmp("blinds", typeStr) == 0) {
embeddedartists 5:f4de114c31c3 177 t = Blinds;
embeddedartists 5:f4de114c31c3 178 } else if (strcmp("fade", typeStr) == 0) {
embeddedartists 5:f4de114c31c3 179 t = Fade;
embeddedartists 5:f4de114c31c3 180 } else {
embeddedartists 5:f4de114c31c3 181 t = Unknown;
embeddedartists 5:f4de114c31c3 182 }
embeddedartists 5:f4de114c31c3 183 };
embeddedartists 5:f4de114c31c3 184 ~Transition();
embeddedartists 5:f4de114c31c3 185 SlideShowError execute(SlideShow* ss, Image::ImageData_t* CurrentImage, Image::ImageData_t* NewImage);
embeddedartists 5:f4de114c31c3 186 Type type() { return this->t; }
embeddedartists 5:f4de114c31c3 187 const char* typeString() {
embeddedartists 5:f4de114c31c3 188 switch(t) {
embeddedartists 5:f4de114c31c3 189 case None: return "No";
embeddedartists 5:f4de114c31c3 190 case LeftRight: return "Left to Right";
embeddedartists 5:f4de114c31c3 191 case TopDown: return "Top to Bottom";
embeddedartists 5:f4de114c31c3 192 case Blinds: return "Blinds";
embeddedartists 5:f4de114c31c3 193 case Unknown:
embeddedartists 5:f4de114c31c3 194 default:
embeddedartists 5:f4de114c31c3 195 return "Unknown";
embeddedartists 5:f4de114c31c3 196 }
embeddedartists 5:f4de114c31c3 197 };
embeddedartists 5:f4de114c31c3 198
embeddedartists 5:f4de114c31c3 199 private:
embeddedartists 5:f4de114c31c3 200 Type t;
embeddedartists 5:f4de114c31c3 201
embeddedartists 5:f4de114c31c3 202 enum Constants {
embeddedartists 5:f4de114c31c3 203 LeftRight_DelayMs = 100,
embeddedartists 5:f4de114c31c3 204 LeftRight_PixelsToSkip = 20,
embeddedartists 5:f4de114c31c3 205 DownUp_DelayMs = 100,
embeddedartists 5:f4de114c31c3 206 DownUp_LineSkip = 20,
embeddedartists 5:f4de114c31c3 207 TopDown_DelayMs = 100,
embeddedartists 5:f4de114c31c3 208 TopDown_LineSkip = 20,
embeddedartists 5:f4de114c31c3 209 Blinds_LinesPerBlock = 8,
embeddedartists 5:f4de114c31c3 210 Blinds_DelayMs = 20,
embeddedartists 5:f4de114c31c3 211 Blinds_BeamColor = 0xffff,
embeddedartists 5:f4de114c31c3 212 Blinds_BackColor = 0x0000,
embeddedartists 5:f4de114c31c3 213 Fade_DelayMs = 80,
embeddedartists 5:f4de114c31c3 214 };
embeddedartists 5:f4de114c31c3 215 };
embeddedartists 5:f4de114c31c3 216
embeddedartists 5:f4de114c31c3 217 class Command {
embeddedartists 5:f4de114c31c3 218 public:
embeddedartists 5:f4de114c31c3 219 typedef enum
embeddedartists 5:f4de114c31c3 220 {
embeddedartists 5:f4de114c31c3 221 Clear,
embeddedartists 5:f4de114c31c3 222 Goto,
embeddedartists 5:f4de114c31c3 223 LoadImage,
embeddedartists 5:f4de114c31c3 224 Show,
embeddedartists 5:f4de114c31c3 225 Wait,
embeddedartists 5:f4de114c31c3 226 Callout,
embeddedartists 5:f4de114c31c3 227 } Type;
embeddedartists 5:f4de114c31c3 228
embeddedartists 5:f4de114c31c3 229 Command(Type cmd, int info=0, Transition* t=NULL, const char* filename=NULL, const char* prefix=NULL) {
embeddedartists 5:f4de114c31c3 230 type = cmd;
embeddedartists 5:f4de114c31c3 231 information = info;
embeddedartists 5:f4de114c31c3 232 transition = t;
embeddedartists 5:f4de114c31c3 233 if (filename == NULL) {
embeddedartists 5:f4de114c31c3 234 fname = NULL;
embeddedartists 5:f4de114c31c3 235 } else {
embeddedartists 5:f4de114c31c3 236 fname = (char*)malloc(strlen(filename) + strlen(prefix) + 1); //+1 for null termination
embeddedartists 5:f4de114c31c3 237 if (fname != NULL) {
embeddedartists 5:f4de114c31c3 238 fname[0] = '\0';
embeddedartists 5:f4de114c31c3 239 strcat(fname, prefix);
embeddedartists 5:f4de114c31c3 240 strcat(fname, filename);
embeddedartists 5:f4de114c31c3 241 }
embeddedartists 5:f4de114c31c3 242 }
embeddedartists 5:f4de114c31c3 243 };
embeddedartists 5:f4de114c31c3 244 ~Command() {
embeddedartists 5:f4de114c31c3 245 if (fname != NULL) {
embeddedartists 5:f4de114c31c3 246 free(fname);
embeddedartists 5:f4de114c31c3 247 fname = NULL;
embeddedartists 5:f4de114c31c3 248 }
embeddedartists 5:f4de114c31c3 249 };
embeddedartists 5:f4de114c31c3 250 void updateInfo(int newInfo) { information = newInfo; }
embeddedartists 5:f4de114c31c3 251 int info() { return information; }
embeddedartists 5:f4de114c31c3 252 void print();
embeddedartists 5:f4de114c31c3 253 SlideShowError handle(SlideShow* ss, int* seqIdx, int* lastTime);
embeddedartists 5:f4de114c31c3 254 private:
embeddedartists 5:f4de114c31c3 255 Type type;
embeddedartists 5:f4de114c31c3 256 Transition* transition;
embeddedartists 5:f4de114c31c3 257 int information;
embeddedartists 5:f4de114c31c3 258 char* fname;
embeddedartists 5:f4de114c31c3 259 };
embeddedartists 5:f4de114c31c3 260
embeddedartists 5:f4de114c31c3 261
embeddedartists 5:f4de114c31c3 262 typedef enum
embeddedartists 5:f4de114c31c3 263 {
embeddedartists 5:f4de114c31c3 264 Bmp,
embeddedartists 5:f4de114c31c3 265 Raw
embeddedartists 5:f4de114c31c3 266 } FileFormat;
embeddedartists 5:f4de114c31c3 267
embeddedartists 5:f4de114c31c3 268 typedef struct
embeddedartists 5:f4de114c31c3 269 {
embeddedartists 5:f4de114c31c3 270 const char* pLabel;
embeddedartists 5:f4de114c31c3 271 int index;
embeddedartists 5:f4de114c31c3 272 } LabelInfo;
embeddedartists 5:f4de114c31c3 273
embeddedartists 5:f4de114c31c3 274 enum {
embeddedartists 5:f4de114c31c3 275 MaxNumPreparedImages = 100,
embeddedartists 5:f4de114c31c3 276 } Constants;
embeddedartists 5:f4de114c31c3 277
embeddedartists 5:f4de114c31c3 278 int screenWidth;
embeddedartists 5:f4de114c31c3 279 int screenHeight;
embeddedartists 5:f4de114c31c3 280 int screenPixels;
embeddedartists 5:f4de114c31c3 281 int screenBytes;
embeddedartists 5:f4de114c31c3 282 int drawXoff;
embeddedartists 5:f4de114c31c3 283 int drawYoff;
embeddedartists 5:f4de114c31c3 284
embeddedartists 5:f4de114c31c3 285 image_t ImageBackBuffer;
embeddedartists 5:f4de114c31c3 286 Command** Sequence;
embeddedartists 5:f4de114c31c3 287 int allocatedSequenceItems;
embeddedartists 5:f4de114c31c3 288 int usedSequenceItems;
embeddedartists 5:f4de114c31c3 289
embeddedartists 5:f4de114c31c3 290 const char* pathPrefix;
embeddedartists 5:f4de114c31c3 291
embeddedartists 5:f4de114c31c3 292 int CurrentSlot;
embeddedartists 5:f4de114c31c3 293 Image::ImageData_t PreparedImages[MaxNumPreparedImages];
embeddedartists 5:f4de114c31c3 294
embeddedartists 5:f4de114c31c3 295 Mutex* fileMutex;
embeddedartists 5:f4de114c31c3 296
embeddedartists 5:f4de114c31c3 297 Renderer* rend;
embeddedartists 5:f4de114c31c3 298 uint32_t rendHnd;
embeddedartists 5:f4de114c31c3 299 int layer;
embeddedartists 5:f4de114c31c3 300
embeddedartists 5:f4de114c31c3 301 calloutFunc callout;
embeddedartists 5:f4de114c31c3 302 int calloutId;
embeddedartists 5:f4de114c31c3 303
embeddedartists 5:f4de114c31c3 304 bool abortBeforeNextStep;
embeddedartists 5:f4de114c31c3 305
embeddedartists 5:f4de114c31c3 306 // Utilities
embeddedartists 5:f4de114c31c3 307 SlideShowError loadFile(const char* path, uint8_t** pData, uint32_t* pSize);
embeddedartists 5:f4de114c31c3 308
embeddedartists 5:f4de114c31c3 309 // Parsing functions
embeddedartists 5:f4de114c31c3 310 int getNextLine(char* pBuf, int* pOffset, char** ppLine);
embeddedartists 5:f4de114c31c3 311 int splitLine(char* pLine, char** ppPart1, char** ppPart2, char** ppPart3);
embeddedartists 5:f4de114c31c3 312 int findLabel(LabelInfo* pLabels, int numLabels, const char* pLabel);
embeddedartists 5:f4de114c31c3 313 void freeSequence(void);
embeddedartists 5:f4de114c31c3 314 SlideShowError expandSequence();
embeddedartists 5:f4de114c31c3 315 SlideShowError parseScript(char* pBuf);
embeddedartists 5:f4de114c31c3 316
embeddedartists 5:f4de114c31c3 317 // Command related functions
embeddedartists 5:f4de114c31c3 318 SlideShowError loadImage(const char* pFileName, int slot);
embeddedartists 5:f4de114c31c3 319 void delay(int lastTime, int millis);
embeddedartists 5:f4de114c31c3 320 SlideShowError runScript();
embeddedartists 5:f4de114c31c3 321
embeddedartists 5:f4de114c31c3 322 };
embeddedartists 5:f4de114c31c3 323
embeddedartists 5:f4de114c31c3 324 #endif