Example using the application launcher.
Dependencies: DMBasicGUI DMSupport
main.cpp
00001 /****************************************************************************** 00002 * Includes 00003 *****************************************************************************/ 00004 00005 #include "mbed.h" 00006 #include "mbed_interface.h" 00007 #include "rtos.h" 00008 00009 #include "DMBoard.h" 00010 00011 #include "AppLauncher.h" 00012 #include "AppTouchCalibration.h" 00013 00014 #include "AppTemplate.h" 00015 #include "image_data.h" 00016 00017 00018 /****************************************************************************** 00019 * Typedefs and defines 00020 *****************************************************************************/ 00021 00022 typedef enum { 00023 MyFirstApp, 00024 00025 // Add an application ID here 00026 00027 CalibrationApp = AppLauncher::CalibrationApp, 00028 } myapps_t; 00029 00030 /****************************************************************************** 00031 * Local functions 00032 *****************************************************************************/ 00033 00034 static App* launchApp(uint32_t id) 00035 { 00036 App* a = NULL; 00037 switch ((myapps_t)id) { 00038 case CalibrationApp: 00039 a = new AppTouchCalibration(); 00040 break; 00041 case MyFirstApp: 00042 a = new AppTemplate(); 00043 break; 00044 00045 // Create your application here 00046 00047 default: 00048 break; 00049 } 00050 return a; 00051 } 00052 00053 void guiTask(void) 00054 { 00055 RtosLog* log = DMBoard::instance().logger(); 00056 00057 log->printf("guiTask started\n"); 00058 00059 AppLauncher launcher; 00060 00061 00062 if (launcher.setup()) { 00063 launcher.addImageButton(MyFirstApp, "Something", RED, img_empty, img_size_empty); 00064 00065 // Add more buttons here 00066 00067 launcher.setAppCreatorFunc(launchApp); 00068 log->printf("Starting menu system\n"); 00069 launcher.runToCompletion(); 00070 launcher.teardown(); 00071 } else { 00072 log->printf("Failed to prepare menu system\n"); 00073 } 00074 00075 // Should never end up here 00076 mbed_die(); 00077 } 00078 00079 /****************************************************************************** 00080 * Main function 00081 *****************************************************************************/ 00082 int main() 00083 { 00084 DMBoard::BoardError err; 00085 DMBoard* board = &DMBoard::instance(); 00086 RtosLog* log = board->logger(); 00087 err = board->init(); 00088 if (err != DMBoard::Ok) { 00089 log->printf("Failed to initialize the board, got error %d\r\n", err); 00090 ThisThread::sleep_for(2000); // allow RtosLog to flush messages 00091 mbed_die(); 00092 } 00093 00094 log->printf("\n\n---\nApplication Launcher Example\nBuilt: " __DATE__ " at " __TIME__ "\n\n"); 00095 00096 Thread tGui(osPriorityNormal, 8192); 00097 tGui.start(guiTask); 00098 00099 while(1) { 00100 // Wait forever (in 1h increments) to prevent the tGui 00101 // thread from being garbage collected. 00102 ThisThread::sleep_for(3600*1000); 00103 } 00104 } 00105
Generated on Thu Jul 14 2022 03:32:21 by 1.7.2