Example using the application launcher.

Dependencies:   DMBasicGUI DMSupport

Example use of the AppLauncher class in the DMBasicGUI library.

This project is used in the TBD guide as a starting point when creating your own menu system. It can also be selected as a template when creating a new project based on the LPC4088 Display Module.

Information

This project works on both the 4.3" and 5" display modules.

This is what it looks like:

/media/uploads/embeddedartists/launcher_cap_000.png

If you click on the Something button:

/media/uploads/embeddedartists/launcher_cap_001.png

Files at this revision

API Documentation at this revision

Comitter:
alindvall
Date:
Fri Feb 20 12:24:05 2015 +0000
Child:
1:2b9c48157f2d
Commit message:
First version

Changed in this revision

AppTemplate.cpp Show annotated file Show diff for this revision Revisions of this file
AppTemplate.h Show annotated file Show diff for this revision Revisions of this file
DMBasicGUI.lib Show annotated file Show diff for this revision Revisions of this file
DMSupport.lib Show annotated file Show diff for this revision Revisions of this file
dm_board_config.h Show annotated file Show diff for this revision Revisions of this file
image_data.c Show annotated file Show diff for this revision Revisions of this file
image_data.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AppTemplate.cpp	Fri Feb 20 12:24:05 2015 +0000
@@ -0,0 +1,144 @@
+/*
+ *  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 "AppTemplate.h"
+#include "lpc_swim_font.h"
+#include "lpc_colors.h"
+#include "image_data.h"
+
+/******************************************************************************
+ * Defines and typedefs
+ *****************************************************************************/
+ 
+#define BTN_WIDTH  65
+#define BTN_HEIGHT 40
+#define BTN_OFF    20
+
+/******************************************************************************
+ * Local variables
+ *****************************************************************************/
+
+
+/******************************************************************************
+ * Private functions
+ *****************************************************************************/
+
+static void buttonClicked(uint32_t x)
+{
+  bool* done = (bool*)x;
+  *done = true;
+}
+
+void AppTemplate::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
+                   BLUE, WHITE, BLACK);                    // colors: pen, backgr, forgr
+    
+    // Show a message
+    swim_put_text_xy(_win, "Hello World!", 100, 100);
+    
+    // Create the OK button that will end this application
+    _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
+ *****************************************************************************/
+
+AppTemplate::AppTemplate() : _disp(NULL), _win(NULL), _fb(NULL), _btn(NULL)
+{
+}
+
+AppTemplate::~AppTemplate()
+{
+    teardown();
+}
+
+bool AppTemplate::setup()
+{
+    _disp = DMBoard::instance().display();
+    _win = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T));
+    _fb = _disp->allocateFramebuffer();
+
+    return (_win != NULL && _fb != NULL);
+}
+
+void AppTemplate::runToCompletion()
+{
+    // Draw on the frame buffer
+    draw();
+    
+    // Configure the button to call buttonClicked() when clicked
+    bool done = false;
+    _btn->setAction(buttonClicked, (uint32_t)&done);
+    
+    // Switch to "our" frame buffer, but save the old one so it can be 
+    // restored when we exit our application
+    void* oldFB = _disp->swapFramebuffer(_fb);
+    
+    TouchPanel* touch = DMBoard::instance().touchPanel();
+    touch_coordinate_t coord;
+    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(coord) == TouchPanel::TouchError_Ok) {
+        
+        // you can do something where with the touch event if you like
+        // for example
+        //
+        //  swim_put_circle(_win, coord.x, coord.y, 2, 1);
+        //
+        
+        
+        // See if the touch event effects the button
+        if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
+          _btn->draw();
+        }
+      }
+    }
+    
+    // User has clicked the button, restore the original frame buffer
+    _disp->swapFramebuffer(oldFB);
+    swim_window_close(_win);
+}
+
+bool AppTemplate::teardown()
+{
+    if (_win != NULL) {
+        free(_win);
+        _win = NULL;
+    }
+    if (_fb != NULL) {
+        free(_fb);
+        _fb = NULL;
+    }
+    if (_btn != NULL) {
+        delete _btn;
+        _btn = NULL;
+    }
+    return true;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AppTemplate.h	Fri Feb 20 12:24:05 2015 +0000
@@ -0,0 +1,48 @@
+/*
+ *  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.
+ */
+
+#ifndef APP_TEMPLATE_H
+#define APP_TEMPLATE_H
+
+#include "App.h"
+#include "DMBoard.h"
+#include "lpc_swim.h"
+#include "ImageButton.h"
+
+/**
+ * An App example. 
+ */
+class AppTemplate : public App {
+public:
+
+	AppTemplate();
+	virtual ~AppTemplate();
+
+    virtual bool setup();
+    virtual void runToCompletion();
+    virtual bool teardown();
+
+private:
+    Display* _disp;
+    SWIM_WINDOW_T* _win;
+    void* _fb;
+    ImageButton* _btn;
+
+    void draw();
+};
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DMBasicGUI.lib	Fri Feb 20 12:24:05 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Embedded-Artists/code/DMBasicGUI/#53601973f7eb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DMSupport.lib	Fri Feb 20 12:24:05 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Embedded-Artists/code/DMSupport/#8a0a99d54bf8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dm_board_config.h	Fri Feb 20 12:24:05 2015 +0000
@@ -0,0 +1,39 @@
+/*
+ *  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.
+ */
+
+#ifndef DM_BOARD_CONFIG_H
+#define DM_BOARD_CONFIG_H
+
+// Template to use for the project-specific settings. Copy this file to your project,
+// rename it to dm_board_config.h and uncomment the wanted features below:
+
+// #define DM_BOARD_USE_USB_DEVICE
+// #define DM_BOARD_USE_USB_HOST
+// #define DM_BOARD_USE_MCI_FS
+// #define DM_BOARD_USE_QSPI_FS
+// #define DM_BOARD_USE_QSPI
+#define DM_BOARD_USE_DISPLAY
+#define DM_BOARD_USE_TOUCH
+// #define DM_BOARD_USE_ETHERNET
+#define DM_BOARD_USE_FAST_UART
+// #define DM_BOARD_DISABLE_STANDARD_PRINTF
+// #define DM_BOARD_ENABLE_MEASSURING_PINS
+// #define DM_BOARD_BIOS_DEVELOPMENT
+// #define DM_BOARD_USE_REGISTRY
+#define DM_BOARD_USE_BUILTIN_IMAGES
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/image_data.c	Fri Feb 20 12:24:05 2015 +0000
@@ -0,0 +1,53 @@
+#define IMAGE_LOCATION
+//#define IMAGE_LOCATION  __attribute__((section("SPIFI_MEM"))) 
+
+const unsigned char img_empty[] = {
+	0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A,0x00,0x00,0x00,0x0D,0x49,0x48,0x44,0x52, 
+	0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x08,0x02,0x00,0x00,0x00,0x25,0x0B,0xE6, 
+	0x89,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0E,0xC4,0x00,0x00,0x0E, 
+	0xC4,0x01,0x95,0x2B,0x0E,0x1B,0x00,0x00,0x02,0x8B,0x49,0x44,0x41,0x54,0x78,0x9C, 
+	0xD5,0x9A,0xBF,0x79,0xC2,0x30,0x10,0xC5,0xA5,0x7C,0x19,0xC5,0x6E,0x18,0xC1,0x99, 
+	0xC0,0xA4,0xA1,0x4A,0x9B,0x8E,0x96,0x34,0xE9,0x32,0x04,0x29,0xCD,0x08,0xE9,0xC3, 
+	0x06,0x66,0x82,0x7C,0x14,0x81,0x5D,0x9C,0xC2,0xC1,0x58,0x3A,0xEB,0xCF,0xE9,0x4E, 
+	0x96,0xFC,0x3A,0x23,0x12,0xDE,0x4F,0xD2,0x3D,0x1F,0xC2,0x42,0x2C,0x5C,0xD2,0x3E, 
+	0xDC,0x75,0xDD,0x3C,0x3E,0xEC,0x92,0xD2,0xE8,0x73,0x7A,0x20,0x13,0xDF,0x9A,0x26, 
+	0x31,0x26,0x5E,0xCA,0xD3,0xFD,0x20,0x0D,0x43,0x07,0xC8,0xDC,0x7D,0xAF,0x31,0x83, 
+	0x02,0xB0,0x08,0xF7,0xBD,0x06,0x86,0xC7,0xE1,0x25,0x93,0x7B,0x4B,0x01,0xCD,0x23, 
+	0xFB,0xB4,0x4A,0xCB,0x9B,0x92,0x5B,0x1F,0x64,0xB1,0xF7,0x60,0xFA,0x1B,0x16,0xF7, 
+	0x75,0xD3,0x01,0x35,0x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01,0x38,0xF6,0x24,0xA6, 
+	0x06,0x78,0x85,0xCE,0x65,0x62,0x8C,0xB2,0x8B,0x21,0x97,0xD3,0x02,0x30,0xE5,0x72, 
+	0x07,0xC4,0x63,0xCF,0x4B,0xB8,0x1A,0x98,0x8E,0x51,0xB1,0x90,0x24,0x85,0x33,0x6B, 
+	0x8C,0xD1,0x79,0x17,0xC1,0x4B,0x93,0xEE,0xC5,0xF8,0x99,0xB9,0x49,0xD3,0x99,0x2C, 
+	0x85,0xC5,0x9B,0x03,0x20,0x5B,0x0D,0x33,0xBB,0xC8,0xA7,0x16,0x8D,0x8F,0x5D,0x8A, 
+	0x25,0x30,0x38,0x1E,0x7C,0xED,0x95,0x2D,0x06,0xAC,0x49,0x63,0x8D,0xE6,0xC6,0x90, 
+	0x49,0x9C,0xF0,0xEB,0x0F,0xB7,0x97,0x16,0xD2,0x38,0x59,0xDC,0x57,0x00,0x00,0x00, 
+	0x00,0x49,0x45,0x4E,0x44,0xAE,0x42,0x60,0x82
+};
+const unsigned int img_size_empty = sizeof(img_empty);
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/image_data.h	Fri Feb 20 12:24:05 2015 +0000
@@ -0,0 +1,6 @@
+#include "basic_image_data.h"
+
+extern const unsigned char img_empty[];
+extern const unsigned int img_size_empty;
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 20 12:24:05 2015 +0000
@@ -0,0 +1,104 @@
+/******************************************************************************
+ * Includes
+ *****************************************************************************/
+ 
+#include "mbed.h"
+#include "mbed_interface.h"
+#include "rtos.h"
+
+#include "DMBoard.h"
+
+#include "AppLauncher.h"
+#include "AppTouchCalibration.h"
+
+#include "AppTemplate.h"
+#include "image_data.h"
+
+
+/******************************************************************************
+ * Typedefs and defines
+ *****************************************************************************/
+
+typedef enum {
+    MyFirstApp,
+    
+    // Add an application ID here
+    
+    CalibrationApp =  AppLauncher::CalibrationApp,
+} myapps_t;
+
+/******************************************************************************
+ * Local functions
+ *****************************************************************************/
+
+static App* launchApp(uint32_t id)
+{
+  App* a = NULL;
+  switch ((myapps_t)id) {
+      case CalibrationApp:
+          a = new AppTouchCalibration();
+          break;
+      case MyFirstApp:
+          a = new AppTemplate();
+          break;
+      
+      // Create your application here
+      
+      default:
+          break;
+  }
+  return a;
+}
+
+void guiTask(void const* args)
+{
+  RtosLog* log = DMBoard::instance().logger();
+    
+  log->printf("guiTask started\n");
+  
+  AppLauncher launcher;
+    
+    
+  if (launcher.setup()) {
+    launcher.addImageButton(MyFirstApp, "Something", RED, img_empty, img_size_empty);
+    
+    // Add more buttons here
+      
+    launcher.setAppCreatorFunc(launchApp);
+    log->printf("Starting menu system\n");
+    launcher.runToCompletion();
+    launcher.teardown();
+  } else {
+    log->printf("Failed to prepare menu system\n");
+  }
+  
+  // Should never end up here  
+  mbed_die();
+}
+
+/******************************************************************************
+ * Main function
+ *****************************************************************************/
+int main()
+{
+  DMBoard::BoardError err;
+  DMBoard* board = &DMBoard::instance();
+  RtosLog* log = board->logger();
+  err = board->init();
+  if (err != DMBoard::Ok) {
+    log->printf("Failed to initialize the board, got error %d\r\n", err);
+    wait_ms(2000); // allow RtosLog to flush messages
+    mbed_die();
+  }
+  
+  log->printf("\n\n---\nApplication Launcher Example\nBuilt: " __DATE__ " at " __TIME__ "\n\n");
+  
+  Thread tGui(guiTask, NULL, osPriorityNormal, 8192);
+  
+  while(1) { 
+    // Wait forever (in 1h increments) to prevent the tGui
+    // thread from being garbage collected.
+    Thread::wait(3600*1000);
+  }
+}
+