Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DMBasicGUI DMSupport
Demo running on several LPC4088 Display Modules on the Embedded World 2015 exhibition.
Information
To run the demo first drag-n-drop the to_sync.fs3 file to the MBED drive and then drag-n-drop the demo itself. This way both the file system and software are up to date.
This is what the launcher will look like:

AppStatus.cpp
- Committer:
- alindvall
- Date:
- 2015-02-19
- Revision:
- 0:6bd24cbb88a1
- Child:
- 1:1a01ef434a72
File content as of revision 0:6bd24cbb88a1:
/*
* 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 "EthernetInterface.h"
#include "AppStatus.h"
#include "lpc_swim_image.h"
#include "lpc_swim_font.h"
#include "image_data.h"
#include "BiosLoader.h"
/******************************************************************************
* Defines and typedefs
*****************************************************************************/
#define HEADER_X_OFF (20-5)
#define HEADER_Y_SPACING (20-5)
#define ITEM_CAPTION_X_OFF (40-15)
#define ITEM_CAPTION_Y_SPACING (swim_get_font_height(_win) + 5)
#define ITEM_VALUE_X_OFF (140-25)
#define COL3_OFF (230+70)
#define COL4 (COL3_OFF + ITEM_VALUE_X_OFF - 5)
#define BTN_WIDTH 40
#define BTN_HEIGHT 40
#define BTN_OFF 20
#define DEMO_VERSION "v0.9"
#define DEMO_BUILD_INFO __DATE__ " " __TIME__
#define DESCR(__res, __disp) \
(((__res) == ((__disp)->currentResolution())) ? ("Active") : (((__disp)->isSupported(__res)) ? ("Supported") : ("N/A")))
/******************************************************************************
* Global variables
*****************************************************************************/
extern EthernetInterface eth;
extern bool ethInitialized;
extern bool ethUsingDHCP;
/******************************************************************************
* Private functions
*****************************************************************************/
static void buttonClicked(uint32_t x)
{
bool* done = (bool*)x;
*done = true;
}
void AppStatus::draw()
{
// Prepare fullscreen
swim_window_open(_win,
_disp->width(), _disp->height(), // full size
(COLOR_T*)_fb,
0,0,_disp->width()-1, _disp->height()-1, // window position and size
1, // border
BLACK, WHITE, BLACK); // colors: pen, backgr, forgr
//swim_set_title(_win, "Application Status", BLACK);
swim_put_image_xy(_win, _bgImg.pixels, _bgImg.width, _bgImg.height, (_disp->width()-_bgImg.width)/2, 5+(_disp->height()-_bgImg.height)/2);
char buff[120];
// Column 1
swim_put_text_xy(_win, "Demo:", HEADER_X_OFF, HEADER_Y_SPACING);
swim_put_text_xy(_win, "Version:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
swim_put_text_xy(_win, "Build:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2);
swim_put_text_xy(_win, "Network:", HEADER_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
swim_put_text_xy(_win, "DHCP/Static:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
swim_put_text_xy(_win, "IP Address:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6);
swim_put_text_xy(_win, "NetMask:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 7);
swim_put_text_xy(_win, "Gateway:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8);
swim_put_text_xy(_win, "MAC Address:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 9);
char mac[6];
mbed_mac_address(mac);
snprintf(buff, 19, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
swim_put_text_xy(_win, buff, ITEM_CAPTION_X_OFF+10, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 10);
// Column 2
swim_put_text_xy(_win, DEMO_VERSION, ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
swim_put_text_xy(_win, DEMO_BUILD_INFO, ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2);
swim_put_text_xy(_win, ethUsingDHCP?"DHCP":"Static IP", ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
if (ethInitialized) {
swim_put_text_xy(_win, eth.getIPAddress(), ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6);
swim_put_text_xy(_win, eth.getNetworkMask(), ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 7);
swim_put_text_xy(_win, eth.getGateway(), ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8);
//swim_put_text_xy(_win, eth.getMACAddress(), ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
} else {
swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6);
swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 7);
swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8);
}
// Column 3
swim_put_text_xy(_win, "Display:", COL3_OFF+HEADER_X_OFF, HEADER_Y_SPACING);
swim_put_text_xy(_win, "Size:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
swim_put_text_xy(_win, "Landscape:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2);
swim_put_text_xy(_win, "Resolutions:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 3);
swim_put_text_xy(_win, "16bit rgb565:", COL3_OFF+ITEM_CAPTION_X_OFF+10, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
swim_put_text_xy(_win, "18bit rgb666:", COL3_OFF+ITEM_CAPTION_X_OFF+10, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
swim_put_text_xy(_win, "24bit rgb888:", COL3_OFF+ITEM_CAPTION_X_OFF+10, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6);
swim_put_text_xy(_win, "BIOS:", COL3_OFF+HEADER_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8);
//swim_put_text_xy(_win, "Info:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8);
//swim_put_text_xy(_win, "Board Type:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 9);
{
uint8_t type, maj, min, rev;
BiosLoader::instance().getBiosStats(type, maj, min, rev);
//snprintf(buff, 19, "v%u.%u.%u", maj, min, rev);
//swim_put_text_xy(_win, buff, COL4 -20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8);
//snprintf(buff, 19, "%u", type);
//swim_put_text_xy(_win, buff, COL4 -20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 9);
snprintf(buff, 25, "v%u.%u.%u (board type %u)", maj, min, rev, type);
swim_put_text_xy(_win, buff, COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 9);
}
// Column 4
sprintf(buff, "%d x %d pixels", _disp->width(), _disp->height());
swim_put_text_xy(_win, buff, COL4 -20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
sprintf(buff, "%s", _disp->landscape()?"YES":"NO");
swim_put_text_xy(_win, buff, COL4 -20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2);
//sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_16bit_rgb565)?"Supported":"N/A", _disp->currentResolution()==Display::Resolution_16bit_rgb565?" (Active)":"");
sprintf(buff, "%s", DESCR(Display::Resolution_16bit_rgb565, _disp));
swim_put_text_xy(_win, buff, COL4, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
//sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_18bit_rgb666)?"Supported":"N/A", _disp->currentResolution()==Display::Resolution_18bit_rgb666?" (Active)":"");
sprintf(buff, "%s", DESCR(Display::Resolution_18bit_rgb666, _disp));
swim_put_text_xy(_win, buff, COL4, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
//sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_24bit_rgb888)?"Supported":"N/A", _disp->currentResolution()==Display::Resolution_24bit_rgb888?" (Active)":"");
sprintf(buff, "%s", DESCR(Display::Resolution_24bit_rgb888, _disp));
swim_put_text_xy(_win, buff, COL4, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6);
_btn = new ImageButton(_win->fb, _win->xpmax - BTN_OFF - BTN_WIDTH, _win->ypmax - BTN_OFF - BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT);
_btn->loadImages(img_ok, img_size_ok);
_btn->draw();
}
/******************************************************************************
* Public functions
*****************************************************************************/
AppStatus::AppStatus() : _disp(NULL), _win(NULL), _fb(NULL), _btn(NULL)
{
_bgImg.pointerToFree = NULL;
_bgImg.pixels = NULL;
}
AppStatus::~AppStatus()
{
teardown();
}
bool AppStatus::setup()
{
RtosLog* log = DMBoard::instance().logger();
_disp = DMBoard::instance().display();
_win = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T));
_fb = _disp->allocateFramebuffer();
if (_win == NULL || _fb == NULL) {
log->printf("Failed to allocate memory for framebuffer\r\n");
return false;
}
if (Image::decode(img_about, img_size_about, Image::RES_16BIT, &_bgImg) != 0) {
log->printf("Failed to load background image\n");
return false;
}
return true;
}
void AppStatus::runToCompletion()
{
// Alternative 1: use the calling thread's context to run in
bool done = false;
draw();
_btn->setAction(buttonClicked, (uint32_t)&done);
void* oldFB = _disp->swapFramebuffer(_fb);
// Wait for touches, but the AppLauncher is already listening
// for new touch event and sends a signal to its thread which
// is the same as runs this function so it is enough to wait
// for that signal.
TouchPanel* touch = DMBoard::instance().touchPanel();
touch_coordinate_t coord;
while(!done) {
Thread::signal_wait(0x1);
if (touch->read(coord) == TouchPanel::TouchError_Ok) {
if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
_btn->draw();
}
}
}
// User has clicked the button, restore the original FB
_disp->swapFramebuffer(oldFB);
swim_window_close(_win);
}
bool AppStatus::teardown()
{
if (_win != NULL) {
free(_win);
_win = NULL;
}
if (_fb != NULL) {
free(_fb);
_fb = NULL;
}
if (_btn != NULL) {
delete _btn;
_btn = NULL;
}
if (_bgImg.pointerToFree != NULL) {
free(_bgImg.pointerToFree);
_bgImg.pointerToFree = NULL;
}
return true;
}