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/AppSlideShow.cpp@22:f0d00f29bfeb, 2019-11-04 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Nov 04 14:31:50 2019 +0000
- Revision:
- 22:f0d00f29bfeb
- Parent:
- 21:0038059e3a8f
More updates related to mbed OS 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 5:f4de114c31c3 | 1 | /* |
embeddedartists | 5:f4de114c31c3 | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 5:f4de114c31c3 | 3 | * |
embeddedartists | 5:f4de114c31c3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 5:f4de114c31c3 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 5:f4de114c31c3 | 6 | * You may obtain a copy of the License at |
embeddedartists | 5:f4de114c31c3 | 7 | * |
embeddedartists | 5:f4de114c31c3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 5:f4de114c31c3 | 9 | * |
embeddedartists | 5:f4de114c31c3 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 5:f4de114c31c3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 5:f4de114c31c3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 5:f4de114c31c3 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 5:f4de114c31c3 | 14 | * limitations under the License. |
embeddedartists | 5:f4de114c31c3 | 15 | */ |
embeddedartists | 5:f4de114c31c3 | 16 | |
embeddedartists | 5:f4de114c31c3 | 17 | |
embeddedartists | 5:f4de114c31c3 | 18 | #include "mbed.h" |
embeddedartists | 5:f4de114c31c3 | 19 | #include "AppSlideShow.h" |
embeddedartists | 17:6e2abf107800 | 20 | |
embeddedartists | 5:f4de114c31c3 | 21 | |
embeddedartists | 5:f4de114c31c3 | 22 | /****************************************************************************** |
embeddedartists | 5:f4de114c31c3 | 23 | * Defines and typedefs |
embeddedartists | 5:f4de114c31c3 | 24 | *****************************************************************************/ |
embeddedartists | 5:f4de114c31c3 | 25 | |
embeddedartists | 5:f4de114c31c3 | 26 | #define TICKER_RESOLUTION_IN_MS 10 |
embeddedartists | 5:f4de114c31c3 | 27 | |
embeddedartists | 11:265884fa7fdd | 28 | #define BTN_OFF 20 |
embeddedartists | 11:265884fa7fdd | 29 | |
embeddedartists | 5:f4de114c31c3 | 30 | /****************************************************************************** |
embeddedartists | 5:f4de114c31c3 | 31 | * Global variables |
embeddedartists | 5:f4de114c31c3 | 32 | *****************************************************************************/ |
embeddedartists | 5:f4de114c31c3 | 33 | |
embeddedartists | 5:f4de114c31c3 | 34 | volatile uint32_t msTicks = 0; |
embeddedartists | 5:f4de114c31c3 | 35 | |
embeddedartists | 5:f4de114c31c3 | 36 | /****************************************************************************** |
embeddedartists | 5:f4de114c31c3 | 37 | * Private functions |
embeddedartists | 5:f4de114c31c3 | 38 | *****************************************************************************/ |
embeddedartists | 5:f4de114c31c3 | 39 | |
embeddedartists | 5:f4de114c31c3 | 40 | static void tRender(void const *args) |
embeddedartists | 5:f4de114c31c3 | 41 | { |
embeddedartists | 5:f4de114c31c3 | 42 | Renderer* s = (Renderer*)args; |
embeddedartists | 5:f4de114c31c3 | 43 | s->render(); |
embeddedartists | 5:f4de114c31c3 | 44 | } |
embeddedartists | 5:f4de114c31c3 | 45 | |
embeddedartists | 5:f4de114c31c3 | 46 | static void ticker(void const *n) { |
embeddedartists | 5:f4de114c31c3 | 47 | msTicks += TICKER_RESOLUTION_IN_MS; |
embeddedartists | 5:f4de114c31c3 | 48 | } |
embeddedartists | 5:f4de114c31c3 | 49 | |
embeddedartists | 11:265884fa7fdd | 50 | static void buttonClicked(uint32_t x) |
embeddedartists | 11:265884fa7fdd | 51 | { |
embeddedartists | 11:265884fa7fdd | 52 | bool* done = (bool*)x; |
embeddedartists | 11:265884fa7fdd | 53 | *done = true; |
embeddedartists | 11:265884fa7fdd | 54 | } |
embeddedartists | 11:265884fa7fdd | 55 | |
embeddedartists | 5:f4de114c31c3 | 56 | /****************************************************************************** |
embeddedartists | 5:f4de114c31c3 | 57 | * Public functions |
embeddedartists | 5:f4de114c31c3 | 58 | *****************************************************************************/ |
embeddedartists | 5:f4de114c31c3 | 59 | |
embeddedartists | 11:265884fa7fdd | 60 | AppSlideShow::AppSlideShow(const char* scriptFile, const char* pathPrefix, int xoff, int yoff) : |
embeddedartists | 11:265884fa7fdd | 61 | _fb(NULL), _disp(NULL), _show(NULL), _rend(NULL), |
embeddedartists | 11:265884fa7fdd | 62 | _fileMutex(), _btnDone(NULL), _btnRepeat(NULL), _script(NULL), _path(NULL) |
embeddedartists | 5:f4de114c31c3 | 63 | { |
embeddedartists | 11:265884fa7fdd | 64 | _script = (char*)malloc(strlen(scriptFile)+1); |
embeddedartists | 11:265884fa7fdd | 65 | if (_script != NULL) { |
embeddedartists | 11:265884fa7fdd | 66 | strcpy(_script, scriptFile); |
embeddedartists | 11:265884fa7fdd | 67 | } |
embeddedartists | 11:265884fa7fdd | 68 | if (pathPrefix != NULL) { |
embeddedartists | 11:265884fa7fdd | 69 | _path = (char*)malloc(strlen(pathPrefix)+1); |
embeddedartists | 11:265884fa7fdd | 70 | if (_path != NULL) { |
embeddedartists | 11:265884fa7fdd | 71 | strcpy(_path, pathPrefix); |
embeddedartists | 11:265884fa7fdd | 72 | } |
embeddedartists | 11:265884fa7fdd | 73 | } |
embeddedartists | 11:265884fa7fdd | 74 | _xoff = xoff; |
embeddedartists | 11:265884fa7fdd | 75 | _yoff = yoff; |
embeddedartists | 5:f4de114c31c3 | 76 | } |
embeddedartists | 5:f4de114c31c3 | 77 | |
embeddedartists | 5:f4de114c31c3 | 78 | AppSlideShow::~AppSlideShow() |
embeddedartists | 5:f4de114c31c3 | 79 | { |
embeddedartists | 5:f4de114c31c3 | 80 | teardown(); |
embeddedartists | 5:f4de114c31c3 | 81 | } |
embeddedartists | 5:f4de114c31c3 | 82 | |
embeddedartists | 5:f4de114c31c3 | 83 | bool AppSlideShow::setup() |
embeddedartists | 5:f4de114c31c3 | 84 | { |
embeddedartists | 5:f4de114c31c3 | 85 | SlideShow::SlideShowError err; |
embeddedartists | 5:f4de114c31c3 | 86 | |
embeddedartists | 5:f4de114c31c3 | 87 | _disp = DMBoard::instance().display(); |
embeddedartists | 5:f4de114c31c3 | 88 | |
embeddedartists | 5:f4de114c31c3 | 89 | _fb = _disp->allocateFramebuffer(); |
embeddedartists | 5:f4de114c31c3 | 90 | if (_fb == NULL) { |
embeddedartists | 5:f4de114c31c3 | 91 | err = SlideShow::OutOfMemory; |
embeddedartists | 5:f4de114c31c3 | 92 | } else { |
embeddedartists | 5:f4de114c31c3 | 93 | memset(_fb, 0xff, _disp->fbSize()); |
embeddedartists | 5:f4de114c31c3 | 94 | _rend = new Renderer(); |
embeddedartists | 13:bff2288c2c61 | 95 | _show = new SlideShow(_rend, _path, _xoff, _yoff, 1, &_fileMutex); |
embeddedartists | 11:265884fa7fdd | 96 | err = _show->prepare(_script); |
embeddedartists | 5:f4de114c31c3 | 97 | } |
embeddedartists | 5:f4de114c31c3 | 98 | |
embeddedartists | 17:6e2abf107800 | 99 | _btnRepeat = new ImageButton((COLOR_T*)_fb, _disp->width() - 2*BTN_OFF - _resOk->width() - _resRepeat->width(), _disp->height() - BTN_OFF - _resRepeat->height(), _resRepeat->width(), _resRepeat->height()); |
embeddedartists | 17:6e2abf107800 | 100 | _btnRepeat->loadImages(_resRepeat); |
embeddedartists | 17:6e2abf107800 | 101 | _btnDone = new ImageButton((COLOR_T*)_fb, _disp->width() - BTN_OFF - _resOk->width(), _disp->height() - BTN_OFF - _resOk->height(), _resOk->width(), _resOk->height()); |
embeddedartists | 17:6e2abf107800 | 102 | _btnDone->loadImages(_resOk); |
embeddedartists | 5:f4de114c31c3 | 103 | return (err == SlideShow::Ok); |
embeddedartists | 5:f4de114c31c3 | 104 | } |
embeddedartists | 5:f4de114c31c3 | 105 | |
embeddedartists | 5:f4de114c31c3 | 106 | void AppSlideShow::runToCompletion() |
embeddedartists | 5:f4de114c31c3 | 107 | { |
embeddedartists | 5:f4de114c31c3 | 108 | // Save existing frame buffer |
embeddedartists | 5:f4de114c31c3 | 109 | void* oldFB = _disp->swapFramebuffer(_fb); |
embeddedartists | 5:f4de114c31c3 | 110 | |
embeddedartists | 11:265884fa7fdd | 111 | bool done = false; |
embeddedartists | 11:265884fa7fdd | 112 | bool repeat = false; |
embeddedartists | 11:265884fa7fdd | 113 | _btnDone->setAction(buttonClicked, (uint32_t)&done); |
embeddedartists | 11:265884fa7fdd | 114 | _btnRepeat->setAction(buttonClicked, (uint32_t)&repeat); |
embeddedartists | 11:265884fa7fdd | 115 | |
embeddedartists | 11:265884fa7fdd | 116 | |
embeddedartists | 5:f4de114c31c3 | 117 | // Alternative 1: use the calling thread's context to run in |
embeddedartists | 21:0038059e3a8f | 118 | //Thread tr(tRender, _rend, osPriorityHigh); |
embeddedartists | 21:0038059e3a8f | 119 | Thread tr; |
embeddedartists | 21:0038059e3a8f | 120 | tr.start(callback(tRender, _rend)); |
embeddedartists | 5:f4de114c31c3 | 121 | |
embeddedartists | 5:f4de114c31c3 | 122 | // Generate the millisecond ticks for the slideshow |
embeddedartists | 21:0038059e3a8f | 123 | //RtosTimer rtosTimer(ticker, osTimerPeriodic); |
embeddedartists | 21:0038059e3a8f | 124 | //rtosTimer.start(TICKER_RESOLUTION_IN_MS); |
embeddedartists | 21:0038059e3a8f | 125 | EventQueue rtosTimer(4*EVENTS_EVENT_SIZE); |
embeddedartists | 21:0038059e3a8f | 126 | rtosTimer.call_every(TICKER_RESOLUTION_IN_MS, ticker, &done); |
embeddedartists | 21:0038059e3a8f | 127 | rtosTimer.dispatch(0); |
embeddedartists | 5:f4de114c31c3 | 128 | |
embeddedartists | 11:265884fa7fdd | 129 | // Wait for touches |
embeddedartists | 11:265884fa7fdd | 130 | TouchPanel* touch = DMBoard::instance().touchPanel(); |
embeddedartists | 11:265884fa7fdd | 131 | touch_coordinate_t coord; |
embeddedartists | 11:265884fa7fdd | 132 | |
embeddedartists | 11:265884fa7fdd | 133 | do { |
embeddedartists | 5:f4de114c31c3 | 134 | // Wait for slideshow to complete |
embeddedartists | 5:f4de114c31c3 | 135 | _show->run(); |
embeddedartists | 11:265884fa7fdd | 136 | |
embeddedartists | 11:265884fa7fdd | 137 | // Temporary ugly way to get current framebuffer |
embeddedartists | 11:265884fa7fdd | 138 | _btnDone->draw((COLOR_T*)LPC_LCD->UPBASE); |
embeddedartists | 11:265884fa7fdd | 139 | _btnRepeat->draw((COLOR_T*)LPC_LCD->UPBASE); |
embeddedartists | 11:265884fa7fdd | 140 | |
embeddedartists | 11:265884fa7fdd | 141 | done = repeat = false; |
embeddedartists | 11:265884fa7fdd | 142 | while (!done && !repeat) { |
embeddedartists | 21:0038059e3a8f | 143 | ThisThread::flags_wait_any(0x1); |
embeddedartists | 11:265884fa7fdd | 144 | if (touch->read(coord) == TouchPanel::TouchError_Ok) { |
embeddedartists | 11:265884fa7fdd | 145 | if (_btnDone->handle(coord.x, coord.y, coord.z > 0)) { |
embeddedartists | 11:265884fa7fdd | 146 | _btnDone->draw(); |
embeddedartists | 11:265884fa7fdd | 147 | } |
embeddedartists | 11:265884fa7fdd | 148 | if (_btnRepeat->handle(coord.x, coord.y, coord.z > 0)) { |
embeddedartists | 11:265884fa7fdd | 149 | _btnRepeat->draw(); |
embeddedartists | 11:265884fa7fdd | 150 | } |
embeddedartists | 11:265884fa7fdd | 151 | } |
embeddedartists | 11:265884fa7fdd | 152 | } |
embeddedartists | 11:265884fa7fdd | 153 | |
embeddedartists | 11:265884fa7fdd | 154 | } while(!done); |
embeddedartists | 5:f4de114c31c3 | 155 | |
embeddedartists | 5:f4de114c31c3 | 156 | tr.terminate(); |
embeddedartists | 5:f4de114c31c3 | 157 | |
embeddedartists | 5:f4de114c31c3 | 158 | // Restore the original FB |
embeddedartists | 5:f4de114c31c3 | 159 | _disp->swapFramebuffer(oldFB); |
embeddedartists | 5:f4de114c31c3 | 160 | } |
embeddedartists | 5:f4de114c31c3 | 161 | |
embeddedartists | 5:f4de114c31c3 | 162 | bool AppSlideShow::teardown() |
embeddedartists | 5:f4de114c31c3 | 163 | { |
embeddedartists | 5:f4de114c31c3 | 164 | if (_show != NULL) { |
embeddedartists | 5:f4de114c31c3 | 165 | free(_show); |
embeddedartists | 5:f4de114c31c3 | 166 | _show = NULL; |
embeddedartists | 5:f4de114c31c3 | 167 | } |
embeddedartists | 5:f4de114c31c3 | 168 | if (_rend != NULL) { |
embeddedartists | 5:f4de114c31c3 | 169 | free(_rend); |
embeddedartists | 5:f4de114c31c3 | 170 | _rend = NULL; |
embeddedartists | 5:f4de114c31c3 | 171 | } |
embeddedartists | 5:f4de114c31c3 | 172 | if (_fb != NULL) { |
embeddedartists | 5:f4de114c31c3 | 173 | free(_fb); |
embeddedartists | 5:f4de114c31c3 | 174 | _fb = NULL; |
embeddedartists | 5:f4de114c31c3 | 175 | } |
embeddedartists | 11:265884fa7fdd | 176 | if (_script != NULL) { |
embeddedartists | 11:265884fa7fdd | 177 | free(_script); |
embeddedartists | 11:265884fa7fdd | 178 | _script = NULL; |
embeddedartists | 11:265884fa7fdd | 179 | } |
embeddedartists | 11:265884fa7fdd | 180 | if (_path != NULL) { |
embeddedartists | 11:265884fa7fdd | 181 | free(_path); |
embeddedartists | 11:265884fa7fdd | 182 | _path = NULL; |
embeddedartists | 11:265884fa7fdd | 183 | } |
embeddedartists | 5:f4de114c31c3 | 184 | return true; |
embeddedartists | 5:f4de114c31c3 | 185 | } |
embeddedartists | 5:f4de114c31c3 | 186 | |
embeddedartists | 5:f4de114c31c3 | 187 | |
embeddedartists | 17:6e2abf107800 | 188 | void AppSlideShow::addResource(Resources id, Resource* res) |
embeddedartists | 17:6e2abf107800 | 189 | { |
embeddedartists | 17:6e2abf107800 | 190 | if (id == Resource_Ok_button) { |
embeddedartists | 17:6e2abf107800 | 191 | _resOk = res; |
embeddedartists | 17:6e2abf107800 | 192 | } else { |
embeddedartists | 17:6e2abf107800 | 193 | _resRepeat = res; |
embeddedartists | 17:6e2abf107800 | 194 | } |
embeddedartists | 17:6e2abf107800 | 195 | } |
embeddedartists | 17:6e2abf107800 | 196 |