Demo for Embedded World 2015.
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:
AppDraw.cpp
- Committer:
- embeddedartists
- Date:
- 2019-11-05
- Revision:
- 1:1a01ef434a72
- Parent:
- 0:6bd24cbb88a1
File content as of revision 1:1a01ef434a72:
/* * 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 "AppDraw.h" #include "lpc_swim_font.h" #include "lpc_colors.h" #include "image_data.h" /****************************************************************************** * Defines and typedefs *****************************************************************************/ #define BOX_SIDE 192 //256 #define BTN_WIDTH 65 #define BTN_HEIGHT 40 #define BTN_OFF 20 /****************************************************************************** * Local variables *****************************************************************************/ static const COLOR_T COLORS[] = { RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, BLACK, }; /****************************************************************************** * Private functions *****************************************************************************/ static void buttonClicked(uint32_t x) { bool* done = (bool*)x; *done = true; } void AppDraw::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 0, // border WHITE, WHITE, BLACK); // colors: pen, backgr, forgr _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 *****************************************************************************/ AppDraw::AppDraw() : _disp(NULL), _win(NULL), _fb(NULL), _btn(NULL) { } AppDraw::~AppDraw() { teardown(); } bool AppDraw::setup() { _disp = DMBoard::instance().display(); _win = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T)); _fb = _disp->allocateFramebuffer(); return (_win != NULL && _fb != NULL); } void AppDraw::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 TouchPanel* touch = DMBoard::instance().touchPanel(); bool ignore; int fingers = 0; touch->info(&ignore, &fingers, &ignore); if (fingers > MaxSupportedFingers) { fingers = MaxSupportedFingers; } while(!done) { // wait for a new touch signal (signal is sent from AppLauncher, // which listens for touch events) Thread::signal_wait(0x1); if (touch->read(_coords, fingers) == TouchPanel::TouchError_Ok) { for (int i = 0; i < fingers; i++) { if (_coords[i].z > 0) { _win->pen = COLORS[i]; swim_put_circle(_win, _coords[i].x, _coords[i].y, 2, 1); } } if (_btn->handle(_coords[0].x, _coords[0].y, _coords[0].z > 0)) { _btn->draw(); } } } // User has clicked the button, restore the original FB _disp->swapFramebuffer(oldFB); swim_window_close(_win); } bool AppDraw::teardown() { if (_win != NULL) { free(_win); _win = NULL; } if (_fb != NULL) { free(_fb); _fb = NULL; } if (_btn != NULL) { delete _btn; _btn = NULL; } return true; }