Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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:
main.cpp@23:3f8bc89e0b23, 2015-01-26 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Jan 26 14:48:37 2015 +0000
- Revision:
- 23:3f8bc89e0b23
- Parent:
- 18:715f542538b3
- Child:
- 24:768f5958c308
Removed dead code in main. Included SDRAM fix in new version of DMSupport lib
Who changed what in which revision?
User | Revision | Line number | New 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 | |
embeddedartists | 0:dfad71908d59 | 202 | #define NET_TASK_PREFIX "[NET] " |
embeddedartists | 0:dfad71908d59 | 203 | |
embeddedartists | 0:dfad71908d59 | 204 | void netTask(void const* args) |
embeddedartists | 0:dfad71908d59 | 205 | { |
embeddedartists | 0:dfad71908d59 | 206 | RtosLog* log = DMBoard::instance().logger(); |
embeddedartists | 0:dfad71908d59 | 207 | log->printf(NET_TASK_PREFIX"EthernetInterface Setting up...\r\n"); |
embeddedartists | 0:dfad71908d59 | 208 | if(eth.init()!=0) { //for DHCP Server |
embeddedartists | 0:dfad71908d59 | 209 | //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address |
embeddedartists | 0:dfad71908d59 | 210 | log->printf(NET_TASK_PREFIX"EthernetInterface Initialize Error \r\n"); |
embeddedartists | 0:dfad71908d59 | 211 | mbed_die(); |
embeddedartists | 0:dfad71908d59 | 212 | } |
embeddedartists | 2:070e9c054796 | 213 | while (eth.connect() != 0) { |
embeddedartists | 2:070e9c054796 | 214 | Thread::wait(1000); |
embeddedartists | 0:dfad71908d59 | 215 | } |
embeddedartists | 0:dfad71908d59 | 216 | |
embeddedartists | 2:070e9c054796 | 217 | ethInitialized = true; |
embeddedartists | 2:070e9c054796 | 218 | ethUsingDHCP = true; |
embeddedartists | 2:070e9c054796 | 219 | |
embeddedartists | 0:dfad71908d59 | 220 | log->printf(NET_TASK_PREFIX"IP Address is %s\r\n", eth.getIPAddress()); |
embeddedartists | 0:dfad71908d59 | 221 | log->printf(NET_TASK_PREFIX"NetMask is %s\r\n", eth.getNetworkMask()); |
embeddedartists | 0:dfad71908d59 | 222 | log->printf(NET_TASK_PREFIX"Gateway Address is %s\r\n", eth.getGateway()); |
embeddedartists | 0:dfad71908d59 | 223 | log->printf(NET_TASK_PREFIX"Ethernet Setup OK\r\n"); |
embeddedartists | 0:dfad71908d59 | 224 | |
embeddedartists | 0:dfad71908d59 | 225 | HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler |
embeddedartists | 0:dfad71908d59 | 226 | FSHandler::mount("/usb", "/"); |
embeddedartists | 0:dfad71908d59 | 227 | HTTPServerAddHandler<FSHandler>("/"); |
embeddedartists | 0:dfad71908d59 | 228 | //HTTPServerAddHandler<RPCHandler>("/rpc"); |
embeddedartists | 0:dfad71908d59 | 229 | //lcd.locate(0,0); |
embeddedartists | 0:dfad71908d59 | 230 | //lcd.printf("%s",eth.getIPAddress()); |
embeddedartists | 0:dfad71908d59 | 231 | HTTPServerStart(80); |
embeddedartists | 0:dfad71908d59 | 232 | } |
embeddedartists | 0:dfad71908d59 | 233 | |
embeddedartists | 13:57e65aba9802 | 234 | static int8_t mouse_button, mouse_x, mouse_y, mouse_z; |
embeddedartists | 13:57e65aba9802 | 235 | static uint16_t cursor_x=0, cursor_y=0; |
embeddedartists | 1:15ea03d72dd7 | 236 | void mouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) |
embeddedartists | 1:15ea03d72dd7 | 237 | { |
embeddedartists | 1:15ea03d72dd7 | 238 | mouse_button = buttons; |
embeddedartists | 1:15ea03d72dd7 | 239 | mouse_x = x; |
embeddedartists | 1:15ea03d72dd7 | 240 | mouse_y = y; |
embeddedartists | 1:15ea03d72dd7 | 241 | mouse_z = z; |
embeddedartists | 13:57e65aba9802 | 242 | |
embeddedartists | 13:57e65aba9802 | 243 | if (x < 0) { |
embeddedartists | 13:57e65aba9802 | 244 | if (cursor_x > -x) { |
embeddedartists | 13:57e65aba9802 | 245 | cursor_x += x; |
embeddedartists | 13:57e65aba9802 | 246 | } else { |
embeddedartists | 13:57e65aba9802 | 247 | cursor_x = 0; |
embeddedartists | 13:57e65aba9802 | 248 | } |
embeddedartists | 13:57e65aba9802 | 249 | } else { |
embeddedartists | 13:57e65aba9802 | 250 | if ((cursor_x + x) >= 480) { |
embeddedartists | 13:57e65aba9802 | 251 | cursor_x = 479; |
embeddedartists | 13:57e65aba9802 | 252 | } else { |
embeddedartists | 13:57e65aba9802 | 253 | cursor_x += x; |
embeddedartists | 13:57e65aba9802 | 254 | } |
embeddedartists | 13:57e65aba9802 | 255 | } |
embeddedartists | 13:57e65aba9802 | 256 | y = y/8; |
embeddedartists | 13:57e65aba9802 | 257 | if (y < 0) { |
embeddedartists | 13:57e65aba9802 | 258 | if (cursor_y > -y) { |
embeddedartists | 13:57e65aba9802 | 259 | cursor_y += y; |
embeddedartists | 13:57e65aba9802 | 260 | } else { |
embeddedartists | 13:57e65aba9802 | 261 | cursor_y = 0; |
embeddedartists | 13:57e65aba9802 | 262 | } |
embeddedartists | 13:57e65aba9802 | 263 | } else { |
embeddedartists | 13:57e65aba9802 | 264 | if ((cursor_y + y) >= 272) { |
embeddedartists | 13:57e65aba9802 | 265 | cursor_y = 271; |
embeddedartists | 13:57e65aba9802 | 266 | } else { |
embeddedartists | 13:57e65aba9802 | 267 | cursor_y += y; |
embeddedartists | 13:57e65aba9802 | 268 | } |
embeddedartists | 13:57e65aba9802 | 269 | } |
embeddedartists | 13:57e65aba9802 | 270 | |
embeddedartists | 13:57e65aba9802 | 271 | //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y); |
embeddedartists | 13:57e65aba9802 | 272 | LPC_LCD->CRSR_XY = (cursor_x & 0x3FF) | ((cursor_y & 0x3FF) << 16); |
embeddedartists | 13:57e65aba9802 | 273 | } |
embeddedartists | 13:57e65aba9802 | 274 | |
embeddedartists | 13:57e65aba9802 | 275 | #define LCD_CURSOR_32x32 0 |
embeddedartists | 13:57e65aba9802 | 276 | #define LCD_CURSOR_64x64 1 |
embeddedartists | 13:57e65aba9802 | 277 | #define CURSOR_SIZE LCD_CURSOR_32x32 |
embeddedartists | 13:57e65aba9802 | 278 | #define CURSOR_H_SIZE 32 |
embeddedartists | 13:57e65aba9802 | 279 | #define CURSOR_V_SIZE 32 |
embeddedartists | 13:57e65aba9802 | 280 | #define CURSOR_NUM 0 |
embeddedartists | 13:57e65aba9802 | 281 | #define CURSOR_H_OFS (10) |
embeddedartists | 13:57e65aba9802 | 282 | #define CURSOR_V_OFS (6) |
embeddedartists | 13:57e65aba9802 | 283 | |
embeddedartists | 13:57e65aba9802 | 284 | const unsigned char __attribute__ ((aligned(4))) Cursor[(CURSOR_H_SIZE / 4) * CURSOR_V_SIZE] = |
embeddedartists | 13:57e65aba9802 | 285 | { |
embeddedartists | 13:57e65aba9802 | 286 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 287 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 288 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 289 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 290 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 291 | 0xAA, 0xAA, 0xAA, 0xFA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 292 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 293 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 294 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 295 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 296 | 0xAA, 0xAA, 0xAB, 0xFF, 0xEA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 297 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 298 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 299 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 300 | 0xAA, 0xAB, 0xFB, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 301 | 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 302 | 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 303 | 0xAA, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 304 | 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 305 | 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 306 | 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 307 | 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 308 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 309 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 310 | 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 311 | 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 312 | 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 313 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 314 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 315 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 316 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
embeddedartists | 13:57e65aba9802 | 317 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA |
embeddedartists | 13:57e65aba9802 | 318 | }; |
embeddedartists | 13:57e65aba9802 | 319 | |
embeddedartists | 13:57e65aba9802 | 320 | void prepareCursor(bool enable) { |
embeddedartists | 13:57e65aba9802 | 321 | //Chip_LCD_Cursor_Disable(LPC_LCD, 0); |
embeddedartists | 13:57e65aba9802 | 322 | LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4); |
embeddedartists | 13:57e65aba9802 | 323 | |
embeddedartists | 13:57e65aba9802 | 324 | if (enable) { |
embeddedartists | 13:57e65aba9802 | 325 | //Chip_LCD_Cursor_Config(LPC_LCD, LCD_CURSOR_32x32, true); |
embeddedartists | 13:57e65aba9802 | 326 | LPC_LCD->CRSR_CFG = ((true ? 1 : 0) << 1) | CURSOR_SIZE; |
embeddedartists | 13:57e65aba9802 | 327 | |
embeddedartists | 13:57e65aba9802 | 328 | //Chip_LCD_Cursor_WriteImage(LPC_LCD, 0, (void *) Cursor); |
embeddedartists | 13:57e65aba9802 | 329 | { |
embeddedartists | 13:57e65aba9802 | 330 | int i, j; |
embeddedartists | 13:57e65aba9802 | 331 | uint32_t *fifoptr, *crsr_ptr = (uint32_t *) Cursor; |
embeddedartists | 13:57e65aba9802 | 332 | |
embeddedartists | 13:57e65aba9802 | 333 | /* Check if Cursor Size was configured as 32x32 or 64x64*/ |
embeddedartists | 13:57e65aba9802 | 334 | if (CURSOR_SIZE == LCD_CURSOR_32x32) { |
embeddedartists | 13:57e65aba9802 | 335 | i = CURSOR_NUM * 64; |
embeddedartists | 13:57e65aba9802 | 336 | j = i + 64; |
embeddedartists | 13:57e65aba9802 | 337 | } |
embeddedartists | 13:57e65aba9802 | 338 | else { |
embeddedartists | 13:57e65aba9802 | 339 | i = 0; |
embeddedartists | 13:57e65aba9802 | 340 | j = 256; |
embeddedartists | 13:57e65aba9802 | 341 | } |
embeddedartists | 13:57e65aba9802 | 342 | fifoptr = (uint32_t *) &(LPC_LCD->CRSR_IMG[0]); |
embeddedartists | 13:57e65aba9802 | 343 | |
embeddedartists | 13:57e65aba9802 | 344 | /* Copy Cursor Image content to FIFO */ |
embeddedartists | 13:57e65aba9802 | 345 | for (; i < j; i++) { |
embeddedartists | 13:57e65aba9802 | 346 | |
embeddedartists | 13:57e65aba9802 | 347 | *fifoptr = *crsr_ptr; |
embeddedartists | 13:57e65aba9802 | 348 | crsr_ptr++; |
embeddedartists | 13:57e65aba9802 | 349 | fifoptr++; |
embeddedartists | 13:57e65aba9802 | 350 | } |
embeddedartists | 13:57e65aba9802 | 351 | } |
embeddedartists | 13:57e65aba9802 | 352 | |
embeddedartists | 13:57e65aba9802 | 353 | //Chip_LCD_Cursor_SetClip(LPC_LCD, CURSOR_H_OFS, CURSOR_V_OFS); |
embeddedartists | 13:57e65aba9802 | 354 | LPC_LCD->CRSR_CLIP = (CURSOR_H_OFS & 0x3F) | ((CURSOR_V_OFS & 0x3F) << 8); |
embeddedartists | 13:57e65aba9802 | 355 | |
embeddedartists | 13:57e65aba9802 | 356 | //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y); |
embeddedartists | 13:57e65aba9802 | 357 | |
embeddedartists | 13:57e65aba9802 | 358 | //Chip_LCD_Cursor_Enable(LPC_LCD, 0); |
embeddedartists | 13:57e65aba9802 | 359 | LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4) | 1; |
embeddedartists | 13:57e65aba9802 | 360 | } |
embeddedartists | 1:15ea03d72dd7 | 361 | } |
embeddedartists | 1:15ea03d72dd7 | 362 | |
embeddedartists | 1:15ea03d72dd7 | 363 | |
embeddedartists | 1:15ea03d72dd7 | 364 | #define CIRCBUFF_SIZE 256 |
embeddedartists | 1:15ea03d72dd7 | 365 | static uint8_t circbuff[CIRCBUFF_SIZE]; |
embeddedartists | 1:15ea03d72dd7 | 366 | static uint32_t circbuff_read = 0; |
embeddedartists | 1:15ea03d72dd7 | 367 | static uint32_t circbuff_write = 0; |
embeddedartists | 1:15ea03d72dd7 | 368 | void keyEvent(uint8_t key) |
embeddedartists | 1:15ea03d72dd7 | 369 | { |
embeddedartists | 1:15ea03d72dd7 | 370 | circbuff[circbuff_write%CIRCBUFF_SIZE] = key; |
embeddedartists | 1:15ea03d72dd7 | 371 | circbuff_write++; |
embeddedartists | 1:15ea03d72dd7 | 372 | } |
embeddedartists | 1:15ea03d72dd7 | 373 | |
embeddedartists | 1:15ea03d72dd7 | 374 | |
embeddedartists | 18:715f542538b3 | 375 | #define USB_TASK_PREFIX "[USB] " |
embeddedartists | 18:715f542538b3 | 376 | #define USB_CONNECTION_EVENT (1<<4) |
embeddedartists | 18:715f542538b3 | 377 | void usbTask(void const* args) |
embeddedartists | 18:715f542538b3 | 378 | { |
embeddedartists | 18:715f542538b3 | 379 | bool msdConnected = false; |
embeddedartists | 18:715f542538b3 | 380 | bool keyboardConnected = false; |
embeddedartists | 18:715f542538b3 | 381 | bool mouseConnected = false; |
embeddedartists | 18:715f542538b3 | 382 | |
embeddedartists | 18:715f542538b3 | 383 | USBHostMSD* msd = new USBHostMSD("usb"); |
embeddedartists | 18:715f542538b3 | 384 | USBHostKeyboard* keyboard = new USBHostKeyboard(); |
embeddedartists | 18:715f542538b3 | 385 | USBHostMouse* mouse = new USBHostMouse(); |
embeddedartists | 18:715f542538b3 | 386 | USBHost* host = USBHost::getHostInst(); |
embeddedartists | 18:715f542538b3 | 387 | host->signalOnConnections(Thread::gettid(), USB_CONNECTION_EVENT); |
embeddedartists | 18:715f542538b3 | 388 | |
embeddedartists | 18:715f542538b3 | 389 | RtosLog* log = DMBoard::instance().logger(); |
embeddedartists | 18:715f542538b3 | 390 | |
embeddedartists | 18:715f542538b3 | 391 | log->printf(USB_TASK_PREFIX"usbTask started\n"); |
embeddedartists | 18:715f542538b3 | 392 | |
embeddedartists | 18:715f542538b3 | 393 | prepareCursor(false); |
embeddedartists | 18:715f542538b3 | 394 | |
embeddedartists | 18:715f542538b3 | 395 | while (true) { |
embeddedartists | 18:715f542538b3 | 396 | // wait for connect/disconnect message from USBHost |
embeddedartists | 18:715f542538b3 | 397 | Thread::signal_wait(USB_CONNECTION_EVENT); |
embeddedartists | 18:715f542538b3 | 398 | log->printf(USB_TASK_PREFIX"got USB event\n"); |
embeddedartists | 18:715f542538b3 | 399 | |
embeddedartists | 18:715f542538b3 | 400 | if (msd->connected()) { |
embeddedartists | 18:715f542538b3 | 401 | if (!msdConnected) { |
embeddedartists | 18:715f542538b3 | 402 | msdConnected = true; |
embeddedartists | 18:715f542538b3 | 403 | haveUSBMSD = true; |
embeddedartists | 18:715f542538b3 | 404 | log->printf(USB_TASK_PREFIX"USB MassStorage Device - Connected\n"); |
embeddedartists | 18:715f542538b3 | 405 | } |
embeddedartists | 18:715f542538b3 | 406 | } else { |
embeddedartists | 18:715f542538b3 | 407 | if (msdConnected) { |
embeddedartists | 18:715f542538b3 | 408 | msdConnected = false; |
embeddedartists | 18:715f542538b3 | 409 | haveUSBMSD = false; |
embeddedartists | 18:715f542538b3 | 410 | log->printf(USB_TASK_PREFIX"USB MassStorage Device - Ejected\n"); |
embeddedartists | 18:715f542538b3 | 411 | } |
embeddedartists | 18:715f542538b3 | 412 | |
embeddedartists | 18:715f542538b3 | 413 | if (msd->connect()) { |
embeddedartists | 18:715f542538b3 | 414 | msdConnected = true; |
embeddedartists | 18:715f542538b3 | 415 | haveUSBMSD = true; |
embeddedartists | 18:715f542538b3 | 416 | log->printf(USB_TASK_PREFIX"USB MassStorage Device - Connected\n"); |
embeddedartists | 18:715f542538b3 | 417 | } |
embeddedartists | 18:715f542538b3 | 418 | } |
embeddedartists | 18:715f542538b3 | 419 | |
embeddedartists | 18:715f542538b3 | 420 | if (keyboard->connected()) { |
embeddedartists | 18:715f542538b3 | 421 | if (!keyboardConnected) { |
embeddedartists | 18:715f542538b3 | 422 | keyboardConnected = true; |
embeddedartists | 18:715f542538b3 | 423 | log->printf(USB_TASK_PREFIX"USB Keyboard - Connected\n"); |
embeddedartists | 18:715f542538b3 | 424 | keyboard->attach(keyEvent); |
embeddedartists | 18:715f542538b3 | 425 | } |
embeddedartists | 18:715f542538b3 | 426 | } else { |
embeddedartists | 18:715f542538b3 | 427 | if (keyboardConnected) { |
embeddedartists | 18:715f542538b3 | 428 | keyboardConnected = false; |
embeddedartists | 18:715f542538b3 | 429 | log->printf(USB_TASK_PREFIX"USB Keyboard - Ejected\n"); |
embeddedartists | 18:715f542538b3 | 430 | } |
embeddedartists | 18:715f542538b3 | 431 | if (keyboard->connect()) { |
embeddedartists | 18:715f542538b3 | 432 | keyboardConnected = true; |
embeddedartists | 18:715f542538b3 | 433 | log->printf(USB_TASK_PREFIX"USB Keyboard - Connected\n"); |
embeddedartists | 18:715f542538b3 | 434 | keyboard->attach(keyEvent); |
embeddedartists | 18:715f542538b3 | 435 | } |
embeddedartists | 18:715f542538b3 | 436 | } |
embeddedartists | 18:715f542538b3 | 437 | |
embeddedartists | 18:715f542538b3 | 438 | if (mouse->connected()) { |
embeddedartists | 18:715f542538b3 | 439 | if (!mouseConnected) { |
embeddedartists | 18:715f542538b3 | 440 | mouseConnected = true; |
embeddedartists | 18:715f542538b3 | 441 | log->printf(USB_TASK_PREFIX"USB Mouse - Connected\n"); |
embeddedartists | 18:715f542538b3 | 442 | mouse->attachEvent(mouseEvent); |
embeddedartists | 18:715f542538b3 | 443 | prepareCursor(true); |
embeddedartists | 18:715f542538b3 | 444 | } |
embeddedartists | 18:715f542538b3 | 445 | } else { |
embeddedartists | 18:715f542538b3 | 446 | if (mouseConnected) { |
embeddedartists | 18:715f542538b3 | 447 | prepareCursor(false); |
embeddedartists | 18:715f542538b3 | 448 | mouseConnected = false; |
embeddedartists | 18:715f542538b3 | 449 | log->printf(USB_TASK_PREFIX"USB Mouse - Ejected\n"); |
embeddedartists | 18:715f542538b3 | 450 | } |
embeddedartists | 18:715f542538b3 | 451 | if (mouse->connect()) { |
embeddedartists | 18:715f542538b3 | 452 | mouseConnected = true; |
embeddedartists | 18:715f542538b3 | 453 | log->printf(USB_TASK_PREFIX"USB Mouse - Connected\n"); |
embeddedartists | 18:715f542538b3 | 454 | mouse->attachEvent(mouseEvent); |
embeddedartists | 18:715f542538b3 | 455 | prepareCursor(true); |
embeddedartists | 18:715f542538b3 | 456 | } |
embeddedartists | 18:715f542538b3 | 457 | } |
embeddedartists | 18:715f542538b3 | 458 | } |
embeddedartists | 18:715f542538b3 | 459 | } |
embeddedartists | 18:715f542538b3 | 460 | |
embeddedartists | 18:715f542538b3 | 461 | |
embeddedartists | 14:73f6c425b2b5 | 462 | #define REGTEST "[REG] " |
embeddedartists | 14:73f6c425b2b5 | 463 | static void testRegistry() |
embeddedartists | 14:73f6c425b2b5 | 464 | { |
embeddedartists | 14:73f6c425b2b5 | 465 | Registry* reg = DMBoard::instance().registry(); |
embeddedartists | 14:73f6c425b2b5 | 466 | RtosLog* log = DMBoard::instance().logger(); |
embeddedartists | 14:73f6c425b2b5 | 467 | char* key; |
embeddedartists | 14:73f6c425b2b5 | 468 | char* val; |
embeddedartists | 14:73f6c425b2b5 | 469 | Registry::RegistryError err; |
embeddedartists | 14:73f6c425b2b5 | 470 | |
embeddedartists | 14:73f6c425b2b5 | 471 | log->printf(REGTEST"Before:\n"); |
embeddedartists | 14:73f6c425b2b5 | 472 | for (int i = 0; i < reg->numEntries(); i++) { |
embeddedartists | 14:73f6c425b2b5 | 473 | err = reg->entryAt(i, &key, &val); |
embeddedartists | 14:73f6c425b2b5 | 474 | if (err == Registry::Ok) { |
embeddedartists | 14:73f6c425b2b5 | 475 | log->printf(REGTEST" [%2d] '%s' = '%s'\n", i, key, val); |
embeddedartists | 14:73f6c425b2b5 | 476 | free(key); |
embeddedartists | 14:73f6c425b2b5 | 477 | free(val); |
embeddedartists | 14:73f6c425b2b5 | 478 | } else { |
embeddedartists | 14:73f6c425b2b5 | 479 | log->printf(REGTEST" [%2d] got error %d\n", i, err); |
embeddedartists | 14:73f6c425b2b5 | 480 | } |
embeddedartists | 14:73f6c425b2b5 | 481 | } |
embeddedartists | 14:73f6c425b2b5 | 482 | |
embeddedartists | 14:73f6c425b2b5 | 483 | log->printf(REGTEST"Getting existing value:\n"); |
embeddedartists | 14:73f6c425b2b5 | 484 | err = reg->getValue("IP Address", &val); |
embeddedartists | 14:73f6c425b2b5 | 485 | if (err == Registry::Ok) { |
embeddedartists | 14:73f6c425b2b5 | 486 | log->printf(REGTEST" Existing 'IP Address' = '%s'\n", val); |
embeddedartists | 14:73f6c425b2b5 | 487 | free(val); |
embeddedartists | 14:73f6c425b2b5 | 488 | } else { |
embeddedartists | 14:73f6c425b2b5 | 489 | log->printf(REGTEST" Existing 'IP Address' got error %d\n", err); |
embeddedartists | 14:73f6c425b2b5 | 490 | } |
embeddedartists | 14:73f6c425b2b5 | 491 | |
embeddedartists | 14:73f6c425b2b5 | 492 | log->printf(REGTEST"Getting missing value:\n"); |
embeddedartists | 14:73f6c425b2b5 | 493 | err = reg->getValue("X78g4dfwx", &val); |
embeddedartists | 14:73f6c425b2b5 | 494 | if (err == Registry::Ok) { |
embeddedartists | 14:73f6c425b2b5 | 495 | log->printf(REGTEST" Missing 'X78g4dfwx' = '%s'\n", val); |
embeddedartists | 14:73f6c425b2b5 | 496 | free(val); |
embeddedartists | 14:73f6c425b2b5 | 497 | } else if (err == Registry::NoSuchKeyError) { |
embeddedartists | 14:73f6c425b2b5 | 498 | log->printf(REGTEST" Missing 'X78g4dfwx' was missing.\n", err); |
embeddedartists | 14:73f6c425b2b5 | 499 | } else { |
embeddedartists | 14:73f6c425b2b5 | 500 | log->printf(REGTEST" Existing 'X78g4dfwx' got error %d\n", err); |
embeddedartists | 14:73f6c425b2b5 | 501 | } |
embeddedartists | 14:73f6c425b2b5 | 502 | |
embeddedartists | 14:73f6c425b2b5 | 503 | log->printf(REGTEST"Updating value:\n"); |
embeddedartists | 14:73f6c425b2b5 | 504 | err = reg->getValue("EATest", &val); |
embeddedartists | 14:73f6c425b2b5 | 505 | if (err == Registry::Ok) { |
embeddedartists | 14:73f6c425b2b5 | 506 | log->printf(REGTEST" Old value for 'EATest' = '%s'\n", val); |
embeddedartists | 14:73f6c425b2b5 | 507 | char buf[32]; |
embeddedartists | 14:73f6c425b2b5 | 508 | sprintf(buf, "%d", atoi(val)+1); |
embeddedartists | 14:73f6c425b2b5 | 509 | free(val); |
embeddedartists | 14:73f6c425b2b5 | 510 | err = reg->setValue("EATest", buf); |
embeddedartists | 14:73f6c425b2b5 | 511 | if (err == Registry::Ok) { |
embeddedartists | 14:73f6c425b2b5 | 512 | log->printf(REGTEST" Updated 'EATest' to '%s'\n", buf); |
embeddedartists | 14:73f6c425b2b5 | 513 | } else { |
embeddedartists | 14:73f6c425b2b5 | 514 | log->printf(REGTEST" Failed to update 'EATest', got error %d\n", err); |
embeddedartists | 14:73f6c425b2b5 | 515 | } |
embeddedartists | 14:73f6c425b2b5 | 516 | } else if (err == Registry::NoSuchKeyError) { |
embeddedartists | 14:73f6c425b2b5 | 517 | log->printf(REGTEST" No value for 'EATest', adding one\n", err); |
embeddedartists | 14:73f6c425b2b5 | 518 | err = reg->setValue("EATest", "-3"); |
embeddedartists | 14:73f6c425b2b5 | 519 | if (err == Registry::Ok) { |
embeddedartists | 14:73f6c425b2b5 | 520 | log->printf(REGTEST" Set 'EATest' to '0'\n"); |
embeddedartists | 14:73f6c425b2b5 | 521 | } else { |
embeddedartists | 14:73f6c425b2b5 | 522 | log->printf(REGTEST" Failed to set 'EATest', got error %d\n", err); |
embeddedartists | 14:73f6c425b2b5 | 523 | } |
embeddedartists | 14:73f6c425b2b5 | 524 | } else { |
embeddedartists | 14:73f6c425b2b5 | 525 | log->printf(REGTEST" Failed to read 'EATest' got error %d\n", err); |
embeddedartists | 14:73f6c425b2b5 | 526 | } |
embeddedartists | 14:73f6c425b2b5 | 527 | |
embeddedartists | 14:73f6c425b2b5 | 528 | log->printf(REGTEST"Storing values persistently\n"); |
embeddedartists | 14:73f6c425b2b5 | 529 | err = reg->store(); |
embeddedartists | 14:73f6c425b2b5 | 530 | if (err != Registry::Ok) { |
embeddedartists | 14:73f6c425b2b5 | 531 | log->printf(REGTEST" Failed to store values, got error %d\n", err); |
embeddedartists | 14:73f6c425b2b5 | 532 | } |
embeddedartists | 14:73f6c425b2b5 | 533 | |
embeddedartists | 14:73f6c425b2b5 | 534 | log->printf(REGTEST"After:\n"); |
embeddedartists | 14:73f6c425b2b5 | 535 | for (int i = 0; i < reg->numEntries(); i++) { |
embeddedartists | 14:73f6c425b2b5 | 536 | err = reg->entryAt(i, &key, &val); |
embeddedartists | 14:73f6c425b2b5 | 537 | if (err == Registry::Ok) { |
embeddedartists | 14:73f6c425b2b5 | 538 | log->printf(REGTEST" [%2d] '%s' = '%s'\n", i, key, val); |
embeddedartists | 14:73f6c425b2b5 | 539 | free(key); |
embeddedartists | 14:73f6c425b2b5 | 540 | free(val); |
embeddedartists | 14:73f6c425b2b5 | 541 | } else { |
embeddedartists | 14:73f6c425b2b5 | 542 | log->printf(REGTEST" [%2d] got error %d\n", i, err); |
embeddedartists | 14:73f6c425b2b5 | 543 | } |
embeddedartists | 14:73f6c425b2b5 | 544 | } |
embeddedartists | 14:73f6c425b2b5 | 545 | } |
embeddedartists | 14:73f6c425b2b5 | 546 | |
embeddedartists | 0:dfad71908d59 | 547 | /****************************************************************************** |
embeddedartists | 0:dfad71908d59 | 548 | * Main function |
embeddedartists | 0:dfad71908d59 | 549 | *****************************************************************************/ |
embeddedartists | 0:dfad71908d59 | 550 | int main() |
embeddedartists | 0:dfad71908d59 | 551 | { |
embeddedartists | 0:dfad71908d59 | 552 | DMBoard::BoardError err; |
embeddedartists | 0:dfad71908d59 | 553 | DMBoard* board = &DMBoard::instance(); |
embeddedartists | 0:dfad71908d59 | 554 | RtosLog* log = board->logger(); |
embeddedartists | 0:dfad71908d59 | 555 | err = board->init(); |
embeddedartists | 0:dfad71908d59 | 556 | if (err != DMBoard::Ok) { |
embeddedartists | 0:dfad71908d59 | 557 | log->printf("Failed to initialize the board, got error %d\r\n", err); |
embeddedartists | 16:77f4f42eb6a7 | 558 | log->printf("\nTERMINATING\n"); |
embeddedartists | 16:77f4f42eb6a7 | 559 | wait_ms(2000); // allow RtosLog to flush messages |
embeddedartists | 0:dfad71908d59 | 560 | mbed_die(); |
embeddedartists | 0:dfad71908d59 | 561 | } |
embeddedartists | 0:dfad71908d59 | 562 | |
embeddedartists | 11:4830c7689843 | 563 | board->buzzer(440,50); |
embeddedartists | 11:4830c7689843 | 564 | wait_ms(30); |
embeddedartists | 11:4830c7689843 | 565 | board->buzzer(660,50); |
embeddedartists | 11:4830c7689843 | 566 | wait_ms(30); |
embeddedartists | 11:4830c7689843 | 567 | board->buzzer(440,50); |
embeddedartists | 11:4830c7689843 | 568 | |
embeddedartists | 0:dfad71908d59 | 569 | log->printf("\n\n---\nMulti-threaded demo\nBuilt: " __DATE__ " at " __TIME__ "\n\n"); |
embeddedartists | 0:dfad71908d59 | 570 | |
embeddedartists | 16:77f4f42eb6a7 | 571 | //testRegistry(); |
embeddedartists | 14:73f6c425b2b5 | 572 | |
embeddedartists | 14:73f6c425b2b5 | 573 | |
embeddedartists | 0:dfad71908d59 | 574 | Thread tAlive(aliveTask); |
embeddedartists | 0:dfad71908d59 | 575 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 2:070e9c054796 | 576 | Thread tSwim(swimTask, NULL, osPriorityNormal, 8192); |
embeddedartists | 0:dfad71908d59 | 577 | #endif |
embeddedartists | 0:dfad71908d59 | 578 | Thread tNetwork(netTask, NULL, osPriorityNormal, 8192); |
embeddedartists | 18:715f542538b3 | 579 | Thread tUSBHandler(usbTask, NULL, osPriorityNormal, 8192); |
embeddedartists | 0:dfad71908d59 | 580 | |
embeddedartists | 18:715f542538b3 | 581 | while(1) { |
embeddedartists | 18:715f542538b3 | 582 | wait(5); |
embeddedartists | 18:715f542538b3 | 583 | time_t seconds = time(NULL); |
embeddedartists | 18:715f542538b3 | 584 | log->printf("Time: %s\n", ctime(&seconds)); |
embeddedartists | 18:715f542538b3 | 585 | } |
embeddedartists | 0:dfad71908d59 | 586 | } |