uint8_t fsmanInit(uint8_t * result_code, uint8_t* buffer){ struct tm ts; fsbuf = buffer; RTC_GetTimeDateDecimal(&ts); SetClockVars (ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec); fsmanInitHardwareSD(); if (!fsmanMountSD(result_code)){ *result_code = UNKNOWN_SD_MOUNT_ERROR;//from FILEIO_ERROR_TYPE return 0; } //Create a VI_LOG directory if there isnt already one if(FSchdir("VI_LOG") != CE_GOOD){ __debug("VI_LOG Directory was not found, creating it"); if(FSmkdir(".\\VI_LOG") != CE_GOOD){ __debug("Unable to create a VI_LOG directory"); *result_code = UNKNOWN_WRITE_ERROR; return 0; } else{ if(FSchdir ("VI_LOG") != CE_GOOD){ *result_code = UNKNOWN_WRITE_ERROR; __debug("VI_LOG Directory was created but not found"); return 0; } } } return 1; }
/************************************************************************ Function: WORD JPEGMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) Overview: This function is called by GOLMsg() function when in this particular demo each time the valid message is received for the objects in the demo. Input: objMsg - translated message for the object, pObj - pointer to the object, pMsg - pointer to the non-translated, raw GOL message Output: If the function returns non-zero the message will be processed by the object directly affected by the message. Default action on the object based on the message will be performed. ************************************************************************/ WORD JPEGMsgCallback(WORD objMsg, OBJ_HEADER *pObj, GOL_MSG *pMsg) { LISTITEM *pItemSel; // check if an image is being shown if((blImageOnScreen == 1) || (blSlideShowOn == 1)) { // this is the routine to go back and show the list when an // image is being shown on the screen or the slide show is // currently ongoing if(pMsg->uiEvent == EVENT_RELEASE) { blImageOnScreen = 0; blSlideShowOn = 0; GOLRedrawRec(0, 0, GetMaxX(), GetMaxY()); } return (0); } switch(GetObjID(pObj)) { case ID_BUTTON_A: if(objMsg == BTN_MSG_RELEASED) { // check if button is pressed // do not process if user moved the touch away from the button // returning 1 wil update the button if(pMsg->uiEvent == EVENT_MOVE) return (1); screenState = CREATE_DEMOSELECTION; } return (1); case ID_BUTTON_D: if(objMsg == BTN_MSG_RELEASED) { // check if button is pressed // do not process if user moved the touch away from the button // returning 1 wil update the button if(pMsg->uiEvent == EVENT_MOVE) return (1); // enable the slide show blSlideShowOn = 1; // initialize the screen SetColor(BLACK); ClearDevice(); ClrState(pObj, BTN_PRESSED); // clear the pressed state, will be shown only when redrawn blSlideShowDelay = 0; // force slide show to immediately start return (0); } return (1); case ID_JPGLISTBOX: if(pMsg->uiEvent == EVENT_MOVE) { pMsg->uiEvent = EVENT_PRESS; // change event for listbox // Process message by default LbMsgDefault(objMsg, (LISTBOX *)pObj, pMsg); // Set new list box position SldSetPos(pSlider, LbGetCount(pListBox) - LbGetFocusedItem(pListBox) - 1); SetState(pSlider, SLD_DRAW_THUMB); pMsg->uiEvent = EVENT_MOVE; // restore event for listbox } else if(pMsg->uiEvent == EVENT_PRESS) { // call the message default processing of the list box to select the item LbMsgDefault(objMsg, (LISTBOX *)pObj, pMsg); } else if(pMsg->uiEvent == EVENT_RELEASE) { // check which item was selected and display appropriate screen pItemSel = LbGetSel(pListBox, NULL); // get the selected item if(aFolderElement[pItemSel->data].blFolder == 1) { if(FSchdir(aFolderElement[pItemSel->data].Name) == 0) { FillNewElements(); return (1); } } else if(aFolderElement[pItemSel->data].blText == 0) { IMG_FILE *pImgFile = IMG_FOPEN(aFolderElement[pItemSel->data].Name, "rb"); if(pImgFile != NULL) { blImageOnScreen = 1; // initialize the screen SetColor(BLACK); ClearDevice(); if ( ImageDecode ( pImgFile, aFolderElement[pItemSel->data].ImgType, 0, 0, IMG_SCREEN_WIDTH, IMG_SCREEN_HEIGHT, (IMG_DOWN_SCALE | IMG_ALIGN_CENTER), NULL, NULL ) ) { DisplayErrorInfo(); } IMG_FCLOSE(pImgFile); } } } // The message was processed. To avoid other objects processing the // processed message reset the message. pMsg->uiEvent = EVENT_INVALID; return (0); case ID_SLD4LB: if((objMsg == SLD_MSG_INC) || (objMsg == SLD_MSG_DEC)) { // check slider was touched. // Process message by default SldMsgDefault(objMsg, (SLIDER *)pObj, pMsg); // Set new list box position if(LbGetFocusedItem(pListBox) != LbGetCount(pListBox) - SldGetPos(pSlider)) { LbSetFocusedItem(pListBox, LbGetCount(pListBox) - SldGetPos(pSlider)); SetState(pListBox, LB_DRAW_ITEMS); } } // The message was processed return (0); case ID_BTNUP4LB: // slider up button was pressed if(objMsg == BTN_MSG_RELEASED) { // check if we have reached the very first then stay there. if (LbGetFocusedItem(pListBox) == 0) LbSetFocusedItem(pListBox,0); else LbSetFocusedItem(pListBox,LbGetFocusedItem(pListBox)-1); SetState(pListBox, LB_DRAW_ITEMS); SldSetPos(pSlider, SldGetPos(pSlider) + 1); SetState(pSlider, SLD_DRAW_THUMB); } return (1); case ID_BTNDN4LB: // slider down button was pressed if(objMsg == BTN_MSG_RELEASED) { // set all items to be not displayed pItemSel = pListBox->pItemList; while(pItemSel != NULL) { pItemSel->status = 0; pItemSel = pItemSel->pNextItem; } LbSetFocusedItem(pListBox, LbGetFocusedItem(pListBox) + 1); SetState(pListBox, LB_DRAW_ITEMS); SldSetPos(pSlider, SldGetPos(pSlider) - 1); SetState(pSlider, SLD_DRAW_THUMB); } return (1); } return (1); }
int main (void) { FSFILE * pointer; #if defined(SUPPORT_LFN) char count = 80; #endif char * pointer2; SearchRec rec; unsigned char attributes; unsigned char size = 0, i; // Initialize and configure Primary PLL, and enabled Secondary Oscillator PLLFBD = 58; /* M = 60 */ CLKDIVbits.PLLPOST = 0; /* N1 = 2 */ CLKDIVbits.PLLPRE = 0; /* N2 = 2 */ OSCTUN = 0; __builtin_write_OSCCONH(0x03); __builtin_write_OSCCONL(0x03); while (OSCCONbits.COSC != 0x3); while (_LOCK == 0); // Activate the RTCC module __builtin_write_RTCWEN(); Nop(); Nop(); RCFGCALbits.RTCPTR0 = 1; RCFGCALbits.RTCPTR1 = 1; // Set it to the correct time // These values won't be accurate RTCVAL = 0x0011; RTCVAL = 0x0815; RTCVAL = 0x0108; RTCVAL = 0x2137; RCFGCAL = 0x8000; while (!MDD_MediaDetect()); // Initialize the library while (!FSInit()); #ifdef ALLOW_WRITES // Create a file pointer = FSfopen ("FILE1.TXT", "w"); if (pointer == NULL) while(1); // Write 21 1-byte objects from sendBuffer into the file if (FSfwrite (sendBuffer, 1, 21, pointer) != 21) while(1); // FSftell returns the file's current position if (FSftell (pointer) != 21) while(1); // FSfseek sets the position one byte before the end // It can also set the position of a file forward from the // beginning or forward from the current position if (FSfseek(pointer, 1, SEEK_END)) while(1); // Write a 2 at the end of the string if (FSfwrite (send2, 1, 1, pointer) != 1) while(1); // Close the file if (FSfclose (pointer)) while(1); // Create a second file pointer = FSfopen ("Microchip File 1.TXT", "w"); if (pointer == NULL) while(1); // Write the string to it again if (FSfwrite ((void *)sendBuffer, 1, 21, pointer) != 21) while(1); // Close the file if (FSfclose (pointer)) while(1); #endif // Open file 1 in read mode pointer = FSfopen ("FILE1.TXT", "r"); if (pointer == NULL) while(1); if (FSrename ("Microchip File 2.TXT", pointer)) while(1); // Read one four-byte object if (FSfread (receiveBuffer, 4, 1, pointer) != 1) while(1); // Check if this is the end of the file- it shouldn't be if (FSfeof (pointer)) while(1); // Close the file if (FSfclose (pointer)) while(1); // Make sure we read correctly if ((receiveBuffer[0] != 'T') || (receiveBuffer[1] != 'h') || (receiveBuffer[2] != 'i') || (receiveBuffer[3] != 's')) { while(1); } #ifdef ALLOW_DIRS // Create a small directory tree // Beginning the path string with a '.' will create the tree in // the current directory. Beginning with a '..' would create the // tree in the previous directory. Beginning with just a '\' would // create the tree in the root directory. Beginning with a dir name // would also create the tree in the current directory if (FSmkdir (".\\Mchp Directory 1\\Dir2\\Directory 3")) while(1); // Change to 'Directory 3' in our new tree if (FSchdir ("Mchp Directory 1\\Dir2\\Directory 3")) while(1); // Create another tree in 'Directory 3' if (FSmkdir ("Directory 4\\Directory 5\\Directory 6")) while(1); // Create a third file in directory THREE pointer = FSfopen ("CWD.TXT", "w"); if (pointer == NULL) while(1); #if defined(SUPPORT_LFN) // Get the name of the current working directory /* it should be "\Mchp Directory 1\Dir2\Directory 3" */ pointer2 = wFSgetcwd ((unsigned short int *)path1, count); #endif if (pointer2 != path1) while(1); // Simple string length calculation i = 0; while(*((unsigned short int *)path1 + i) != 0x00) { size++; size++; i++; } // Write the name to CWD.TXT if (FSfwrite (path1, size, 1, pointer) != 1) while(1); // Close the file if (FSfclose (pointer)) while(1); // Create some more directories if (FSmkdir ("Directory 4\\Directory 5\\Directory 7\\..\\Directory 8\\..\\..\\DIRNINE\\Directory 10\\..\\Directory 11\\..\\Directory 12")) while(1); /******************************************************************* Now our tree looks like this \ -> Mchp Directory 1 -> Dir2 -> Directory 3 -> Directory 4 -> Directory 5 -> Directory 6 -> Directory 7 -> Directory 8 DIRNINE -> Directory 10 -> Directory 11 -> Directory 12 ********************************************************************/ // This will delete only Directory 8 // If we tried to delete Directory 5 with this call, the FSrmdir // function would return -1, since Directory 5 is non-empty if (FSrmdir ("\\Mchp Directory 1\\Dir2\\Directory 3\\Directory 4\\Directory 5\\Directory 8", FALSE)) while(1); // This will delete DIRNINE and all three of its sub-directories if (FSrmdir ("Directory 4\\DIRNINE", TRUE)) while(1); // Change directory to the root dir if (FSchdir ("\\")) while(1); #endif #ifdef ALLOW_FILESEARCH // Set attributes attributes = ATTR_ARCHIVE | ATTR_READ_ONLY | ATTR_HIDDEN; // Functions "FindFirst" & "FindNext" can be used to find files // and directories with required attributes in the current working directory. // Find the first TXT file with any (or none) of those attributes that // has a name beginning with the letters "Mic" // These functions are more useful for finding out which files are // in your current working directory if (FindFirst ("Mic*.TXT", attributes, &rec)) while(1); // Find file to get "Microchip File 2.TXT" if (FindNext (&rec)) while(1); #if defined(SUPPORT_LFN) // Delete file 2 // If the file name is long if(rec.utf16LFNfoundLength) { // NOTE : "wFSremove" function deletes specific file not directory. // To delete directories use "wFSrmdir" function if (wFSremove (rec.utf16LFNfound)) while(1); } else #endif { // NOTE : "FSremove" function deletes specific file not directory. // To delete directories use "FSrmdir" function if (FSremove (rec.filename)) while(1); } #endif /********************************************************************* The final contents of our card should look like this: \ -> Microchip File 1.TXT -> Mchp Directory 1 -> Dir2 -> Directory 3 -> CWD.TXT -> Directory 4 -> Directory 5 -> Directory 6 -> Directory 7 *********************************************************************/ while(1); }
int main (void) { FSFILE * pointer; #if defined(SUPPORT_LFN) char count = 80; #endif char * pointer2; SearchRec rec; unsigned char attributes; unsigned char size = 0, i; // Turn on the secondary oscillator __asm__ ("MOV #OSCCON,w1"); __asm__ ("MOV.b #0x02, w0"); __asm__ ("MOV #0x46, w2"); __asm__ ("MOV #0x57, w3"); __asm__ ("MOV.b w2, [w1]"); __asm__ ("MOV.b w3, [w1]"); __asm__ ("MOV.b w0, [w1]"); // Activate the RTCC module __asm__ ("mov #NVMKEY,W0"); __asm__ ("mov #0x55,W1"); __asm__ ("mov #0xAA,W2"); __asm__ ("mov W1,[W0]"); __asm__ ("nop"); __asm__ ("mov W2,[W0]"); __asm__ ("bset RCFGCAL,#13"); __asm__ ("nop"); __asm__ ("nop"); RCFGCALbits.RTCPTR0 = 1; RCFGCALbits.RTCPTR1 = 1; // Set it to the correct time // These values won't be accurate RTCVAL = 0x0007; RTCVAL = 0x0717; RTCVAL = 0x0208; RTCVAL = 0x2137; RCFGCAL = 0x8000; #if defined(__PIC24FJ256DA210__) // Make Analog Pins Digital ANSB = 0x0000 ; ANSA = 0x0000; ANSC = 0x0000; ANSD = 0x0000; // Enable PLL CLKDIVbits.PLLEN = 1; // Configure SPI1 PPS pins (ENC28J60/ENCX24J600/MRF24WB0M or other PICtail Plus cards) __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS RPOR1bits.RP2R = 8; // assign RP2 for SCK1 RPOR0bits.RP1R = 7; // assign RP1 for SDO1 RPINR20bits.SDI1R = 0; // assign RP0 for SDI1 __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS #elif defined(__PIC24FJ256GB110__) AD1PCFGL = 0xFFFF; //Initialize the SPI RPINR20bits.SDI1R = 23; RPOR7bits.RP15R = 7; RPOR0bits.RP0R = 8; //enable a pull-up for the card detect, just in case the SD-Card isn't attached // then lets have a pull-up to make sure we don't think it is there. CNPU5bits.CN68PUE = 1; #endif while (!MDD_MediaDetect()); // Initialize the library while (!FSInit()); #ifdef ALLOW_WRITES // Create a file pointer = FSfopen ("FILE1.TXT", "w"); if (pointer == NULL) while(1); // Write 21 1-byte objects from sendBuffer into the file if (FSfwrite (sendBuffer, 1, 21, pointer) != 21) while(1); // FSftell returns the file's current position if (FSftell (pointer) != 21) while(1); // FSfseek sets the position one byte before the end // It can also set the position of a file forward from the // beginning or forward from the current position if (FSfseek(pointer, 1, SEEK_END)) while(1); // Write a 2 at the end of the string if (FSfwrite (send2, 1, 1, pointer) != 1) while(1); // Close the file if (FSfclose (pointer)) while(1); // Create a second file pointer = FSfopen ("Microchip File 1.TXT", "w"); if (pointer == NULL) while(1); // Write the string to it again if (FSfwrite ((void *)sendBuffer, 1, 21, pointer) != 21) while(1); // Close the file if (FSfclose (pointer)) while(1); #endif // Open file 1 in read mode pointer = FSfopen ("FILE1.TXT", "r"); if (pointer == NULL) while(1); if (FSrename ("Microchip File 2.TXT", pointer)) while(1); // Read one four-byte object if (FSfread (receiveBuffer, 4, 1, pointer) != 1) while(1); // Check if this is the end of the file- it shouldn't be if (FSfeof (pointer)) while(1); // Close the file if (FSfclose (pointer)) while(1); // Make sure we read correctly if ((receiveBuffer[0] != 'T') || (receiveBuffer[1] != 'h') || (receiveBuffer[2] != 'i') || (receiveBuffer[3] != 's')) { while(1); } #ifdef ALLOW_DIRS // Create a small directory tree // Beginning the path string with a '.' will create the tree in // the current directory. Beginning with a '..' would create the // tree in the previous directory. Beginning with just a '\' would // create the tree in the root directory. Beginning with a dir name // would also create the tree in the current directory if (FSmkdir (".\\Mchp Directory 1\\Dir2\\Directory 3")) while(1); // Change to 'Directory 3' in our new tree if (FSchdir ("Mchp Directory 1\\Dir2\\Directory 3")) while(1); // Create another tree in 'Directory 3' if (FSmkdir ("Directory 4\\Directory 5\\Directory 6")) while(1); // Create a third file in directory THREE pointer = FSfopen ("CWD.TXT", "w"); if (pointer == NULL) while(1); #if defined(SUPPORT_LFN) // Get the name of the current working directory /* it should be "\Microchip Directory 1\Dir2\Directory 3" */ pointer2 = wFSgetcwd ((unsigned short int *)path1, count); #endif if (pointer2 != path1) while(1); // Simple string length calculation i = 0; while(*((unsigned short int *)path1 + i) != 0x00) { size++; size++; i++; } // Write the name to CWD.TXT if (FSfwrite (path1, size, 1, pointer) != 1) while(1); // Close the file if (FSfclose (pointer)) while(1); // Create some more directories if (FSmkdir ("Directory 4\\Directory 5\\Directory 7\\..\\Directory 8\\..\\..\\DIRNINE\\Directory 10\\..\\Directory 11\\..\\Directory 12")) while(1); /******************************************************************* Now our tree looks like this \ -> Mchp Directory 1 -> Dir2 -> Directory 3 -> Directory 4 -> Directory 5 -> Directory 6 -> Directory 7 -> Directory 8 DIRNINE -> Directory 10 -> Directory 11 -> Directory 12 ********************************************************************/ // This will delete only Directory 8 // If we tried to delete Directory 5 with this call, the FSrmdir // function would return -1, since Directory 5 is non-empty if (FSrmdir ("\\Mchp Directory 1\\Dir2\\Directory 3\\Directory 4\\Directory 5\\Directory 8", FALSE)) while(1); // This will delete DIRNINE and all three of its sub-directories if (FSrmdir ("Directory 4\\DIRNINE", TRUE)) while(1); // Change directory to the root dir if (FSchdir ("\\")) while(1); #endif #ifdef ALLOW_FILESEARCH // Set attributes attributes = ATTR_ARCHIVE | ATTR_READ_ONLY | ATTR_HIDDEN; // Functions "FindFirst" & "FindNext" can be used to find files // and directories with required attributes in the current working directory. // Find the first TXT file with any (or none) of those attributes that // has a name beginning with the letters "Mic" // These functions are more useful for finding out which files are // in your current working directory if (FindFirst ("Mic*.TXT", attributes, &rec)) while(1); // Find file to get "Microchip File 2.TXT" if (FindNext (&rec)) while(1); #if defined(SUPPORT_LFN) // Delete file 2 // If the file name is long if(rec.utf16LFNfoundLength) { // NOTE : "wFSremove" function deletes specific file not directory. // To delete directories use "wFSrmdir" function if (wFSremove (rec.utf16LFNfound)) while(1); } else #endif { // NOTE : "FSremove" function deletes specific file not directory. // To delete directories use "FSrmdir" function if (FSremove (rec.filename)) while(1); } #endif /********************************************************************* The final contents of our card should look like this: \ -> Microchip File 1.TXT -> Mchp Directory 1 -> Dir2 -> Directory 3 -> CWD.TXT -> Directory 4 -> Directory 5 -> Directory 6 -> Directory 7 *********************************************************************/ while(1); }