Sample GUI for LPC4088. Base code to begin dev
Dependencies: DMBasicGUI DMSupport
Fork of lpc4088_displaymodule_shipped_demo by
main.cpp@4:a7cbb22e4348, 2015-04-28 (annotated)
- Committer:
- alindvall
- Date:
- Tue Apr 28 12:21:14 2015 +0000
- Revision:
- 4:a7cbb22e4348
- Parent:
- 3:57de4d043115
Updated to latest version of the DMSupport and DMBasicGUI libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alindvall | 0:b94e330c98ac | 1 | /****************************************************************************** |
alindvall | 0:b94e330c98ac | 2 | * Includes |
alindvall | 0:b94e330c98ac | 3 | *****************************************************************************/ |
alindvall | 0:b94e330c98ac | 4 | |
alindvall | 0:b94e330c98ac | 5 | #include "mbed.h" |
alindvall | 0:b94e330c98ac | 6 | #include "mbed_interface.h" |
alindvall | 0:b94e330c98ac | 7 | #include "rtos.h" |
alindvall | 0:b94e330c98ac | 8 | #include "EthernetInterface.h" |
alindvall | 0:b94e330c98ac | 9 | #include "HTTPServer.h" |
alindvall | 0:b94e330c98ac | 10 | #include "mbed_rpc.h" |
alindvall | 0:b94e330c98ac | 11 | #include "USBHostMSD.h" |
alindvall | 0:b94e330c98ac | 12 | #include "USBHostMouse.h" |
alindvall | 0:b94e330c98ac | 13 | #include "USBHostKeyboard.h" |
alindvall | 0:b94e330c98ac | 14 | |
alindvall | 0:b94e330c98ac | 15 | #include "DMBoard.h" |
alindvall | 0:b94e330c98ac | 16 | |
alindvall | 0:b94e330c98ac | 17 | #include "AppLauncherSpecial.h" |
alindvall | 0:b94e330c98ac | 18 | #include "meas.h" |
alindvall | 0:b94e330c98ac | 19 | |
alindvall | 0:b94e330c98ac | 20 | #include "AppNetworkSettings.h" |
alindvall | 0:b94e330c98ac | 21 | #include "AppStatus.h" |
alindvall | 0:b94e330c98ac | 22 | #include "AppTouchCalibration.h" |
alindvall | 0:b94e330c98ac | 23 | #include "AppColorPicker.h" |
alindvall | 0:b94e330c98ac | 24 | #include "AppImageViewer.h" |
alindvall | 0:b94e330c98ac | 25 | #include "AppSlideShow.h" |
alindvall | 0:b94e330c98ac | 26 | #include "AppRTCSettings.h" |
alindvall | 0:b94e330c98ac | 27 | #include "AppUSBStatus.h" |
alindvall | 0:b94e330c98ac | 28 | #include "AppDraw.h" |
alindvall | 0:b94e330c98ac | 29 | #include "image_data.h" |
alindvall | 0:b94e330c98ac | 30 | #include "Resource.h" |
alindvall | 0:b94e330c98ac | 31 | |
alindvall | 0:b94e330c98ac | 32 | #include "lpc_swim.h" |
alindvall | 0:b94e330c98ac | 33 | #include "lpc_helvr10.h" |
alindvall | 0:b94e330c98ac | 34 | #include "lpc_winfreesystem14x16.h" |
alindvall | 0:b94e330c98ac | 35 | |
alindvall | 0:b94e330c98ac | 36 | /****************************************************************************** |
alindvall | 0:b94e330c98ac | 37 | * Typedefs and defines |
alindvall | 0:b94e330c98ac | 38 | *****************************************************************************/ |
alindvall | 0:b94e330c98ac | 39 | |
alindvall | 0:b94e330c98ac | 40 | typedef enum { |
alindvall | 0:b94e330c98ac | 41 | Res_ok, |
alindvall | 0:b94e330c98ac | 42 | Res_cancel, |
alindvall | 0:b94e330c98ac | 43 | Res_arrow_up, |
alindvall | 0:b94e330c98ac | 44 | Res_arrow_down, |
alindvall | 0:b94e330c98ac | 45 | Res_arrow_left, |
alindvall | 0:b94e330c98ac | 46 | Res_arrow_right, |
alindvall | 0:b94e330c98ac | 47 | Res_repeat, |
alindvall | 0:b94e330c98ac | 48 | Res_digits, |
alindvall | 0:b94e330c98ac | 49 | Res_background, |
alindvall | 0:b94e330c98ac | 50 | Res_about, |
alindvall | 0:b94e330c98ac | 51 | Res_ColorPickerApp, |
alindvall | 0:b94e330c98ac | 52 | Res_ImageViewerApp, |
alindvall | 0:b94e330c98ac | 53 | Res_SlideshowApp, |
alindvall | 0:b94e330c98ac | 54 | Res_SettingsApp, |
alindvall | 0:b94e330c98ac | 55 | Res_StatusApp, |
alindvall | 0:b94e330c98ac | 56 | //Res_TouchTestApp, |
alindvall | 0:b94e330c98ac | 57 | Res_RtcApp, |
alindvall | 0:b94e330c98ac | 58 | Res_USBStatusApp, |
alindvall | 0:b94e330c98ac | 59 | Res_DrawingApp, |
alindvall | 0:b94e330c98ac | 60 | //Res_CalibrationApp, |
alindvall | 0:b94e330c98ac | 61 | NumResources, |
alindvall | 0:b94e330c98ac | 62 | } resorces_t; |
alindvall | 0:b94e330c98ac | 63 | |
alindvall | 0:b94e330c98ac | 64 | /****************************************************************************** |
alindvall | 0:b94e330c98ac | 65 | * Local variables |
alindvall | 0:b94e330c98ac | 66 | *****************************************************************************/ |
alindvall | 0:b94e330c98ac | 67 | |
alindvall | 0:b94e330c98ac | 68 | static Resource* RESOURCES[NumResources] = {0}; |
alindvall | 0:b94e330c98ac | 69 | |
alindvall | 3:57de4d043115 | 70 | /****************************************************************************** |
alindvall | 3:57de4d043115 | 71 | * Global variables |
alindvall | 3:57de4d043115 | 72 | *****************************************************************************/ |
alindvall | 3:57de4d043115 | 73 | |
alindvall | 3:57de4d043115 | 74 | EthernetInterface eth; |
alindvall | 3:57de4d043115 | 75 | bool ethInitialized = false; |
alindvall | 3:57de4d043115 | 76 | bool ethUsingDHCP = true; |
alindvall | 3:57de4d043115 | 77 | bool haveUSBMSD = false; |
alindvall | 3:57de4d043115 | 78 | |
alindvall | 3:57de4d043115 | 79 | /****************************************************************************** |
alindvall | 3:57de4d043115 | 80 | * Local functions |
alindvall | 3:57de4d043115 | 81 | *****************************************************************************/ |
alindvall | 3:57de4d043115 | 82 | |
alindvall | 0:b94e330c98ac | 83 | static void prepareResources() |
alindvall | 0:b94e330c98ac | 84 | { |
alindvall | 0:b94e330c98ac | 85 | Display* disp = DMBoard::instance().display(); |
alindvall | 0:b94e330c98ac | 86 | |
alindvall | 0:b94e330c98ac | 87 | // select which images to use based on display size |
alindvall | 0:b94e330c98ac | 88 | if (disp->width() == 480) { |
alindvall | 0:b94e330c98ac | 89 | RESOURCES[Res_ok ] = new Resource(img_480x272_ok, img_size_480x272_ok, 40, 40); |
alindvall | 0:b94e330c98ac | 90 | RESOURCES[Res_cancel ] = new Resource(img_480x272_cancel, img_size_480x272_cancel, 40, 40); |
alindvall | 0:b94e330c98ac | 91 | RESOURCES[Res_arrow_up ] = new Resource(img_480x272_arrow_up, img_size_480x272_arrow_up, 52, 52); |
alindvall | 0:b94e330c98ac | 92 | RESOURCES[Res_arrow_down ] = new Resource(img_480x272_arrow_down, img_size_480x272_arrow_down, 52, 52); |
alindvall | 0:b94e330c98ac | 93 | RESOURCES[Res_arrow_left ] = new Resource(img_480x272_arrow_left, img_size_480x272_arrow_left, 52, 52); |
alindvall | 0:b94e330c98ac | 94 | RESOURCES[Res_arrow_right] = new Resource(img_480x272_arrow_right, img_size_480x272_arrow_right, 52, 52); |
alindvall | 0:b94e330c98ac | 95 | RESOURCES[Res_repeat ] = new Resource(img_480x272_repeat, img_size_480x272_repeat, 40, 40); |
alindvall | 0:b94e330c98ac | 96 | RESOURCES[Res_digits ] = new Resource(img_numbers_16b, img_size_numbers_16b, 13, 242); |
alindvall | 0:b94e330c98ac | 97 | |
alindvall | 0:b94e330c98ac | 98 | RESOURCES[Res_ColorPickerApp] = new Resource(img_480x272_super_mono_3d_part2_19, img_size_480x272_super_mono_3d_part2_19, 64, 64); |
alindvall | 0:b94e330c98ac | 99 | RESOURCES[Res_ImageViewerApp] = new Resource(img_480x272_super_mono_3d_48, img_size_480x272_super_mono_3d_48, 64, 64); |
alindvall | 0:b94e330c98ac | 100 | RESOURCES[Res_SlideshowApp ] = new Resource(img_480x272_super_mono_3d_87, img_size_480x272_super_mono_3d_87, 64, 64); |
alindvall | 0:b94e330c98ac | 101 | RESOURCES[Res_SettingsApp ] = new Resource(img_480x272_super_mono_3d_93, img_size_480x272_super_mono_3d_93, 64, 64); |
alindvall | 0:b94e330c98ac | 102 | RESOURCES[Res_StatusApp ] = new Resource(img_480x272_super_mono_3d_part2_68, img_size_480x272_super_mono_3d_part2_68, 64, 64); |
alindvall | 0:b94e330c98ac | 103 | RESOURCES[Res_RtcApp ] = new Resource(img_480x272_super_mono_3d_02, img_size_480x272_super_mono_3d_02, 64, 64); |
alindvall | 0:b94e330c98ac | 104 | RESOURCES[Res_USBStatusApp ] = new Resource(img_480x272_super_mono_3d_57, img_size_480x272_super_mono_3d_57, 64, 64); |
alindvall | 0:b94e330c98ac | 105 | RESOURCES[Res_DrawingApp ] = new Resource(img_480x272_super_mono_3d_22, img_size_480x272_super_mono_3d_22, 64, 64); |
alindvall | 0:b94e330c98ac | 106 | RESOURCES[Res_background ] = new Resource(img_480x272_background, img_size_480x272_background, 364, 57); |
alindvall | 0:b94e330c98ac | 107 | RESOURCES[Res_about ] = new Resource(img_480x272_about, img_size_480x272_about, 240, 245); |
alindvall | 0:b94e330c98ac | 108 | |
alindvall | 0:b94e330c98ac | 109 | swim_set_default_font(&font_helvr10); |
alindvall | 0:b94e330c98ac | 110 | } else { |
alindvall | 0:b94e330c98ac | 111 | RESOURCES[Res_ok ] = new Resource(img_800x480_ok, img_size_800x480_ok, 64, 64); |
alindvall | 0:b94e330c98ac | 112 | RESOURCES[Res_cancel ] = new Resource(img_800x480_cancel, img_size_800x480_cancel, 64, 64); |
alindvall | 0:b94e330c98ac | 113 | RESOURCES[Res_arrow_up ] = new Resource("/qspi/800x480_arrow_up.raw", 128, 128); |
alindvall | 0:b94e330c98ac | 114 | RESOURCES[Res_arrow_down ] = new Resource("/qspi/800x480_arrow_down.raw", 128, 128); |
alindvall | 0:b94e330c98ac | 115 | RESOURCES[Res_arrow_left ] = new Resource("/qspi/800x480_arrow_left.raw", 128, 128); |
alindvall | 0:b94e330c98ac | 116 | RESOURCES[Res_arrow_right] = new Resource("/qspi/800x480_arrow_right.raw", 128, 128); |
alindvall | 0:b94e330c98ac | 117 | RESOURCES[Res_repeat ] = new Resource(img_800x480_repeat, img_size_800x480_repeat, 64, 64); |
alindvall | 0:b94e330c98ac | 118 | RESOURCES[Res_digits ] = new Resource(img_numbers_20b, img_size_numbers_20b, 16, 322); |
alindvall | 0:b94e330c98ac | 119 | |
alindvall | 0:b94e330c98ac | 120 | RESOURCES[Res_ColorPickerApp] = new Resource("/qspi/800x480_super-mono-3d-part2-19.raw", 64, 64); |
alindvall | 0:b94e330c98ac | 121 | RESOURCES[Res_ImageViewerApp] = new Resource("/qspi/800x480_super-mono-3d-48.raw", 64, 64); |
alindvall | 0:b94e330c98ac | 122 | RESOURCES[Res_SlideshowApp ] = new Resource("/qspi/800x480_super-mono-3d-87.raw", 64, 64); |
alindvall | 0:b94e330c98ac | 123 | RESOURCES[Res_SettingsApp ] = new Resource("/qspi/800x480_super-mono-3d-93.raw", 64, 64); |
alindvall | 0:b94e330c98ac | 124 | RESOURCES[Res_StatusApp ] = new Resource("/qspi/800x480_super-mono-3d-part2-68.raw", 64, 64); |
alindvall | 0:b94e330c98ac | 125 | RESOURCES[Res_RtcApp ] = new Resource("/qspi/800x480_super-mono-3d-02.raw", 64, 64); |
alindvall | 0:b94e330c98ac | 126 | RESOURCES[Res_USBStatusApp ] = new Resource("/qspi/800x480_super-mono-3d-57.raw", 64, 64); |
alindvall | 0:b94e330c98ac | 127 | RESOURCES[Res_DrawingApp ] = new Resource("/qspi/800x480_super-mono-3d-22.raw", 64, 64); |
alindvall | 0:b94e330c98ac | 128 | RESOURCES[Res_background ] = new Resource("/qspi/800x480_background.raw", 548, 80); |
alindvall | 0:b94e330c98ac | 129 | RESOURCES[Res_about ] = new Resource("/qspi/800x480_about.raw", 420, 429); |
alindvall | 0:b94e330c98ac | 130 | |
alindvall | 0:b94e330c98ac | 131 | swim_set_default_font(&font_winfreesys14x16); |
alindvall | 0:b94e330c98ac | 132 | } |
alindvall | 0:b94e330c98ac | 133 | } |
alindvall | 0:b94e330c98ac | 134 | |
alindvall | 0:b94e330c98ac | 135 | void aliveTask(void const* args) |
alindvall | 0:b94e330c98ac | 136 | { |
alindvall | 0:b94e330c98ac | 137 | DMBoard* board = &DMBoard::instance(); |
alindvall | 0:b94e330c98ac | 138 | |
alindvall | 0:b94e330c98ac | 139 | while(true) |
alindvall | 0:b94e330c98ac | 140 | { |
alindvall | 0:b94e330c98ac | 141 | board->setLED(DMBoard::Led4, false); |
alindvall | 0:b94e330c98ac | 142 | board->setLED(DMBoard::Led1, true); |
alindvall | 0:b94e330c98ac | 143 | Thread::wait(300); |
alindvall | 0:b94e330c98ac | 144 | board->setLED(DMBoard::Led1, false); |
alindvall | 0:b94e330c98ac | 145 | board->setLED(DMBoard::Led2, true); |
alindvall | 0:b94e330c98ac | 146 | Thread::wait(300); |
alindvall | 0:b94e330c98ac | 147 | board->setLED(DMBoard::Led2, false); |
alindvall | 0:b94e330c98ac | 148 | board->setLED(DMBoard::Led3, true); |
alindvall | 0:b94e330c98ac | 149 | Thread::wait(300); |
alindvall | 0:b94e330c98ac | 150 | board->setLED(DMBoard::Led3, false); |
alindvall | 0:b94e330c98ac | 151 | board->setLED(DMBoard::Led4, true); |
alindvall | 0:b94e330c98ac | 152 | Thread::wait(300); |
alindvall | 0:b94e330c98ac | 153 | } |
alindvall | 0:b94e330c98ac | 154 | } |
alindvall | 0:b94e330c98ac | 155 | |
alindvall | 0:b94e330c98ac | 156 | #if defined(DM_BOARD_USE_DISPLAY) |
alindvall | 0:b94e330c98ac | 157 | |
alindvall | 0:b94e330c98ac | 158 | typedef enum { |
alindvall | 0:b94e330c98ac | 159 | ColorPickerApp, |
alindvall | 0:b94e330c98ac | 160 | ImageViewerApp, |
alindvall | 0:b94e330c98ac | 161 | SlideshowApp, |
alindvall | 0:b94e330c98ac | 162 | SettingsApp, |
alindvall | 0:b94e330c98ac | 163 | StatusApp, |
alindvall | 0:b94e330c98ac | 164 | TouchTestApp, |
alindvall | 0:b94e330c98ac | 165 | RtcApp, |
alindvall | 0:b94e330c98ac | 166 | USBStatusApp, |
alindvall | 0:b94e330c98ac | 167 | DrawingApp, |
alindvall | 0:b94e330c98ac | 168 | CalibrationApp = AppLauncherSpecial::CalibrationApp, |
alindvall | 0:b94e330c98ac | 169 | Placeholder, |
alindvall | 0:b94e330c98ac | 170 | } myapps_t; |
alindvall | 0:b94e330c98ac | 171 | |
alindvall | 0:b94e330c98ac | 172 | static App* launchApp(uint32_t id) |
alindvall | 0:b94e330c98ac | 173 | { |
alindvall | 0:b94e330c98ac | 174 | App* a = NULL; |
alindvall | 0:b94e330c98ac | 175 | switch ((myapps_t)id) { |
alindvall | 0:b94e330c98ac | 176 | case CalibrationApp: |
alindvall | 0:b94e330c98ac | 177 | a = new AppTouchCalibration(); |
alindvall | 0:b94e330c98ac | 178 | ((AppTouchCalibration*)a)->addResource(AppTouchCalibration::Resource_Ok_button, RESOURCES[Res_ok]); |
alindvall | 0:b94e330c98ac | 179 | break; |
alindvall | 0:b94e330c98ac | 180 | case SettingsApp: |
alindvall | 0:b94e330c98ac | 181 | a = new AppNetworkSettings(); |
alindvall | 0:b94e330c98ac | 182 | ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_Ok_button, RESOURCES[Res_ok]); |
alindvall | 0:b94e330c98ac | 183 | ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_Cancel_button, RESOURCES[Res_cancel]); |
alindvall | 0:b94e330c98ac | 184 | ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_ArrowUp_button, RESOURCES[Res_arrow_up]); |
alindvall | 0:b94e330c98ac | 185 | ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_ArrowDown_button, RESOURCES[Res_arrow_down]); |
alindvall | 0:b94e330c98ac | 186 | ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_ArrowLeft_button, RESOURCES[Res_arrow_left]); |
alindvall | 0:b94e330c98ac | 187 | ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_ArrowRight_button, RESOURCES[Res_arrow_right]); |
alindvall | 0:b94e330c98ac | 188 | ((AppNetworkSettings*)a)->addResource(AppNetworkSettings::Resource_Digits, RESOURCES[Res_digits]); |
alindvall | 0:b94e330c98ac | 189 | break; |
alindvall | 0:b94e330c98ac | 190 | case ColorPickerApp: |
alindvall | 0:b94e330c98ac | 191 | a = new AppColorPicker(); |
alindvall | 0:b94e330c98ac | 192 | ((AppColorPicker*)a)->addResource(AppColorPicker::Resource_Ok_button, RESOURCES[Res_ok]); |
alindvall | 0:b94e330c98ac | 193 | break; |
alindvall | 0:b94e330c98ac | 194 | case ImageViewerApp: |
alindvall | 0:b94e330c98ac | 195 | a = new AppImageViewer(); |
alindvall | 0:b94e330c98ac | 196 | ((AppImageViewer*)a)->addResource(AppImageViewer::Resource_Ok_button, RESOURCES[Res_ok]); |
alindvall | 0:b94e330c98ac | 197 | break; |
alindvall | 0:b94e330c98ac | 198 | case SlideshowApp: |
alindvall | 0:b94e330c98ac | 199 | { |
alindvall | 0:b94e330c98ac | 200 | // Select folder for the slideshow based on display size |
alindvall | 0:b94e330c98ac | 201 | Display* d = DMBoard::instance().display(); |
alindvall | 0:b94e330c98ac | 202 | if (d->width() == 480) { |
alindvall | 0:b94e330c98ac | 203 | a = new AppSlideShow("/qspi/slides.txt", "/qspi/480x272", 0, 0); |
alindvall | 0:b94e330c98ac | 204 | } else { |
alindvall | 0:b94e330c98ac | 205 | a = new AppSlideShow("/qspi/slides.txt", "/qspi/800x480", 0, 0); |
alindvall | 0:b94e330c98ac | 206 | } |
alindvall | 0:b94e330c98ac | 207 | |
alindvall | 0:b94e330c98ac | 208 | ((AppSlideShow*)a)->addResource(AppSlideShow::Resource_Ok_button, RESOURCES[Res_ok]); |
alindvall | 0:b94e330c98ac | 209 | ((AppSlideShow*)a)->addResource(AppSlideShow::Resource_Repeat_button, RESOURCES[Res_repeat]); |
alindvall | 0:b94e330c98ac | 210 | } |
alindvall | 0:b94e330c98ac | 211 | break; |
alindvall | 0:b94e330c98ac | 212 | case StatusApp: |
alindvall | 0:b94e330c98ac | 213 | a = new AppStatus(); |
alindvall | 0:b94e330c98ac | 214 | ((AppStatus*)a)->addResource(AppStatus::Resource_Ok_button, RESOURCES[Res_ok]); |
alindvall | 0:b94e330c98ac | 215 | ((AppStatus*)a)->addResource(AppStatus::Resource_About_image, RESOURCES[Res_about]); |
alindvall | 0:b94e330c98ac | 216 | break; |
alindvall | 0:b94e330c98ac | 217 | case RtcApp: |
alindvall | 0:b94e330c98ac | 218 | a = new AppRTCSettings(); |
alindvall | 0:b94e330c98ac | 219 | ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_Ok_button, RESOURCES[Res_ok]); |
alindvall | 0:b94e330c98ac | 220 | ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_Cancel_button, RESOURCES[Res_cancel]); |
alindvall | 0:b94e330c98ac | 221 | ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_ArrowUp_button, RESOURCES[Res_arrow_up]); |
alindvall | 0:b94e330c98ac | 222 | ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_ArrowDown_button, RESOURCES[Res_arrow_down]); |
alindvall | 0:b94e330c98ac | 223 | ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_ArrowLeft_button, RESOURCES[Res_arrow_left]); |
alindvall | 0:b94e330c98ac | 224 | ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_ArrowRight_button, RESOURCES[Res_arrow_right]); |
alindvall | 0:b94e330c98ac | 225 | ((AppRTCSettings*)a)->addResource(AppRTCSettings::Resource_Digits, RESOURCES[Res_digits]); |
alindvall | 0:b94e330c98ac | 226 | break; |
alindvall | 0:b94e330c98ac | 227 | case USBStatusApp: |
alindvall | 0:b94e330c98ac | 228 | a = new AppUSBStatus(); |
alindvall | 0:b94e330c98ac | 229 | ((AppUSBStatus*)a)->addResource(AppUSBStatus::Resource_Ok_button, RESOURCES[Res_ok]); |
alindvall | 0:b94e330c98ac | 230 | break; |
alindvall | 0:b94e330c98ac | 231 | case DrawingApp: |
alindvall | 0:b94e330c98ac | 232 | a = new AppDraw(); |
alindvall | 0:b94e330c98ac | 233 | ((AppDraw*)a)->addResource(AppDraw::Resource_Ok_button, RESOURCES[Res_ok]); |
alindvall | 0:b94e330c98ac | 234 | break; |
alindvall | 0:b94e330c98ac | 235 | default: |
alindvall | 0:b94e330c98ac | 236 | break; |
alindvall | 0:b94e330c98ac | 237 | } |
alindvall | 0:b94e330c98ac | 238 | return a; |
alindvall | 0:b94e330c98ac | 239 | } |
alindvall | 0:b94e330c98ac | 240 | |
alindvall | 0:b94e330c98ac | 241 | #define SWIM_TASK_PREFIX "[SWIM] " |
alindvall | 0:b94e330c98ac | 242 | void swimTask(void const* args) |
alindvall | 0:b94e330c98ac | 243 | { |
alindvall | 0:b94e330c98ac | 244 | RtosLog* log = DMBoard::instance().logger(); |
alindvall | 0:b94e330c98ac | 245 | Display* disp = DMBoard::instance().display(); |
alindvall | 0:b94e330c98ac | 246 | |
alindvall | 0:b94e330c98ac | 247 | log->printf(SWIM_TASK_PREFIX"swimTask started\n"); |
alindvall | 0:b94e330c98ac | 248 | |
alindvall | 0:b94e330c98ac | 249 | int iconsize = (disp->width()==480) ? 64 : 128; |
alindvall | 0:b94e330c98ac | 250 | AppLauncherSpecial launcher(iconsize, iconsize); |
alindvall | 0:b94e330c98ac | 251 | launcher.addResource(AppLauncherSpecial::Resource_Background, RESOURCES[Res_background]); |
alindvall | 0:b94e330c98ac | 252 | |
alindvall | 0:b94e330c98ac | 253 | if (launcher.setup()) { |
alindvall | 0:b94e330c98ac | 254 | launcher.addImageButton(SettingsApp, "Network", 0x2d5c, RESOURCES[Res_SettingsApp ]); |
alindvall | 0:b94e330c98ac | 255 | launcher.addImageButton(DrawingApp, "Drawing", 0x2d5c, RESOURCES[Res_DrawingApp ]); |
alindvall | 0:b94e330c98ac | 256 | launcher.addImageButton(SlideshowApp, "Slideshow", 0x2d5c, RESOURCES[Res_SlideshowApp ]); |
alindvall | 0:b94e330c98ac | 257 | launcher.addImageButton(ColorPickerApp, "Color Picker", 0x2d5c, RESOURCES[Res_ColorPickerApp]); |
alindvall | 0:b94e330c98ac | 258 | launcher.addImageButton(ImageViewerApp, "Image Viewer", 0x2d5c, RESOURCES[Res_ImageViewerApp]); |
alindvall | 0:b94e330c98ac | 259 | launcher.addImageButton(StatusApp, "About", 0x2d5c, RESOURCES[Res_StatusApp ]); |
alindvall | 0:b94e330c98ac | 260 | launcher.addImageButton(USBStatusApp, "USB Status", 0x2d5c, RESOURCES[Res_USBStatusApp ]); |
alindvall | 0:b94e330c98ac | 261 | launcher.addImageButton(RtcApp, "Clock", 0x2d5c, RESOURCES[Res_RtcApp ]); |
alindvall | 0:b94e330c98ac | 262 | |
alindvall | 0:b94e330c98ac | 263 | launcher.setAppCreatorFunc(launchApp); |
alindvall | 0:b94e330c98ac | 264 | log->printf(SWIM_TASK_PREFIX"Starting menu system\n"); |
alindvall | 0:b94e330c98ac | 265 | launcher.runToCompletion(); |
alindvall | 0:b94e330c98ac | 266 | launcher.teardown(); |
alindvall | 0:b94e330c98ac | 267 | } else { |
alindvall | 0:b94e330c98ac | 268 | log->printf(SWIM_TASK_PREFIX"Failed to prepare menu system\n"); |
alindvall | 0:b94e330c98ac | 269 | } |
alindvall | 0:b94e330c98ac | 270 | |
alindvall | 0:b94e330c98ac | 271 | // Should never end up here |
alindvall | 0:b94e330c98ac | 272 | mbed_die(); |
alindvall | 0:b94e330c98ac | 273 | } |
alindvall | 0:b94e330c98ac | 274 | |
alindvall | 0:b94e330c98ac | 275 | #endif //DM_BOARD_USE_DISPLAY |
alindvall | 0:b94e330c98ac | 276 | |
alindvall | 0:b94e330c98ac | 277 | |
alindvall | 0:b94e330c98ac | 278 | #define NET_TASK_PREFIX "[NET] " |
alindvall | 0:b94e330c98ac | 279 | |
alindvall | 0:b94e330c98ac | 280 | void netTask(void const* args) |
alindvall | 0:b94e330c98ac | 281 | { |
alindvall | 0:b94e330c98ac | 282 | RtosLog* log = DMBoard::instance().logger(); |
alindvall | 0:b94e330c98ac | 283 | log->printf(NET_TASK_PREFIX"EthernetInterface Setting up...\r\n"); |
alindvall | 0:b94e330c98ac | 284 | if(eth.init()!=0) { //for DHCP Server |
alindvall | 0:b94e330c98ac | 285 | //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address |
alindvall | 0:b94e330c98ac | 286 | log->printf(NET_TASK_PREFIX"EthernetInterface Initialize Error \r\n"); |
alindvall | 0:b94e330c98ac | 287 | mbed_die(); |
alindvall | 0:b94e330c98ac | 288 | } |
alindvall | 0:b94e330c98ac | 289 | while (eth.connect() != 0) { |
alindvall | 0:b94e330c98ac | 290 | Thread::wait(1000); |
alindvall | 0:b94e330c98ac | 291 | } |
alindvall | 0:b94e330c98ac | 292 | |
alindvall | 0:b94e330c98ac | 293 | ethInitialized = true; |
alindvall | 0:b94e330c98ac | 294 | ethUsingDHCP = true; |
alindvall | 0:b94e330c98ac | 295 | |
alindvall | 0:b94e330c98ac | 296 | log->printf(NET_TASK_PREFIX"IP Address is %s\r\n", eth.getIPAddress()); |
alindvall | 0:b94e330c98ac | 297 | log->printf(NET_TASK_PREFIX"NetMask is %s\r\n", eth.getNetworkMask()); |
alindvall | 0:b94e330c98ac | 298 | log->printf(NET_TASK_PREFIX"Gateway Address is %s\r\n", eth.getGateway()); |
alindvall | 0:b94e330c98ac | 299 | log->printf(NET_TASK_PREFIX"Ethernet Setup OK\r\n"); |
alindvall | 0:b94e330c98ac | 300 | |
alindvall | 0:b94e330c98ac | 301 | HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler |
alindvall | 0:b94e330c98ac | 302 | FSHandler::mount("/usb", "/"); |
alindvall | 0:b94e330c98ac | 303 | HTTPServerAddHandler<FSHandler>("/"); |
alindvall | 0:b94e330c98ac | 304 | //HTTPServerAddHandler<RPCHandler>("/rpc"); |
alindvall | 0:b94e330c98ac | 305 | //lcd.locate(0,0); |
alindvall | 0:b94e330c98ac | 306 | //lcd.printf("%s",eth.getIPAddress()); |
alindvall | 0:b94e330c98ac | 307 | HTTPServerStart(80); |
alindvall | 0:b94e330c98ac | 308 | } |
alindvall | 0:b94e330c98ac | 309 | |
alindvall | 0:b94e330c98ac | 310 | static volatile int8_t mouse_button, mouse_x, mouse_y, mouse_z; |
alindvall | 0:b94e330c98ac | 311 | static uint16_t cursor_x=0, cursor_y=0, mouse_max_x = 0, mouse_max_y = 0; |
alindvall | 0:b94e330c98ac | 312 | void mouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) |
alindvall | 0:b94e330c98ac | 313 | { |
alindvall | 0:b94e330c98ac | 314 | mouse_button = buttons; |
alindvall | 0:b94e330c98ac | 315 | mouse_x = x; |
alindvall | 0:b94e330c98ac | 316 | mouse_y = y; |
alindvall | 0:b94e330c98ac | 317 | mouse_z = z; |
alindvall | 0:b94e330c98ac | 318 | |
alindvall | 0:b94e330c98ac | 319 | if (mouse_max_x == 0) { |
alindvall | 0:b94e330c98ac | 320 | mouse_max_x = DMBoard::instance().display()->width() - 1; |
alindvall | 0:b94e330c98ac | 321 | } |
alindvall | 0:b94e330c98ac | 322 | if (mouse_max_y == 0) { |
alindvall | 0:b94e330c98ac | 323 | mouse_max_y = DMBoard::instance().display()->height() - 1; |
alindvall | 0:b94e330c98ac | 324 | } |
alindvall | 0:b94e330c98ac | 325 | |
alindvall | 0:b94e330c98ac | 326 | if (x < 0) { |
alindvall | 0:b94e330c98ac | 327 | if (cursor_x > -x) { |
alindvall | 0:b94e330c98ac | 328 | cursor_x += x; |
alindvall | 0:b94e330c98ac | 329 | } else { |
alindvall | 0:b94e330c98ac | 330 | cursor_x = 0; |
alindvall | 0:b94e330c98ac | 331 | } |
alindvall | 0:b94e330c98ac | 332 | } else { |
alindvall | 0:b94e330c98ac | 333 | if ((cursor_x + x) > mouse_max_x) { |
alindvall | 0:b94e330c98ac | 334 | cursor_x = mouse_max_x; |
alindvall | 0:b94e330c98ac | 335 | } else { |
alindvall | 0:b94e330c98ac | 336 | cursor_x += x; |
alindvall | 0:b94e330c98ac | 337 | } |
alindvall | 0:b94e330c98ac | 338 | } |
alindvall | 0:b94e330c98ac | 339 | y = y/8; |
alindvall | 0:b94e330c98ac | 340 | if (y < 0) { |
alindvall | 0:b94e330c98ac | 341 | if (cursor_y > -y) { |
alindvall | 0:b94e330c98ac | 342 | cursor_y += y; |
alindvall | 0:b94e330c98ac | 343 | } else { |
alindvall | 0:b94e330c98ac | 344 | cursor_y = 0; |
alindvall | 0:b94e330c98ac | 345 | } |
alindvall | 0:b94e330c98ac | 346 | } else { |
alindvall | 0:b94e330c98ac | 347 | if ((cursor_y + y) > mouse_max_y) { |
alindvall | 0:b94e330c98ac | 348 | cursor_y = mouse_max_y; |
alindvall | 0:b94e330c98ac | 349 | } else { |
alindvall | 0:b94e330c98ac | 350 | cursor_y += y; |
alindvall | 0:b94e330c98ac | 351 | } |
alindvall | 0:b94e330c98ac | 352 | } |
alindvall | 0:b94e330c98ac | 353 | |
alindvall | 0:b94e330c98ac | 354 | //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y); |
alindvall | 0:b94e330c98ac | 355 | LPC_LCD->CRSR_XY = (cursor_x & 0x3FF) | ((cursor_y & 0x3FF) << 16); |
alindvall | 0:b94e330c98ac | 356 | } |
alindvall | 0:b94e330c98ac | 357 | |
alindvall | 0:b94e330c98ac | 358 | #define LCD_CURSOR_32x32 0 |
alindvall | 0:b94e330c98ac | 359 | #define LCD_CURSOR_64x64 1 |
alindvall | 0:b94e330c98ac | 360 | #define CURSOR_SIZE LCD_CURSOR_32x32 |
alindvall | 0:b94e330c98ac | 361 | #define CURSOR_H_SIZE 32 |
alindvall | 0:b94e330c98ac | 362 | #define CURSOR_V_SIZE 32 |
alindvall | 0:b94e330c98ac | 363 | #define CURSOR_NUM 0 |
alindvall | 0:b94e330c98ac | 364 | #define CURSOR_H_OFS (10) |
alindvall | 0:b94e330c98ac | 365 | #define CURSOR_V_OFS (6) |
alindvall | 0:b94e330c98ac | 366 | |
alindvall | 0:b94e330c98ac | 367 | const unsigned char __attribute__ ((aligned(4))) Cursor[(CURSOR_H_SIZE / 4) * CURSOR_V_SIZE] = |
alindvall | 0:b94e330c98ac | 368 | { |
alindvall | 0:b94e330c98ac | 369 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 370 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 371 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 372 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 373 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 374 | 0xAA, 0xAA, 0xAA, 0xFA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 375 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 376 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 377 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 378 | 0xAA, 0xAA, 0xAB, 0xFE, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 379 | 0xAA, 0xAA, 0xAB, 0xFF, 0xEA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 380 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 381 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 382 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 383 | 0xAA, 0xAB, 0xFB, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 384 | 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 385 | 0xAA, 0xAB, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 386 | 0xAA, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 387 | 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 388 | 0xAA, 0xAA, 0xBF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 389 | 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFF, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 390 | 0xAA, 0xAA, 0xAF, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 391 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 392 | 0xAA, 0xAA, 0xAB, 0xFF, 0xFF, 0xFE, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 393 | 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 394 | 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 395 | 0xAA, 0xAA, 0xAA, 0xFF, 0xFF, 0xFA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 396 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 397 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 398 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 399 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, |
alindvall | 0:b94e330c98ac | 400 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA |
alindvall | 0:b94e330c98ac | 401 | }; |
alindvall | 0:b94e330c98ac | 402 | |
alindvall | 0:b94e330c98ac | 403 | void prepareCursor(bool enable) { |
alindvall | 0:b94e330c98ac | 404 | //Chip_LCD_Cursor_Disable(LPC_LCD, 0); |
alindvall | 0:b94e330c98ac | 405 | LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4); |
alindvall | 0:b94e330c98ac | 406 | |
alindvall | 0:b94e330c98ac | 407 | if (enable) { |
alindvall | 0:b94e330c98ac | 408 | //Chip_LCD_Cursor_Config(LPC_LCD, LCD_CURSOR_32x32, true); |
alindvall | 0:b94e330c98ac | 409 | LPC_LCD->CRSR_CFG = ((true ? 1 : 0) << 1) | CURSOR_SIZE; |
alindvall | 0:b94e330c98ac | 410 | |
alindvall | 0:b94e330c98ac | 411 | //Chip_LCD_Cursor_WriteImage(LPC_LCD, 0, (void *) Cursor); |
alindvall | 0:b94e330c98ac | 412 | { |
alindvall | 0:b94e330c98ac | 413 | int i, j; |
alindvall | 0:b94e330c98ac | 414 | uint32_t *fifoptr, *crsr_ptr = (uint32_t *) Cursor; |
alindvall | 0:b94e330c98ac | 415 | |
alindvall | 0:b94e330c98ac | 416 | /* Check if Cursor Size was configured as 32x32 or 64x64*/ |
alindvall | 0:b94e330c98ac | 417 | if (CURSOR_SIZE == LCD_CURSOR_32x32) { |
alindvall | 0:b94e330c98ac | 418 | i = CURSOR_NUM * 64; |
alindvall | 0:b94e330c98ac | 419 | j = i + 64; |
alindvall | 0:b94e330c98ac | 420 | } |
alindvall | 0:b94e330c98ac | 421 | else { |
alindvall | 0:b94e330c98ac | 422 | i = 0; |
alindvall | 0:b94e330c98ac | 423 | j = 256; |
alindvall | 0:b94e330c98ac | 424 | } |
alindvall | 0:b94e330c98ac | 425 | fifoptr = (uint32_t *) &(LPC_LCD->CRSR_IMG[0]); |
alindvall | 0:b94e330c98ac | 426 | |
alindvall | 0:b94e330c98ac | 427 | /* Copy Cursor Image content to FIFO */ |
alindvall | 0:b94e330c98ac | 428 | for (; i < j; i++) { |
alindvall | 0:b94e330c98ac | 429 | |
alindvall | 0:b94e330c98ac | 430 | *fifoptr = *crsr_ptr; |
alindvall | 0:b94e330c98ac | 431 | crsr_ptr++; |
alindvall | 0:b94e330c98ac | 432 | fifoptr++; |
alindvall | 0:b94e330c98ac | 433 | } |
alindvall | 0:b94e330c98ac | 434 | } |
alindvall | 0:b94e330c98ac | 435 | |
alindvall | 0:b94e330c98ac | 436 | //Chip_LCD_Cursor_SetClip(LPC_LCD, CURSOR_H_OFS, CURSOR_V_OFS); |
alindvall | 0:b94e330c98ac | 437 | LPC_LCD->CRSR_CLIP = (CURSOR_H_OFS & 0x3F) | ((CURSOR_V_OFS & 0x3F) << 8); |
alindvall | 0:b94e330c98ac | 438 | |
alindvall | 0:b94e330c98ac | 439 | //Chip_LCD_Cursor_SetPos(LPC_LCD, cursor_x, cursor_y); |
alindvall | 0:b94e330c98ac | 440 | |
alindvall | 0:b94e330c98ac | 441 | //Chip_LCD_Cursor_Enable(LPC_LCD, 0); |
alindvall | 0:b94e330c98ac | 442 | LPC_LCD->CRSR_CTRL = (CURSOR_NUM << 4) | 1; |
alindvall | 0:b94e330c98ac | 443 | } |
alindvall | 0:b94e330c98ac | 444 | } |
alindvall | 0:b94e330c98ac | 445 | |
alindvall | 0:b94e330c98ac | 446 | |
alindvall | 0:b94e330c98ac | 447 | #define CIRCBUFF_SIZE 256 |
alindvall | 0:b94e330c98ac | 448 | static volatile uint8_t circbuff[CIRCBUFF_SIZE]; |
alindvall | 0:b94e330c98ac | 449 | static volatile uint32_t circbuff_read = 0; |
alindvall | 0:b94e330c98ac | 450 | static uint32_t circbuff_write = 0; |
alindvall | 0:b94e330c98ac | 451 | void keyEvent(uint8_t key) |
alindvall | 0:b94e330c98ac | 452 | { |
alindvall | 0:b94e330c98ac | 453 | circbuff[circbuff_write%CIRCBUFF_SIZE] = key; |
alindvall | 0:b94e330c98ac | 454 | circbuff_write++; |
alindvall | 0:b94e330c98ac | 455 | } |
alindvall | 0:b94e330c98ac | 456 | |
alindvall | 0:b94e330c98ac | 457 | bool msdConnected = false; |
alindvall | 0:b94e330c98ac | 458 | bool keyboardConnected = false; |
alindvall | 0:b94e330c98ac | 459 | bool mouseConnected = false; |
alindvall | 0:b94e330c98ac | 460 | |
alindvall | 0:b94e330c98ac | 461 | #define USB_TASK_PREFIX "[USB] " |
alindvall | 0:b94e330c98ac | 462 | #define USB_CONNECTION_EVENT (1<<4) |
alindvall | 0:b94e330c98ac | 463 | void usbTask(void const* args) |
alindvall | 0:b94e330c98ac | 464 | { |
alindvall | 0:b94e330c98ac | 465 | USBHostMSD* msd = new USBHostMSD("usb"); |
alindvall | 0:b94e330c98ac | 466 | USBHostKeyboard* keyboard = new USBHostKeyboard(); |
alindvall | 0:b94e330c98ac | 467 | USBHostMouse* mouse = new USBHostMouse(); |
alindvall | 0:b94e330c98ac | 468 | USBHost* host = USBHost::getHostInst(); |
alindvall | 0:b94e330c98ac | 469 | host->signalOnConnections(Thread::gettid(), USB_CONNECTION_EVENT); |
alindvall | 0:b94e330c98ac | 470 | |
alindvall | 0:b94e330c98ac | 471 | RtosLog* log = DMBoard::instance().logger(); |
alindvall | 0:b94e330c98ac | 472 | |
alindvall | 0:b94e330c98ac | 473 | log->printf(USB_TASK_PREFIX"usbTask started\n"); |
alindvall | 0:b94e330c98ac | 474 | |
alindvall | 0:b94e330c98ac | 475 | prepareCursor(false); |
alindvall | 0:b94e330c98ac | 476 | |
alindvall | 0:b94e330c98ac | 477 | while (true) { |
alindvall | 0:b94e330c98ac | 478 | // wait for connect/disconnect message from USBHost |
alindvall | 0:b94e330c98ac | 479 | Thread::signal_wait(USB_CONNECTION_EVENT); |
alindvall | 0:b94e330c98ac | 480 | log->printf(USB_TASK_PREFIX"got USB event\n"); |
alindvall | 0:b94e330c98ac | 481 | |
alindvall | 0:b94e330c98ac | 482 | if (msd->connected()) { |
alindvall | 0:b94e330c98ac | 483 | if (!msdConnected) { |
alindvall | 0:b94e330c98ac | 484 | msdConnected = true; |
alindvall | 0:b94e330c98ac | 485 | haveUSBMSD = true; |
alindvall | 0:b94e330c98ac | 486 | log->printf(USB_TASK_PREFIX"USB MassStorage Device - Connected\n"); |
alindvall | 0:b94e330c98ac | 487 | } |
alindvall | 0:b94e330c98ac | 488 | } else { |
alindvall | 0:b94e330c98ac | 489 | if (msdConnected) { |
alindvall | 0:b94e330c98ac | 490 | msdConnected = false; |
alindvall | 0:b94e330c98ac | 491 | haveUSBMSD = false; |
alindvall | 0:b94e330c98ac | 492 | log->printf(USB_TASK_PREFIX"USB MassStorage Device - Ejected\n"); |
alindvall | 0:b94e330c98ac | 493 | } |
alindvall | 0:b94e330c98ac | 494 | |
alindvall | 0:b94e330c98ac | 495 | if (msd->connect()) { |
alindvall | 0:b94e330c98ac | 496 | msdConnected = true; |
alindvall | 0:b94e330c98ac | 497 | haveUSBMSD = true; |
alindvall | 0:b94e330c98ac | 498 | log->printf(USB_TASK_PREFIX"USB MassStorage Device - Connected\n"); |
alindvall | 0:b94e330c98ac | 499 | } |
alindvall | 0:b94e330c98ac | 500 | } |
alindvall | 0:b94e330c98ac | 501 | |
alindvall | 0:b94e330c98ac | 502 | if (keyboard->connected()) { |
alindvall | 0:b94e330c98ac | 503 | if (!keyboardConnected) { |
alindvall | 0:b94e330c98ac | 504 | keyboardConnected = true; |
alindvall | 0:b94e330c98ac | 505 | log->printf(USB_TASK_PREFIX"USB Keyboard - Connected\n"); |
alindvall | 0:b94e330c98ac | 506 | keyboard->attach(keyEvent); |
alindvall | 0:b94e330c98ac | 507 | } |
alindvall | 0:b94e330c98ac | 508 | } else { |
alindvall | 0:b94e330c98ac | 509 | if (keyboardConnected) { |
alindvall | 0:b94e330c98ac | 510 | keyboardConnected = false; |
alindvall | 0:b94e330c98ac | 511 | log->printf(USB_TASK_PREFIX"USB Keyboard - Ejected\n"); |
alindvall | 0:b94e330c98ac | 512 | } |
alindvall | 0:b94e330c98ac | 513 | if (keyboard->connect()) { |
alindvall | 0:b94e330c98ac | 514 | keyboardConnected = true; |
alindvall | 0:b94e330c98ac | 515 | log->printf(USB_TASK_PREFIX"USB Keyboard - Connected\n"); |
alindvall | 0:b94e330c98ac | 516 | keyboard->attach(keyEvent); |
alindvall | 0:b94e330c98ac | 517 | } |
alindvall | 0:b94e330c98ac | 518 | } |
alindvall | 0:b94e330c98ac | 519 | |
alindvall | 0:b94e330c98ac | 520 | if (mouse->connected()) { |
alindvall | 0:b94e330c98ac | 521 | if (!mouseConnected) { |
alindvall | 0:b94e330c98ac | 522 | mouseConnected = true; |
alindvall | 0:b94e330c98ac | 523 | log->printf(USB_TASK_PREFIX"USB Mouse - Connected\n"); |
alindvall | 0:b94e330c98ac | 524 | mouse->attachEvent(mouseEvent); |
alindvall | 0:b94e330c98ac | 525 | prepareCursor(true); |
alindvall | 0:b94e330c98ac | 526 | } |
alindvall | 0:b94e330c98ac | 527 | } else { |
alindvall | 0:b94e330c98ac | 528 | if (mouseConnected) { |
alindvall | 0:b94e330c98ac | 529 | prepareCursor(false); |
alindvall | 0:b94e330c98ac | 530 | mouseConnected = false; |
alindvall | 0:b94e330c98ac | 531 | log->printf(USB_TASK_PREFIX"USB Mouse - Ejected\n"); |
alindvall | 0:b94e330c98ac | 532 | } |
alindvall | 0:b94e330c98ac | 533 | if (mouse->connect()) { |
alindvall | 0:b94e330c98ac | 534 | mouseConnected = true; |
alindvall | 0:b94e330c98ac | 535 | log->printf(USB_TASK_PREFIX"USB Mouse - Connected\n"); |
alindvall | 0:b94e330c98ac | 536 | mouse->attachEvent(mouseEvent); |
alindvall | 0:b94e330c98ac | 537 | prepareCursor(true); |
alindvall | 0:b94e330c98ac | 538 | } |
alindvall | 0:b94e330c98ac | 539 | } |
alindvall | 0:b94e330c98ac | 540 | } |
alindvall | 0:b94e330c98ac | 541 | } |
alindvall | 0:b94e330c98ac | 542 | |
alindvall | 0:b94e330c98ac | 543 | |
alindvall | 0:b94e330c98ac | 544 | |
alindvall | 0:b94e330c98ac | 545 | /****************************************************************************** |
alindvall | 0:b94e330c98ac | 546 | * Main function |
alindvall | 0:b94e330c98ac | 547 | *****************************************************************************/ |
alindvall | 0:b94e330c98ac | 548 | int main() |
alindvall | 0:b94e330c98ac | 549 | { |
alindvall | 0:b94e330c98ac | 550 | DMBoard::BoardError err; |
alindvall | 0:b94e330c98ac | 551 | DMBoard* board = &DMBoard::instance(); |
alindvall | 0:b94e330c98ac | 552 | RtosLog* log = board->logger(); |
alindvall | 0:b94e330c98ac | 553 | err = board->init(); |
alindvall | 0:b94e330c98ac | 554 | if (err != DMBoard::Ok) { |
alindvall | 0:b94e330c98ac | 555 | log->printf("Failed to initialize the board, got error %d\r\n", err); |
alindvall | 0:b94e330c98ac | 556 | log->printf("\nTERMINATING\n"); |
alindvall | 0:b94e330c98ac | 557 | wait_ms(2000); // allow RtosLog to flush messages |
alindvall | 0:b94e330c98ac | 558 | mbed_die(); |
alindvall | 0:b94e330c98ac | 559 | } |
alindvall | 0:b94e330c98ac | 560 | |
alindvall | 0:b94e330c98ac | 561 | // select which images to use based on display size |
alindvall | 0:b94e330c98ac | 562 | prepareResources(); |
alindvall | 0:b94e330c98ac | 563 | |
alindvall | 0:b94e330c98ac | 564 | board->buzzer(440,50); |
alindvall | 0:b94e330c98ac | 565 | wait_ms(30); |
alindvall | 0:b94e330c98ac | 566 | board->buzzer(660,50); |
alindvall | 0:b94e330c98ac | 567 | wait_ms(30); |
alindvall | 0:b94e330c98ac | 568 | board->buzzer(440,50); |
alindvall | 0:b94e330c98ac | 569 | |
alindvall | 4:a7cbb22e4348 | 570 | log->printf("\n\n---\nDemo flashed on new Display Modules.\nBuilt: " __DATE__ " at " __TIME__ "\n\n"); |
alindvall | 0:b94e330c98ac | 571 | |
alindvall | 0:b94e330c98ac | 572 | |
alindvall | 0:b94e330c98ac | 573 | Thread tAlive(aliveTask); |
alindvall | 0:b94e330c98ac | 574 | #if defined(DM_BOARD_USE_DISPLAY) |
alindvall | 0:b94e330c98ac | 575 | Thread tSwim(swimTask, NULL, osPriorityNormal, 8192); |
alindvall | 0:b94e330c98ac | 576 | #endif |
alindvall | 0:b94e330c98ac | 577 | Thread tNetwork(netTask, NULL, osPriorityNormal, 8192); |
alindvall | 0:b94e330c98ac | 578 | Thread tUSBHandler(usbTask, NULL, osPriorityNormal, 8192); |
alindvall | 0:b94e330c98ac | 579 | |
alindvall | 0:b94e330c98ac | 580 | while(1) { |
alindvall | 0:b94e330c98ac | 581 | // Wait forever (in 1h increments) to prevent the tAlive, tSwim, |
alindvall | 0:b94e330c98ac | 582 | // tNetwork and tUSBHandler thread from being garbage collected. |
alindvall | 0:b94e330c98ac | 583 | Thread::wait(3600*1000); |
alindvall | 0:b94e330c98ac | 584 | } |
alindvall | 0:b94e330c98ac | 585 | } |