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: mbed C12832_lcd USBHost USBHostPTP LCD_Menu
main.cpp@4:a95225ec39ac, 2013-09-03 (annotated)
- Committer:
- jakowisp
- Date:
- Tue Sep 03 08:38:30 2013 +0000
- Revision:
- 4:a95225ec39ac
- Parent:
- 3:1e2f56de7d5d
- Child:
- 5:013bdb272a9c
Publish the project for class turn in.;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jakowisp | 4:a95225ec39ac | 1 | /** |
| jakowisp | 4:a95225ec39ac | 2 | * @file main.cpp |
| jakowisp | 4:a95225ec39ac | 3 | * @brief Function to call USBHostPTP Library |
| jakowisp | 4:a95225ec39ac | 4 | * @author Dwayne Dilbeck |
| jakowisp | 4:a95225ec39ac | 5 | * @date 8/23/2013 |
| jakowisp | 4:a95225ec39ac | 6 | * |
| jakowisp | 4:a95225ec39ac | 7 | * mbed USBHostPTP Library |
| jakowisp | 4:a95225ec39ac | 8 | * |
| jakowisp | 4:a95225ec39ac | 9 | * @par Copyright: |
| jakowisp | 4:a95225ec39ac | 10 | * Copyright (c) 2013 Dwayne Dilbeck |
| jakowisp | 4:a95225ec39ac | 11 | * @par License: |
| jakowisp | 4:a95225ec39ac | 12 | * This software is distributed under the terms of the GNU Lesser General Public License |
| jakowisp | 4:a95225ec39ac | 13 | */ |
| jakowisp | 0:ec1356628850 | 14 | #include "mbed.h" |
| jakowisp | 0:ec1356628850 | 15 | #include "C12832_lcd.h" |
| jakowisp | 0:ec1356628850 | 16 | #include "USBHostMSD.h" |
| jakowisp | 0:ec1356628850 | 17 | #include "USBHostPTP.h" |
| jakowisp | 3:1e2f56de7d5d | 18 | #include "Selection.h" |
| jakowisp | 3:1e2f56de7d5d | 19 | #include "Menu.h" |
| jakowisp | 3:1e2f56de7d5d | 20 | #include "Navigator.h" |
| jakowisp | 3:1e2f56de7d5d | 21 | |
| jakowisp | 4:a95225ec39ac | 22 | /** |
| jakowisp | 4:a95225ec39ac | 23 | * Define codes to represent Test Functions |
| jakowisp | 4:a95225ec39ac | 24 | */ |
| jakowisp | 3:1e2f56de7d5d | 25 | #define GETALLJPG 0x01 |
| jakowisp | 3:1e2f56de7d5d | 26 | #define GETALLJPGTHUMB 0x02 |
| jakowisp | 3:1e2f56de7d5d | 27 | #define GETNUMJPG 0x03 |
| jakowisp | 3:1e2f56de7d5d | 28 | #define GETNUMOBJ 0x04 |
| jakowisp | 3:1e2f56de7d5d | 29 | #define DUMPDEVICEINFO 0x05 |
| jakowisp | 3:1e2f56de7d5d | 30 | #define CLOSESESSION 0xFF |
| jakowisp | 3:1e2f56de7d5d | 31 | |
| jakowisp | 4:a95225ec39ac | 32 | /** |
| jakowisp | 4:a95225ec39ac | 33 | * Initiate Global variables |
| jakowisp | 4:a95225ec39ac | 34 | */ |
| jakowisp | 0:ec1356628850 | 35 | DigitalOut led(LED1); |
| jakowisp | 0:ec1356628850 | 36 | FILE * fp2; |
| jakowisp | 0:ec1356628850 | 37 | C12832_LCD lcd; |
| jakowisp | 3:1e2f56de7d5d | 38 | USBHostPTP *ptpdev = NULL; |
| jakowisp | 3:1e2f56de7d5d | 39 | USBHostMSD *msddev = NULL; |
| jakowisp | 0:ec1356628850 | 40 | char fname[256]; |
| jakowisp | 3:1e2f56de7d5d | 41 | uint8_t command=0x00; |
| jakowisp | 3:1e2f56de7d5d | 42 | bool commandActive=false; |
| jakowisp | 3:1e2f56de7d5d | 43 | void (*statusFunction)(void); |
| jakowisp | 0:ec1356628850 | 44 | |
| jakowisp | 4:a95225ec39ac | 45 | /** |
| jakowisp | 4:a95225ec39ac | 46 | * This function is used to handle the raw data recieved via the bulk pipes |
| jakowisp | 4:a95225ec39ac | 47 | * |
| jakowisp | 4:a95225ec39ac | 48 | * @param ptp Pointer to the PTP device |
| jakowisp | 4:a95225ec39ac | 49 | * @param buffer Pointer to the data recieved |
| jakowisp | 4:a95225ec39ac | 50 | * @param length Total data received to be processed |
| jakowisp | 4:a95225ec39ac | 51 | * |
| jakowisp | 4:a95225ec39ac | 52 | * @return Void |
| jakowisp | 4:a95225ec39ac | 53 | */ |
| jakowisp | 0:ec1356628850 | 54 | void WriteObjectHandles(void *ptp,uint8_t *buffer,uint16_t length){ |
| jakowisp | 0:ec1356628850 | 55 | int writeResult,errorcode; |
| jakowisp | 0:ec1356628850 | 56 | uint16_t transferLength=length; |
| jakowisp | 0:ec1356628850 | 57 | uint8_t *dataPtr=buffer; |
| jakowisp | 0:ec1356628850 | 58 | |
| jakowisp | 0:ec1356628850 | 59 | writeResult=fwrite(dataPtr,sizeof(uint8_t),transferLength,fp2); |
| jakowisp | 0:ec1356628850 | 60 | if( writeResult != transferLength) { |
| jakowisp | 0:ec1356628850 | 61 | errorcode=ferror(fp2); |
| jakowisp | 0:ec1356628850 | 62 | if( errorcode ) |
| jakowisp | 0:ec1356628850 | 63 | { |
| jakowisp | 0:ec1356628850 | 64 | printf("\r\nError in writing to file %d\n",errorcode); |
| jakowisp | 0:ec1356628850 | 65 | error("Yucky@!"); |
| jakowisp | 0:ec1356628850 | 66 | } |
| jakowisp | 0:ec1356628850 | 67 | } |
| jakowisp | 0:ec1356628850 | 68 | } |
| jakowisp | 0:ec1356628850 | 69 | |
| jakowisp | 4:a95225ec39ac | 70 | /** |
| jakowisp | 4:a95225ec39ac | 71 | * Test function 0x01 |
| jakowisp | 4:a95225ec39ac | 72 | * |
| jakowisp | 4:a95225ec39ac | 73 | * @param numberOfImages A pointer to where to write the images on the device |
| jakowisp | 4:a95225ec39ac | 74 | * @param numberOfThumbs A pointer to where to write the images on the device |
| jakowisp | 4:a95225ec39ac | 75 | * @return void |
| jakowisp | 4:a95225ec39ac | 76 | */ |
| jakowisp | 2:912d86148549 | 77 | void GetNumberOfThumbsAndImages(int *numberOfImages,int *numberOfThumbs){ |
| jakowisp | 2:912d86148549 | 78 | uint32_t fileHandle=0,numImages=0; |
| jakowisp | 2:912d86148549 | 79 | int internalNumberOfImages=0; |
| jakowisp | 2:912d86148549 | 80 | int internalNumberOfThumbs=0; |
| jakowisp | 2:912d86148549 | 81 | |
| jakowisp | 2:912d86148549 | 82 | FILE *fp = fopen("/usb2/objHandles.bin", "rb"); |
| jakowisp | 2:912d86148549 | 83 | fread(&numImages,sizeof(uint32_t),1,fp); |
| jakowisp | 2:912d86148549 | 84 | while(numImages>0){ |
| jakowisp | 2:912d86148549 | 85 | fread(&fileHandle,sizeof(uint32_t),1,fp); |
| jakowisp | 3:1e2f56de7d5d | 86 | ptpdev->GetObjectInfo(fileHandle); |
| jakowisp | 3:1e2f56de7d5d | 87 | |
| jakowisp | 3:1e2f56de7d5d | 88 | if (ptpdev->objectInfo.thumbFormat == 0x3801 ) { |
| jakowisp | 2:912d86148549 | 89 | internalNumberOfThumbs++; |
| jakowisp | 2:912d86148549 | 90 | } |
| jakowisp | 3:1e2f56de7d5d | 91 | if (ptpdev->objectInfo.objectFormat == 0x3801 ) { |
| jakowisp | 2:912d86148549 | 92 | internalNumberOfImages++; |
| jakowisp | 2:912d86148549 | 93 | } |
| jakowisp | 2:912d86148549 | 94 | numImages--; |
| jakowisp | 2:912d86148549 | 95 | } |
| jakowisp | 2:912d86148549 | 96 | fclose(fp); |
| jakowisp | 2:912d86148549 | 97 | *numberOfImages = internalNumberOfImages; |
| jakowisp | 2:912d86148549 | 98 | *numberOfThumbs = internalNumberOfThumbs; |
| jakowisp | 2:912d86148549 | 99 | |
| jakowisp | 2:912d86148549 | 100 | } |
| jakowisp | 2:912d86148549 | 101 | |
| jakowisp | 4:a95225ec39ac | 102 | /** |
| jakowisp | 4:a95225ec39ac | 103 | * Retrieve all thumbnail images and real images that are JPG files. |
| jakowisp | 4:a95225ec39ac | 104 | */ |
| jakowisp | 3:1e2f56de7d5d | 105 | void GetAllImagesAndThumbs(void) { |
| jakowisp | 0:ec1356628850 | 106 | FILE *fp; |
| jakowisp | 0:ec1356628850 | 107 | |
| jakowisp | 0:ec1356628850 | 108 | uint32_t fileHandle=0,numImages=0; |
| jakowisp | 0:ec1356628850 | 109 | |
| jakowisp | 3:1e2f56de7d5d | 110 | printf("objectid,objectinfosize,imagetype,thumbtype\r\n"); |
| jakowisp | 3:1e2f56de7d5d | 111 | fp = fopen("/usb2/objHandles.bin", "rb"); |
| jakowisp | 0:ec1356628850 | 112 | |
| jakowisp | 0:ec1356628850 | 113 | fread(&numImages,sizeof(uint32_t),1,fp); |
| jakowisp | 0:ec1356628850 | 114 | while(numImages>0){ |
| jakowisp | 3:1e2f56de7d5d | 115 | fread(&fileHandle,sizeof(uint32_t),1,fp); |
| jakowisp | 3:1e2f56de7d5d | 116 | ptpdev->GetObjectInfo(fileHandle); |
| jakowisp | 4:a95225ec39ac | 117 | printf("%ld,%x,%x,%x\r\n",numImages,fileHandle,ptpdev->objectInfo.objectFormat,ptpdev->objectInfo.thumbFormat); |
| jakowisp | 3:1e2f56de7d5d | 118 | |
| jakowisp | 3:1e2f56de7d5d | 119 | if (ptpdev->objectInfo.thumbFormat == 0x3801 && numImages < 864 ) { |
| jakowisp | 3:1e2f56de7d5d | 120 | sprintf(fname,"/usb2/thumb_%s",ptpdev->objectInfo.filename.getString()); |
| jakowisp | 3:1e2f56de7d5d | 121 | fp2 = fopen(fname, "wb"); |
| jakowisp | 0:ec1356628850 | 122 | printf("Starting transfer of %s\r\n",fname); |
| jakowisp | 3:1e2f56de7d5d | 123 | ptpdev->GetThumb(fileHandle,(void *)&WriteObjectHandles); |
| jakowisp | 0:ec1356628850 | 124 | fclose(fp2); |
| jakowisp | 0:ec1356628850 | 125 | printf("GetThumb Transaction Complete\r\n"); |
| jakowisp | 0:ec1356628850 | 126 | } |
| jakowisp | 0:ec1356628850 | 127 | |
| jakowisp | 3:1e2f56de7d5d | 128 | if (ptpdev->objectInfo.objectFormat == 0x3801 && numImages < 864 ) { |
| jakowisp | 3:1e2f56de7d5d | 129 | sprintf(fname,"/usb2/%s",ptpdev->objectInfo.filename.getString()); |
| jakowisp | 3:1e2f56de7d5d | 130 | printf("%s -Type: 0x%04x\r\n",fname,ptpdev->objectInfo.objectFormat); |
| jakowisp | 0:ec1356628850 | 131 | printf("Starting transfer of %s\r\n",fname); |
| jakowisp | 2:912d86148549 | 132 | fp2 = fopen(fname, "wb"); |
| jakowisp | 3:1e2f56de7d5d | 133 | ptpdev->GetObject(fileHandle,(void *)&WriteObjectHandles); |
| jakowisp | 0:ec1356628850 | 134 | fclose(fp2); |
| jakowisp | 2:912d86148549 | 135 | printf("GetObject Transaction Complete\r\n"); |
| jakowisp | 0:ec1356628850 | 136 | } |
| jakowisp | 0:ec1356628850 | 137 | numImages--; |
| jakowisp | 0:ec1356628850 | 138 | } |
| jakowisp | 0:ec1356628850 | 139 | fclose(fp); |
| jakowisp | 3:1e2f56de7d5d | 140 | } |
| jakowisp | 2:912d86148549 | 141 | |
| jakowisp | 4:a95225ec39ac | 142 | /** |
| jakowisp | 4:a95225ec39ac | 143 | * Thread to Watch for MSD image |
| jakowisp | 4:a95225ec39ac | 144 | */ |
| jakowisp | 3:1e2f56de7d5d | 145 | void msd_task(void const *) { |
| jakowisp | 3:1e2f56de7d5d | 146 | USBHostMSD msd2("usb2"); |
| jakowisp | 3:1e2f56de7d5d | 147 | |
| jakowisp | 3:1e2f56de7d5d | 148 | msddev=&msd2; |
| jakowisp | 3:1e2f56de7d5d | 149 | while(true) { |
| jakowisp | 3:1e2f56de7d5d | 150 | while(!msd2.connect()) { |
| jakowisp | 3:1e2f56de7d5d | 151 | Thread::wait(500); |
| jakowisp | 3:1e2f56de7d5d | 152 | } |
| jakowisp | 3:1e2f56de7d5d | 153 | |
| jakowisp | 3:1e2f56de7d5d | 154 | DIR *dp; |
| jakowisp | 3:1e2f56de7d5d | 155 | struct dirent *ep; |
| jakowisp | 3:1e2f56de7d5d | 156 | dp = opendir ("/usb2"); |
| jakowisp | 3:1e2f56de7d5d | 157 | |
| jakowisp | 3:1e2f56de7d5d | 158 | if (dp != NULL) |
| jakowisp | 3:1e2f56de7d5d | 159 | { |
| jakowisp | 3:1e2f56de7d5d | 160 | ep = readdir (dp); |
| jakowisp | 3:1e2f56de7d5d | 161 | while (ep!=NULL) { |
| jakowisp | 3:1e2f56de7d5d | 162 | printf("%s\r\n",ep->d_name); |
| jakowisp | 3:1e2f56de7d5d | 163 | ep = readdir (dp); |
| jakowisp | 3:1e2f56de7d5d | 164 | } |
| jakowisp | 3:1e2f56de7d5d | 165 | (void) closedir (dp); |
| jakowisp | 3:1e2f56de7d5d | 166 | } |
| jakowisp | 3:1e2f56de7d5d | 167 | |
| jakowisp | 3:1e2f56de7d5d | 168 | while(msd2.connect()) { |
| jakowisp | 3:1e2f56de7d5d | 169 | Thread::wait(500); |
| jakowisp | 3:1e2f56de7d5d | 170 | } |
| jakowisp | 3:1e2f56de7d5d | 171 | } |
| jakowisp | 3:1e2f56de7d5d | 172 | } |
| jakowisp | 3:1e2f56de7d5d | 173 | |
| jakowisp | 4:a95225ec39ac | 174 | /** |
| jakowisp | 4:a95225ec39ac | 175 | * Function TO be called by the menu system to start the execution thread to execute the call. |
| jakowisp | 4:a95225ec39ac | 176 | */ |
| jakowisp | 3:1e2f56de7d5d | 177 | void SetCommandGETALLJPG(void) { |
| jakowisp | 3:1e2f56de7d5d | 178 | command=GETALLJPG; |
| jakowisp | 3:1e2f56de7d5d | 179 | } |
| jakowisp | 3:1e2f56de7d5d | 180 | |
| jakowisp | 4:a95225ec39ac | 181 | /** |
| jakowisp | 4:a95225ec39ac | 182 | * Function to display status during image transfers |
| jakowisp | 4:a95225ec39ac | 183 | */ |
| jakowisp | 3:1e2f56de7d5d | 184 | void GetAllJPGStatus(void) { |
| jakowisp | 3:1e2f56de7d5d | 185 | led=!led; |
| jakowisp | 3:1e2f56de7d5d | 186 | lcd.cls(); |
| jakowisp | 3:1e2f56de7d5d | 187 | if(ptpdev->dataLeftToTransfer>0) { |
| jakowisp | 3:1e2f56de7d5d | 188 | lcd.locate(10,0); |
| jakowisp | 3:1e2f56de7d5d | 189 | lcd.printf("%ld/%ld", ptpdev->dataLeftToTransfer, ptpdev->totalDataToTransfer); |
| jakowisp | 3:1e2f56de7d5d | 190 | lcd.locate(0,10); |
| jakowisp | 3:1e2f56de7d5d | 191 | lcd.printf("%s",fname); |
| jakowisp | 3:1e2f56de7d5d | 192 | } |
| jakowisp | 3:1e2f56de7d5d | 193 | } |
| jakowisp | 3:1e2f56de7d5d | 194 | |
| jakowisp | 4:a95225ec39ac | 195 | /** |
| jakowisp | 4:a95225ec39ac | 196 | * Thread to watch for the PTP device connected, and commands that need to be executed. |
| jakowisp | 4:a95225ec39ac | 197 | */ |
| jakowisp | 3:1e2f56de7d5d | 198 | void ptp_task2(void const *) { |
| jakowisp | 3:1e2f56de7d5d | 199 | USBHostPTP ptp; |
| jakowisp | 3:1e2f56de7d5d | 200 | ptpdev=&ptp; |
| jakowisp | 3:1e2f56de7d5d | 201 | |
| jakowisp | 3:1e2f56de7d5d | 202 | int numi,numt; |
| jakowisp | 3:1e2f56de7d5d | 203 | uint32_t objCount=0; |
| jakowisp | 3:1e2f56de7d5d | 204 | |
| jakowisp | 3:1e2f56de7d5d | 205 | while(true) { |
| jakowisp | 3:1e2f56de7d5d | 206 | while(!ptpdev->connect()) { |
| jakowisp | 3:1e2f56de7d5d | 207 | Thread::wait(500); |
| jakowisp | 3:1e2f56de7d5d | 208 | } |
| jakowisp | 3:1e2f56de7d5d | 209 | |
| jakowisp | 3:1e2f56de7d5d | 210 | while(!msddev->connected()){ |
| jakowisp | 3:1e2f56de7d5d | 211 | Thread::wait(500); |
| jakowisp | 3:1e2f56de7d5d | 212 | } |
| jakowisp | 4:a95225ec39ac | 213 | |
| jakowisp | 4:a95225ec39ac | 214 | /* after device connected open a session, get device information, and object handles |
| jakowisp | 4:a95225ec39ac | 215 | */ |
| jakowisp | 3:1e2f56de7d5d | 216 | ptp.OpenSession(); |
| jakowisp | 3:1e2f56de7d5d | 217 | printf("OpenSession Transaction Complete\r\n\r\n"); |
| jakowisp | 3:1e2f56de7d5d | 218 | ptp.GetDeviceInfo(); |
| jakowisp | 3:1e2f56de7d5d | 219 | printf("GetDeviceInfo Transaction Complete\r\n"); |
| jakowisp | 3:1e2f56de7d5d | 220 | fp2 = fopen("/usb2/objHandles.bin", "wb"); |
| jakowisp | 3:1e2f56de7d5d | 221 | ptp.GetObjectHandles(0xffffffff,0x0000,0x0000,(void *)&WriteObjectHandles); |
| jakowisp | 3:1e2f56de7d5d | 222 | fclose(fp2); |
| jakowisp | 3:1e2f56de7d5d | 223 | printf("GetObjecthandles Transaction Complete\r\n"); |
| jakowisp | 3:1e2f56de7d5d | 224 | |
| jakowisp | 4:a95225ec39ac | 225 | //While ptp device connected watch for commands. |
| jakowisp | 3:1e2f56de7d5d | 226 | while(ptpdev->connected()) { |
| jakowisp | 3:1e2f56de7d5d | 227 | commandActive=true; |
| jakowisp | 3:1e2f56de7d5d | 228 | switch(command) { |
| jakowisp | 3:1e2f56de7d5d | 229 | case GETALLJPG: |
| jakowisp | 3:1e2f56de7d5d | 230 | statusFunction=&GetAllJPGStatus; |
| jakowisp | 3:1e2f56de7d5d | 231 | GetAllImagesAndThumbs(); |
| jakowisp | 3:1e2f56de7d5d | 232 | statusFunction=NULL; |
| jakowisp | 3:1e2f56de7d5d | 233 | break; |
| jakowisp | 3:1e2f56de7d5d | 234 | case GETALLJPGTHUMB: |
| jakowisp | 3:1e2f56de7d5d | 235 | break; |
| jakowisp | 3:1e2f56de7d5d | 236 | case GETNUMJPG: |
| jakowisp | 3:1e2f56de7d5d | 237 | GetNumberOfThumbsAndImages(&numi,&numt); |
| jakowisp | 3:1e2f56de7d5d | 238 | printf("images: %d, thumbs:%d\r\n",numi,numt); |
| jakowisp | 3:1e2f56de7d5d | 239 | break; |
| jakowisp | 3:1e2f56de7d5d | 240 | case GETNUMOBJ: |
| jakowisp | 3:1e2f56de7d5d | 241 | ptp.GetNumObjects(&objCount); |
| jakowisp | 3:1e2f56de7d5d | 242 | printf("GetNumObjects Transaction Complete - Count:%ld\r\n",objCount); |
| jakowisp | 3:1e2f56de7d5d | 243 | break; |
| jakowisp | 3:1e2f56de7d5d | 244 | case DUMPDEVICEINFO: |
| jakowisp | 3:1e2f56de7d5d | 245 | ptp.DumpDeviceInfo(); |
| jakowisp | 3:1e2f56de7d5d | 246 | break; |
| jakowisp | 3:1e2f56de7d5d | 247 | case CLOSESESSION: |
| jakowisp | 3:1e2f56de7d5d | 248 | ptpdev->CloseSession(); |
| jakowisp | 3:1e2f56de7d5d | 249 | printf("CloseSession Transaction Complete\r\n"); |
| jakowisp | 3:1e2f56de7d5d | 250 | break; |
| jakowisp | 3:1e2f56de7d5d | 251 | default: |
| jakowisp | 3:1e2f56de7d5d | 252 | commandActive=false; |
| jakowisp | 3:1e2f56de7d5d | 253 | break; |
| jakowisp | 3:1e2f56de7d5d | 254 | } |
| jakowisp | 3:1e2f56de7d5d | 255 | command=0x00; |
| jakowisp | 3:1e2f56de7d5d | 256 | Thread::wait(100); |
| jakowisp | 0:ec1356628850 | 257 | } |
| jakowisp | 0:ec1356628850 | 258 | } |
| jakowisp | 0:ec1356628850 | 259 | } |
| jakowisp | 0:ec1356628850 | 260 | |
| jakowisp | 4:a95225ec39ac | 261 | ///Menu function to set the Command to be executed. |
| jakowisp | 3:1e2f56de7d5d | 262 | void SetCommandGETNUMJPG(void) { |
| jakowisp | 3:1e2f56de7d5d | 263 | command=GETNUMJPG; |
| jakowisp | 3:1e2f56de7d5d | 264 | } |
| jakowisp | 3:1e2f56de7d5d | 265 | |
| jakowisp | 4:a95225ec39ac | 266 | ///Menu function to set the Command to be executed. |
| jakowisp | 3:1e2f56de7d5d | 267 | void SetCommandGETNUMOBJ(void) { |
| jakowisp | 3:1e2f56de7d5d | 268 | command=GETNUMOBJ; |
| jakowisp | 3:1e2f56de7d5d | 269 | } |
| jakowisp | 3:1e2f56de7d5d | 270 | |
| jakowisp | 4:a95225ec39ac | 271 | ///Menu function to set the Command to be executed. |
| jakowisp | 3:1e2f56de7d5d | 272 | void SetCommandDUMPDEVICEINFO(void) { |
| jakowisp | 3:1e2f56de7d5d | 273 | command=DUMPDEVICEINFO; |
| jakowisp | 3:1e2f56de7d5d | 274 | } |
| jakowisp | 3:1e2f56de7d5d | 275 | |
| jakowisp | 4:a95225ec39ac | 276 | ///Menu function to set the Command to be executed. |
| jakowisp | 3:1e2f56de7d5d | 277 | void SetCommandCLOSESESSION(void) { |
| jakowisp | 3:1e2f56de7d5d | 278 | command=CLOSESESSION; |
| jakowisp | 3:1e2f56de7d5d | 279 | } |
| jakowisp | 3:1e2f56de7d5d | 280 | |
| jakowisp | 4:a95225ec39ac | 281 | ///Main fuction to display the Status of the application. |
| jakowisp | 0:ec1356628850 | 282 | int main() { |
| jakowisp | 0:ec1356628850 | 283 | lcd.cls(); |
| jakowisp | 0:ec1356628850 | 284 | lcd.locate(10,3); |
| jakowisp | 0:ec1356628850 | 285 | lcd.printf("Initializing"); |
| jakowisp | 3:1e2f56de7d5d | 286 | Thread ptpTask2(ptp_task2, NULL, osPriorityNormal, 1024 * 4); |
| jakowisp | 3:1e2f56de7d5d | 287 | Thread msdTask2(msd_task, NULL, osPriorityNormal, 1024 * 4); |
| jakowisp | 3:1e2f56de7d5d | 288 | Menu rootMenu("root"); |
| jakowisp | 3:1e2f56de7d5d | 289 | Menu testMenu("Test menu"); |
| jakowisp | 3:1e2f56de7d5d | 290 | testMenu.add(Selection(&SetCommandDUMPDEVICEINFO, 2, NULL, "Dump Device Info")); // The function argument of selection can be added directly |
| jakowisp | 3:1e2f56de7d5d | 291 | testMenu.add(Selection(&SetCommandGETALLJPG, 2, NULL, "Get All Images")); // The function argument of selection can be added directly |
| jakowisp | 3:1e2f56de7d5d | 292 | testMenu.add(Selection(&SetCommandGETNUMOBJ, 1, NULL, "Get Number of Objects")); |
| jakowisp | 3:1e2f56de7d5d | 293 | testMenu.add(Selection(&SetCommandGETNUMJPG, 3, NULL, "Get Number of Images")); |
| jakowisp | 3:1e2f56de7d5d | 294 | //testMenu.add(Selection(NULL, 4, NULL, "Get Number of Thumbnails")); |
| jakowisp | 3:1e2f56de7d5d | 295 | //testMenu.add(Selection(NULL, 5, NULL, "Get Number of Thumbnails")); |
| jakowisp | 3:1e2f56de7d5d | 296 | testMenu.add(Selection(&SetCommandCLOSESESSION, 4, NULL, "Close Session")); |
| jakowisp | 3:1e2f56de7d5d | 297 | testMenu.add(Selection(NULL, 5, &rootMenu, " Go back")); // always add a Selection at the end to point to the parent |
| jakowisp | 4:a95225ec39ac | 298 | Menu aboutMenu("About Menu"); // about menu |
| jakowisp | 3:1e2f56de7d5d | 299 | aboutMenu.add(Selection(NULL, 0, NULL, "Author:")); |
| jakowisp | 3:1e2f56de7d5d | 300 | aboutMenu.add(Selection(NULL, 1, NULL, " Dwayne S Dilbeck")); |
| jakowisp | 3:1e2f56de7d5d | 301 | aboutMenu.add(Selection(NULL, 2, NULL, " 8/29/2013")); |
| jakowisp | 3:1e2f56de7d5d | 302 | aboutMenu.add(Selection(NULL, 3, NULL, " USB Device Interface:")); |
| jakowisp | 3:1e2f56de7d5d | 303 | aboutMenu.add(Selection(NULL, 4, NULL, " Architecture,")); |
| jakowisp | 3:1e2f56de7d5d | 304 | aboutMenu.add(Selection(NULL, 5, NULL, " Protocols,")); |
| jakowisp | 3:1e2f56de7d5d | 305 | aboutMenu.add(Selection(NULL, 6, NULL, " and programming.")); |
| jakowisp | 3:1e2f56de7d5d | 306 | aboutMenu.add(Selection(NULL, 7, &rootMenu, " Go back")); |
| jakowisp | 3:1e2f56de7d5d | 307 | rootMenu.add(Selection(NULL, 0, &testMenu, "TEST MENU")); |
| jakowisp | 3:1e2f56de7d5d | 308 | rootMenu.add(Selection(NULL, 1, &aboutMenu, "About menu")); |
| jakowisp | 3:1e2f56de7d5d | 309 | Navigator navigator(&rootMenu, &lcd); |
| jakowisp | 3:1e2f56de7d5d | 310 | |
| jakowisp | 0:ec1356628850 | 311 | while(1) { |
| jakowisp | 3:1e2f56de7d5d | 312 | if(ptpdev!=NULL) { |
| jakowisp | 3:1e2f56de7d5d | 313 | if(ptpdev->connected()) { |
| jakowisp | 3:1e2f56de7d5d | 314 | if(!commandActive) { |
| jakowisp | 3:1e2f56de7d5d | 315 | navigator.poll(); |
| jakowisp | 3:1e2f56de7d5d | 316 | } else { |
| jakowisp | 3:1e2f56de7d5d | 317 | if(statusFunction!=NULL) |
| jakowisp | 3:1e2f56de7d5d | 318 | (*statusFunction)(); |
| jakowisp | 3:1e2f56de7d5d | 319 | else { |
| jakowisp | 3:1e2f56de7d5d | 320 | wait_ms(20); |
| jakowisp | 3:1e2f56de7d5d | 321 | } |
| jakowisp | 3:1e2f56de7d5d | 322 | } |
| jakowisp | 3:1e2f56de7d5d | 323 | |
| jakowisp | 3:1e2f56de7d5d | 324 | } else { |
| jakowisp | 3:1e2f56de7d5d | 325 | lcd.cls(); |
| jakowisp | 3:1e2f56de7d5d | 326 | lcd.locate(10,3); |
| jakowisp | 3:1e2f56de7d5d | 327 | lcd.printf("Please connect PTP device."); |
| jakowisp | 3:1e2f56de7d5d | 328 | } |
| jakowisp | 3:1e2f56de7d5d | 329 | } |
| jakowisp | 3:1e2f56de7d5d | 330 | Thread::wait(200); |
| jakowisp | 0:ec1356628850 | 331 | } |
| jakowisp | 0:ec1356628850 | 332 | } |
| jakowisp | 0:ec1356628850 | 333 | |
| jakowisp | 0:ec1356628850 | 334 | |
| jakowisp | 0:ec1356628850 | 335 | |
| jakowisp | 0:ec1356628850 | 336 |