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:
Tue Jan 20 09:15:05 2015 +0100
Revision:
18:715f542538b3
Parent:
16:77f4f42eb6a7
Child:
23:3f8bc89e0b23
- Added AppRTCSettings to allow user to configure the RTC
- Added shared image loading for AppNetworkSettings and AppRTCSettings
- Modified some icons
- Merged the three USB threads for Keyboard,Mouse and MSD into one and had it listen for signals from the USBHost instead of polling

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 13:57e65aba9802 20 #include "AppNetworkSettings.h"
embeddedartists 13:57e65aba9802 21 #include "AppStatus.h"
embeddedartists 7:c8bef6a4b019 22 #include "AppTouchCalibration.h"
embeddedartists 7:c8bef6a4b019 23 #include "AppColorPicker.h"
embeddedartists 7:c8bef6a4b019 24 #include "AppImageViewer.h"
embeddedartists 7:c8bef6a4b019 25 #include "AppSlideShow.h"
embeddedartists 18:715f542538b3 26 #include "AppRTCSettings.h"
embeddedartists 7:c8bef6a4b019 27 #include "image_data.h"
embeddedartists 7:c8bef6a4b019 28
embeddedartists 2:070e9c054796 29
embeddedartists 0:dfad71908d59 30 /******************************************************************************
embeddedartists 0:dfad71908d59 31 * Typedefs and defines
embeddedartists 0:dfad71908d59 32 *****************************************************************************/
embeddedartists 0:dfad71908d59 33
embeddedartists 0:dfad71908d59 34 /* Number of colors in 565 mode */
embeddedartists 0:dfad71908d59 35 #define NUM_COLORS 65536
embeddedartists 0:dfad71908d59 36 /* Number of red colors in 565 mode */
embeddedartists 0:dfad71908d59 37 #define RED_COLORS 0x20
embeddedartists 0:dfad71908d59 38 /* Number of green colors in 565 mode */
embeddedartists 0:dfad71908d59 39 #define GREEN_COLORS 0x40
embeddedartists 0:dfad71908d59 40 /* Number of blue colors in 565 mode */
embeddedartists 0:dfad71908d59 41 #define BLUE_COLORS 0x20
embeddedartists 0:dfad71908d59 42 /* Black color, 565 mode */
embeddedartists 0:dfad71908d59 43 #define BLACK 0x0000
embeddedartists 0:dfad71908d59 44
embeddedartists 0:dfad71908d59 45 /******************************************************************************
embeddedartists 0:dfad71908d59 46 * Local variables
embeddedartists 0:dfad71908d59 47 *****************************************************************************/
embeddedartists 0:dfad71908d59 48
embeddedartists 1:15ea03d72dd7 49 Mutex usbInitGuard;
embeddedartists 0:dfad71908d59 50
embeddedartists 0:dfad71908d59 51 /******************************************************************************
embeddedartists 0:dfad71908d59 52 * Global variables
embeddedartists 0:dfad71908d59 53 *****************************************************************************/
embeddedartists 0:dfad71908d59 54
embeddedartists 2:070e9c054796 55 EthernetInterface eth;
embeddedartists 2:070e9c054796 56 bool ethInitialized = false;
embeddedartists 2:070e9c054796 57 bool ethUsingDHCP = true;
embeddedartists 4:37a60b9bdb99 58 bool haveUSBMSD = false;
embeddedartists 2:070e9c054796 59
embeddedartists 0:dfad71908d59 60 /******************************************************************************
embeddedartists 0:dfad71908d59 61 * Local functions
embeddedartists 0:dfad71908d59 62 *****************************************************************************/
embeddedartists 0:dfad71908d59 63
embeddedartists 0:dfad71908d59 64 void aliveTask(void const* args)
embeddedartists 0:dfad71908d59 65 {
embeddedartists 0:dfad71908d59 66 DMBoard* board = &DMBoard::instance();
embeddedartists 0:dfad71908d59 67
embeddedartists 0:dfad71908d59 68 while(true)
embeddedartists 0:dfad71908d59 69 {
embeddedartists 0:dfad71908d59 70 board->setLED(DMBoard::Led4, false);
embeddedartists 0:dfad71908d59 71 board->setLED(DMBoard::Led1, true);
embeddedartists 0:dfad71908d59 72 Thread::wait(300);
embeddedartists 0:dfad71908d59 73 board->setLED(DMBoard::Led1, false);
embeddedartists 0:dfad71908d59 74 board->setLED(DMBoard::Led2, true);
embeddedartists 0:dfad71908d59 75 Thread::wait(300);
embeddedartists 0:dfad71908d59 76 board->setLED(DMBoard::Led2, false);
embeddedartists 0:dfad71908d59 77 board->setLED(DMBoard::Led3, true);
embeddedartists 0:dfad71908d59 78 Thread::wait(300);
embeddedartists 0:dfad71908d59 79 board->setLED(DMBoard::Led3, false);
embeddedartists 0:dfad71908d59 80 board->setLED(DMBoard::Led4, true);
embeddedartists 0:dfad71908d59 81 Thread::wait(300);
embeddedartists 0:dfad71908d59 82 }
embeddedartists 0:dfad71908d59 83 }
embeddedartists 0:dfad71908d59 84
embeddedartists 0:dfad71908d59 85 /*
embeddedartists 0:dfad71908d59 86 * Reads the /message.txt file from the file system and prints the content
embeddedartists 0:dfad71908d59 87 */
embeddedartists 0:dfad71908d59 88 void readMessageFile(const char* prefix)
embeddedartists 0:dfad71908d59 89 {
embeddedartists 0:dfad71908d59 90 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 91 log->printf("%sTesting to read from USB\n", prefix);
embeddedartists 0:dfad71908d59 92
embeddedartists 1:15ea03d72dd7 93 FILE * fp = fopen("/usb/message.txt", "r");
embeddedartists 0:dfad71908d59 94
embeddedartists 0:dfad71908d59 95 if (fp != NULL) {
embeddedartists 0:dfad71908d59 96 uint8_t* buff = (uint8_t*)malloc(1024+1);
embeddedartists 0:dfad71908d59 97 if (buff == NULL) {
embeddedartists 0:dfad71908d59 98 log->printf("%sFailed to allocate memory for test\n", prefix);
embeddedartists 0:dfad71908d59 99 } else {
embeddedartists 0:dfad71908d59 100 int num = fread(buff, 1, 1024, fp);
embeddedartists 0:dfad71908d59 101 if (num <= 0) {
embeddedartists 0:dfad71908d59 102 log->printf("%sUnable to read file, got %d as result\n", prefix, num);
embeddedartists 0:dfad71908d59 103 } else if (num < 1024) {
embeddedartists 3:4301d34173cf 104 log->printf("%sHave read all %d bytes in the file:\n---\n", prefix, num);
embeddedartists 0:dfad71908d59 105 buff[num] = '\0';
embeddedartists 0:dfad71908d59 106 log->printf((const char*)buff);
embeddedartists 3:4301d34173cf 107 log->printf("\n---\n");
embeddedartists 0:dfad71908d59 108 } else {
embeddedartists 0:dfad71908d59 109 log->printf("%sHave read %d bytes with more to read\n", prefix, num);
embeddedartists 0:dfad71908d59 110 }
embeddedartists 0:dfad71908d59 111 free(buff);
embeddedartists 0:dfad71908d59 112 }
embeddedartists 0:dfad71908d59 113 fclose(fp);
embeddedartists 0:dfad71908d59 114 } else {
embeddedartists 0:dfad71908d59 115 log->printf("%sFILE == NULL\r\n", prefix);
embeddedartists 0:dfad71908d59 116 }
embeddedartists 0:dfad71908d59 117 }
embeddedartists 0:dfad71908d59 118
embeddedartists 0:dfad71908d59 119
embeddedartists 0:dfad71908d59 120 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 2:070e9c054796 121
embeddedartists 7:c8bef6a4b019 122 typedef enum {
embeddedartists 7:c8bef6a4b019 123 ColorPickerApp,
embeddedartists 7:c8bef6a4b019 124 ImageViewerApp,
embeddedartists 7:c8bef6a4b019 125 SlideshowApp,
embeddedartists 7:c8bef6a4b019 126 SettingsApp,
embeddedartists 13:57e65aba9802 127 StatusApp,
embeddedartists 7:c8bef6a4b019 128 TouchTestApp,
embeddedartists 18:715f542538b3 129 RtcApp,
embeddedartists 7:c8bef6a4b019 130 CalibrationApp = AppLauncher::CalibrationApp,
embeddedartists 7:c8bef6a4b019 131 Placeholder,
embeddedartists 7:c8bef6a4b019 132 } myapps_t;
embeddedartists 7:c8bef6a4b019 133
embeddedartists 7:c8bef6a4b019 134 static App* launchApp(uint32_t id)
embeddedartists 7:c8bef6a4b019 135 {
embeddedartists 7:c8bef6a4b019 136 App* a = NULL;
embeddedartists 7:c8bef6a4b019 137 switch ((myapps_t)id) {
embeddedartists 7:c8bef6a4b019 138 case CalibrationApp:
embeddedartists 7:c8bef6a4b019 139 a = new AppTouchCalibration();
embeddedartists 7:c8bef6a4b019 140 break;
embeddedartists 7:c8bef6a4b019 141 case SettingsApp:
embeddedartists 13:57e65aba9802 142 a = new AppNetworkSettings();
embeddedartists 7:c8bef6a4b019 143 break;
embeddedartists 7:c8bef6a4b019 144 case ColorPickerApp:
embeddedartists 7:c8bef6a4b019 145 a = new AppColorPicker();
embeddedartists 7:c8bef6a4b019 146 break;
embeddedartists 7:c8bef6a4b019 147 case ImageViewerApp:
embeddedartists 7:c8bef6a4b019 148 a = new AppImageViewer();
embeddedartists 7:c8bef6a4b019 149 break;
embeddedartists 7:c8bef6a4b019 150 case SlideshowApp:
embeddedartists 7:c8bef6a4b019 151 a = new AppSlideShow();
embeddedartists 7:c8bef6a4b019 152 break;
embeddedartists 13:57e65aba9802 153 case StatusApp:
embeddedartists 13:57e65aba9802 154 a = new AppStatus();
embeddedartists 13:57e65aba9802 155 break;
embeddedartists 18:715f542538b3 156 case RtcApp:
embeddedartists 18:715f542538b3 157 a = new AppRTCSettings();
embeddedartists 18:715f542538b3 158 break;
embeddedartists 7:c8bef6a4b019 159 default:
embeddedartists 7:c8bef6a4b019 160 break;
embeddedartists 7:c8bef6a4b019 161 }
embeddedartists 7:c8bef6a4b019 162 return a;
embeddedartists 7:c8bef6a4b019 163 }
embeddedartists 7:c8bef6a4b019 164
embeddedartists 2:070e9c054796 165 #define SWIM_TASK_PREFIX "[SWIM] "
embeddedartists 2:070e9c054796 166 void swimTask(void const* args)
embeddedartists 2:070e9c054796 167 {
embeddedartists 2:070e9c054796 168 RtosLog* log = DMBoard::instance().logger();
embeddedartists 2:070e9c054796 169
embeddedartists 2:070e9c054796 170 log->printf(SWIM_TASK_PREFIX"swimTask started\n");
embeddedartists 4:37a60b9bdb99 171
embeddedartists 2:070e9c054796 172 AppLauncher launcher;
embeddedartists 7:c8bef6a4b019 173
embeddedartists 7:c8bef6a4b019 174
embeddedartists 2:070e9c054796 175 if (launcher.setup()) {
embeddedartists 18:715f542538b3 176 launcher.addImageButton(SettingsApp, img_preferences_system_network, img_size_preferences_system_network);
embeddedartists 7:c8bef6a4b019 177 launcher.addImageButton(Placeholder, img_bijiben, img_size_bijiben);
embeddedartists 7:c8bef6a4b019 178 launcher.addImageButton(SlideshowApp, img_multimedia_photo_manager, img_size_multimedia_photo_manager);
embeddedartists 7:c8bef6a4b019 179 //launcher.addImageButton(TouchGFXApp, "TouchGFX");
embeddedartists 7:c8bef6a4b019 180 //launcher.addImageButton(EmWinApp, "emWin");
embeddedartists 7:c8bef6a4b019 181 launcher.addImageButton(ColorPickerApp, img_preferences_color, img_size_preferences_color);
embeddedartists 7:c8bef6a4b019 182 launcher.addImageButton(ImageViewerApp, img_multimedia_photo_manager, img_size_multimedia_photo_manager);
embeddedartists 18:715f542538b3 183 launcher.addImageButton(StatusApp, img_utilities_system_monitor, img_size_utilities_system_monitor);
embeddedartists 7:c8bef6a4b019 184 launcher.addImageButton(Placeholder, img_unetbootin, img_size_unetbootin);
embeddedartists 18:715f542538b3 185 launcher.addImageButton(RtcApp, img_preferences_system_time, img_size_preferences_system_time);
embeddedartists 4:37a60b9bdb99 186
embeddedartists 7:c8bef6a4b019 187 launcher.setAppCreatorFunc(launchApp);
embeddedartists 2:070e9c054796 188 log->printf(SWIM_TASK_PREFIX"Starting menu system\n");
embeddedartists 2:070e9c054796 189 launcher.runToCompletion();
embeddedartists 2:070e9c054796 190 launcher.teardown();
embeddedartists 2:070e9c054796 191 } else {
embeddedartists 4:37a60b9bdb99 192 log->printf(SWIM_TASK_PREFIX"Failed to prepare menu system\n");
embeddedartists 2:070e9c054796 193 }
embeddedartists 2:070e9c054796 194
embeddedartists 2:070e9c054796 195 // Should never end up here
embeddedartists 2:070e9c054796 196 mbed_die();
embeddedartists 2:070e9c054796 197 }
embeddedartists 2:070e9c054796 198
embeddedartists 0:dfad71908d59 199 #endif //DM_BOARD_USE_DISPLAY
embeddedartists 0:dfad71908d59 200
embeddedartists 0:dfad71908d59 201 #define MSD_TASK_PREFIX "[MSD] "
embeddedartists 0:dfad71908d59 202
embeddedartists 0:dfad71908d59 203 void msdTask(void const* args)
embeddedartists 1:15ea03d72dd7 204 {
embeddedartists 1:15ea03d72dd7 205 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 206 USBHostMSD* msd = new USBHostMSD("usb");
embeddedartists 1:15ea03d72dd7 207 usbInitGuard.unlock();
embeddedartists 0:dfad71908d59 208 USBHost* host = USBHost::getHostInst();
embeddedartists 0:dfad71908d59 209 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 210
embeddedartists 0:dfad71908d59 211 log->printf(MSD_TASK_PREFIX"msdTask started\n");
embeddedartists 0:dfad71908d59 212
embeddedartists 0:dfad71908d59 213 while(1) {
embeddedartists 0:dfad71908d59 214
embeddedartists 0:dfad71908d59 215 log->printf(MSD_TASK_PREFIX"Attempting to connect...\n");
embeddedartists 0:dfad71908d59 216
embeddedartists 0:dfad71908d59 217 // try to connect a MSD device
embeddedartists 1:15ea03d72dd7 218 bool connected = false;
embeddedartists 1:15ea03d72dd7 219 do {
embeddedartists 1:15ea03d72dd7 220 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 221 connected = msd->connect();
embeddedartists 1:15ea03d72dd7 222 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 223 if (!connected) {
embeddedartists 1:15ea03d72dd7 224 //log->printf(MSD_TASK_PREFIX"Failed to connect, waiting and trying again!\n");
embeddedartists 1:15ea03d72dd7 225 Thread::wait(500);
embeddedartists 3:4301d34173cf 226 //DMBoard::instance().buzzer(440, 100);
embeddedartists 0:dfad71908d59 227 }
embeddedartists 1:15ea03d72dd7 228 } while(!connected);
embeddedartists 0:dfad71908d59 229
embeddedartists 0:dfad71908d59 230 log->printf(MSD_TASK_PREFIX"Connected!\n");
embeddedartists 4:37a60b9bdb99 231 haveUSBMSD = true;
embeddedartists 0:dfad71908d59 232
embeddedartists 0:dfad71908d59 233 // read a file
embeddedartists 4:37a60b9bdb99 234 //readMessageFile(MSD_TASK_PREFIX);
embeddedartists 0:dfad71908d59 235
embeddedartists 0:dfad71908d59 236 // if/when the device is disconnected, we try to connect it again
embeddedartists 0:dfad71908d59 237 while(1) {
embeddedartists 0:dfad71908d59 238
embeddedartists 0:dfad71908d59 239 Thread::wait(500);
embeddedartists 0:dfad71908d59 240
embeddedartists 0:dfad71908d59 241 // if device disconnected, try to connect again
embeddedartists 4:37a60b9bdb99 242 if (!msd->connected()) {
embeddedartists 0:dfad71908d59 243 break;
embeddedartists 4:37a60b9bdb99 244 }
embeddedartists 0:dfad71908d59 245 }
embeddedartists 4:37a60b9bdb99 246 haveUSBMSD = false;
embeddedartists 0:dfad71908d59 247 log->printf(MSD_TASK_PREFIX"Disconnected\n");
embeddedartists 0:dfad71908d59 248 }
embeddedartists 0:dfad71908d59 249 }
embeddedartists 0:dfad71908d59 250
embeddedartists 0:dfad71908d59 251 #define NET_TASK_PREFIX "[NET] "
embeddedartists 0:dfad71908d59 252
embeddedartists 0:dfad71908d59 253 void netTask(void const* args)
embeddedartists 0:dfad71908d59 254 {
embeddedartists 0:dfad71908d59 255 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 256 log->printf(NET_TASK_PREFIX"EthernetInterface Setting up...\r\n");
embeddedartists 0:dfad71908d59 257 if(eth.init()!=0) { //for DHCP Server
embeddedartists 0:dfad71908d59 258 //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address
embeddedartists 0:dfad71908d59 259 log->printf(NET_TASK_PREFIX"EthernetInterface Initialize Error \r\n");
embeddedartists 0:dfad71908d59 260 mbed_die();
embeddedartists 0:dfad71908d59 261 }
embeddedartists 2:070e9c054796 262 while (eth.connect() != 0) {
embeddedartists 2:070e9c054796 263 Thread::wait(1000);
embeddedartists 0:dfad71908d59 264 }
embeddedartists 0:dfad71908d59 265
embeddedartists 2:070e9c054796 266 ethInitialized = true;
embeddedartists 2:070e9c054796 267 ethUsingDHCP = true;
embeddedartists 2:070e9c054796 268
embeddedartists 0:dfad71908d59 269 log->printf(NET_TASK_PREFIX"IP Address is %s\r\n", eth.getIPAddress());
embeddedartists 0:dfad71908d59 270 log->printf(NET_TASK_PREFIX"NetMask is %s\r\n", eth.getNetworkMask());
embeddedartists 0:dfad71908d59 271 log->printf(NET_TASK_PREFIX"Gateway Address is %s\r\n", eth.getGateway());
embeddedartists 0:dfad71908d59 272 log->printf(NET_TASK_PREFIX"Ethernet Setup OK\r\n");
embeddedartists 0:dfad71908d59 273
embeddedartists 0:dfad71908d59 274 HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler
embeddedartists 0:dfad71908d59 275 FSHandler::mount("/usb", "/");
embeddedartists 0:dfad71908d59 276 HTTPServerAddHandler<FSHandler>("/");
embeddedartists 0:dfad71908d59 277 //HTTPServerAddHandler<RPCHandler>("/rpc");
embeddedartists 0:dfad71908d59 278 //lcd.locate(0,0);
embeddedartists 0:dfad71908d59 279 //lcd.printf("%s",eth.getIPAddress());
embeddedartists 0:dfad71908d59 280 HTTPServerStart(80);
embeddedartists 0:dfad71908d59 281 }
embeddedartists 0:dfad71908d59 282
embeddedartists 13:57e65aba9802 283 static int8_t mouse_button, mouse_x, mouse_y, mouse_z;
embeddedartists 13:57e65aba9802 284 static uint16_t cursor_x=0, cursor_y=0;
embeddedartists 1:15ea03d72dd7 285 void mouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z)
embeddedartists 1:15ea03d72dd7 286 {
embeddedartists 1:15ea03d72dd7 287 mouse_button = buttons;
embeddedartists 1:15ea03d72dd7 288 mouse_x = x;
embeddedartists 1:15ea03d72dd7 289 mouse_y = y;
embeddedartists 1:15ea03d72dd7 290 mouse_z = z;
embeddedartists 13:57e65aba9802 291
embeddedartists 13:57e65aba9802 292 if (x < 0) {
embeddedartists 13:57e65aba9802 293 if (cursor_x > -x) {
embeddedartists 13:57e65aba9802 294 cursor_x += x;
embeddedartists 13:57e65aba9802 295 } else {
embeddedartists 13:57e65aba9802 296 cursor_x = 0;
embeddedartists 13:57e65aba9802 297 }
embeddedartists 13:57e65aba9802 298 } else {
embeddedartists 13:57e65aba9802 299 if ((cursor_x + x) >= 480) {
embeddedartists 13:57e65aba9802 300 cursor_x = 479;
embeddedartists 13:57e65aba9802 301 } else {
embeddedartists 13:57e65aba9802 302 cursor_x += x;
embeddedartists 13:57e65aba9802 303 }
embeddedartists 13:57e65aba9802 304 }
embeddedartists 13:57e65aba9802 305 y = y/8;
embeddedartists 13:57e65aba9802 306 if (y < 0) {
embeddedartists 13:57e65aba9802 307 if (cursor_y > -y) {
embeddedartists 13:57e65aba9802 308 cursor_y += y;
embeddedartists 13:57e65aba9802 309 } else {
embeddedartists 13:57e65aba9802 310 cursor_y = 0;
embeddedartists 13:57e65aba9802 311 }
embeddedartists 13:57e65aba9802 312 } else {
embeddedartists 13:57e65aba9802 313 if ((cursor_y + y) >= 272) {
embeddedartists 13:57e65aba9802 314 cursor_y = 271;
embeddedartists 13:57e65aba9802 315 } else {
embeddedartists 13:57e65aba9802 316 cursor_y += y;
embeddedartists 13:57e65aba9802 317 }
embeddedartists 13:57e65aba9802 318 }
embeddedartists 13:57e65aba9802 319
embeddedartists 13:57e65aba9802 320 //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y);
embeddedartists 13:57e65aba9802 321 LPC_LCD->CRSR_XY = (cursor_x & 0x3FF) | ((cursor_y & 0x3FF) << 16);
embeddedartists 13:57e65aba9802 322 }
embeddedartists 13:57e65aba9802 323
embeddedartists 13:57e65aba9802 324 #define LCD_CURSOR_32x32 0
embeddedartists 13:57e65aba9802 325 #define LCD_CURSOR_64x64 1
embeddedartists 13:57e65aba9802 326 #define CURSOR_SIZE LCD_CURSOR_32x32
embeddedartists 13:57e65aba9802 327 #define CURSOR_H_SIZE 32
embeddedartists 13:57e65aba9802 328 #define CURSOR_V_SIZE 32
embeddedartists 13:57e65aba9802 329 #define CURSOR_NUM 0
embeddedartists 13:57e65aba9802 330 #define CURSOR_H_OFS (10)
embeddedartists 13:57e65aba9802 331 #define CURSOR_V_OFS (6)
embeddedartists 13:57e65aba9802 332
embeddedartists 13:57e65aba9802 333 const unsigned char __attribute__ ((aligned(4))) Cursor[(CURSOR_H_SIZE / 4) * CURSOR_V_SIZE] =
embeddedartists 13:57e65aba9802 334 {
embeddedartists 13:57e65aba9802 335 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 336 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 337 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 338 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 339 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 340 0xAA, 0xAA, 0xAA, 0xFA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 341 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 342 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 343 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 344 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 345 0xAA, 0xAA, 0xAB, 0xFF, 0xEA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 346 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 347 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 348 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 349 0xAA, 0xAB, 0xFB, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 350 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 351 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 352 0xAA, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 353 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 354 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 355 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 356 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 357 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 358 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 359 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 360 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 361 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 362 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 363 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 364 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 365 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
embeddedartists 13:57e65aba9802 366 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
embeddedartists 13:57e65aba9802 367 };
embeddedartists 13:57e65aba9802 368
embeddedartists 13:57e65aba9802 369 void prepareCursor(bool enable) {
embeddedartists 13:57e65aba9802 370 //Chip_LCD_Cursor_Disable(LPC_LCD, 0);
embeddedartists 13:57e65aba9802 371 LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4);
embeddedartists 13:57e65aba9802 372
embeddedartists 13:57e65aba9802 373 if (enable) {
embeddedartists 13:57e65aba9802 374 //Chip_LCD_Cursor_Config(LPC_LCD, LCD_CURSOR_32x32, true);
embeddedartists 13:57e65aba9802 375 LPC_LCD->CRSR_CFG = ((true ? 1 : 0) << 1) | CURSOR_SIZE;
embeddedartists 13:57e65aba9802 376
embeddedartists 13:57e65aba9802 377 //Chip_LCD_Cursor_WriteImage(LPC_LCD, 0, (void *) Cursor);
embeddedartists 13:57e65aba9802 378 {
embeddedartists 13:57e65aba9802 379 int i, j;
embeddedartists 13:57e65aba9802 380 uint32_t *fifoptr, *crsr_ptr = (uint32_t *) Cursor;
embeddedartists 13:57e65aba9802 381
embeddedartists 13:57e65aba9802 382 /* Check if Cursor Size was configured as 32x32 or 64x64*/
embeddedartists 13:57e65aba9802 383 if (CURSOR_SIZE == LCD_CURSOR_32x32) {
embeddedartists 13:57e65aba9802 384 i = CURSOR_NUM * 64;
embeddedartists 13:57e65aba9802 385 j = i + 64;
embeddedartists 13:57e65aba9802 386 }
embeddedartists 13:57e65aba9802 387 else {
embeddedartists 13:57e65aba9802 388 i = 0;
embeddedartists 13:57e65aba9802 389 j = 256;
embeddedartists 13:57e65aba9802 390 }
embeddedartists 13:57e65aba9802 391 fifoptr = (uint32_t *) &(LPC_LCD->CRSR_IMG[0]);
embeddedartists 13:57e65aba9802 392
embeddedartists 13:57e65aba9802 393 /* Copy Cursor Image content to FIFO */
embeddedartists 13:57e65aba9802 394 for (; i < j; i++) {
embeddedartists 13:57e65aba9802 395
embeddedartists 13:57e65aba9802 396 *fifoptr = *crsr_ptr;
embeddedartists 13:57e65aba9802 397 crsr_ptr++;
embeddedartists 13:57e65aba9802 398 fifoptr++;
embeddedartists 13:57e65aba9802 399 }
embeddedartists 13:57e65aba9802 400 }
embeddedartists 13:57e65aba9802 401
embeddedartists 13:57e65aba9802 402 //Chip_LCD_Cursor_SetClip(LPC_LCD, CURSOR_H_OFS, CURSOR_V_OFS);
embeddedartists 13:57e65aba9802 403 LPC_LCD->CRSR_CLIP = (CURSOR_H_OFS & 0x3F) | ((CURSOR_V_OFS & 0x3F) << 8);
embeddedartists 13:57e65aba9802 404
embeddedartists 13:57e65aba9802 405 //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y);
embeddedartists 13:57e65aba9802 406
embeddedartists 13:57e65aba9802 407 //Chip_LCD_Cursor_Enable(LPC_LCD, 0);
embeddedartists 13:57e65aba9802 408 LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4) | 1;
embeddedartists 13:57e65aba9802 409 }
embeddedartists 1:15ea03d72dd7 410 }
embeddedartists 1:15ea03d72dd7 411
embeddedartists 1:15ea03d72dd7 412 #define MOUSE_TASK_PREFIX "[MOUSE] "
embeddedartists 1:15ea03d72dd7 413
embeddedartists 1:15ea03d72dd7 414 void mouseTask(void const* args)
embeddedartists 1:15ea03d72dd7 415 {
embeddedartists 1:15ea03d72dd7 416 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 417 USBHostMouse* mouse = new USBHostMouse();
embeddedartists 1:15ea03d72dd7 418 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 419 RtosLog* log = DMBoard::instance().logger();
embeddedartists 13:57e65aba9802 420
embeddedartists 1:15ea03d72dd7 421 log->printf(MOUSE_TASK_PREFIX"mouseTask started\n");
embeddedartists 1:15ea03d72dd7 422
embeddedartists 1:15ea03d72dd7 423 while(1) {
embeddedartists 1:15ea03d72dd7 424
embeddedartists 13:57e65aba9802 425 prepareCursor(false);
embeddedartists 1:15ea03d72dd7 426 log->printf(MOUSE_TASK_PREFIX"Attempting to connect...\n");
embeddedartists 1:15ea03d72dd7 427
embeddedartists 1:15ea03d72dd7 428 // try to connect a mouse
embeddedartists 1:15ea03d72dd7 429 bool connected = false;
embeddedartists 1:15ea03d72dd7 430 do {
embeddedartists 1:15ea03d72dd7 431 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 432 connected = mouse->connect();
embeddedartists 1:15ea03d72dd7 433 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 434 if (!connected) {
embeddedartists 1:15ea03d72dd7 435 //log->printf(MOUSE_TASK_PREFIX"Failed to connect, waiting and trying again!\n");
embeddedartists 1:15ea03d72dd7 436 Thread::wait(500);
embeddedartists 1:15ea03d72dd7 437 }
embeddedartists 1:15ea03d72dd7 438 } while(!connected);
embeddedartists 1:15ea03d72dd7 439
embeddedartists 1:15ea03d72dd7 440 log->printf(MOUSE_TASK_PREFIX"Connected!\n");
embeddedartists 1:15ea03d72dd7 441 mouse->attachEvent(mouseEvent);
embeddedartists 13:57e65aba9802 442 prepareCursor(true);
embeddedartists 1:15ea03d72dd7 443
embeddedartists 1:15ea03d72dd7 444 while(mouse->connected()) {
embeddedartists 1:15ea03d72dd7 445 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 446 Thread::wait(500);
embeddedartists 1:15ea03d72dd7 447 }
embeddedartists 1:15ea03d72dd7 448
embeddedartists 1:15ea03d72dd7 449 log->printf(MOUSE_TASK_PREFIX"Disconnected\n");
embeddedartists 1:15ea03d72dd7 450 }
embeddedartists 1:15ea03d72dd7 451 }
embeddedartists 1:15ea03d72dd7 452
embeddedartists 1:15ea03d72dd7 453 #define CIRCBUFF_SIZE 256
embeddedartists 1:15ea03d72dd7 454 static uint8_t circbuff[CIRCBUFF_SIZE];
embeddedartists 1:15ea03d72dd7 455 static uint32_t circbuff_read = 0;
embeddedartists 1:15ea03d72dd7 456 static uint32_t circbuff_write = 0;
embeddedartists 1:15ea03d72dd7 457 void keyEvent(uint8_t key)
embeddedartists 1:15ea03d72dd7 458 {
embeddedartists 1:15ea03d72dd7 459 circbuff[circbuff_write%CIRCBUFF_SIZE] = key;
embeddedartists 1:15ea03d72dd7 460 circbuff_write++;
embeddedartists 1:15ea03d72dd7 461 }
embeddedartists 1:15ea03d72dd7 462
embeddedartists 1:15ea03d72dd7 463 #define KEY_TASK_PREFIX "[KEY] "
embeddedartists 1:15ea03d72dd7 464
embeddedartists 1:15ea03d72dd7 465 void keyTask(void const* args)
embeddedartists 1:15ea03d72dd7 466 {
embeddedartists 1:15ea03d72dd7 467 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 468 USBHostKeyboard* keyboard = new USBHostKeyboard();
embeddedartists 1:15ea03d72dd7 469 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 470
embeddedartists 1:15ea03d72dd7 471 RtosLog* log = DMBoard::instance().logger();
embeddedartists 1:15ea03d72dd7 472 uint8_t buff[10+1] = {0};
embeddedartists 1:15ea03d72dd7 473 int pos;
embeddedartists 1:15ea03d72dd7 474
embeddedartists 1:15ea03d72dd7 475 log->printf(KEY_TASK_PREFIX"keyTask started\n");
embeddedartists 1:15ea03d72dd7 476
embeddedartists 1:15ea03d72dd7 477 while(1) {
embeddedartists 1:15ea03d72dd7 478
embeddedartists 1:15ea03d72dd7 479 log->printf(KEY_TASK_PREFIX"Attempting to connect...\n");
embeddedartists 1:15ea03d72dd7 480
embeddedartists 1:15ea03d72dd7 481 // try to connect a keyboard
embeddedartists 1:15ea03d72dd7 482 bool connected = false;
embeddedartists 1:15ea03d72dd7 483 do {
embeddedartists 1:15ea03d72dd7 484 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 485 connected = keyboard->connect();
embeddedartists 1:15ea03d72dd7 486 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 487 if (!connected) {
embeddedartists 1:15ea03d72dd7 488 //log->printf(KEY_TASK_PREFIX"Failed to connect, waiting and trying again!\n");
embeddedartists 1:15ea03d72dd7 489 Thread::wait(1000);
embeddedartists 1:15ea03d72dd7 490 }
embeddedartists 1:15ea03d72dd7 491 } while(!connected);
embeddedartists 1:15ea03d72dd7 492
embeddedartists 1:15ea03d72dd7 493 log->printf(KEY_TASK_PREFIX"Connected!\n");
embeddedartists 1:15ea03d72dd7 494 keyboard->attach(keyEvent);
embeddedartists 1:15ea03d72dd7 495
embeddedartists 1:15ea03d72dd7 496 while(keyboard->connected()) {
embeddedartists 1:15ea03d72dd7 497 for (pos = 0; pos < 10; pos++) {
embeddedartists 1:15ea03d72dd7 498 if (circbuff_read < circbuff_write) {
embeddedartists 1:15ea03d72dd7 499 buff[pos++] = circbuff[circbuff_read%CIRCBUFF_SIZE];
embeddedartists 1:15ea03d72dd7 500 circbuff_read++;
embeddedartists 1:15ea03d72dd7 501 } else {
embeddedartists 1:15ea03d72dd7 502 break;
embeddedartists 1:15ea03d72dd7 503 }
embeddedartists 1:15ea03d72dd7 504 }
embeddedartists 1:15ea03d72dd7 505 if (pos > 0) {
embeddedartists 1:15ea03d72dd7 506 log->printf(KEY_TASK_PREFIX"%s\n", buff);
embeddedartists 1:15ea03d72dd7 507 }
embeddedartists 1:15ea03d72dd7 508 Thread::wait(20);
embeddedartists 1:15ea03d72dd7 509 }
embeddedartists 1:15ea03d72dd7 510
embeddedartists 1:15ea03d72dd7 511 log->printf(KEY_TASK_PREFIX"Disconnected\n");
embeddedartists 1:15ea03d72dd7 512 }
embeddedartists 1:15ea03d72dd7 513 }
embeddedartists 1:15ea03d72dd7 514
embeddedartists 18:715f542538b3 515 #define USB_TASK_PREFIX "[USB] "
embeddedartists 18:715f542538b3 516 #define USB_CONNECTION_EVENT (1<<4)
embeddedartists 18:715f542538b3 517 void usbTask(void const* args)
embeddedartists 18:715f542538b3 518 {
embeddedartists 18:715f542538b3 519 bool msdConnected = false;
embeddedartists 18:715f542538b3 520 bool keyboardConnected = false;
embeddedartists 18:715f542538b3 521 bool mouseConnected = false;
embeddedartists 18:715f542538b3 522
embeddedartists 18:715f542538b3 523 USBHostMSD* msd = new USBHostMSD("usb");
embeddedartists 18:715f542538b3 524 USBHostKeyboard* keyboard = new USBHostKeyboard();
embeddedartists 18:715f542538b3 525 USBHostMouse* mouse = new USBHostMouse();
embeddedartists 18:715f542538b3 526 USBHost* host = USBHost::getHostInst();
embeddedartists 18:715f542538b3 527 host->signalOnConnections(Thread::gettid(), USB_CONNECTION_EVENT);
embeddedartists 18:715f542538b3 528
embeddedartists 18:715f542538b3 529 RtosLog* log = DMBoard::instance().logger();
embeddedartists 18:715f542538b3 530
embeddedartists 18:715f542538b3 531 log->printf(USB_TASK_PREFIX"usbTask started\n");
embeddedartists 18:715f542538b3 532
embeddedartists 18:715f542538b3 533 prepareCursor(false);
embeddedartists 18:715f542538b3 534
embeddedartists 18:715f542538b3 535 while (true) {
embeddedartists 18:715f542538b3 536 // wait for connect/disconnect message from USBHost
embeddedartists 18:715f542538b3 537 Thread::signal_wait(USB_CONNECTION_EVENT);
embeddedartists 18:715f542538b3 538 log->printf(USB_TASK_PREFIX"got USB event\n");
embeddedartists 18:715f542538b3 539
embeddedartists 18:715f542538b3 540 if (msd->connected()) {
embeddedartists 18:715f542538b3 541 if (!msdConnected) {
embeddedartists 18:715f542538b3 542 msdConnected = true;
embeddedartists 18:715f542538b3 543 haveUSBMSD = true;
embeddedartists 18:715f542538b3 544 log->printf(USB_TASK_PREFIX"USB MassStorage Device - Connected\n");
embeddedartists 18:715f542538b3 545 }
embeddedartists 18:715f542538b3 546 } else {
embeddedartists 18:715f542538b3 547 if (msdConnected) {
embeddedartists 18:715f542538b3 548 msdConnected = false;
embeddedartists 18:715f542538b3 549 haveUSBMSD = false;
embeddedartists 18:715f542538b3 550 log->printf(USB_TASK_PREFIX"USB MassStorage Device - Ejected\n");
embeddedartists 18:715f542538b3 551 }
embeddedartists 18:715f542538b3 552
embeddedartists 18:715f542538b3 553 if (msd->connect()) {
embeddedartists 18:715f542538b3 554 msdConnected = true;
embeddedartists 18:715f542538b3 555 haveUSBMSD = true;
embeddedartists 18:715f542538b3 556 log->printf(USB_TASK_PREFIX"USB MassStorage Device - Connected\n");
embeddedartists 18:715f542538b3 557 }
embeddedartists 18:715f542538b3 558 }
embeddedartists 18:715f542538b3 559
embeddedartists 18:715f542538b3 560 if (keyboard->connected()) {
embeddedartists 18:715f542538b3 561 if (!keyboardConnected) {
embeddedartists 18:715f542538b3 562 keyboardConnected = true;
embeddedartists 18:715f542538b3 563 log->printf(USB_TASK_PREFIX"USB Keyboard - Connected\n");
embeddedartists 18:715f542538b3 564 keyboard->attach(keyEvent);
embeddedartists 18:715f542538b3 565 }
embeddedartists 18:715f542538b3 566 } else {
embeddedartists 18:715f542538b3 567 if (keyboardConnected) {
embeddedartists 18:715f542538b3 568 keyboardConnected = false;
embeddedartists 18:715f542538b3 569 log->printf(USB_TASK_PREFIX"USB Keyboard - Ejected\n");
embeddedartists 18:715f542538b3 570 }
embeddedartists 18:715f542538b3 571 if (keyboard->connect()) {
embeddedartists 18:715f542538b3 572 keyboardConnected = true;
embeddedartists 18:715f542538b3 573 log->printf(USB_TASK_PREFIX"USB Keyboard - Connected\n");
embeddedartists 18:715f542538b3 574 keyboard->attach(keyEvent);
embeddedartists 18:715f542538b3 575 }
embeddedartists 18:715f542538b3 576 }
embeddedartists 18:715f542538b3 577
embeddedartists 18:715f542538b3 578 if (mouse->connected()) {
embeddedartists 18:715f542538b3 579 if (!mouseConnected) {
embeddedartists 18:715f542538b3 580 mouseConnected = true;
embeddedartists 18:715f542538b3 581 log->printf(USB_TASK_PREFIX"USB Mouse - Connected\n");
embeddedartists 18:715f542538b3 582 mouse->attachEvent(mouseEvent);
embeddedartists 18:715f542538b3 583 prepareCursor(true);
embeddedartists 18:715f542538b3 584 }
embeddedartists 18:715f542538b3 585 } else {
embeddedartists 18:715f542538b3 586 if (mouseConnected) {
embeddedartists 18:715f542538b3 587 prepareCursor(false);
embeddedartists 18:715f542538b3 588 mouseConnected = false;
embeddedartists 18:715f542538b3 589 log->printf(USB_TASK_PREFIX"USB Mouse - Ejected\n");
embeddedartists 18:715f542538b3 590 }
embeddedartists 18:715f542538b3 591 if (mouse->connect()) {
embeddedartists 18:715f542538b3 592 mouseConnected = true;
embeddedartists 18:715f542538b3 593 log->printf(USB_TASK_PREFIX"USB Mouse - Connected\n");
embeddedartists 18:715f542538b3 594 mouse->attachEvent(mouseEvent);
embeddedartists 18:715f542538b3 595 prepareCursor(true);
embeddedartists 18:715f542538b3 596 }
embeddedartists 18:715f542538b3 597 }
embeddedartists 18:715f542538b3 598 }
embeddedartists 18:715f542538b3 599 }
embeddedartists 18:715f542538b3 600
embeddedartists 18:715f542538b3 601
embeddedartists 14:73f6c425b2b5 602 #define REGTEST "[REG] "
embeddedartists 14:73f6c425b2b5 603 static void testRegistry()
embeddedartists 14:73f6c425b2b5 604 {
embeddedartists 14:73f6c425b2b5 605 Registry* reg = DMBoard::instance().registry();
embeddedartists 14:73f6c425b2b5 606 RtosLog* log = DMBoard::instance().logger();
embeddedartists 14:73f6c425b2b5 607 char* key;
embeddedartists 14:73f6c425b2b5 608 char* val;
embeddedartists 14:73f6c425b2b5 609 Registry::RegistryError err;
embeddedartists 14:73f6c425b2b5 610
embeddedartists 14:73f6c425b2b5 611 log->printf(REGTEST"Before:\n");
embeddedartists 14:73f6c425b2b5 612 for (int i = 0; i < reg->numEntries(); i++) {
embeddedartists 14:73f6c425b2b5 613 err = reg->entryAt(i, &key, &val);
embeddedartists 14:73f6c425b2b5 614 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 615 log->printf(REGTEST" [%2d] '%s' = '%s'\n", i, key, val);
embeddedartists 14:73f6c425b2b5 616 free(key);
embeddedartists 14:73f6c425b2b5 617 free(val);
embeddedartists 14:73f6c425b2b5 618 } else {
embeddedartists 14:73f6c425b2b5 619 log->printf(REGTEST" [%2d] got error %d\n", i, err);
embeddedartists 14:73f6c425b2b5 620 }
embeddedartists 14:73f6c425b2b5 621 }
embeddedartists 14:73f6c425b2b5 622
embeddedartists 14:73f6c425b2b5 623 log->printf(REGTEST"Getting existing value:\n");
embeddedartists 14:73f6c425b2b5 624 err = reg->getValue("IP Address", &val);
embeddedartists 14:73f6c425b2b5 625 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 626 log->printf(REGTEST" Existing 'IP Address' = '%s'\n", val);
embeddedartists 14:73f6c425b2b5 627 free(val);
embeddedartists 14:73f6c425b2b5 628 } else {
embeddedartists 14:73f6c425b2b5 629 log->printf(REGTEST" Existing 'IP Address' got error %d\n", err);
embeddedartists 14:73f6c425b2b5 630 }
embeddedartists 14:73f6c425b2b5 631
embeddedartists 14:73f6c425b2b5 632 log->printf(REGTEST"Getting missing value:\n");
embeddedartists 14:73f6c425b2b5 633 err = reg->getValue("X78g4dfwx", &val);
embeddedartists 14:73f6c425b2b5 634 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 635 log->printf(REGTEST" Missing 'X78g4dfwx' = '%s'\n", val);
embeddedartists 14:73f6c425b2b5 636 free(val);
embeddedartists 14:73f6c425b2b5 637 } else if (err == Registry::NoSuchKeyError) {
embeddedartists 14:73f6c425b2b5 638 log->printf(REGTEST" Missing 'X78g4dfwx' was missing.\n", err);
embeddedartists 14:73f6c425b2b5 639 } else {
embeddedartists 14:73f6c425b2b5 640 log->printf(REGTEST" Existing 'X78g4dfwx' got error %d\n", err);
embeddedartists 14:73f6c425b2b5 641 }
embeddedartists 14:73f6c425b2b5 642
embeddedartists 14:73f6c425b2b5 643 log->printf(REGTEST"Updating value:\n");
embeddedartists 14:73f6c425b2b5 644 err = reg->getValue("EATest", &val);
embeddedartists 14:73f6c425b2b5 645 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 646 log->printf(REGTEST" Old value for 'EATest' = '%s'\n", val);
embeddedartists 14:73f6c425b2b5 647 char buf[32];
embeddedartists 14:73f6c425b2b5 648 sprintf(buf, "%d", atoi(val)+1);
embeddedartists 14:73f6c425b2b5 649 free(val);
embeddedartists 14:73f6c425b2b5 650 err = reg->setValue("EATest", buf);
embeddedartists 14:73f6c425b2b5 651 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 652 log->printf(REGTEST" Updated 'EATest' to '%s'\n", buf);
embeddedartists 14:73f6c425b2b5 653 } else {
embeddedartists 14:73f6c425b2b5 654 log->printf(REGTEST" Failed to update 'EATest', got error %d\n", err);
embeddedartists 14:73f6c425b2b5 655 }
embeddedartists 14:73f6c425b2b5 656 } else if (err == Registry::NoSuchKeyError) {
embeddedartists 14:73f6c425b2b5 657 log->printf(REGTEST" No value for 'EATest', adding one\n", err);
embeddedartists 14:73f6c425b2b5 658 err = reg->setValue("EATest", "-3");
embeddedartists 14:73f6c425b2b5 659 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 660 log->printf(REGTEST" Set 'EATest' to '0'\n");
embeddedartists 14:73f6c425b2b5 661 } else {
embeddedartists 14:73f6c425b2b5 662 log->printf(REGTEST" Failed to set 'EATest', got error %d\n", err);
embeddedartists 14:73f6c425b2b5 663 }
embeddedartists 14:73f6c425b2b5 664 } else {
embeddedartists 14:73f6c425b2b5 665 log->printf(REGTEST" Failed to read 'EATest' got error %d\n", err);
embeddedartists 14:73f6c425b2b5 666 }
embeddedartists 14:73f6c425b2b5 667
embeddedartists 14:73f6c425b2b5 668 log->printf(REGTEST"Storing values persistently\n");
embeddedartists 14:73f6c425b2b5 669 err = reg->store();
embeddedartists 14:73f6c425b2b5 670 if (err != Registry::Ok) {
embeddedartists 14:73f6c425b2b5 671 log->printf(REGTEST" Failed to store values, got error %d\n", err);
embeddedartists 14:73f6c425b2b5 672 }
embeddedartists 14:73f6c425b2b5 673
embeddedartists 14:73f6c425b2b5 674 log->printf(REGTEST"After:\n");
embeddedartists 14:73f6c425b2b5 675 for (int i = 0; i < reg->numEntries(); i++) {
embeddedartists 14:73f6c425b2b5 676 err = reg->entryAt(i, &key, &val);
embeddedartists 14:73f6c425b2b5 677 if (err == Registry::Ok) {
embeddedartists 14:73f6c425b2b5 678 log->printf(REGTEST" [%2d] '%s' = '%s'\n", i, key, val);
embeddedartists 14:73f6c425b2b5 679 free(key);
embeddedartists 14:73f6c425b2b5 680 free(val);
embeddedartists 14:73f6c425b2b5 681 } else {
embeddedartists 14:73f6c425b2b5 682 log->printf(REGTEST" [%2d] got error %d\n", i, err);
embeddedartists 14:73f6c425b2b5 683 }
embeddedartists 14:73f6c425b2b5 684 }
embeddedartists 14:73f6c425b2b5 685 }
embeddedartists 14:73f6c425b2b5 686
embeddedartists 0:dfad71908d59 687 /******************************************************************************
embeddedartists 0:dfad71908d59 688 * Main function
embeddedartists 0:dfad71908d59 689 *****************************************************************************/
embeddedartists 0:dfad71908d59 690 int main()
embeddedartists 0:dfad71908d59 691 {
embeddedartists 0:dfad71908d59 692 DMBoard::BoardError err;
embeddedartists 0:dfad71908d59 693 DMBoard* board = &DMBoard::instance();
embeddedartists 0:dfad71908d59 694 RtosLog* log = board->logger();
embeddedartists 0:dfad71908d59 695 err = board->init();
embeddedartists 0:dfad71908d59 696 if (err != DMBoard::Ok) {
embeddedartists 0:dfad71908d59 697 log->printf("Failed to initialize the board, got error %d\r\n", err);
embeddedartists 16:77f4f42eb6a7 698 log->printf("\nTERMINATING\n");
embeddedartists 16:77f4f42eb6a7 699 wait_ms(2000); // allow RtosLog to flush messages
embeddedartists 0:dfad71908d59 700 mbed_die();
embeddedartists 0:dfad71908d59 701 }
embeddedartists 0:dfad71908d59 702
embeddedartists 11:4830c7689843 703 board->buzzer(440,50);
embeddedartists 11:4830c7689843 704 wait_ms(30);
embeddedartists 11:4830c7689843 705 board->buzzer(660,50);
embeddedartists 11:4830c7689843 706 wait_ms(30);
embeddedartists 11:4830c7689843 707 board->buzzer(440,50);
embeddedartists 11:4830c7689843 708
embeddedartists 0:dfad71908d59 709 log->printf("\n\n---\nMulti-threaded demo\nBuilt: " __DATE__ " at " __TIME__ "\n\n");
embeddedartists 0:dfad71908d59 710
embeddedartists 1:15ea03d72dd7 711 //log->printf("Press button to start...\r\n");
embeddedartists 1:15ea03d72dd7 712 //while(!board->buttonPressed());
embeddedartists 1:15ea03d72dd7 713 //while(board->buttonPressed());
embeddedartists 0:dfad71908d59 714
embeddedartists 16:77f4f42eb6a7 715 //testRegistry();
embeddedartists 14:73f6c425b2b5 716
embeddedartists 14:73f6c425b2b5 717
embeddedartists 0:dfad71908d59 718 Thread tAlive(aliveTask);
embeddedartists 0:dfad71908d59 719 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 2:070e9c054796 720 Thread tSwim(swimTask, NULL, osPriorityNormal, 8192);
embeddedartists 0:dfad71908d59 721 #endif
embeddedartists 18:715f542538b3 722 //Thread tMemstick(msdTask, NULL, osPriorityNormal, 8192);
embeddedartists 0:dfad71908d59 723 Thread tNetwork(netTask, NULL, osPriorityNormal, 8192);
embeddedartists 18:715f542538b3 724 //Thread tMouse(mouseTask);
embeddedartists 18:715f542538b3 725 //Thread tKeyboard(keyTask);
embeddedartists 18:715f542538b3 726 Thread tUSBHandler(usbTask, NULL, osPriorityNormal, 8192);
embeddedartists 0:dfad71908d59 727
embeddedartists 18:715f542538b3 728 //while(1) { wait(5); }
embeddedartists 18:715f542538b3 729 while(1) {
embeddedartists 18:715f542538b3 730 wait(5);
embeddedartists 18:715f542538b3 731 time_t seconds = time(NULL);
embeddedartists 18:715f542538b3 732 log->printf("Time: %s\n", ctime(&seconds));
embeddedartists 18:715f542538b3 733 }
embeddedartists 0:dfad71908d59 734 }