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@5:f4de114c31c3, 2014-12-21 (annotated)
- Committer:
- embeddedartists
- Date:
- Sun Dec 21 13:53:07 2014 +0100
- Revision:
- 5:f4de114c31c3
- Child:
- 11:265884fa7fdd
- 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 | * 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 | 5:f4de114c31c3 | 20 | |
embeddedartists | 5:f4de114c31c3 | 21 | /****************************************************************************** |
embeddedartists | 5:f4de114c31c3 | 22 | * Defines and typedefs |
embeddedartists | 5:f4de114c31c3 | 23 | *****************************************************************************/ |
embeddedartists | 5:f4de114c31c3 | 24 | |
embeddedartists | 5:f4de114c31c3 | 25 | #define TICKER_RESOLUTION_IN_MS 10 |
embeddedartists | 5:f4de114c31c3 | 26 | |
embeddedartists | 5:f4de114c31c3 | 27 | /****************************************************************************** |
embeddedartists | 5:f4de114c31c3 | 28 | * Global variables |
embeddedartists | 5:f4de114c31c3 | 29 | *****************************************************************************/ |
embeddedartists | 5:f4de114c31c3 | 30 | |
embeddedartists | 5:f4de114c31c3 | 31 | volatile uint32_t msTicks = 0; |
embeddedartists | 5:f4de114c31c3 | 32 | |
embeddedartists | 5:f4de114c31c3 | 33 | /****************************************************************************** |
embeddedartists | 5:f4de114c31c3 | 34 | * Private functions |
embeddedartists | 5:f4de114c31c3 | 35 | *****************************************************************************/ |
embeddedartists | 5:f4de114c31c3 | 36 | |
embeddedartists | 5:f4de114c31c3 | 37 | static void tRender(void const *args) |
embeddedartists | 5:f4de114c31c3 | 38 | { |
embeddedartists | 5:f4de114c31c3 | 39 | Renderer* s = (Renderer*)args; |
embeddedartists | 5:f4de114c31c3 | 40 | s->render(); |
embeddedartists | 5:f4de114c31c3 | 41 | } |
embeddedartists | 5:f4de114c31c3 | 42 | |
embeddedartists | 5:f4de114c31c3 | 43 | static void ticker(void const *n) { |
embeddedartists | 5:f4de114c31c3 | 44 | msTicks += TICKER_RESOLUTION_IN_MS; |
embeddedartists | 5:f4de114c31c3 | 45 | } |
embeddedartists | 5:f4de114c31c3 | 46 | |
embeddedartists | 5:f4de114c31c3 | 47 | /****************************************************************************** |
embeddedartists | 5:f4de114c31c3 | 48 | * Public functions |
embeddedartists | 5:f4de114c31c3 | 49 | *****************************************************************************/ |
embeddedartists | 5:f4de114c31c3 | 50 | |
embeddedartists | 5:f4de114c31c3 | 51 | AppSlideShow::AppSlideShow() : _fb(NULL), _disp(NULL), _show(NULL), _rend(NULL), _fileMutex() |
embeddedartists | 5:f4de114c31c3 | 52 | { |
embeddedartists | 5:f4de114c31c3 | 53 | } |
embeddedartists | 5:f4de114c31c3 | 54 | |
embeddedartists | 5:f4de114c31c3 | 55 | AppSlideShow::~AppSlideShow() |
embeddedartists | 5:f4de114c31c3 | 56 | { |
embeddedartists | 5:f4de114c31c3 | 57 | teardown(); |
embeddedartists | 5:f4de114c31c3 | 58 | } |
embeddedartists | 5:f4de114c31c3 | 59 | |
embeddedartists | 5:f4de114c31c3 | 60 | bool AppSlideShow::setup() |
embeddedartists | 5:f4de114c31c3 | 61 | { |
embeddedartists | 5:f4de114c31c3 | 62 | SlideShow::SlideShowError err; |
embeddedartists | 5:f4de114c31c3 | 63 | |
embeddedartists | 5:f4de114c31c3 | 64 | _disp = DMBoard::instance().display(); |
embeddedartists | 5:f4de114c31c3 | 65 | |
embeddedartists | 5:f4de114c31c3 | 66 | _fb = _disp->allocateFramebuffer(); |
embeddedartists | 5:f4de114c31c3 | 67 | if (_fb == NULL) { |
embeddedartists | 5:f4de114c31c3 | 68 | err = SlideShow::OutOfMemory; |
embeddedartists | 5:f4de114c31c3 | 69 | } else { |
embeddedartists | 5:f4de114c31c3 | 70 | memset(_fb, 0xff, _disp->fbSize()); |
embeddedartists | 5:f4de114c31c3 | 71 | _rend = new Renderer(); |
embeddedartists | 5:f4de114c31c3 | 72 | _show = new SlideShow(_rend, "/mci/elec14", NULL, 150, 95, 1, &_fileMutex); |
embeddedartists | 5:f4de114c31c3 | 73 | err = _show->prepare("/mci/elec14/ea_logo.txt"); |
embeddedartists | 5:f4de114c31c3 | 74 | } |
embeddedartists | 5:f4de114c31c3 | 75 | |
embeddedartists | 5:f4de114c31c3 | 76 | return (err == SlideShow::Ok); |
embeddedartists | 5:f4de114c31c3 | 77 | } |
embeddedartists | 5:f4de114c31c3 | 78 | |
embeddedartists | 5:f4de114c31c3 | 79 | void AppSlideShow::runToCompletion() |
embeddedartists | 5:f4de114c31c3 | 80 | { |
embeddedartists | 5:f4de114c31c3 | 81 | // Save existing frame buffer |
embeddedartists | 5:f4de114c31c3 | 82 | void* oldFB = _disp->swapFramebuffer(_fb); |
embeddedartists | 5:f4de114c31c3 | 83 | |
embeddedartists | 5:f4de114c31c3 | 84 | // Alternative 1: use the calling thread's context to run in |
embeddedartists | 5:f4de114c31c3 | 85 | Thread tr(tRender, _rend, osPriorityHigh); |
embeddedartists | 5:f4de114c31c3 | 86 | _rend->setRenderThread(&tr); |
embeddedartists | 5:f4de114c31c3 | 87 | |
embeddedartists | 5:f4de114c31c3 | 88 | // Generate the millisecond ticks for the slideshow |
embeddedartists | 5:f4de114c31c3 | 89 | RtosTimer rtosTimer(ticker, osTimerPeriodic); |
embeddedartists | 5:f4de114c31c3 | 90 | rtosTimer.start(TICKER_RESOLUTION_IN_MS); |
embeddedartists | 5:f4de114c31c3 | 91 | |
embeddedartists | 5:f4de114c31c3 | 92 | // Wait for slideshow to complete |
embeddedartists | 5:f4de114c31c3 | 93 | _show->run(); |
embeddedartists | 5:f4de114c31c3 | 94 | |
embeddedartists | 5:f4de114c31c3 | 95 | tr.terminate(); |
embeddedartists | 5:f4de114c31c3 | 96 | |
embeddedartists | 5:f4de114c31c3 | 97 | // Restore the original FB |
embeddedartists | 5:f4de114c31c3 | 98 | _disp->swapFramebuffer(oldFB); |
embeddedartists | 5:f4de114c31c3 | 99 | } |
embeddedartists | 5:f4de114c31c3 | 100 | |
embeddedartists | 5:f4de114c31c3 | 101 | bool AppSlideShow::teardown() |
embeddedartists | 5:f4de114c31c3 | 102 | { |
embeddedartists | 5:f4de114c31c3 | 103 | if (_show != NULL) { |
embeddedartists | 5:f4de114c31c3 | 104 | free(_show); |
embeddedartists | 5:f4de114c31c3 | 105 | _show = NULL; |
embeddedartists | 5:f4de114c31c3 | 106 | } |
embeddedartists | 5:f4de114c31c3 | 107 | if (_rend != NULL) { |
embeddedartists | 5:f4de114c31c3 | 108 | free(_rend); |
embeddedartists | 5:f4de114c31c3 | 109 | _rend = NULL; |
embeddedartists | 5:f4de114c31c3 | 110 | } |
embeddedartists | 5:f4de114c31c3 | 111 | if (_fb != NULL) { |
embeddedartists | 5:f4de114c31c3 | 112 | free(_fb); |
embeddedartists | 5:f4de114c31c3 | 113 | _fb = NULL; |
embeddedartists | 5:f4de114c31c3 | 114 | } |
embeddedartists | 5:f4de114c31c3 | 115 | return true; |
embeddedartists | 5:f4de114c31c3 | 116 | } |
embeddedartists | 5:f4de114c31c3 | 117 | |
embeddedartists | 5:f4de114c31c3 | 118 |