bool cmd_if_init(void) { /* Initialize local variables. */ ndr = NULL; ieee_address = eep_read_ieee_address(); nwk_events_missed = 0; for (uint8_t i = 0; (i < NWK_EVENT_FIFO_SIZE); i++) { uint8_t *nwk_event = (uint8_t *)MEM_ALLOC_ARRAY(uint8_t, CMD_EVENT_SIZE); if (NULL == nwk_event) { goto init_failed; } else { nwk_event_fifo[i] = nwk_event; } } /* Initialize USB devic driver. */ usb_task_init(ieee_address); /* Set up the transaction descriptor for the OUT end point where commands will * be received. */ usb_trans_descriptor_t desc; desc.ep = EP_OUT; desc.done_callback = usb_transaction_done; if (USB_SUCCESS != usb_ep_open(&desc)) { goto init_failed; } cmd_if_state = CMD_IF_INITIALIZED; return true; /* Handle failed initialization. */ init_failed: for (uint8_t i = 0; (i < NWK_EVENT_FIFO_SIZE); i++) { MEM_FREE(nwk_event_fifo[i]); nwk_event_fifo[i] = (uint8_t *)NULL; } /* Close EP and turn the USB macro off. */ usb_ep_close(); usb_task_deinit(); return false; }
void Slideshow( void ) { LCD_SetScreen( 0x00 ); FIFO_data_t * fifoBuffer = MEM_ALLOC_ARRAY( Slideshow_event_t, SLIDESHOW_MAXEVENTS ); if (fifoBuffer == NULL) { POPUP_MsgBox( 10, 2, 6, "Not enough\r\nmemory!", NULL ); } else { TIMING_event_t timerEvent; FIFO_handle_t fifo; // Init FIFO. Slideshow_eventFifo = &fifo; FIFO_Init( &fifo, fifoBuffer, SLIDESHOW_MAXEVENTS ); // Init slideshow data and state. static uint8_t const CAL_PGM_DEF(* const pictures[SLIDESHOW_MAXPICS]) = { FLASHPICS_ECARS_DEMO_0, FLASHPICS_ECARS_DEMO_1, FLASHPICS_ECARS_DEMO_2, FLASHPICS_ECARS_DEMO_3, FLASHPICS_ECARS_DEMO_4, FLASHPICS_ECARS_DEMO_5, FLASHPICS_ECARS_DEMO_6, FLASHPICS_ECARS_DEMO_7, FLASHPICS_ECARS_DEMO_8, FLASHPICS_ECARS_DEMO_9 }; int8_t picIdx = 0; int8_t direction = 1; // Install joystick handler. CAL_disable_interrupt(); JOYSTICK_EventHandler_t oldHandler = JOYSTICK_GetEventHandler(); JOYSTICK_SetEventHandler( Slideshow_JoystickCallback ); CAL_enable_interrupt(); // Run main slideshow loop. bool exit = false; do { // Show current picture. PICTURE_CopyFullscreenFlashToLcd( CAL_pgm_read_puint8(&pictures[picIdx]) ); // Register timer event. TIMING_RemoveEvent( &timerEvent ); TIMING_AddCallbackEventAfter( RTC_TICKS_PER_SECOND * SLIDESHOW_DELAYSECONDS, Slideshow_TimerCallback, &timerEvent ); // Wait for event from timer or joystick. Slideshow_event_t event; while (FIFO_HasData( &fifo, Slideshow_event_t ) == false) { POWER_EnterIdleSleepMode(); } FIFO_GetData( &fifo, &event ); // Process event. switch (event) { case SLIDESHOW_EXIT : exit = true; break; case SLIDESHOW_TIMER : Slideshow_UpdateIndex( &picIdx, direction ); break; case SLIDESHOW_NEXT : direction = 1; Slideshow_UpdateIndex( &picIdx, direction ); break; case SLIDESHOW_PREV : direction = -1; Slideshow_UpdateIndex( &picIdx, direction ); break; default : break; } } while (exit == false); // Clean up. CAL_disable_interrupt(); TIMING_RemoveEvent( &timerEvent ); JOYSTICK_SetEventHandler( oldHandler ); CAL_enable_interrupt(); MEM_FREE( fifoBuffer ); } }