Basic swim GUI for LPC4088
Fork of DMBasicGUI by
Diff: SlideShow/AppSlideShow.cpp
- Revision:
- 11:265884fa7fdd
- Parent:
- 5:f4de114c31c3
- Child:
- 13:bff2288c2c61
diff -r 651861441108 -r 265884fa7fdd SlideShow/AppSlideShow.cpp --- a/SlideShow/AppSlideShow.cpp Mon Jan 26 10:06:58 2015 +0100 +++ b/SlideShow/AppSlideShow.cpp Tue Feb 17 10:34:13 2015 +0100 @@ -17,6 +17,7 @@ #include "mbed.h" #include "AppSlideShow.h" +#include "basic_image_data.h" /****************************************************************************** * Defines and typedefs @@ -24,6 +25,10 @@ #define TICKER_RESOLUTION_IN_MS 10 +#define BTN_WIDTH 40 +#define BTN_HEIGHT 40 +#define BTN_OFF 20 + /****************************************************************************** * Global variables *****************************************************************************/ @@ -44,12 +49,32 @@ msTicks += TICKER_RESOLUTION_IN_MS; } +static void buttonClicked(uint32_t x) +{ + bool* done = (bool*)x; + *done = true; +} + /****************************************************************************** * Public functions *****************************************************************************/ -AppSlideShow::AppSlideShow() : _fb(NULL), _disp(NULL), _show(NULL), _rend(NULL), _fileMutex() +AppSlideShow::AppSlideShow(const char* scriptFile, const char* pathPrefix, int xoff, int yoff) : + _fb(NULL), _disp(NULL), _show(NULL), _rend(NULL), + _fileMutex(), _btnDone(NULL), _btnRepeat(NULL), _script(NULL), _path(NULL) { + _script = (char*)malloc(strlen(scriptFile)+1); + if (_script != NULL) { + strcpy(_script, scriptFile); + } + if (pathPrefix != NULL) { + _path = (char*)malloc(strlen(pathPrefix)+1); + if (_path != NULL) { + strcpy(_path, pathPrefix); + } + } + _xoff = xoff; + _yoff = yoff; } AppSlideShow::~AppSlideShow() @@ -69,10 +94,15 @@ } else { memset(_fb, 0xff, _disp->fbSize()); _rend = new Renderer(); - _show = new SlideShow(_rend, "/mci/elec14", NULL, 150, 95, 1, &_fileMutex); - err = _show->prepare("/mci/elec14/ea_logo.txt"); + _show = new SlideShow(_rend, _path, NULL, _xoff, _yoff, 1, &_fileMutex); + err = _show->prepare(_script); } + _btnRepeat = new ImageButton((COLOR_T*)_fb, _disp->width() - 2*BTN_OFF - 2*BTN_WIDTH, _disp->height() - BTN_OFF - BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT); + _btnRepeat->loadImages(img_repeat, img_size_repeat); + _btnDone = new ImageButton((COLOR_T*)_fb, _disp->width() - BTN_OFF - BTN_WIDTH, _disp->height() - BTN_OFF - BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT); + _btnDone->loadImages(img_ok, img_size_ok); + return (err == SlideShow::Ok); } @@ -81,6 +111,12 @@ // Save existing frame buffer void* oldFB = _disp->swapFramebuffer(_fb); + bool done = false; + bool repeat = false; + _btnDone->setAction(buttonClicked, (uint32_t)&done); + _btnRepeat->setAction(buttonClicked, (uint32_t)&repeat); + + // Alternative 1: use the calling thread's context to run in Thread tr(tRender, _rend, osPriorityHigh); _rend->setRenderThread(&tr); @@ -89,8 +125,32 @@ RtosTimer rtosTimer(ticker, osTimerPeriodic); rtosTimer.start(TICKER_RESOLUTION_IN_MS); + // Wait for touches + TouchPanel* touch = DMBoard::instance().touchPanel(); + touch_coordinate_t coord; + + do { // Wait for slideshow to complete _show->run(); + + // Temporary ugly way to get current framebuffer + _btnDone->draw((COLOR_T*)LPC_LCD->UPBASE); + _btnRepeat->draw((COLOR_T*)LPC_LCD->UPBASE); + + done = repeat = false; + while (!done && !repeat) { + Thread::signal_wait(0x1); + if (touch->read(coord) == TouchPanel::TouchError_Ok) { + if (_btnDone->handle(coord.x, coord.y, coord.z > 0)) { + _btnDone->draw(); + } + if (_btnRepeat->handle(coord.x, coord.y, coord.z > 0)) { + _btnRepeat->draw(); + } + } + } + + } while(!done); tr.terminate(); @@ -112,6 +172,14 @@ free(_fb); _fb = NULL; } + if (_script != NULL) { + free(_script); + _script = NULL; + } + if (_path != NULL) { + free(_path); + _path = NULL; + } return true; }