/*---------------------------------------------------------------------------*/ T_uezError FDICmdStart( T_uezDevice aStream, void **aWorkspace, TUInt32 aStackSizeBytes, const T_consoleCmdEntry *aCommandTable) { T_FDICmdWorkspace *p; T_uezError error; // Make sure we have a stream opened if (!aStream) return UEZ_ERROR_NOT_OPEN; // Allocate the workspace p = UEZMemAlloc(sizeof(*p)); if (!p) return UEZ_ERROR_OUT_OF_MEMORY; // Initialize the default parameters p->iStream = aStream; p->iCommandTable = aCommandTable; p->iCmdLen = 0; p->iNeedPrompt = ETrue; p->iLastCmd[0] = '\0'; p->iSemCmdProcess = 0; p->iStop = EFalse; p->iStopped = EFalse; // Create a semaphore to ensure one command // and a time is processed error = UEZSemaphoreCreateBinary(&p->iSemCmdProcess); if (!error) { // Semaphore for command processing created // Create the task error = UEZTaskCreate( FDICmdTask, "CMD", aStackSizeBytes, p, UEZ_PRIORITY_NORMAL, &p->iTask); } // If any error, task is not running and we need to clean up if (error) { // Get rid of the semaphore if (p->iSemCmdProcess) UEZSemaphoreDelete(p->iSemCmdProcess); // Remove the memory used UEZMemFree(p); p = 0; } // Return the workspace pointer (if any) if (aWorkspace) *aWorkspace = (void *)p; return error; }
/*---------------------------------------------------------------------------*/ static void ReleaseTsQueue( T_tsQueue *tsq ) { #ifdef NO_DYNAMIC_MEMORY_ALLOC tsq->iNext = xFreeTsList; xFreeTsList = tsq; #else UEZMemFree(tsq); #endif }
/*---------------------------------------------------------------------------* * Routine: VideoPlayerSelect *---------------------------------------------------------------------------* * Description: * Setup the video player, drawing the video player load screen. Load * images onto the screen and then go into video player scroll mode or * report an error. * Inputs: * const T_choice *aChoice -- Choice used to get here. *---------------------------------------------------------------------------*/ void VideoPlayerSelection(const T_choice *aChoice) { T_uezDevice lcd; T_uezQueue queue; T_uezDevice ts; T_uezInputEvent inputEvent; #if ENABLE_UEZ_BUTTON T_uezDevice keypadDevice; #endif G_ws = UEZMemAlloc(sizeof(T_VideoPlayerSelectWorkspace)); if (!G_ws) return; memset(G_ws, 0, sizeof(*G_ws)); if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { #if ENABLE_UEZ_BUTTON UEZKeypadOpen("BBKeypad", &keypadDevice, &queue); #endif #if UEZ_REGISTER UEZQueueSetName(queue, "VideoSelection", "\0"); #endif // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE) { if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE) { G_ws->iLCD = lcd; G_ws->iDriveError = AudioPlayerSelectionLoad(1); VideoPlayerSelectScreen(lcd); VideoPlayerSelectChoices(); VideoPlayerSelectDraw(); // Sit here in a loop until we are done while (!G_ws->iExit) { //Wait till we get a touchscreen event if (UEZQueueReceive(queue, &inputEvent, UEZ_TIMEOUT_INFINITE)==UEZ_ERROR_NONE) { ChoicesUpdate(&G_win, G_ws->iChoices, queue, 500); } } UEZLCDClose(lcd); } UEZTSClose(ts, queue); } #if ENABLE_UEZ_BUTTON UEZKeypadClose(keypadDevice, &queue); #endif UEZQueueDelete(queue); } UEZMemFree(G_ws); }
/*---------------------------------------------------------------------------*/ void UEZWAVCleanUp() { T_uezError error; error = (*ac)->UseConfiguration((void*)ac, 0); if(error != UEZ_ERROR_NONE){ //the configuration did not take try again. (*ac)->UseConfiguration((void*)ac, 0); } if(G_AudioAmpOpen){ UEZAudioAmpSetLevel(amp, 48); G_AudioAmpOpen = EFalse; } UEZMemFree(wav); UEZMemFree(wav2); UEZAudioAmpClose(amp); numBytesRead = 1; numBytesRead2 = 1; flag = ETrue; UEZSemaphoreDelete(wavSem); }
void AudioPlayerMode(const T_choice *aChoice) { T_uezDevice lcd; T_uezQueue queue; T_uezDevice ts; T_uezInputEvent inputEvent; UEZSemaphoreCreateCounting(&G_AudioSemaphore, 10, 1); G_ws = UEZMemAlloc(sizeof(T_AudioPlayerWorkspace)); if (!G_ws) return; memset(G_ws, 0, sizeof(*G_ws)); if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { #if UEZ_REGISTER UEZQueueSetName(queue, "AudioPlayer", "\0"); #endif // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE) { if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE) { G_ws->iLCD = lcd; G_ws->iDriveError = AudioPlayerLoadDirectory(); AudioPlayerScreen(lcd); AudioPlayerChoices(); AudioPlayerDraw(); // Sit here in a loop until we are done while (!G_ws->iExit) { //Wait till we get a touchscreen event if (UEZQueueReceive(queue, &inputEvent, UEZ_TIMEOUT_INFINITE)==UEZ_ERROR_NONE) { ChoicesUpdate(&G_win, G_ws->iChoices, queue, 500); } } UEZLCDClose(lcd); } UEZTSClose(ts, queue); } UEZQueueDelete(queue); } UEZMemFree(G_ws); }
/*---------------------------------------------------------------------------* * Routine: IQueueRemove *---------------------------------------------------------------------------* * Description: * Remove previously registered queue from the list. * Inputs: * T_Keypad_NXP_I2C_PCA9555_Workspace *p -- Workspace * T_uezQueue aNewQueue -- Queue to remove *---------------------------------------------------------------------------*/ static void IQueueRemove( T_Keypad_NXP_I2C_PCA9555_Workspace *p, T_uezQueue aQueue) { T_keypadRegistered *p_reg=p->iRegisteredQueues; T_keypadRegistered *p_prev=0; while (p_reg) { // Remove it from the list if (p_reg->iQueue == aQueue) { if (p_prev) p_prev->iNext = p_reg->iNext; else p->iRegisteredQueues = p_reg->iNext; UEZMemFree(p_reg); break; } p_prev = p_reg; p_reg = p_reg->iNext; } }
static T_uezError Generic_USBHost_Unregister( void *aWorkspace, T_uezDeviceWorkspace *aDeviceDriverWorkspace) { T_Generic_USBHost_Workspace *p = (T_Generic_USBHost_Workspace *)aWorkspace; T_usbhostRegistration *p_reg; T_usbhostRegistration *p_prev = 0; IGrabList(); // Walk the list look for a match p_reg = p->iRegistrations; while (p_reg) { // Is this the same device driver? if (p_reg->iDeviceDriver == aDeviceDriverWorkspace) break; // Not this one, go to the next p_prev = p_reg; p_reg = p_reg->iNext; } if (p_reg) { // Found a match, unhook it from the list if (p_prev) { p_prev->iNext = p_reg->iNext; } else { p->iRegistrations = p_reg->iNext; } // Free the registration memory p_reg->iNext = 0; UEZMemFree(p_reg); } IReleaseList(); return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------*/ int UEZCmdAudioDAC(void *aWorkspace, int argc, char *argv[]) { T_uezError error; TUInt32 ms; TUInt32 frequency; TUInt32 sampleRate; TUInt32 numBytes; TUInt32 numSamples; #if (FDICMD_AUDIODAC_BIT_SIZE==8) TUInt8 *p_sample; #else TUInt16 *p_sample; #endif TUInt32 i; double r; double v; if (argc == 5) { // Get the frequency frequency = FDICmdUValue(argv[1]); if ((frequency < 1) || (frequency > 100000)) { FDICmdPrintf(aWorkspace, "FAIL: Frequency must be 1 to 100000\n"); return UEZ_ERROR_INVALID_PARAMETER; } // Get the sample rate sampleRate = FDICmdUValue(argv[2]); if ((sampleRate < 1000) || (sampleRate > 100000)) { FDICmdPrintf(aWorkspace, "FAIL: Sample rate must be 1000 to 100000. Usually 22100\n"); return UEZ_ERROR_INVALID_PARAMETER; } // Get the length of time ms = FDICmdUValue(argv[3]); // Set which timer to use error = UEZDACWAVConfig(argv[4]); if (error) { FDICmdPrintf(aWorkspace, "FAIL: Timer error %d\n", error); return UEZ_ERROR_INVALID_PARAMETER; } // Calculate the needed amount of memory // Number of samples: numSamples = sampleRate * ms / 1000; #if (FDICMD_AUDIODAC_BIT_SIZE==8) // 8-bit samples. Memory needed numBytes = numSamples; #else // 16-bit samples. Memory needed numBytes = numSamples * 2; #endif // Try to allocate the needed memory p_sample = UEZMemAlloc(numBytes); if (p_sample) { // Got the memory! // Create the sample mathematically for (i=0; i<numSamples; i++) { // Normalize i into a number of seconds based on sample rate r = i; r /= sampleRate; // r now equals seconds into sample // For sin() we need 2*PI per cycle r *= 2 * M_PI; // We now have a 1 Hz signal, but we need X Hz // Calculate the frequency value r *= frequency; // Now get the sinusoidal position for that v = sin(r); #if (FDICMD_AUDIODAC_BIT_SIZE==8) // This -1.0 .. 1.0 value now needs to be a 0 to 65535 value // First make it a -127 to 127 value v *= 127; // Now add 127 to offset it and get 0 to 254 v += 127; // Store this value in memory p_sample[i] = (TUInt8)v; #else // This -1.0 .. 1.0 value now needs to be a 0 to 65535 value // First make it a -32767 to 32767 value v *= 32767; // Now add 32767 to offset it and get 0 to 65534 v += 32767; // Store this value in memory p_sample[i] = (TUInt16)v; #endif // Next! } // The sample is now created. Let's play it UEZDACWAVPlayBuffer((TUInt8 *)p_sample, numBytes); // Wait for it to end while (UEZDACWAVGetStatus()) { UEZTaskDelay(1); } // Done, free the wave and end UEZMemFree(p_sample); } else { FDICmdPrintf(aWorkspace, "FAIL: Not enough memory to create sample\n"); } } else { FDICmdSendString(aWorkspace, "FAIL: Incorrect parameters.\nAUDIODAC <frequency> <sample rate> <ms to play> <timer driver>\n"); } return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: MultiSlideshowMode *---------------------------------------------------------------------------* * Description: * Setup the slideshow, drawing the slideshow load screen. Load * images onto the screen and then go into slideshow scroll mode or * report an error. * Inputs: * const T_choice *aChoice -- Choice used to get here. *---------------------------------------------------------------------------*/ void MultiSlideshowMode(const T_choice *aChoice) { T_uezDevice lcd; // T_uezError error; // T_uezFile file; TUInt32 drive; T_uezError driveError[2]; T_uezQueue queue; T_uezDevice ts; T_uezInputEvent inputEvent; #if ENABLE_UEZ_BUTTON T_uezDevice keypadDevice; #endif G_ws = UEZMemAlloc(sizeof(T_MSMWorkspace)); if (!G_ws) return; memset(G_ws, 0, sizeof(*G_ws)); if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { #if ENABLE_UEZ_BUTTON UEZKeypadOpen("BBKeypad", &keypadDevice, &queue); #endif #if UEZ_REGISTER UEZQueueSetName(queue, "MultiSlideShow", "\0"); #endif // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE) { if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE) { G_ws->iLCD = lcd; // Is there old slideshows available? driveError[SLIDESHOW_FLASH_DRIVE] = OldSlideshowCheckAvailable(SLIDESHOW_FLASH_DRIVE); driveError[SLIDESHOW_SDCARD_DRIVE] = OldSlideshowCheckAvailable(SLIDESHOW_SDCARD_DRIVE); if (driveError[SLIDESHOW_FLASH_DRIVE] == UEZ_ERROR_NONE) { drive = SLIDESHOW_FLASH_DRIVE; } else if (driveError[SLIDESHOW_SDCARD_DRIVE] == UEZ_ERROR_NONE) { drive = SLIDESHOW_SDCARD_DRIVE; } else { drive = SLIDESHOW_DRIVE_NONE; } if (drive == SLIDESHOW_DRIVE_NONE) { // MultiSlideshow is not loaded, load the slideshow list // Determine on which drives the slideshow is located //check for INI File on both drives driveError[SLIDESHOW_FLASH_DRIVE] = MultiSlideshowCheckAvailableINI(SLIDESHOW_FLASH_DRIVE); driveError[SLIDESHOW_SDCARD_DRIVE] = MultiSlideshowCheckAvailableINI(SLIDESHOW_SDCARD_DRIVE); //if INI if(!driveError[SLIDESHOW_FLASH_DRIVE] || !driveError[SLIDESHOW_SDCARD_DRIVE]) { if ((driveError[SLIDESHOW_FLASH_DRIVE] == UEZ_ERROR_NONE) || (driveError[SLIDESHOW_SDCARD_DRIVE] == UEZ_ERROR_NOT_READY)) drive = SLIDESHOW_FLASH_DRIVE; else drive = SLIDESHOW_SDCARD_DRIVE; G_ws->iDrive = drive; // Load the directory if the drive is active G_ws->iSlideshowList.iCount = 0; if (driveError[drive] == UEZ_ERROR_NONE) driveError[drive] = IMSLoadDirectoryINI(drive); G_ws->iDriveError = driveError[drive]; } else { driveError[SLIDESHOW_FLASH_DRIVE] = MultiSlideshowCheckAvailable(SLIDESHOW_FLASH_DRIVE); driveError[SLIDESHOW_SDCARD_DRIVE] = MultiSlideshowCheckAvailable(SLIDESHOW_SDCARD_DRIVE); // Choose the flash drive if available, otherwise use SDCard if ((driveError[SLIDESHOW_FLASH_DRIVE] == UEZ_ERROR_NONE) || (driveError[SLIDESHOW_SDCARD_DRIVE] == UEZ_ERROR_NOT_READY)) drive = SLIDESHOW_FLASH_DRIVE; else drive = SLIDESHOW_SDCARD_DRIVE; G_ws->iDrive = drive; // Load the directory if the drive is active G_ws->iSlideshowList.iCount = 0; if (driveError[drive] == UEZ_ERROR_NONE) driveError[drive] = IMSLoadDirectory(drive); G_ws->iDriveError = driveError[drive]; } // Put the screen (with options) MultiSlideshowScreen(lcd); MSMSetupChoices(); MSMDraw(); // Sit here in a loop until we are done while (!G_ws->iExit) { //Wait till we get a touchscreen event if (UEZQueueReceive(queue, &inputEvent, UEZ_TIMEOUT_INFINITE)==UEZ_ERROR_NONE) { ChoicesUpdate(&G_win, G_ws->iChoices, queue, 500); } } } else { // Got an old slideshow to show T_slideshowDefinition def; def.iDrive = drive; def.iName[0] = '\0'; def.iDirectory[0] = '\0'; SingleSlideshowMode(&def); } UEZLCDClose(lcd); } UEZTSClose(ts, queue); } #if ENABLE_UEZ_BUTTON UEZKeypadClose(keypadDevice, &queue); #endif UEZQueueDelete(queue); } UEZMemFree(G_ws); }