extern u32 sys_time; // main system time, incremented every 100 mS
static u08 playing = 1; // indicates if player is playing
static u08 display = 0; // indicates if it's okay to display information
static u32 t_announce = 0; // timer for announce message
static u32 t_area = 0; // timer for main area update
static u32 t_index = 0; // timer for index area update
static u32 t_start = 0; // timer for sending startplaying message
static u32 t_time = 0; // timer for updating time in main area
event_e get_bmw_event(void)
{
if (t_announce == 0) // first time here ?
{
t_announce = sys_time + 50; вот тут ругается // set first announce in 5 seconds
}
// и вообше постояно ругаетя на sys_time
while ( uart_haschar() ) // loop while there is data to parse
{
ch = uart_getchar(); // get character to global var
//
// Does the radio poll us ?
//
// NOTE! this never happens on my E46
//
if ( lexer(&cdpoll) )
{
SendCDMsg(cd_pollresp_msg); // send poll response
continue; // parse more messages
}
//
// Request to start playing
//
if ( lexer(&play) )
{
SendCDMsg(cd_statusplaying_msg); // send status message
t_start = sys_time + 1; // send start playing msg in 100 mS
playing = 1; // set playing mode
display = 1; // allow display updates
t_index = sys_time + 5; // update index area in 500 mS
return EV_PLAY;
}
//
// Request to activate after mode change or system power up
//
if ( lexer(&play2) )
{
t_start = sys_time + 3; // send startplaying in 300 mS
playing = 1; // set playing mode
display = 1; // allow display updates
return EV_PLAY; // start player
}
//
// When stop, send the current status to the radio
// The stop command is initiated by changing the mode,
// by radio or ignition off.
//
if ( lexer(&stop) )
{
SendCDMsg(cd_statusnotplaying_msg); // send stopplaying message
playing = 0; // clear playing flag
return EV_STOP; // stop player, disc will spin down after 10 seconds
}
//
// When the radio request the current CD and track,
// Always respond CD 1, Track 1. That will help us
// to recognize writes to MID,NAV or OBC screen commands later.
//
if ( lexer(&getcurtk) )
{
if (playing)
{
SendCDMsg(cd_startplaying01_msg); // send startplaying message
}
else
{
SendCDMsg(cd_statusnotplaying_msg); // send not playing status message
}
continue; // parse more messages
}
//
// Check if the "CDC" string were sent to the nav screen
// That means the CD player is active and can display
//
if ( lexer(&stringcdno) )
{
display = 1; // allow display updates
t_area = sys_time + 2; // update main area in 200 mS
continue; // parse more messages
}
// Check if the CD No and track number were sent to the nav screen
if ( lexer(&refresh) )
{
t_index = sys_time + 5; // update index area in 500 mS
continue; // parse more messages
}
//
// Check if a MENU display was requested by the radio
// If yes, then disable display
//
if ( lexer(&navmenuset) || lexer(&navmenutimed) )
{
display = 0; // stop display updates
continue; // parse more messages
}
//
// Commands to be processed if the CD Mode is active only
//
if (playing)
{
//
// Next and previous track including steering wheel
//
if ( lexer(&prev) || lexer(&prevstw) )
{
SendCDMsg(cd_endplaying_msg); // send endplaying message
return EV_PREV; // start previous song
}
if ( lexer(&next) || lexer(&nextstw) )
{
SendCDMsg(cd_endplaying_msg); // send endplaying message
return EV_NEXT; // start next song
}
// Next and previous PLAYLIST
// Use button 1 for previous, 2, for next.
// Use also "fast scan" to do that : usefull on the steering wheel
// as we can change track and playlist with only one finger.
//
if ( lexer(&but1) || lexer(&fwd) ) // if PREV PLAYLIST
{
SendCDMsg(cd_endplaying_msg); // send endplaying message
t_start = sys_time + 1; // send startplaying in 100 mS
return EV_PREVPL; // start previous playlist
}
if ( lexer(&but2) || lexer(&rev) ) // if NEXT PLAYLIST
{
SendCDMsg(cd_endplaying_msg); // send endplaying message
t_start = sys_time + 1; // send startplaying in 100 mS
return EV_NEXTPL; // start next playlist
}
//
// currently not used
//
if ( lexer(&but3) )
{
SendCDMsg(cd_startplaying03_msg); // send startplaying to keep system happy
continue; // parse more messages
}
//
// currently not used
//
if ( lexer(&but4) )
{
SendCDMsg(cd_startplaying04_msg); // send startplaying to keep system happy
continue; // parse more messages
}
//
// Button 5 controls Repeat mode
//
if (lexer(&but5))
{
SendCDMsg(cd_startplaying05_msg); // send startplaying to keep system happy
t_area = sys_time + 1; // update main area in 100 mS
return EV_REPEAT; // switch repeat mode
}
//
// Button 6 controls Random mode
//
if (lexer(&but6))
{
SendCDMsg(cd_startplaying06_msg); // send startplaying to keep system happy
t_area = sys_time + 1; // update main area in 100 mS
return EV_RANDOM; // switch random mode
}
}// end if playing
} // while
//
// Timer expiration checks
//
//
// check if it's time to send an announce message
//
if (sys_time > t_announce)
{
t_announce += 100; // set next update in 10 seconds
SendCDMsg(cd_announce_msg); // send announce message
}
//
// check if it's time to send an startplaying message
//
if (sys_time > t_start)
{
t_start = (u32) -1; // no more updates
SendCDMsg(cd_startplaying01_msg); // send startplaying message
}
//
// check if it's time to update the index area
//
if (sys_time > t_index)
{
t_index = (u32) -1; // no more updates
if (display) // if displaying allowed
{
DisplayIndex(); // update index area
}
}
//
// check if it's time to update the main area
// also start time area update
//
if (sys_time > t_area)
{
t_area = (u32) -1; // no more updates
t_time = sys_time + 5; // set next update in 500 mS
if (display) // if displaying allowed
{
DisplayInfo(); // update main area
}
}
//
// check if it's time to update the time area
//
/* if (sys_time > t_time)
{
t_area = sys_time + 5; // set next update in 500 mS
if (display) // if displaying allowed
{
DisplayTime(); // display time in main area
}
}
*/
//
// Nothing happened, return idle
//
return EV_IDLE;
}