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

SlideShow/AppSlideShow.cpp

Committer:
embeddedartists
Date:
2014-12-21
Revision:
5:f4de114c31c3
Child:
11:265884fa7fdd

File content as of revision 5:f4de114c31c3:

/*
 *  Copyright 2014 Embedded Artists AB
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */


#include "mbed.h"
#include "AppSlideShow.h"

/******************************************************************************
 * Defines and typedefs
 *****************************************************************************/

#define TICKER_RESOLUTION_IN_MS  10

/******************************************************************************
 * Global variables
 *****************************************************************************/

volatile uint32_t msTicks = 0;

/******************************************************************************
 * Private functions
 *****************************************************************************/

static void tRender(void const *args)
{
  Renderer* s = (Renderer*)args;
  s->render();
}

static void ticker(void const *n) {
  msTicks += TICKER_RESOLUTION_IN_MS;
}

/******************************************************************************
 * Public functions
 *****************************************************************************/

AppSlideShow::AppSlideShow() : _fb(NULL), _disp(NULL), _show(NULL), _rend(NULL), _fileMutex()
{
}

AppSlideShow::~AppSlideShow()
{
    teardown();
}

bool AppSlideShow::setup()
{
    SlideShow::SlideShowError err;
    
    _disp = DMBoard::instance().display();
    
    _fb = _disp->allocateFramebuffer();
    if (_fb == NULL) {
        err = SlideShow::OutOfMemory;
    } 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");
    }

    return (err == SlideShow::Ok);
}

void AppSlideShow::runToCompletion()
{
    // Save existing frame buffer
    void* oldFB = _disp->swapFramebuffer(_fb);
    
    // Alternative 1: use the calling thread's context to run in
    Thread tr(tRender, _rend, osPriorityHigh);
    _rend->setRenderThread(&tr);
    
    // Generate the millisecond ticks for the slideshow
    RtosTimer rtosTimer(ticker, osTimerPeriodic);
    rtosTimer.start(TICKER_RESOLUTION_IN_MS);    

    // Wait for slideshow to complete
    _show->run();
    
    tr.terminate();
    
    // Restore the original FB
    _disp->swapFramebuffer(oldFB);
}

bool AppSlideShow::teardown()
{
    if (_show != NULL) {
        free(_show);
        _show = NULL;
    }
    if (_rend != NULL) {
        free(_rend);
        _rend = NULL;
    }
    if (_fb != NULL) {
        free(_fb);
        _fb = NULL;
    }
    return true;
}