Ejemplo n.º 1
0
void setup() {

  // Init display
  mySerial.begin(9600); // set up serial port for 9600 baud
  delay(500); // wait for display to boot up
  


  // Setup DS1820 temp sensor

  sensors.begin();
  sensors.setResolution(Sensor1, 11);
  sensors.setResolution(Sensor2, 11);
  sensors.setWaitForConversion(false);
  sensors.requestTemperatures();
  delayInMillis = 750 / (1 << (12 - 11)); //750 for 12bit, 400 for 11bit, 220 for 10bit, 100 for 9bit
                        // calc by   delayInMillis = 750 / (1 << (12 - resolution)); 
  lastTempRequest = millis(); 


  // Set next state i FSM
  menu_FSM = M_PAGE1;
  menu_last_state = M_PAGE1;
  system_FSM = S_IDLE;
 
 
   // **************** Set up display *******************
  DisplayClear();
  MenuShowTime = millis();
 
  
  // **************** Set up RTC ***********************
  Wire.begin();
  rtc.begin();
  //TimeDate(rtc.now(),dateTimeString,1);

  //DateTime now = rtc.now();

 // write on display
  DisplayGoto(2,0);
  mySerial.print("Version 0.9B");

  
  // **************** Set up SD card *******************
  pinMode(10, OUTPUT);
  DisplayGoto(1,0);
  mySerial.write("Init SD -> "); // clear display + legends
 
  DisplayGoto(1,11);
  // see if the card is present and can be initialized:
  if (!SD.begin())
    mySerial.write("Fail");
  else
    mySerial.write("OK");
  delay(2000);
  
  // ***************** Clear display ********************
  DisplayClear();
   
  }
Ejemplo n.º 2
0
/*        LCDP::begin
**
**        Synopsis:
**				
**        Parameters:
**				uint8_t bkl	- the pin corresponding to Backlight pin
**				uint8_t rs	- the pin corresponding to RS pin
**				uint8_t rw	- the pin corresponding to RW pin
**				uint8_t enable	- the pin corresponding to Enable pin
**				uint8_t d0	- the pin corresponding to D0 pin
**				uint8_t d1	- the pin corresponding to D1 pin
**				uint8_t d2	- the pin corresponding to D2 pin
**				uint8_t d3	- the pin corresponding to D3 pin
**				uint8_t d4	- the pin corresponding to D4 pin
**				uint8_t d5	- the pin corresponding to D5 pin
**				uint8_t d6	- the pin corresponding to D6 pin
**				uint8_t d7	- the pin corresponding to D7 pin
**
**        Return Values:
**
**        Errors:
**
**
**        Description:
**				This function saves the pins corresponding to the CLP and performs the required LCDP initialization tasks.
**
**
*/
void LCDP::begin(uint8_t bkl, uint8_t rs, uint8_t rw, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
{
	m_bkl_pin = bkl;
	m_rs_pin = rs;
	m_rw_pin = rw;
	m_enable_pin = enable;
	if(d0 == 0 && d1 == 1 && d2 == 2 && d3 == 3 && d4 == 4 && d5 == 5 && d6 == 6 && d7 == 7)
	{
		m_fDirectPortJA = true;
	}
	else
	{
		m_data_pins[0] = d0;
		m_data_pins[1] = d1;
		m_data_pins[2] = d2;
		m_data_pins[3] = d3; 
		m_data_pins[4] = d4;
		m_data_pins[5] = d5;
		m_data_pins[6] = d6;
		m_data_pins[7] = d7; 		
	}
	// declare command pins as output
	pinMode(m_bkl_pin, OUTPUT);
	pinMode(m_rs_pin, OUTPUT);
	pinMode(m_rw_pin, OUTPUT);
	pinMode(m_enable_pin, OUTPUT);	
	
	// perform initialization sequence, according to datasheet

	//	wait 20 ms
	delayMicroseconds(20*1000);
	// Set function
	WriteCommand(LCDP_CMD_LcdFcnInit);
	// Wait 37 us
	delayMicroseconds(37);

	// display on, no cursor, no blinking
	SetDisplay(true);

	// Wait 37 us
	delayMicroseconds(37);
	// Display Clear
	DisplayClear();
	// Wait 1.52 ms
	delayMicroseconds(1520);
}
Ejemplo n.º 3
0
Archivo: stop.c Proyecto: temoto/k411
void KernelStop(uint32_t error, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4)
{
	if (in_stop) {
		/* Its recursive! */
		HalShutdown();
	}
	in_stop = 1;

	DisplayInit();
	DisplaySetAttr(0x4f);
	DisplayClear();

	DisplayString("An error has occured and Dux has been shutdown to prevent damage.\n\n");

	printf("STOP: %x (%x, %x, %x, %x)\n", error, arg1, arg2, arg3, arg4);
 
#ifdef DEBUG
	DisplayString("BREAK\n");
	HalBreak();
#else
	HalShutdown();
#endif
}
Ejemplo n.º 4
0
int main()
{
	uint32_t i;
	int j;
	char uart_str[DISPLAY_CHARS_W+1];
	uart_str[DISPLAY_CHARS_W] = '\0';

	BoardInit(DCO_FREQ_16MHZ, LF_SRC_VLOCLK, CLK_DCO_1, CLK_LF_8);
	I2C_Init( I2C_MODE_MASTER, I2C_SMCLK_SRC );
	//UART_Init();
	__enable_interrupt();
	DisplayInit();
	DisplaySetMirror(1,1);
	DisplaySetVop(127);
	DisplaySetInversion(0);
	DisplayClear();

	const char* lines[] = {
			"Line 1\n",
			"Line 2\n",
			"Line 3\n",
			"4\n","5\n","6\n","7\n","8\n"};
	DisplayPut(img, sizeof img);
	DisplayPrint(lines[0]);
	DumbDelay(100);
	DisplaySetPos(DISPLAY_W_DOTS - DISPLAY_FONT_W * (strlen(lines[1])-1), DISPLAY_CHARS_H-1);
	DisplayPrint(lines[1]);
	j=0;
	while(1) {
		DumbDelay(1000);
		BoardLedToggle();
		//UART_Read(uart_str, DISPLAY_CHARS_W);
		//DisplayPrint(uart_str);
		//DisplayPrint("\n");
	}
}
Ejemplo n.º 5
0
void loop() {
	
  File dataFile;
  //String dataString;
  //char dataToSD[40];
  //String timeString;
  char tempstring[10]; // create string arrays
  //float temp;
  static int WaitingForTemp = 0;
  //int readCount;
  DateTime now; // = rtc.now();
  static int nowriting = 0;
  
 delay(1000);
 
  switch(system_FSM) {
    case S_IDLE:
      //Read time from RTC
      now = rtc.now();
      
      if(now.minute() % 11 == 0)
        nowriting = 0;
      
      //Trigger state change
      if(WaitingForTemp == 1){
        if (millis() - lastTempRequest >= delayInMillis) // waited long enough??
		  system_FSM = S_READ_SENS;
	    }
      if(WaitingForTemp == 0) {
		system_FSM = S_TRIG_TEMP;
		if(now.minute() % 10 == 0 || nowriting == 0)
		  system_FSM = S_WRITE_SD;
		  nowriting = 1;
	    }
    break;
    case S_TRIG_TEMP:
      // Trig async reading of DS1820 temp sensor
      sensors.requestTemperatures(); 
      
      // remember time of trigger
      lastTempRequest = millis();
      WaitingForTemp = 1;
      system_FSM = S_IDLE; 
    break;
    case S_READ_SENS:
      //read value of sensors
      SensorData.sensor1 = sensors.getTempC(Sensor1);
      SensorData.sensor2 = sensors.getTempC(Sensor2);
      //SensorData.sensor1 = sensors.getTempC(Sensor1);
      //SensorData.sensor1 = sensors.getTempC(Sensor1);
      //SensorData.sensor1 = sensors.getTempC(Sensor1);
      WaitingForTemp = 0;

      system_FSM = S_IDLE;
/*
      if(readCount == 0)
        system_FSM = S_WRITE_SD;
        else
          system_FSM = S_IDLE;
      readCount++;
      */
    break;
    case S_WRITE_SD:
      // Read time and date from RTC
      TimeDate(rtc.now(),dateTimeString,1);

      // Open datafile
      dataFile = SD.open("templog.txt", FILE_WRITE);
      
      // Write values to SD card
      if (dataFile) {
        dataFile.print(dateTimeString);
        dataFile.print(";");
        dataFile.print(SensorData.sensor1);
        dataFile.print(";");
        dataFile.println(SensorData.sensor2);
        dataFile.close();
        }  
        
      // state change to IDLE
      system_FSM = S_IDLE;
    break;               
    default:
      system_FSM = S_IDLE;
  }
 
  switch(menu_FSM) {
    case M_PAGE1:
      if(menu_FSM !=menu_last_state) {
        DisplayClear();
        mySerial.write("Time"); // clear display + legends
        MenuShowTime = millis();
      }  
      now = rtc.now();
      DisplayGoto(1,0);
      mySerial.write("Time"); // clear display + legends

      DisplayGoto(1,8);
      TimeDate(now,dateTimeString,2);
      mySerial.print(dateTimeString);

      DisplayGoto(2,6);
      TimeDate(now,dateTimeString,3);
      mySerial.print(dateTimeString);

      //reserved for showing time and SD card status
      menu_last_state = M_PAGE1;

      if(millis() - MenuShowTime >= MenuDelayInMillis)
        menu_FSM = M_PAGE2;
      
      
      
    break;
    case M_PAGE2:
      if(menu_FSM !=menu_last_state) {
        DisplayClear();
        mySerial.write("Sens 1:        C"); 
        mySerial.write("Sens 2:        C"); 
        DisplayGoto(1,14);
        mySerial.write(223); 
        DisplayGoto(2,14);
        mySerial.write(223); 
        MenuShowTime = millis();
      }  

      DisplayGoto(1,10);
      mySerial.write(dtostrf(SensorData.sensor1,4,1,tempstring)); // write out the RPM value

      DisplayGoto(2,10);
      mySerial.write(dtostrf(SensorData.sensor2,4,1,tempstring)); // write out the TEMP value
      //mySerial.write(dtostrf(system_FSM,4,1,tempstring)); DEBUG
      
      menu_last_state = M_PAGE2;

      if(millis() - MenuShowTime >= MenuDelayInMillis)
        menu_FSM = M_PAGE3;
      
    break;
    case M_PAGE3:
      if(menu_FSM !=menu_last_state) {
		DisplayClear();
        mySerial.write("Sens 3:  N/A   C"); // clear display + legends
        mySerial.write("Sens 4:  N/A   C"); 
        DisplayGoto(1,14);
        mySerial.write(223); 
        DisplayGoto(2,14);
        mySerial.write(223);
        MenuShowTime = millis();
      }  

      DisplayGoto(1,7);
      
//    mySerial.write(dtostrf(SensorData.sensor1,4,1,tempstring)); // write out the RPM value

      DisplayGoto(2,7);

      //mySerial.write(dtostrf(MenuShowTime,4,1,tempstring)); // write out the TEMP value
      menu_last_state = M_PAGE3;

      if(millis() - MenuShowTime >= MenuDelayInMillis)
        menu_FSM = M_PAGE1;
      
    break;
    case M_PAGE4:
    break;
    default:
      menu_FSM = M_PAGE1;
  }
 }
/////////////////////////////////////////////////////////////////////////////////////////
//
//>  Name:          int _reentrant MotionVideoMenu(int a, int b, int *pPtr)
//
//   Type:          Function (user menu)
//
//   Description:   This function is the music menu
//
//   Inputs:        none used.
//
//   Outputs:       value of which menu to return to
//
//   Notes:         This function handles the music menu.  It loops until a reason
//                  to exit is reached (PH_STOP held long enough will return MENU_EXIT, and
//                  PR_MENU will return MENU_MAIN)
//
//                  The basic loop is...
//
//                  while (not done)
//                  {
//                      Update display if necessary
//                      Wait for event
//                      Pass event to player state handler
//                      handle event locally
//                  }
//
//                  Sometimes an event may be handled entirely in the player state handler,
//                  sometimes entirely locally, sometimes in both places.
//<
//////////////////////////////////////////////////////////////////////////////////////////
int _reentrant MotionVideoMenu(int a, int b, int *pPtr)
{
    INT iVolumeHoldCount = 0;
    INT iSkipHoldCount = 0;
	union DisplayHints DisplayHint;
	INT  iEvent;
	BOOL bDone = FALSE;
    BOOL bSendToPlayerStateMachine = FALSE;
    int RetValue=NOERROR;
    union EventTypes *pMsg;
	int  iNewMenu = MENU_MAIN;
	BOOL bStartFlag;
	BOOL bPrMenu = FALSE;

#ifdef USE_PLAYLIST3
#ifdef MMC
	BOOL bMediaChanged;
#endif
    BOOL            bSendToPlayerStateMachinePlaylist3 = FALSE;
	_packed char    szFilename[MAX_FILENAME_LENGTH];
	SONGFILEINFO    SongInfo;
#endif
#ifdef USE_PLAYLIST5
	WORD OriginEvent;
    BOOL bLastDisplaySongCnt = FALSE;
#endif

    // if battery is lower than a pre-defined voltage threshold
    if(SysLowResolutionAdcReadBin(BATT) <= MvToLradcResult(SMV_BATTERY_THRESHOLD))
    {   // if decoder is not stop, stop it.
        if(!(g_wDecoderSR&DECODER_STOPPED))
    	{   SysCallFunction(RSRC_PLAY_STATE_MACHINE_CODE_BANK,PlayerLib_SetState,DECODER_STATE_STOP,TRUE,0);
#ifdef USE_PLAYLIST3
	        SysWaitOnEvent(0,0,0);
#endif
            g_iPlayerState = DECODER_STOPPED;
    	    // if it is already smv decoder, change back to the music decoder
    	    if(DecoderResourcePtr == RSRC_DEC_SMVADPCM_MOD_CODE)
    		{   SysSetDecoderResource(RSRC_DECMOD_CODE);
    	        DecoderForceInit();
    		    SysPostMessage(2, DECODER_RESET);
    		}
    	}
    	// close smv file
        SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,CloseSMVFile,0,0,0);
	    // display low battery message
	    DisplayClear();
	    DisplayLowBattery();
	    SysWaitOnEvent(0,0,2000);  // let user see it for 2 seconds
	    return(iNewMenu);   // return to mainmenu
	}
	SysSpeedIncrease(SPEED_PEAK, SPEED_CLIENT_JPEG_DEC);

	// this is required to get the message into the playerstatemachine
	// casted to avoid pointer mismatch warnings
	pPtr = (int *) &gEventInfo;
    pMsg = (union EventTypes * )pPtr;

	a;b;//here to prevent parameter not used messages.

#ifdef USE_PLAYLIST3
	SongInfo.m_wBufferLength = MAX_FILENAME_LENGTH;
	SongInfo.m_pFilename = (_packed BYTE*)szFilename;
#endif
	//set our current menu
	g_iCurrentMenu = MENU_MVIDEO;

    SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK, MotionVideoMenuInitState, 0, 0, (int *)&DisplayHint);

#ifndef USE_PLAYLIST3
	if(Playlist_GetPlaySet() != PLAYSET_MVIDEO)
	{   //sdk2.1 (i.e. if currently not in music mode.)
		//initialize the music player state machine
        SysCallFunction(RSRC_PLAY_STATE_MACHINE_CODE_BANK,PlayerLib_SetState,DECODER_STATE_STOP,TRUE,0);
        g_iPlayerState = DECODER_STOPPED;
        SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,CloseSMVFile,0,0,0);
		ChangePlaySet(PLAYSET_MVIDEO);
	}
#else
    g_wCurrentDirDevId_backup   = g_wCurrentDirDevId;
    g_wTotalSongCount_backup    = g_wTotalSongCount;
    g_wCurrentSongNumber_backup = g_wCurrentSongNumber;
    g_current_size_backup       = g_current_size;
    g_current_index_backup      = g_current_index;

    g_wCurrentDirDevId = 0;
    SysCallFunction(RSRC_JPEG_FILEUTIL_EXTRA_MENU_CODE_BANK,JpegFile_SetPlaySet,PLAYSET_MVIDEO,TRUE,0);

    g_current_size = g_wTotalSongCount;
    if(g_wDecoderSR & DECODER_STOPPED)
    {   g_wCurrentSongNumber = 0;
    }else
    {   g_wCurrentSongNumber = g_wCurrentSongNumber_return;
    }
    g_current_index = g_wCurrentSongNumber;
    g_wCurrentSongNumber_return = 0;
    JpegFile_GetCurrentSongFileInfo(0,0,(INT*)&SongInfo);
    DisplayHint.bits.SongTitle = TRUE;
#endif

	SysCallFunction(RSRC_PLAY_STATE_MACHINE_CODE_BANK, InitPlayerStateMachine,0,0,0);

	//***** Moved from mainmenu.c
	SysPostMessage(3,SOFT_TIMER_KILL_TIMER,TIMER_ANIMATE);
	SysWaitOnEvent(0,0,0);// Let system process SOFT_TIMER_KILL_TIMER message

	//Lets initially display all & clear the screen
    DisplayHint.I = (1<<DISPLAY_CLEAR_DISPLAY_BITPOS);
//
#ifdef USE_PLAYLIST2
		SysCallFunction(RSRC_DISPLAY_CODE_BANK,RefreshDisplay,DisplayHint.I,1,0);
#endif
//end

#ifdef USE_PLAYLIST3
    if(g_wDecoderSR & DECODER_PLAYING)
    {   DisplayHint.I &= ~(1<<DISPLAY_CLEAR_DISPLAY_BITPOS);
        SMVBlackBackground();
    }
#endif
    if (stc_iHandle == -1 && (g_iPlayerState == DECODER_PLAYING))  {
#ifdef BACKLIGHT
        SysPostMessage(3,SOFT_TIMER_KILL_TIMER,TIMER_BACKLIGHT);
#endif
        SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,OpenSMVFile,0,0,0);
        SyncSMVFrame();
    }
    else
	    DisplayHint.I |= MVIDEO_MENU_DISPLAY_ALL;

    bStartFlag = TRUE;
#ifdef USE_PLAYLIST3
#ifdef MMC
    bMediaChanged = FALSE;
#endif
#endif
	while(!bDone)
	{
		//keep only display hints we're interested in displaying in this menu.
		DisplayHint.I &= (MVIDEO_MENU_DISPLAY_ALL|(1<<DISPLAY_CLEAR_DISPLAY_BITPOS));
#ifdef USE_PLAYLIST5
        if (g_iPlayerState == DECODER_STOPPED)
        {
    	    if(!g_PL5_Playback.foundall)
    	    {
    		    DisplayHint.I |= 1<<DISPLAY_CURRENTTRACK_BITPOS;
        		DisplayHint.I |= 1<<DISPLAY_SONGARTISTALBUM_BITPOS;
		g_bLastDisplaySongCnt = TRUE;
    	    }
	else if(g_bLastDisplaySongCnt == TRUE)
    	    {
    		    DisplayHint.I |= 1<<DISPLAY_CURRENTTRACK_BITPOS;
        		DisplayHint.I |= 1<<DISPLAY_SONGARTISTALBUM_BITPOS;
		g_bLastDisplaySongCnt = FALSE;
    	    }
        }
#endif
		if (g_wDecoderSR & DECODER_PLAYING)
		{    //if playback is in progress, get back from system to render video frquently
		    iEvent = SysWaitOnEvent(EVENT_BUTTON|EVENT_MESSAGE, &gEventInfo.msg, 1);
		    //iEvent = SysWaitOnEvent(EVENT_BUTTON|EVENT_MESSAGE, &gEventInfo.msg, 0);
        }else
        {   iEvent = SysWaitOnEvent(EVENT_BUTTON|EVENT_MESSAGE, &gEventInfo.msg, DisplayHint.I? 1 : -1);
        }

        //Lets assume we do want to send all these to the player state machine
        bSendToPlayerStateMachine = TRUE;
#ifdef USE_PLAYLIST3
        bSendToPlayerStateMachinePlaylist3 = FALSE;
#endif
		switch(iEvent)
		{
    		case EVENT_TIMER:
				//update all UI before rendering video
				if(DisplayHint.I)   {
#ifdef USE_PLAYLIST3
                    if ((bStartFlag == TRUE) && (g_wDecoderSR & DECODER_PAUSED))
                    {   SMVBlackBackground();
                    }else
                    {   SysCallFunction(RSRC_DISPLAY_CODE_BANK,RefreshDisplay,DisplayHint.I,1,0);
    					SysWaitOnEvent(0,0,0);
                    }
#else
					SysCallFunction(RSRC_DISPLAY_CODE_BANK,RefreshDisplay,DisplayHint.I,1,0);
					SysWaitOnEvent(0,0,0);
#endif
            		if ((bStartFlag == TRUE) && (g_wDecoderSR & DECODER_PAUSED))
            		{   SyncSMVFrame();
                        DisplaySMVOneFrame();
                        bStartFlag = FALSE;
                    }
				}
				DisplayHint.I = 0;//clear out the bits

				//render video
    		    if (stc_iHandle != -1 && (g_wDecoderSR & DECODER_PLAYING))
   		            DisplaySMV();
				bSendToPlayerStateMachine = FALSE;//don't need to send this to the player state machine
    			break;
            case EVENT_MESSAGE:
                switch(gEventInfo.Message.wMsgCommand)
                {
					case MENU_SONG_TIME_CHNG:   // No need to update song time
                        bSendToPlayerStateMachine = FALSE;
                        break;
                    case MENU_MSG_MEDIA_CHANGED:
                        iNewMenu = MENU_MAIN;
                    	bDone = TRUE;
#ifdef USE_PLAYLIST3
#ifdef MMC
                    	bMediaChanged = TRUE;
#endif
#endif
                    	break;
#ifdef USE_PLAYLIST3
                    case PARSER_NEXT_SONG:
                    case PARSER_PREV_SONG:
                        bSendToPlayerStateMachinePlaylist3 = TRUE;
                        break;
#endif
                    case MENU_DECODER_STATE_CHNG:
#ifdef MMC
                        // Decoder will be already stopped if read MMC file is failed and the 0x800000 will be set by decoder.
                        // 0x800000 is the #FileReadError bit for x:DecoderSR, this bit is set after fileread error.
                    	if((g_wDecoderSR & 0x800000) == 0x800000)
                        {   g_iPlayerState = DECODER_STOPPED;
                            DecoderForceInit();
                            SysPostMessage(2,DECODER_RESET);
#ifdef USE_PLAYLIST5
                            SysPostMessage(2, PL5_PL_MSG_RESUME);
#endif
                            SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,CloseSMVFile,0,0,0);
                        }else
                        {
#endif
                    	   //open a new smv file
                        	if( (g_wDecoderCSR & DECODER_FILE_IS_OPEN) && (stc_iHandle == -1))
	       					{	//a new smv file is being playback
#ifdef USE_PLAYLIST5
                                SysPostMessage(2, PL5_PL_MSG_PAUSE);
#endif
                        		SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,OpenSMVFile,0,0,0);
                         		SyncSMVFrame();

#ifdef USE_PLAYLIST3
                    		    //If use black background, don't clear display by following line.
                                //DisplayHint.I = (1<<DISPLAY_CLEAR_DISPLAY_BITPOS);
#else
                                DisplayHint.I = (1<<DISPLAY_CLEAR_DISPLAY_BITPOS);
#endif
                            }
                        	else if( !(g_wDecoderCSR & DECODER_FILE_IS_OPEN) && (stc_iHandle != -1 ) )
	       					{	//the current smv file is finished
#ifdef USE_PLAYLIST5
	                            SysPostMessage(2, PL5_PL_MSG_RESUME);
#endif
                        		SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,CloseSMVFile,0,0,0);
                            }
#ifdef MMC
                        }

#endif

                        if(g_iPlayerState == DECODER_STOPPED)
                        {	DisplayHint.I = MVIDEO_MENU_DISPLAY_ALL|(1<<DISPLAY_CLEAR_DISPLAY_BITPOS);
                        }
                        UpdateAutoShutdownTimer();
#ifdef BACKLIGHT
            			UpdateBacklightOffTimer();
#endif
                        bSendToPlayerStateMachine = FALSE;

                        break;
                    default:
                        break;
                }
                break;
			case EVENT_BUTTON:
    			// button pressed, so restart timer if enabled
    			UpdateAutoShutdownTimer();
#ifdef BACKLIGHT
    			UpdateBacklightOffTimer();
#endif

    			//remember the last button event (mostly for coming out of FFWD and RWND)
    			switch(g_wLastButton = gEventInfo.Button.wButtonEvent)
    			{
                    case PH_VOL_UP:
                    case PH_VOL_DOWN:
                        // Handle volume change locally to avoid switch codebank
                        iVolumeHoldCount++;
                        if (iVolumeHoldCount>10)
                        	iVolumeHoldCount = 10;
                        g_iUserVolume += (gEventInfo.Button.wButtonEvent == PH_VOL_UP? iVolumeHoldCount : - iVolumeHoldCount);
                        SysUpdateVolume();
                        bSendToPlayerStateMachine = FALSE;
                        break;

                    case PR_VOL_UP:
                    case PR_VOL_DOWN:
                        iVolumeHoldCount = 0;
                        bSendToPlayerStateMachine = FALSE;
                        break;

                    case PH_RW:
                    case PH_FF:
                        if(g_iPlayerState == DECODER_STOPPED)
                            bSendToPlayerStateMachine = FALSE;
                        else
						{   // Update display during fast forward/rewind
							if (g_iSeeking != SEEK_NONE)
							{
								iSkipHoldCount++;
								if (iSkipHoldCount == 3)
								{
									iSkipHoldCount = 0;
										SyncSMVFrame();
                  						DisplaySMVOneFrame();
								}
                            }
                        }
                        break;

                    case PR_RW:
                    case PR_FF:
                        if (g_iSeeking != SEEK_NONE)
						{
                            iSkipHoldCount = 0;
                            SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,CloseSMVFile,0,0,0);
                        }
#ifdef USE_PLAYLIST5                        
                        SysPostMessage(2, PL5_PL_MSG_RESUME);
#endif						
#ifdef USE_PLAYLIST3
                        bSendToPlayerStateMachinePlaylist3 = TRUE;
#endif
                        break;

                    case PR_PLAY:
                        if (g_wDecoderSR & DECODER_PAUSED)
						{
							//resume from pause mode, synchronize the audio and video
                            DisplayHint.I |= SysCallFunction(RSRC_PLAY_STATE_MACHINE_CODE_BANK,HandlePlayerStateMachine,iEvent,0,pPtr);
                            SysWaitOnEvent(0,0,0);
                            SyncSMVFrame();
                            bSendToPlayerStateMachine = FALSE;
                        }
#ifdef USE_PLAYLIST3
                        bSendToPlayerStateMachinePlaylist3 = TRUE;
#endif
                        break;

                    case PR_STOP:
                        DisplayHint.I |= MVIDEO_MENU_DISPLAY_ALL|(1<<DISPLAY_CLEAR_DISPLAY_BITPOS);
                        break;

                    case PR_MENU:
                        iNewMenu = MENU_MAIN;
						bPrMenu = TRUE;
                    	bDone = TRUE;
#ifdef USE_PLAYLIST5						
						g_MenuFlags.MENU_FLAG_RETURN_TO_MUSIC = FALSE;
#endif
                        break;
#ifdef USE_PLAYLIST5
				 case PH_MENU:
                    // Allow user to escape to music mode
                    bDone= TRUE;
                    // Set flag as a command for PR_MENU which always follows a PH_MENU sequence.
                    g_MenuFlags.MENU_FLAG_ESCAPE_TO_MUSIC = TRUE;
                    break;
#endif                
        			case PH_STOP:
        				//if the STOP button is held down, lets call the shutdown menu
        				SysCallFunction(RSRC_MAIN_MENU_CODE_BANK,ShutdownMenu,USERSHUTDOWN,0,0);
        				// if returns update display  -- if doesn't return, powered down
        				if (g_wDecoderSR & DECODER_PLAYING)
						{
                            SyncSMVFrame();
        				}
        				else
        				    DisplayHint.I |= (MVIDEO_MENU_DISPLAY_ALL|(1<<DISPLAY_CLEAR_DISPLAY_BITPOS));
                        bSendToPlayerStateMachine = FALSE;//don't need to send this to the player state machine
        				break;

                    case PR_AB:
                        bSendToPlayerStateMachine = FALSE;
                        break;

        			default:
        				break;
    			}
			    break;

			default:
			    break;
		}
#ifdef USE_PLAYLIST3
        if(bSendToPlayerStateMachinePlaylist3)
        {   HandlePlayerStateMachinePlaylist3(iEvent,0,pPtr,(int*)&SongInfo,(int*)&DisplayHint,(int*)&bSendToPlayerStateMachine);
        }
#endif
#ifdef USE_PLAYLIST5
		if((bPrMenu) && (g_wDecoderSR & DECODER_PLAYING))
		{
			// If press menu and smv playing,stop the smv first before exit to main menu.
			OriginEvent = pMsg->Button.wButtonEvent;
			pMsg->Button.wButtonEvent = PR_STOP;
            SysCallFunction(RSRC_PLAY_STATE_MACHINE_CODE_BANK,HandlePlayerStateMachine,iEvent,0,pPtr);
			pMsg->Button.wButtonEvent = OriginEvent;
		}
        else 
#endif
        if(bSendToPlayerStateMachine)
        {//only send events to the player state machine if necessary (to avoid code bank swapping)
            SysCallFunction(RSRC_PLAY_STATE_MACHINE_CODE_BANK,HandlePlayerStateMachine,iEvent,0,pPtr);
        }
	}

    SysCallFunction(RSRC_MOTION_VIDEO_MENU_INITSTATE_CODE_BANK,CloseSMVFile,0,0,0);
	SysSpeedClockFree(SPEED_CLIENT_JPEG_DEC);
#ifdef USE_PLAYLIST3
    g_wCurrentSongNumber_return = g_wCurrentSongNumber;
#ifdef MMC
    if(bMediaChanged == FALSE)
    {
#endif
        g_wCurrentDirDevId          = g_wCurrentDirDevId_backup;
        g_wTotalSongCount           = g_wTotalSongCount_backup;
        g_wCurrentSongNumber        = g_wCurrentSongNumber_backup;
        g_current_size              = g_current_size_backup;
        g_current_index             = g_current_index_backup;
#ifdef MMC
    }
#endif
	SysCallFunction(RSRC_PLAY_STATE_MACHINE_CODE_BANK,ML_browsing_app_init,0,0,0);
	if( g_wDecoderSR & DECODER_STOPPED)
    {   g_iPlayerState = DECODER_STOPPED;
	    SysSetDecoderResource(RSRC_DECMOD_CODE); // Force to use other audio decoder if smv stopped.
		DecoderForceInit();
		SysPostMessage(2, DECODER_RESET);
	}
#endif
	//don't exit player state machine, cause we want to keep playing when in main menu.
	//sdk2.1
	return iNewMenu;
}
Ejemplo n.º 7
0
/**************************************************************************//**
 * @brief  Initialize the LS013B7DH03 display driver
 *
 * @return  EMSTATUS code of the operation.
 *****************************************************************************/
EMSTATUS DISPLAY_Ls013b7dh03Init(void)
{
  DISPLAY_Device_t      display;
  EMSTATUS              status;

  /* Initialize the Platform Abstraction Layer (PAL) interface.  */
  PAL_TimerInit();
  PAL_SpiInit();
  PAL_GpioInit();

  /* Setup GPIOs */
  PAL_GpioPinModeSet(LCD_PORT_SCLK,    LCD_PIN_SCLK,    palGpioModePushPull,0);
  PAL_GpioPinModeSet(LCD_PORT_SI,      LCD_PIN_SI,      palGpioModePushPull,0);
  PAL_GpioPinModeSet(LCD_PORT_SCS,     LCD_PIN_SCS,     palGpioModePushPull,0);
#if defined( LCD_PORT_DISP_SEL  )
  PAL_GpioPinModeSet(LCD_PORT_DISP_SEL,LCD_PIN_DISP_SEL,palGpioModePushPull,0);
#endif
  
#if defined( LCD_PORT_DISP_PWR )
  PAL_GpioPinModeSet(LCD_PORT_DISP_PWR,LCD_PIN_DISP_PWR,palGpioModePushPull,0);
#endif

#if defined( LCD_PORT_EXTMODE )
  PAL_GpioPinModeSet(LCD_PORT_EXTMODE, LCD_PIN_EXTMODE, palGpioModePushPull,0);
#endif
  PAL_GpioPinModeSet(LCD_PORT_EXTCOMIN,LCD_PIN_EXTCOMIN,palGpioModePushPull,0);

#ifdef PAL_TIMER_REPEAT_FUNCTION
  /* If the platform specifies to use a timer repeat function we should
     register the DisplayPolarityInverse to be called every second in
     order to toggle the EXTCOMIN pin at 1Hz.
  */
  status =
    PAL_TimerRepeat((void(*)(void*)) DisplayPolarityInverse, 0,
                    LS013B7DH03_POLARITY_INVERSION_FREQUENCY);
#elif defined POLARITY_INVERSION_EXTCOMIN_PAL_AUTO_TOGGLE
  /* Setup system (via PAL) to toggle the EXTCOMIN pin every second. */
  status = PAL_GpioPinAutoToggle(LCD_PORT_EXTCOMIN, LCD_PIN_EXTCOMIN,
                                 LS013B7DH03_POLARITY_INVERSION_FREQUENCY);
#else
  /* System does not support toggling the EXTCOMIN pin. Return error. */
  return DISPLAY_EMSTATUS_NOT_SUPPORTED;
#endif
  if (PAL_EMSTATUS_OK != status)
  {
    return status;
  }

  /* Setup and register the LS013B7DH03 as a DISPLAY device now. */
  display.name                  = SHARP_MEMLCD_DEVICE_NAME;
  display.colourMode            = DISPLAY_COLOUR_MODE_MONOCHROME_INVERSE;
  display.addressMode           = DISPLAY_ADDRESSING_BY_ROWS_ONLY;
  display.geometry.width        = LS013B7DH03_WIDTH;
  display.geometry.height       = LS013B7DH03_HEIGHT;
  /* stride = pixels + ctrl bytes */
  display.geometry.stride       =
    display.geometry.width + LS013B7DH03_CONTROL_BYTES*8;

  display.pDisplayPowerOn       = DisplayEnable;
#ifdef PIXEL_MATRIX_ALLOC_SUPPORT
  display.pPixelMatrixAllocate  = PixelMatrixAllocate;
  display.pPixelMatrixFree      = PixelMatrixFree;
#else
  display.pPixelMatrixAllocate  = NULL;
  display.pPixelMatrixFree      = NULL;
#endif
  display.pPixelMatrixDraw      = PixelMatrixDraw;
  display.pPixelMatrixClear     = PixelMatrixClear;
  display.pDriverRefresh        = DriverRefresh;

  status = DISPLAY_DeviceRegister (&display);

  if (DISPLAY_EMSTATUS_OK == status)
  {
    /* Turn on display. */
    DisplayEnable(&display, true);

    /* Clear display */
    DisplayClear();
  }

  return status;
}
Ejemplo n.º 8
0
// Attached to USB
void RunAttached(void)
{
	// Do this first to give the card time to start up
	SD_ENABLE(); 		// Turn on SD card

    // Enable peripherals
	RtcInterruptOn(0);  // Keeps time upto date

	LED_SET(LED_WHITE);
    CLOCK_PLL();		// PLL clock

    // Initialize sensors
    // Check if we have an accelerometer
    AccelVerifyDeviceId();
    // Check if we have a gyro
	#ifdef USE_GYRO 
    GyroVerifyDeviceId();
	#endif
	#ifdef HAS_PROX
	// Check for prox
	ProxVerifyDeviceId();
	ProxStartup();
	#endif

    // Initialize sensors
    AccelStartup(ACCEL_RANGE_4G|ACCEL_RATE_100);
	#ifdef USE_GYRO 
	GyroStartup();
	#endif
	AdcInit();

	#ifndef NO_DISPLAY
	DisplayClear();
	Display_print_xy(" <= USB =>",0,2,2);
	#endif
	
	status.diskMounted = (status.lockCode == 0x0000) ? 1 : 0;
	status.stream = 0;

//   MDD_MediaInitialize();  // KL FIX: The SD card is re-inited in the usb framework which causes a lockup in some cases

	// Power up module if off
	PMD4bits.USB1MD = 0;

    USBInitializeSystem(); 	// Initializes buffer, USB module SFRs and firmware
    #ifdef USB_INTERRUPT
    USBDeviceAttach();
    #endif

    while(USB_BUS_SENSE && restart != 1)
    {
        // Check bus status and service USB interrupts.
        #ifndef USB_INTERRUPT
        USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
        #endif
        USBProcessIO();

        if ((USBGetDeviceState() >= CONFIGURED_STATE) && (USBIsDeviceSuspended() == FALSE))
        {
            const char *line = _user_gets();
            status.attached = 1;
            if (line != NULL)
            {
                status.stream = 0;  // Disable streaming
                SettingsCommand(line, SETTINGS_USB);
            }
        }
        else
        {
            status.attached = -1;
        }
	
        TimedTasks();	


        // Stream accelerometer data
        if (status.stream)
		{
			#define STREAM_RATE 10
			#define STREAM_INTERVAL (0x10000UL / STREAM_RATE)
			static unsigned long lastSampleTicks = 0;
            unsigned long now = RtcTicks();
            if (lastSampleTicks == 0) { lastSampleTicks = now; }
            if (now - lastSampleTicks > STREAM_INTERVAL)
            {
                accel_t accelSample;
				#ifdef USE_GYRO 
				gyro_t gyroSample;
				#endif

				extern unsigned char scratchBuffer[];
				char * ptr = (char *)scratchBuffer;
				unsigned short len;

                lastSampleTicks += STREAM_INTERVAL;
                if (now - lastSampleTicks > 2 * STREAM_INTERVAL) { lastSampleTicks = now; } // not keeping up with sample rate
                
#ifdef HAS_PROX
				// Sample sensors
				if(ProxSampleReady())
				{
					ProxReadSample();
					ProxStartSample();
				}
#endif
                AccelSingleSample(&accelSample);
				#ifdef USE_GYRO
				GyroSingleSample(&gyroSample);
				#endif
			
				// Write ascii to scratch buffer
				ptr = (char *)scratchBuffer;
				ptr += sprintf(ptr, "\f$ACCEL=%d,%d,%d\r\n", accelSample.x, accelSample.y, accelSample.z);
				#ifdef USE_GYRO 
				ptr += sprintf(ptr, "$GYRO=%d,%d,%d\r\n", gyroSample.x, gyroSample.y, gyroSample.z);
				#endif
				#ifdef HAS_PROX
				ptr += sprintf(ptr, "$PROX=%d\r\n", prox.proximity);
				ptr += sprintf(ptr, "$LIGHT=%d\r\n", prox.light);
				#endif
				len = (unsigned short)((void*)ptr - (void*)scratchBuffer);

				// Stream over USB
				if ((status.stream) && status.attached == 1) { usb_write(scratchBuffer, len); }
            }
        }
    }
	#if defined(USB_INTERRUPT)
    USBDeviceDetach();
	#endif
    status.attached = -1;

    return;
}