Example using the support package for LPC4088 DisplayModule

Dependencies:   DMBasicGUI DMSupport

Example using a lot of the features in the software package for the LPC4088 Display Module.

This project can be selected as a template when creating a new project based on the LPC4088 Display Module.

Information

This project works on the 4.3" display modules.

Some of the apps works on the 5" display modules. The ImageViewer and Slideshow app will show the images distorted as it does not take the resolution into consideration.

Information

The USB Status app is disabled. The Image viewer looks for images in the root of SD cards, USB memory sticks or the file system on the QSPI flash. The Slideshow app expects to find a slideshow script in /mci/elec14/ea_logo.txt.

This is what it looks like on the 4.3" display:

/media/uploads/embeddedartists/everything_cap_000.png /media/uploads/embeddedartists/everything_cap_001.png /media/uploads/embeddedartists/everything_cap_003.png /media/uploads/embeddedartists/everything_cap_004.png /media/uploads/embeddedartists/everything_cap_006.png /media/uploads/embeddedartists/everything_cap_008.png

Committer:
embeddedartists
Date:
Sun Dec 21 13:55:46 2014 +0100
Revision:
7:c8bef6a4b019
Parent:
6:8007691f78dc
Child:
11:4830c7689843
- Moved AppLauncher initialization to main.cpp
- Added image file with launcher icons (instead of loading from USB)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:dfad71908d59 1 /******************************************************************************
embeddedartists 0:dfad71908d59 2 * Includes
embeddedartists 0:dfad71908d59 3 *****************************************************************************/
embeddedartists 0:dfad71908d59 4
embeddedartists 0:dfad71908d59 5 #include "mbed.h"
embeddedartists 0:dfad71908d59 6 #include "mbed_interface.h"
embeddedartists 0:dfad71908d59 7 #include "rtos.h"
embeddedartists 0:dfad71908d59 8 #include "EthernetInterface.h"
embeddedartists 0:dfad71908d59 9 #include "HTTPServer.h"
embeddedartists 0:dfad71908d59 10 #include "mbed_rpc.h"
embeddedartists 0:dfad71908d59 11 #include "USBHostMSD.h"
embeddedartists 1:15ea03d72dd7 12 #include "USBHostMouse.h"
embeddedartists 1:15ea03d72dd7 13 #include "USBHostKeyboard.h"
embeddedartists 0:dfad71908d59 14
embeddedartists 0:dfad71908d59 15 #include "DMBoard.h"
embeddedartists 0:dfad71908d59 16
embeddedartists 2:070e9c054796 17 #include "AppLauncher.h"
embeddedartists 2:070e9c054796 18 #include "meas.h"
embeddedartists 2:070e9c054796 19
embeddedartists 7:c8bef6a4b019 20 #include "AppSettings.h"
embeddedartists 7:c8bef6a4b019 21 #include "AppTouchCalibration.h"
embeddedartists 7:c8bef6a4b019 22 #include "AppColorPicker.h"
embeddedartists 7:c8bef6a4b019 23 #include "AppImageViewer.h"
embeddedartists 7:c8bef6a4b019 24 #include "AppSlideShow.h"
embeddedartists 7:c8bef6a4b019 25 #include "image_data.h"
embeddedartists 7:c8bef6a4b019 26
embeddedartists 2:070e9c054796 27
embeddedartists 0:dfad71908d59 28 /******************************************************************************
embeddedartists 0:dfad71908d59 29 * Typedefs and defines
embeddedartists 0:dfad71908d59 30 *****************************************************************************/
embeddedartists 0:dfad71908d59 31
embeddedartists 0:dfad71908d59 32 /* Number of colors in 565 mode */
embeddedartists 0:dfad71908d59 33 #define NUM_COLORS 65536
embeddedartists 0:dfad71908d59 34 /* Number of red colors in 565 mode */
embeddedartists 0:dfad71908d59 35 #define RED_COLORS 0x20
embeddedartists 0:dfad71908d59 36 /* Number of green colors in 565 mode */
embeddedartists 0:dfad71908d59 37 #define GREEN_COLORS 0x40
embeddedartists 0:dfad71908d59 38 /* Number of blue colors in 565 mode */
embeddedartists 0:dfad71908d59 39 #define BLUE_COLORS 0x20
embeddedartists 0:dfad71908d59 40 /* Black color, 565 mode */
embeddedartists 0:dfad71908d59 41 #define BLACK 0x0000
embeddedartists 0:dfad71908d59 42
embeddedartists 0:dfad71908d59 43 /******************************************************************************
embeddedartists 0:dfad71908d59 44 * Local variables
embeddedartists 0:dfad71908d59 45 *****************************************************************************/
embeddedartists 0:dfad71908d59 46
embeddedartists 1:15ea03d72dd7 47 Mutex usbInitGuard;
embeddedartists 0:dfad71908d59 48
embeddedartists 0:dfad71908d59 49 /******************************************************************************
embeddedartists 0:dfad71908d59 50 * Global variables
embeddedartists 0:dfad71908d59 51 *****************************************************************************/
embeddedartists 0:dfad71908d59 52
embeddedartists 2:070e9c054796 53 EthernetInterface eth;
embeddedartists 2:070e9c054796 54 bool ethInitialized = false;
embeddedartists 2:070e9c054796 55 bool ethUsingDHCP = true;
embeddedartists 4:37a60b9bdb99 56 bool haveUSBMSD = false;
embeddedartists 2:070e9c054796 57
embeddedartists 0:dfad71908d59 58 /******************************************************************************
embeddedartists 0:dfad71908d59 59 * Local functions
embeddedartists 0:dfad71908d59 60 *****************************************************************************/
embeddedartists 0:dfad71908d59 61
embeddedartists 0:dfad71908d59 62 void aliveTask(void const* args)
embeddedartists 0:dfad71908d59 63 {
embeddedartists 0:dfad71908d59 64 DMBoard* board = &DMBoard::instance();
embeddedartists 0:dfad71908d59 65
embeddedartists 0:dfad71908d59 66 while(true)
embeddedartists 0:dfad71908d59 67 {
embeddedartists 0:dfad71908d59 68 board->setLED(DMBoard::Led4, false);
embeddedartists 0:dfad71908d59 69 board->setLED(DMBoard::Led1, true);
embeddedartists 0:dfad71908d59 70 Thread::wait(300);
embeddedartists 0:dfad71908d59 71 board->setLED(DMBoard::Led1, false);
embeddedartists 0:dfad71908d59 72 board->setLED(DMBoard::Led2, true);
embeddedartists 0:dfad71908d59 73 Thread::wait(300);
embeddedartists 0:dfad71908d59 74 board->setLED(DMBoard::Led2, false);
embeddedartists 0:dfad71908d59 75 board->setLED(DMBoard::Led3, true);
embeddedartists 0:dfad71908d59 76 Thread::wait(300);
embeddedartists 0:dfad71908d59 77 board->setLED(DMBoard::Led3, false);
embeddedartists 0:dfad71908d59 78 board->setLED(DMBoard::Led4, true);
embeddedartists 0:dfad71908d59 79 Thread::wait(300);
embeddedartists 0:dfad71908d59 80 }
embeddedartists 0:dfad71908d59 81 }
embeddedartists 0:dfad71908d59 82
embeddedartists 0:dfad71908d59 83 /*
embeddedartists 0:dfad71908d59 84 * Reads the /message.txt file from the file system and prints the content
embeddedartists 0:dfad71908d59 85 */
embeddedartists 0:dfad71908d59 86 void readMessageFile(const char* prefix)
embeddedartists 0:dfad71908d59 87 {
embeddedartists 0:dfad71908d59 88 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 89 log->printf("%sTesting to read from USB\n", prefix);
embeddedartists 0:dfad71908d59 90
embeddedartists 1:15ea03d72dd7 91 FILE * fp = fopen("/usb/message.txt", "r");
embeddedartists 0:dfad71908d59 92
embeddedartists 0:dfad71908d59 93 if (fp != NULL) {
embeddedartists 0:dfad71908d59 94 uint8_t* buff = (uint8_t*)malloc(1024+1);
embeddedartists 0:dfad71908d59 95 if (buff == NULL) {
embeddedartists 0:dfad71908d59 96 log->printf("%sFailed to allocate memory for test\n", prefix);
embeddedartists 0:dfad71908d59 97 } else {
embeddedartists 0:dfad71908d59 98 int num = fread(buff, 1, 1024, fp);
embeddedartists 0:dfad71908d59 99 if (num <= 0) {
embeddedartists 0:dfad71908d59 100 log->printf("%sUnable to read file, got %d as result\n", prefix, num);
embeddedartists 0:dfad71908d59 101 } else if (num < 1024) {
embeddedartists 3:4301d34173cf 102 log->printf("%sHave read all %d bytes in the file:\n---\n", prefix, num);
embeddedartists 0:dfad71908d59 103 buff[num] = '\0';
embeddedartists 0:dfad71908d59 104 log->printf((const char*)buff);
embeddedartists 3:4301d34173cf 105 log->printf("\n---\n");
embeddedartists 0:dfad71908d59 106 } else {
embeddedartists 0:dfad71908d59 107 log->printf("%sHave read %d bytes with more to read\n", prefix, num);
embeddedartists 0:dfad71908d59 108 }
embeddedartists 0:dfad71908d59 109 free(buff);
embeddedartists 0:dfad71908d59 110 }
embeddedartists 0:dfad71908d59 111 fclose(fp);
embeddedartists 0:dfad71908d59 112 } else {
embeddedartists 0:dfad71908d59 113 log->printf("%sFILE == NULL\r\n", prefix);
embeddedartists 0:dfad71908d59 114 }
embeddedartists 0:dfad71908d59 115 }
embeddedartists 0:dfad71908d59 116
embeddedartists 0:dfad71908d59 117
embeddedartists 0:dfad71908d59 118 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 2:070e9c054796 119
embeddedartists 7:c8bef6a4b019 120 typedef enum {
embeddedartists 7:c8bef6a4b019 121 ColorPickerApp,
embeddedartists 7:c8bef6a4b019 122 ImageViewerApp,
embeddedartists 7:c8bef6a4b019 123 SlideshowApp,
embeddedartists 7:c8bef6a4b019 124 SettingsApp,
embeddedartists 7:c8bef6a4b019 125 TouchTestApp,
embeddedartists 7:c8bef6a4b019 126 CalibrationApp = AppLauncher::CalibrationApp,
embeddedartists 7:c8bef6a4b019 127 Placeholder,
embeddedartists 7:c8bef6a4b019 128 } myapps_t;
embeddedartists 7:c8bef6a4b019 129
embeddedartists 7:c8bef6a4b019 130 static App* launchApp(uint32_t id)
embeddedartists 7:c8bef6a4b019 131 {
embeddedartists 7:c8bef6a4b019 132 App* a = NULL;
embeddedartists 7:c8bef6a4b019 133 switch ((myapps_t)id) {
embeddedartists 7:c8bef6a4b019 134 case CalibrationApp:
embeddedartists 7:c8bef6a4b019 135 a = new AppTouchCalibration();
embeddedartists 7:c8bef6a4b019 136 break;
embeddedartists 7:c8bef6a4b019 137 case SettingsApp:
embeddedartists 7:c8bef6a4b019 138 a = new AppSettings();
embeddedartists 7:c8bef6a4b019 139 break;
embeddedartists 7:c8bef6a4b019 140 case ColorPickerApp:
embeddedartists 7:c8bef6a4b019 141 a = new AppColorPicker();
embeddedartists 7:c8bef6a4b019 142 break;
embeddedartists 7:c8bef6a4b019 143 case ImageViewerApp:
embeddedartists 7:c8bef6a4b019 144 a = new AppImageViewer();
embeddedartists 7:c8bef6a4b019 145 break;
embeddedartists 7:c8bef6a4b019 146 case SlideshowApp:
embeddedartists 7:c8bef6a4b019 147 a = new AppSlideShow();
embeddedartists 7:c8bef6a4b019 148 break;
embeddedartists 7:c8bef6a4b019 149 default:
embeddedartists 7:c8bef6a4b019 150 break;
embeddedartists 7:c8bef6a4b019 151 }
embeddedartists 7:c8bef6a4b019 152 return a;
embeddedartists 7:c8bef6a4b019 153 }
embeddedartists 7:c8bef6a4b019 154
embeddedartists 2:070e9c054796 155 #define SWIM_TASK_PREFIX "[SWIM] "
embeddedartists 2:070e9c054796 156 void swimTask(void const* args)
embeddedartists 2:070e9c054796 157 {
embeddedartists 2:070e9c054796 158 RtosLog* log = DMBoard::instance().logger();
embeddedartists 2:070e9c054796 159
embeddedartists 2:070e9c054796 160 log->printf(SWIM_TASK_PREFIX"swimTask started\n");
embeddedartists 4:37a60b9bdb99 161
embeddedartists 2:070e9c054796 162 AppLauncher launcher;
embeddedartists 7:c8bef6a4b019 163
embeddedartists 7:c8bef6a4b019 164
embeddedartists 2:070e9c054796 165 if (launcher.setup()) {
embeddedartists 7:c8bef6a4b019 166 launcher.addImageButton(SettingsApp, img_preferences_desktop_applications, img_size_preferences_desktop_applications);
embeddedartists 7:c8bef6a4b019 167 launcher.addImageButton(Placeholder, img_bijiben, img_size_bijiben);
embeddedartists 7:c8bef6a4b019 168 launcher.addImageButton(SlideshowApp, img_multimedia_photo_manager, img_size_multimedia_photo_manager);
embeddedartists 7:c8bef6a4b019 169 //launcher.addImageButton(TouchGFXApp, "TouchGFX");
embeddedartists 7:c8bef6a4b019 170 //launcher.addImageButton(EmWinApp, "emWin");
embeddedartists 7:c8bef6a4b019 171 launcher.addImageButton(ColorPickerApp, img_preferences_color, img_size_preferences_color);
embeddedartists 7:c8bef6a4b019 172 launcher.addImageButton(ImageViewerApp, img_multimedia_photo_manager, img_size_multimedia_photo_manager);
embeddedartists 7:c8bef6a4b019 173 launcher.addImageButton(Placeholder, img_help_info, img_size_help_info);
embeddedartists 7:c8bef6a4b019 174 launcher.addImageButton(Placeholder, img_unetbootin, img_size_unetbootin);
embeddedartists 4:37a60b9bdb99 175
embeddedartists 7:c8bef6a4b019 176 launcher.setAppCreatorFunc(launchApp);
embeddedartists 2:070e9c054796 177 log->printf(SWIM_TASK_PREFIX"Starting menu system\n");
embeddedartists 2:070e9c054796 178 launcher.runToCompletion();
embeddedartists 2:070e9c054796 179 launcher.teardown();
embeddedartists 2:070e9c054796 180 } else {
embeddedartists 4:37a60b9bdb99 181 log->printf(SWIM_TASK_PREFIX"Failed to prepare menu system\n");
embeddedartists 2:070e9c054796 182 }
embeddedartists 2:070e9c054796 183
embeddedartists 2:070e9c054796 184 // Should never end up here
embeddedartists 2:070e9c054796 185 mbed_die();
embeddedartists 2:070e9c054796 186 }
embeddedartists 2:070e9c054796 187
embeddedartists 0:dfad71908d59 188 #endif //DM_BOARD_USE_DISPLAY
embeddedartists 0:dfad71908d59 189
embeddedartists 0:dfad71908d59 190 #define MSD_TASK_PREFIX "[MSD] "
embeddedartists 0:dfad71908d59 191
embeddedartists 0:dfad71908d59 192 void msdTask(void const* args)
embeddedartists 1:15ea03d72dd7 193 {
embeddedartists 1:15ea03d72dd7 194 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 195 USBHostMSD* msd = new USBHostMSD("usb");
embeddedartists 1:15ea03d72dd7 196 usbInitGuard.unlock();
embeddedartists 0:dfad71908d59 197 USBHost* host = USBHost::getHostInst();
embeddedartists 0:dfad71908d59 198 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 199
embeddedartists 0:dfad71908d59 200 log->printf(MSD_TASK_PREFIX"msdTask started\n");
embeddedartists 0:dfad71908d59 201
embeddedartists 0:dfad71908d59 202 while(1) {
embeddedartists 0:dfad71908d59 203
embeddedartists 0:dfad71908d59 204 log->printf(MSD_TASK_PREFIX"Attempting to connect...\n");
embeddedartists 0:dfad71908d59 205
embeddedartists 0:dfad71908d59 206 // try to connect a MSD device
embeddedartists 1:15ea03d72dd7 207 bool connected = false;
embeddedartists 1:15ea03d72dd7 208 do {
embeddedartists 1:15ea03d72dd7 209 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 210 connected = msd->connect();
embeddedartists 1:15ea03d72dd7 211 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 212 if (!connected) {
embeddedartists 1:15ea03d72dd7 213 //log->printf(MSD_TASK_PREFIX"Failed to connect, waiting and trying again!\n");
embeddedartists 1:15ea03d72dd7 214 Thread::wait(500);
embeddedartists 3:4301d34173cf 215 //DMBoard::instance().buzzer(440, 100);
embeddedartists 0:dfad71908d59 216 }
embeddedartists 1:15ea03d72dd7 217 } while(!connected);
embeddedartists 0:dfad71908d59 218
embeddedartists 0:dfad71908d59 219 log->printf(MSD_TASK_PREFIX"Connected!\n");
embeddedartists 4:37a60b9bdb99 220 haveUSBMSD = true;
embeddedartists 0:dfad71908d59 221
embeddedartists 0:dfad71908d59 222 // read a file
embeddedartists 4:37a60b9bdb99 223 //readMessageFile(MSD_TASK_PREFIX);
embeddedartists 0:dfad71908d59 224
embeddedartists 0:dfad71908d59 225 // if/when the device is disconnected, we try to connect it again
embeddedartists 0:dfad71908d59 226 while(1) {
embeddedartists 0:dfad71908d59 227
embeddedartists 0:dfad71908d59 228 Thread::wait(500);
embeddedartists 0:dfad71908d59 229
embeddedartists 0:dfad71908d59 230 // if device disconnected, try to connect again
embeddedartists 4:37a60b9bdb99 231 if (!msd->connected()) {
embeddedartists 0:dfad71908d59 232 break;
embeddedartists 4:37a60b9bdb99 233 }
embeddedartists 0:dfad71908d59 234 }
embeddedartists 4:37a60b9bdb99 235 haveUSBMSD = false;
embeddedartists 0:dfad71908d59 236 log->printf(MSD_TASK_PREFIX"Disconnected\n");
embeddedartists 0:dfad71908d59 237 }
embeddedartists 0:dfad71908d59 238 }
embeddedartists 0:dfad71908d59 239
embeddedartists 0:dfad71908d59 240 #define NET_TASK_PREFIX "[NET] "
embeddedartists 0:dfad71908d59 241
embeddedartists 0:dfad71908d59 242 void netTask(void const* args)
embeddedartists 0:dfad71908d59 243 {
embeddedartists 0:dfad71908d59 244 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 245 log->printf(NET_TASK_PREFIX"EthernetInterface Setting up...\r\n");
embeddedartists 0:dfad71908d59 246 if(eth.init()!=0) { //for DHCP Server
embeddedartists 0:dfad71908d59 247 //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address
embeddedartists 0:dfad71908d59 248 log->printf(NET_TASK_PREFIX"EthernetInterface Initialize Error \r\n");
embeddedartists 0:dfad71908d59 249 mbed_die();
embeddedartists 0:dfad71908d59 250 }
embeddedartists 2:070e9c054796 251 while (eth.connect() != 0) {
embeddedartists 2:070e9c054796 252 Thread::wait(1000);
embeddedartists 0:dfad71908d59 253 }
embeddedartists 0:dfad71908d59 254
embeddedartists 2:070e9c054796 255 ethInitialized = true;
embeddedartists 2:070e9c054796 256 ethUsingDHCP = true;
embeddedartists 2:070e9c054796 257
embeddedartists 0:dfad71908d59 258 log->printf(NET_TASK_PREFIX"IP Address is %s\r\n", eth.getIPAddress());
embeddedartists 0:dfad71908d59 259 log->printf(NET_TASK_PREFIX"NetMask is %s\r\n", eth.getNetworkMask());
embeddedartists 0:dfad71908d59 260 log->printf(NET_TASK_PREFIX"Gateway Address is %s\r\n", eth.getGateway());
embeddedartists 0:dfad71908d59 261 log->printf(NET_TASK_PREFIX"Ethernet Setup OK\r\n");
embeddedartists 0:dfad71908d59 262
embeddedartists 0:dfad71908d59 263 HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler
embeddedartists 0:dfad71908d59 264 FSHandler::mount("/usb", "/");
embeddedartists 0:dfad71908d59 265 HTTPServerAddHandler<FSHandler>("/");
embeddedartists 0:dfad71908d59 266 //HTTPServerAddHandler<RPCHandler>("/rpc");
embeddedartists 0:dfad71908d59 267 //lcd.locate(0,0);
embeddedartists 0:dfad71908d59 268 //lcd.printf("%s",eth.getIPAddress());
embeddedartists 0:dfad71908d59 269 HTTPServerStart(80);
embeddedartists 0:dfad71908d59 270 }
embeddedartists 0:dfad71908d59 271
embeddedartists 1:15ea03d72dd7 272 static uint8_t mouse_button, mouse_x, mouse_y, mouse_z;
embeddedartists 1:15ea03d72dd7 273 void mouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z)
embeddedartists 1:15ea03d72dd7 274 {
embeddedartists 1:15ea03d72dd7 275 mouse_button = buttons;
embeddedartists 1:15ea03d72dd7 276 mouse_x = x;
embeddedartists 1:15ea03d72dd7 277 mouse_y = y;
embeddedartists 1:15ea03d72dd7 278 mouse_z = z;
embeddedartists 1:15ea03d72dd7 279 }
embeddedartists 1:15ea03d72dd7 280
embeddedartists 1:15ea03d72dd7 281 #define MOUSE_TASK_PREFIX "[MOUSE] "
embeddedartists 1:15ea03d72dd7 282
embeddedartists 1:15ea03d72dd7 283 void mouseTask(void const* args)
embeddedartists 1:15ea03d72dd7 284 {
embeddedartists 1:15ea03d72dd7 285 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 286 USBHostMouse* mouse = new USBHostMouse();
embeddedartists 1:15ea03d72dd7 287 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 288 RtosLog* log = DMBoard::instance().logger();
embeddedartists 1:15ea03d72dd7 289
embeddedartists 1:15ea03d72dd7 290 log->printf(MOUSE_TASK_PREFIX"mouseTask started\n");
embeddedartists 1:15ea03d72dd7 291
embeddedartists 1:15ea03d72dd7 292 while(1) {
embeddedartists 1:15ea03d72dd7 293
embeddedartists 1:15ea03d72dd7 294 log->printf(MOUSE_TASK_PREFIX"Attempting to connect...\n");
embeddedartists 1:15ea03d72dd7 295
embeddedartists 1:15ea03d72dd7 296 // try to connect a mouse
embeddedartists 1:15ea03d72dd7 297 bool connected = false;
embeddedartists 1:15ea03d72dd7 298 do {
embeddedartists 1:15ea03d72dd7 299 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 300 connected = mouse->connect();
embeddedartists 1:15ea03d72dd7 301 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 302 if (!connected) {
embeddedartists 1:15ea03d72dd7 303 //log->printf(MOUSE_TASK_PREFIX"Failed to connect, waiting and trying again!\n");
embeddedartists 1:15ea03d72dd7 304 Thread::wait(500);
embeddedartists 1:15ea03d72dd7 305 }
embeddedartists 1:15ea03d72dd7 306 } while(!connected);
embeddedartists 1:15ea03d72dd7 307
embeddedartists 1:15ea03d72dd7 308 log->printf(MOUSE_TASK_PREFIX"Connected!\n");
embeddedartists 1:15ea03d72dd7 309 mouse->attachEvent(mouseEvent);
embeddedartists 1:15ea03d72dd7 310
embeddedartists 1:15ea03d72dd7 311 while(mouse->connected()) {
embeddedartists 1:15ea03d72dd7 312 log->printf(MOUSE_TASK_PREFIX"Buttons: 0x%02x, X %3d, Y %3d, Z %3d\n", mouse_button, mouse_x, mouse_y, mouse_z);
embeddedartists 1:15ea03d72dd7 313 Thread::wait(500);
embeddedartists 1:15ea03d72dd7 314 }
embeddedartists 1:15ea03d72dd7 315
embeddedartists 1:15ea03d72dd7 316 log->printf(MOUSE_TASK_PREFIX"Disconnected\n");
embeddedartists 1:15ea03d72dd7 317 }
embeddedartists 1:15ea03d72dd7 318 }
embeddedartists 1:15ea03d72dd7 319
embeddedartists 1:15ea03d72dd7 320 #define CIRCBUFF_SIZE 256
embeddedartists 1:15ea03d72dd7 321 static uint8_t circbuff[CIRCBUFF_SIZE];
embeddedartists 1:15ea03d72dd7 322 static uint32_t circbuff_read = 0;
embeddedartists 1:15ea03d72dd7 323 static uint32_t circbuff_write = 0;
embeddedartists 1:15ea03d72dd7 324 void keyEvent(uint8_t key)
embeddedartists 1:15ea03d72dd7 325 {
embeddedartists 1:15ea03d72dd7 326 circbuff[circbuff_write%CIRCBUFF_SIZE] = key;
embeddedartists 1:15ea03d72dd7 327 circbuff_write++;
embeddedartists 1:15ea03d72dd7 328 }
embeddedartists 1:15ea03d72dd7 329
embeddedartists 1:15ea03d72dd7 330 #define KEY_TASK_PREFIX "[KEY] "
embeddedartists 1:15ea03d72dd7 331
embeddedartists 1:15ea03d72dd7 332 void keyTask(void const* args)
embeddedartists 1:15ea03d72dd7 333 {
embeddedartists 1:15ea03d72dd7 334 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 335 USBHostKeyboard* keyboard = new USBHostKeyboard();
embeddedartists 1:15ea03d72dd7 336 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 337
embeddedartists 1:15ea03d72dd7 338 RtosLog* log = DMBoard::instance().logger();
embeddedartists 1:15ea03d72dd7 339 uint8_t buff[10+1] = {0};
embeddedartists 1:15ea03d72dd7 340 int pos;
embeddedartists 1:15ea03d72dd7 341
embeddedartists 1:15ea03d72dd7 342 log->printf(KEY_TASK_PREFIX"keyTask started\n");
embeddedartists 1:15ea03d72dd7 343
embeddedartists 1:15ea03d72dd7 344 while(1) {
embeddedartists 1:15ea03d72dd7 345
embeddedartists 1:15ea03d72dd7 346 log->printf(KEY_TASK_PREFIX"Attempting to connect...\n");
embeddedartists 1:15ea03d72dd7 347
embeddedartists 1:15ea03d72dd7 348 // try to connect a keyboard
embeddedartists 1:15ea03d72dd7 349 bool connected = false;
embeddedartists 1:15ea03d72dd7 350 do {
embeddedartists 1:15ea03d72dd7 351 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 352 connected = keyboard->connect();
embeddedartists 1:15ea03d72dd7 353 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 354 if (!connected) {
embeddedartists 1:15ea03d72dd7 355 //log->printf(KEY_TASK_PREFIX"Failed to connect, waiting and trying again!\n");
embeddedartists 1:15ea03d72dd7 356 Thread::wait(1000);
embeddedartists 1:15ea03d72dd7 357 }
embeddedartists 1:15ea03d72dd7 358 } while(!connected);
embeddedartists 1:15ea03d72dd7 359
embeddedartists 1:15ea03d72dd7 360 log->printf(KEY_TASK_PREFIX"Connected!\n");
embeddedartists 1:15ea03d72dd7 361 keyboard->attach(keyEvent);
embeddedartists 1:15ea03d72dd7 362
embeddedartists 1:15ea03d72dd7 363 while(keyboard->connected()) {
embeddedartists 1:15ea03d72dd7 364 for (pos = 0; pos < 10; pos++) {
embeddedartists 1:15ea03d72dd7 365 if (circbuff_read < circbuff_write) {
embeddedartists 1:15ea03d72dd7 366 buff[pos++] = circbuff[circbuff_read%CIRCBUFF_SIZE];
embeddedartists 1:15ea03d72dd7 367 circbuff_read++;
embeddedartists 1:15ea03d72dd7 368 } else {
embeddedartists 1:15ea03d72dd7 369 break;
embeddedartists 1:15ea03d72dd7 370 }
embeddedartists 1:15ea03d72dd7 371 }
embeddedartists 1:15ea03d72dd7 372 if (pos > 0) {
embeddedartists 1:15ea03d72dd7 373 log->printf(KEY_TASK_PREFIX"%s\n", buff);
embeddedartists 1:15ea03d72dd7 374 }
embeddedartists 1:15ea03d72dd7 375 Thread::wait(20);
embeddedartists 1:15ea03d72dd7 376 }
embeddedartists 1:15ea03d72dd7 377
embeddedartists 1:15ea03d72dd7 378 log->printf(KEY_TASK_PREFIX"Disconnected\n");
embeddedartists 1:15ea03d72dd7 379 }
embeddedartists 1:15ea03d72dd7 380 }
embeddedartists 1:15ea03d72dd7 381
embeddedartists 0:dfad71908d59 382 /******************************************************************************
embeddedartists 0:dfad71908d59 383 * Main function
embeddedartists 0:dfad71908d59 384 *****************************************************************************/
embeddedartists 0:dfad71908d59 385 int main()
embeddedartists 0:dfad71908d59 386 {
embeddedartists 0:dfad71908d59 387 DMBoard::BoardError err;
embeddedartists 0:dfad71908d59 388 DMBoard* board = &DMBoard::instance();
embeddedartists 0:dfad71908d59 389 RtosLog* log = board->logger();
embeddedartists 0:dfad71908d59 390 err = board->init();
embeddedartists 0:dfad71908d59 391 if (err != DMBoard::Ok) {
embeddedartists 0:dfad71908d59 392 log->printf("Failed to initialize the board, got error %d\r\n", err);
embeddedartists 0:dfad71908d59 393 mbed_die();
embeddedartists 0:dfad71908d59 394 }
embeddedartists 0:dfad71908d59 395
embeddedartists 0:dfad71908d59 396 log->printf("\n\n---\nMulti-threaded demo\nBuilt: " __DATE__ " at " __TIME__ "\n\n");
embeddedartists 0:dfad71908d59 397
embeddedartists 1:15ea03d72dd7 398 //log->printf("Press button to start...\r\n");
embeddedartists 1:15ea03d72dd7 399 //while(!board->buttonPressed());
embeddedartists 1:15ea03d72dd7 400 //while(board->buttonPressed());
embeddedartists 0:dfad71908d59 401
embeddedartists 0:dfad71908d59 402 Thread tAlive(aliveTask);
embeddedartists 0:dfad71908d59 403 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 2:070e9c054796 404 Thread tSwim(swimTask, NULL, osPriorityNormal, 8192);
embeddedartists 0:dfad71908d59 405 #endif
embeddedartists 0:dfad71908d59 406 Thread tMemstick(msdTask, NULL, osPriorityNormal, 8192);
embeddedartists 0:dfad71908d59 407 Thread tNetwork(netTask, NULL, osPriorityNormal, 8192);
embeddedartists 1:15ea03d72dd7 408 Thread tMouse(mouseTask);
embeddedartists 1:15ea03d72dd7 409 Thread tKeyboard(keyTask);
embeddedartists 0:dfad71908d59 410
embeddedartists 0:dfad71908d59 411 while(1) { wait(5); }
embeddedartists 0:dfad71908d59 412 }