static void Connect(void) { Task_t tasks[2]; /* listen for link forever... */ while (1) { if (SMPL_SUCCESS == SMPL_LinkListen(&sLinkID2)) { break; } /* Implement fail-to-link policy here. otherwise, listen again. */ } LedOff(&led_red); LedOff(&led_green); /* turn on RX. default is RX off. */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0); TaskLoopCtor(&tasks[0], PingCheckStep); TaskLoopCtor(&tasks[1], MotorStep); TaskMasterRun(&tasks, 2); //begin our scheduler.. not coming back }
/* Wait for channel to close */ static void UserAppSM_WaitChannelClose(void) { /* Monitor the channel status to check if channel is closed */ if(AntRadioStatus() == ANT_CLOSED) { #ifdef MPG1 LedOff(GREEN); LedOn(YELLOW); #endif /* MPG1 */ #ifdef MPG2 LedOn(GREEN0); LedOn(RED0); #endif /* MPG2 */ UserApp_StateMachine = UserAppSM_Idle; } /* Check for timeout */ if( IsTimeUp(&UserApp_u32Timeout, TIMEOUT_VALUE) ) { #ifdef MPG1 LedOff(GREEN); LedOff(YELLOW); LedBlink(RED, LED_4HZ); #endif /* MPG1 */ #ifdef MPG2 LedBlink(RED0, LED_4HZ); LedOff(GREEN0); #endif /* MPG2 */ UserApp_StateMachine = UserAppSM_Error; } } /* end UserAppSM_WaitChannelClose() */
void BoardInit( void ) { uint8_t i; /* Setup SysTick Timer for 1 us interrupts ( not too often to save power ) */ if( SysTick_Config( SystemCoreClock / 1000 ) ) { /* Capture error */ while (1); } // Initialize unused GPIO to optimize power consumption InitUnusedGPIO( ); // Initialize Selector SelectorInit( ); // Initialize SPI SpiInit( ); // Initialize LED for( i = 0; i < LED_NB; i++ ) { LedInit( ( tLed )i ); } LedOn( LED1 ); LedOn( LED2 ); LedOn( LED3 ); LongDelay( 1 ); LedOff( LED1 ); LedOff( LED2 ); LedOff( LED3 ); }
/*---------------------------------------------------------------------------------------------------------------------- Function: LedUpdate Description: Update all LEDs for the current cycle. Requires: - G_u32SystemTime1ms is counting Promises: - All LEDs updated based on their counters */ void LedUpdate(void) { /* Loop through each LED */ for(u8 i = 0; i < TOTAL_LEDS; i++) { /* Check if LED is PWMing */ if(Leds_asLedArray[(LedNumberType)i].eMode == LED_PWM_MODE) { /* Handle special case of 0% duty cycle */ if( Leds_asLedArray[i].eRate == LED_PWM_0 ) { LedOff( (LedNumberType)i ); } /* Handle special case of 100% duty cycle */ else if( Leds_asLedArray[i].eRate == LED_PWM_100 ) { LedOn( (LedNumberType)i ); } /* Otherwise, regular PWM: decrement counter; toggle and reload if counter reaches 0 */ else { if(--Leds_asLedArray[(LedNumberType)i].u16Count == 0) { if(Leds_asLedArray[(LedNumberType)i].eCurrentDuty == LED_PWM_DUTY_HIGH) { /* Turn the LED off and update the counters for the next cycle */ LedOff( (LedNumberType)i ); Leds_asLedArray[(LedNumberType)i].u16Count = LED_PWM_PERIOD - Leds_asLedArray[(LedNumberType)i].eRate; Leds_asLedArray[(LedNumberType)i].eCurrentDuty = LED_PWM_DUTY_LOW; } else { /* Turn the LED on and update the counters for the next cycle */ LedOn( (LedNumberType)i ); Leds_asLedArray[i].u16Count = Leds_asLedArray[i].eRate; Leds_asLedArray[i].eCurrentDuty = LED_PWM_DUTY_HIGH; } } } /* Set the LED back to PWM mode since LedOff and LedOn set it to normal mode */ Leds_asLedArray[(LedNumberType)i].eMode = LED_PWM_MODE; } /* end if PWM mode */ /* LED is in LED_BLINK_MODE mode */ else if(Leds_asLedArray[(LedNumberType)i].eMode == LED_BLINK_MODE) { /* Decrement counter; toggle and reload if counter reaches 0 */ if( --Leds_asLedArray[(LedNumberType)i].u16Count == 0) { LedToggle( (LedNumberType)i ); Leds_asLedArray[(LedNumberType)i].u16Count = Leds_asLedArray[(LedNumberType)i].eRate; } } } /* end for */ } /* end LedUpdate() */
/* * Esta función se debe llamar a la máxima velocidad * para poder tener la base de tiempo */ void RgbLedUpdate(void){ // Supongo que paso una unidad de tiempo de la base de tiempo. ++timeBaseCounter; if( timeBaseCounter >= cyclesPerPeriod ){ // Prender todos los leds if( redIntensityCycles > 0 ){ LedOn(RGBLED_RED); } if( greenIntensityCycles > 0 ){ LedOn(RGBLED_GREEN); } if( blueIntensityCycles > 0 ){ LedOn(RGBLED_BLUE); } // Reiniciar el contador timeBaseCounter = 0; ellapsedRedCycles = 0; ellapsedGreenCycles = 0; ellapsedBlueCycles = 0; } else{ // Controlar el estado del led Verde if( ellapsedRedCycles < redIntensityCycles ){ ++ellapsedRedCycles; } else{ LedOff(RGBLED_RED); } // Controlar el estado del led verde if( ellapsedGreenCycles < greenIntensityCycles ){ ++ellapsedGreenCycles; } else{ LedOff(RGBLED_GREEN); } // Controlar el estado del led Azul if( ellapsedBlueCycles < blueIntensityCycles ){ ++ellapsedBlueCycles; } else{ LedOff(RGBLED_BLUE); } } }
void vibrate(int offMsec, int id) { if (!InitLed()) return; LedOn(id); Sleep(offMsec); LedOff(id); }
/* ** Perform file operations on MMCSD */ static void ActionMMCSD(void) { pmFlag = FALSE; rtcSetFlag = FALSE; tmrClick = FALSE; tmrFlag = FALSE; LedOff(); if(TRUE == HSMMCSDCardPresentStat()) { sdCardAccessFlag = TRUE; } else { sdCardAccessFlag = FALSE; ConsoleUtilsPrintf("\n\rSD card not present. Please insert an" " SD card and try again! \n\r"); } /* ** Check for SD Card */ if(TRUE == sdCardAccessFlag) { HSMMCSDCardAccessSetup(); } pageIndex = MENU_IDX_SD; UpdateUartConsoleHelp(); }
void Led::CyclTask(void) { unsigned long time = millis(); _currentTime += (time - _prevTime); _prevTime = time; if(_currentTime > _wakeup) { _currentTime = 0; if(_led_is_on == true) { LedOff(); _wakeup = (_winkCurrent > 0) ? _delay_between_two_wink : _delay_between_two_cycle; } else { _wakeup = _delay_wink; if(_winkCurrent > 0) { LedOn(); _winkCurrent--; } else { _winkCurrent = _winkNumber; } } } }
/* Wait for channel to open */ static void UserAppSM_WaitChannelOpen(void) { /* Monitor the channel status to check if channel is opened */ if(AntRadioStatus() == ANT_OPEN) { #ifdef MPG1 LedOn(GREEN); #endif /* MPG1 */ #ifdef MPG2 LedOn(GREEN0); #endif /* MPG2 */ UserApp_StateMachine = UserAppSM_ChannelOpen; } /* Check for timeout */ if( IsTimeUp(&UserApp_u32Timeout, TIMEOUT_VALUE) ) { AntCloseChannel(); #ifdef MPG1 LedOff(GREEN); LedOn(YELLOW); #endif /* MPG1 */ #ifdef MPG2 LedOn(RED0); LedOn(GREEN0); #endif /* MPG2 */ UserApp_StateMachine = UserAppSM_Idle; } } /* end UserAppSM_WaitChannelOpen() */
void LedInit(void) { /* Set pins as output */ TM_GPIO_Init(LED_PORT, LED_ALL, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_High); /* Turn leds off */ LedOff(LED_ALL); }
/*----------------------------------------------------------------------------- * Led Statemachine */ void LedCheck(void) { uint16_t currTimeMs; uint8_t i; TState *pState; GET_TIME_MS16(currTimeMs); pState = &sLedState[0]; for (i = 0; i < NUM_LED; i++) { if ((pState->offTime != FOREVER) && (pState->onTime != FOREVER)) { if (pState->state == LED_ON) { if (((uint16_t)(currTimeMs - pState->switchTime)) >= pState->onTime) { pState->switchTime = currTimeMs; LedOff(i); if (pState->cyclic == false) { pState->offTime = FOREVER; } } } else { if (((uint16_t)(currTimeMs - pState->switchTime)) >= pState->offTime) { pState->switchTime = currTimeMs; LedOn(i); } } } pState++; } }
/* Wait for a message to be queued */ static void UserAppSM_Idle(void) { /* Look for BUTTON 0 to open channel */ if(WasButtonPressed(BUTTON0)) { /* Got the button, so complete one-time actions before next state */ ButtonAcknowledge(BUTTON0); LcdClearScreen(); PixelBlockType sideScale = {0,19,128,5}; LcdLoadBitmap(&au8Scale[0][0], &sideScale); PixelAddressType line0 = {0,0}; LcdLoadString("183", LCD_FONT_SMALL, &line0); PixelAddressType line1 = {8,0}; LcdLoadString("167", LCD_FONT_SMALL, &line1); PixelAddressType line2 = {16,0}; LcdLoadString("151", LCD_FONT_SMALL, &line2); PixelAddressType line3 = {24,0}; LcdLoadString("135", LCD_FONT_SMALL, &line3); PixelAddressType line4 = {32,0}; LcdLoadString("119", LCD_FONT_SMALL, &line4); PixelAddressType line5 = {40,0}; LcdLoadString("103", LCD_FONT_SMALL, &line5); PixelAddressType line6 = {48,0}; LcdLoadString("87", LCD_FONT_SMALL, &line6); PixelAddressType line7 = {56,0}; LcdLoadString("71", LCD_FONT_SMALL, &line7); /* Queue open channel and change LED0 from yellow to blinking green to indicate channel is opening */ AntOpenChannel(); #ifdef MPG1 LedOff(YELLOW); LedBlink(GREEN, LED_2HZ); #endif /* MPG1 */ #ifdef MPG2 LedOff(RED0); LedBlink(GREEN0, LED_2HZ); #endif /* MPG2 */ /* Set timer and advance states */ UserApp_u32Timeout = G_u32SystemTime1ms; UserApp_StateMachine = UserAppSM_WaitChannelOpen; } } /* end UserAppSM_Idle() */
/* ** Resets the state */ static void ContextReset(void) { tmrFlag = FALSE; LedOff( USER_LED_3 ); rtcSetFlag = FALSE; rtcSecUpdate = FALSE; // sdCardAccessFlag = FALSE; }
/* ** Resets the state */ static void ContextReset(void) { tmrFlag = FALSE; LedOff(); rtcSetFlag = FALSE; rtcSecUpdate = FALSE; sdCardAccessFlag = FALSE; }
/* ** Action for menu RTC icon click */ static void ActionMenuRTC(void) { pmFlag = FALSE; sdCardAccessFlag = FALSE; tmrFlag = FALSE; tmrClick = FALSE; LedOff(); pageIndex = MENU_IDX_RTC; UpdateUartConsoleHelp(); }
/* ** Action for menu MMCSD icon click */ static void ActionMenuMMCSD(void) { pmFlag = FALSE; rtcSetFlag = FALSE; tmrClick = FALSE; tmrFlag = FALSE; LedOff(); pageIndex = MENU_IDX_SD; UpdateUartConsoleHelp(); }
/* ** Action for menu PM icon click */ static void ActionMenuPM(void) { pmFlag = TRUE; rtcSetFlag = FALSE; tmrClick = FALSE; tmrFlag = FALSE; LedOff(); Timer2Stop(); pageIndex = MENU_IDX_PM; UpdateUartConsoleHelp(); }
/* ** Action for Web Menu */ static void ActionMenuWeb(void) { pmFlag = FALSE; sdCardAccessFlag = FALSE; tmrFlag = FALSE; tmrClick = FALSE; rtcSetFlag = FALSE; Timer2Stop(); LedOff(); pageIndex = MENU_IDX_WWW; UpdateUartConsoleHelp(); }
/********************************* LED初始化 *************************************/ void ledInit(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable the GPIO_LED Clock */ RCC_APB2PeriphClockCmd(LED_RCC, ENABLE); /* Configure the GPIO_LED pin */ GPIO_InitStructure.GPIO_Pin = LED_X_G|LED_X_R|LED_GPS_G|LED_GPS_R |LED_CH_G|LED_CH_R; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(LED_GPIO, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(CHG_RCC, ENABLE); /* Configure the GPIO_LED pin */ GPIO_InitStructure.GPIO_Pin = CHG_ERR|CHG_STA; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(CHG_GPIO, &GPIO_InitStructure); LedOff(LED_X_G); LedOff(LED_GPS_G); LedOff(LED_CH_G); LedOff(LED_X_R); LedOff(LED_GPS_R); LedOff(LED_CH_R); }
void BoardInit( void ) { uint8_t i; /* Setup SysTick Timer for 1 us interrupts ( not too often to save power ) */ if( SysTick_Config( SystemCoreClock / 1000 ) ) { /* Capture error */ while (1); } // Initialize SPI SpiInit( ); // Initialize LED for( i = 0; i < LED_NB; i++ ) { LedInit( ( tLed )i ); } LedOff( LED_RED ); LedOff( LED_GREEN ); }
void LedAllOff() { LedOff(LED_TRIPOD); LedOff(LED_RBOG); LedOff(LED_BBOG); LedOff(LED_LBOG); LedOff(LED_DNT); LedOff(LED_STATUS); }
void RgbLedInit(void){ currentColor.red = 255; currentColor.green = 255; currentColor.blue = 255; cyclesPerPeriod = 20; ScaleColorToCycles(); // Contadores para prender y apagar los leds timeBaseCounter = cyclesPerPeriod; // Iniciar el contador base igual al periodo ellapsedRedCycles = 0; ellapsedGreenCycles = 0; ellapsedBlueCycles = 0; // Inicializar el led rbg y apagarlo InitLed(); LedOff(RGBLED_RED); LedOff(RGBLED_GREEN); LedOff(RGBLED_BLUE); }
void Led::Setup(int led_pin) { _led_pin = led_pin; pinMode(_led_pin, OUTPUT); LedOff(); _winkCurrent = 0 ; _winkNumber = 0 ; _wakeup = 0; _currentTime = 0; _prevTime = 0 ; }
/** * @brief TMRB0 interrupt service routine (1ms) * @param None * @retval None */ void INTTB0_IRQHandler(void) { static uint16_t tbcount = 0U; static uint8_t ledon = 1U; tbcount++; if (tbcount >= 500U) { tbcount = 0U; /* reverse LED output */ ledon = (ledon == 0U) ? 1U : 0U; if (0U == ledon) { LedOff(LED1); } else { LedOn(LED1); } } else { /* do nothing */ } }
int main(void){ unsigned long i,last,now,dataLast, dataIndex; TExaS_Init(SW_PIN_PF40, LED_PIN_PF1); // activate grader and set system clock to 16 MHz PortF_Init(); // initialize PF1 to output SysTick_Init(); // initialize SysTick, runs at 16 MHz i = 0; // array index last = NVIC_ST_CURRENT_R; dataIndex=0; dataLast = GPIO_PORTF_DATA_R; EnableInterrupts(); // enable interrupts for the grader while(1){ dataNow = GPIO_PORTF_DATA_R; if(ShouldFlashLed()){ LedToggle(); }else{ LedOff(); } if(dataLast != dataNow) { GPIO_PORTF_DATA_R = dataNow; dataLast = dataNow; if(dataIndex<50){ Data[dataIndex] = dataNow; dataIndex++; } } if(i<50){ now = NVIC_ST_CURRENT_R; Time[i] = (last-now)&0x00FFFFFF; // 24-bit time difference //Data[i] = GPIO_PORTF_DATA_R&0x02; // record PF1 last = now; i++; } Delay(); } }
void TMRB_TIMER(void) { TMRB_InitTypeDef m_tmrb; CG_InitSystem(); /* CG_SetSystem */ GPIO_SetOutput(GPIO_PA,0xFFU); GPIO_WriteData(GPIO_PA,0xFFU); /* LED initialize */ LedOff(LED1 | LED2 | LED3 | LED4); m_tmrb.Mode = TMRB_INTERVAL_TIMER; m_tmrb.ClkDiv = TMRB_CLK_DIV_8; m_tmrb.Cycle = TMRB_1MS; /* periodic time is 1ms */ m_tmrb.UpCntCtrl = TMRB_AUTO_CLEAR; m_tmrb.Duty = TMRB_1MS; /* periodic time is 1ms */ TMRB_Enable(TSB_TB0); TMRB_Init(TSB_TB0, &m_tmrb); NVIC_EnableIRQ(INTTB0_IRQn); TMRB_SetRunState(TSB_TB0, TMRB_RUN); while (1) { /* Do nothing */ } }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { u32 i=0; while(1) { i++; if(i>3*MHZ) break; } #ifdef DEBUG debug(); #endif BspInit(); CommonInit(); FLASH_Unlock(); LedOff(LED_5); while (1) { CommonExec(); } }
/*int main(void)*/ void CG_ModeSwitch(void) { uint8_t TSW_info = 0U; /* Initialize system */ CG_SetSystem(); GPIO_SetINT(); LEDInit(); LedOn(LED0); #ifdef DEBUG printf("TMPM341 CG_ModeSwitch DEMO\r\n"); #endif while (1) { TSW_info = GPIO_ReadData(TSW_PORT) & TSWBITS; if (TSW_info == TSW1) { fSysSleep = SLEEP; LedOff(LED0); #ifdef DEBUG printf("Now, Going to Sleep\r\n"); #endif CG_NormalToStop1(); /* connect PG3(INT0) to VCC to recover from STOP mode */ LedOn(LED0); fSysSleep = WAKE; NVIC_DisableIRQ(INT0_IRQn); #ifdef DEBUG printf("Wakeup from Sleep\r\n"); #endif } else { /* Do nothing */ } } }
/* Channel is open, so monitor data */ static void UserAppSM_ChannelOpen(void) { static u8 u8LastState = 0xff; static u8 au8TickMessage[] = "EVENT x\n\r"; /* "x" at index [6] will be replaced by the current code */ static u8 au8DataContent[] = "xxxxxxxxxxxxxxxx"; static u8 au8LastAntData[ANT_APPLICATION_MESSAGE_BYTES] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; static u8 au8TestMessage[] = {0, 0, 0, 0, 0xA5, 0, 0, 0}; bool bGotNewData; /* Check for BUTTON0 to close channel */ if(WasButtonPressed(BUTTON0)) { /* Got the button, so complete one-time actions before next state */ ButtonAcknowledge(BUTTON0); /* Queue close channel and change LED to blinking green to indicate channel is closing */ AntCloseChannel(); u8LastState = 0xff; #ifdef MPG1 LedOff(YELLOW); LedOff(BLUE); LedBlink(GREEN, LED_2HZ); #endif /* MPG1 */ #ifdef MPG2 LedOff(RED0); LedOff(BLUE0); LedBlink(GREEN0, LED_2HZ); #endif /* MPG2 */ /* Set timer and advance states */ UserApp_u32Timeout = G_u32SystemTime1ms; UserApp_StateMachine = UserAppSM_WaitChannelClose; } /* end if(WasButtonPressed(BUTTON0)) */ /* Always check for ANT messages */ if( AntReadData() ) { /* New data message: check what it is */ if(G_eAntApiCurrentMessageClass == ANT_DATA) { UserApp_u32DataMsgCount++; /* Check if the new data is the same as the old data and update as we go */ bGotNewData = TRUE;//used to be false for(u8 i = 0; i < ANT_APPLICATION_MESSAGE_BYTES; i++) { if(G_au8AntApiCurrentData[i] != au8LastAntData[i]) { bGotNewData = TRUE; au8LastAntData[i] = G_au8AntApiCurrentData[i]; au8DataContent[2 * i] = HexToASCIICharUpper(G_au8AntApiCurrentData[i] / 16); au8DataContent[2 * i + 1] = HexToASCIICharUpper(G_au8AntApiCurrentData[i] % 16); } } if(bGotNewData) { /* We got new data: show on LCD */ #ifdef MPG1 LCDClearChars(LINE2_START_ADDR, 20); LCDMessage(LINE2_START_ADDR, au8DataContent); #endif /* MPG1 */ #ifdef MPG2 PixelAddressType sStringLocation1 = {0, 122}; PixelAddressType sStringLocation2 = {8, 122}; PixelAddressType sStringLocation3 = {16, 122}; const unsigned char * HRTop = ReturnTopDigit(G_au8AntApiCurrentData[7]); const unsigned char * HRMiddle = ReturnMiddleDigit(G_au8AntApiCurrentData[7]); const unsigned char * HRBottom = ReturnLastDigit(G_au8AntApiCurrentData[7]); LcdLoadString(HRTop, LCD_FONT_SMALL, &sStringLocation1); LcdLoadString(HRMiddle, LCD_FONT_SMALL, &sStringLocation2); LcdLoadString(HRBottom, LCD_FONT_SMALL, &sStringLocation3); //LcdLoadString(" ",LCD_FONT_SMALL, &sStringLocation); printToScreen(G_au8AntApiCurrentData[7]); #endif /* MPG2 */ /* Update our local message counter and send the message back */ au8TestMessage[7]++; if(au8TestMessage[7] == 0) { au8TestMessage[6]++; if(au8TestMessage[6] == 0) { au8TestMessage[5]++; } } AntQueueBroadcastMessage(au8TestMessage); /* Check for a special packet and respond */ #ifdef MPG1 if(G_au8AntApiCurrentData[0] == 0xA5) { LedOff(LCD_RED); LedOff(LCD_GREEN); LedOff(LCD_BLUE); if(G_au8AntApiCurrentData[1] == 1) { LedOn(LCD_RED); } if(G_au8AntApiCurrentData[2] == 1) { LedOn(LCD_GREEN); } if(G_au8AntApiCurrentData[3] == 1) { LedOn(LCD_BLUE); } } #endif /* MPG1 */ #ifdef MPG2 /*if(G_au8AntApiCurrentData[0] == 0xFF) { LedOff(RED3); LedOff(GREEN3); LedOff(BLUE3); if(G_au8AntApiCurrentData[1] == 0xFF) { LedOn(RED3); } if(G_au8AntApiCurrentData[2] == 0xFF) { LedOn(GREEN3); } if(G_au8AntApiCurrentData[3] == 0xFF) { LedOn(BLUE3); } }*/ #endif /* MPG2 */ } /* end if(bGotNewData) */ } /* end if(G_eAntApiCurrentMessageClass == ANT_DATA) */ else if(G_eAntApiCurrentMessageClass == ANT_TICK) { UserApp_u32TickMsgCount++; /* Look at the TICK contents to check the event code and respond only if it's different */ if(u8LastState != G_au8AntApiCurrentData[ANT_TICK_MSG_EVENT_CODE_INDEX]) { /* The state changed so update u8LastState and queue a debug message */ u8LastState = G_au8AntApiCurrentData[ANT_TICK_MSG_EVENT_CODE_INDEX]; au8TickMessage[6] = HexToASCIICharUpper(u8LastState); DebugPrintf(au8TickMessage); /* Parse u8LastState to update LED status */ switch (u8LastState) { #ifdef MPG1 /* If we are synced with a device, blue is solid */ case RESPONSE_NO_ERROR: { LedOff(GREEN); LedOn(BLUE); break; } /* If we are paired but missing messages, blue blinks */ case EVENT_RX_FAIL: { LedOff(GREEN); LedBlink(BLUE, LED_2HZ); break; } /* If we drop to search, LED is green */ case EVENT_RX_FAIL_GO_TO_SEARCH: { LedOff(BLUE); LedOn(GREEN); break; } #endif /* MPG 1 */ #ifdef MPG2 /* If we are synced with a device, blue is solid */ case RESPONSE_NO_ERROR: { LedOff(GREEN0); LedOn(BLUE0); break; } /* If we are paired but missing messages, blue blinks */ case EVENT_RX_FAIL: { LedOff(GREEN0); LedBlink(BLUE0, LED_2HZ); break; } /* If we drop to search, LED is green */ case EVENT_RX_FAIL_GO_TO_SEARCH: { LedOff(BLUE0); LedOn(GREEN0); break; } #endif /* MPG 2 */ /* If the search times out, the channel should automatically close */ case EVENT_RX_SEARCH_TIMEOUT: { DebugPrintf("Search timeout\r\n"); break; } default: { DebugPrintf("Unexpected Event\r\n"); break; } } /* end switch (G_au8AntApiCurrentData) */ } /* end if (u8LastState != G_au8AntApiCurrentData[ANT_TICK_MSG_EVENT_CODE_INDEX]) */ } /* end else if(G_eAntApiCurrentMessageClass == ANT_TICK) */ } /* end AntReadData() */ /* A slave channel can close on its own, so explicitly check channel status */ if(AntRadioStatus() != ANT_OPEN) { #ifdef MPG1 LedBlink(GREEN, LED_2HZ); LedOff(BLUE); #endif /* MPG1 */ #ifdef MPG2 LedBlink(GREEN0, LED_2HZ); LedOff(BLUE0); #endif /* MPG2 */ u8LastState = 0xff; UserApp_u32Timeout = G_u32SystemTime1ms; UserApp_StateMachine = UserAppSM_WaitChannelClose; } /* if(AntRadioStatus() != ANT_OPEN) */ } /* end UserAppSM_ChannelOpen() */
/*-------------------------------------------------------------------------------------------------------------------- Function: UserAppInitialize Description: Initializes the State Machine and its variables. Requires: - Promises: - */ void UserAppInitialize(void) { u8 au8WelcomeMessage[] = "REAL TIME HR GRAPH"; u8 au8Instructions[] = "B0 toggles radio"; /* Clear screen and place start messages */ #ifdef MPG1 LCDCommand(LCD_CLEAR_CMD); LCDMessage(LINE1_START_ADDR, au8WelcomeMessage); LCDMessage(LINE2_START_ADDR, au8Instructions); /* Start with LED0 in RED state = channel is not configured */ LedOn(RED); #endif /* MPG1 */ #ifdef MPG2 PixelAddressType sStringLocation = {LCD_SMALL_FONT_LINE0, LCD_LEFT_MOST_COLUMN}; LcdClearScreen(); LcdLoadString(au8WelcomeMessage, LCD_FONT_SMALL, &sStringLocation); sStringLocation.u16PixelRowAddress = LCD_SMALL_FONT_LINE1; LcdLoadString(au8Instructions, LCD_FONT_SMALL, &sStringLocation); /* Start with LED0 in RED state = channel is not configured */ LedOn(RED0); #endif /* MPG2 */ /* Configure ANT for this application */ G_stAntSetupData.AntChannel = ANT_CHANNEL_USERAPP; G_stAntSetupData.AntSerialLo = ANT_SERIAL_LO_USERAPP; G_stAntSetupData.AntSerialHi = ANT_SERIAL_HI_USERAPP; G_stAntSetupData.AntDeviceType = ANT_DEVICE_TYPE_USERAPP; G_stAntSetupData.AntTransmissionType = ANT_TRANSMISSION_TYPE_USERAPP; G_stAntSetupData.AntChannelPeriodLo = ANT_CHANNEL_PERIOD_LO_USERAPP; G_stAntSetupData.AntChannelPeriodHi = ANT_CHANNEL_PERIOD_HI_USERAPP; G_stAntSetupData.AntFrequency = ANT_FREQUENCY_USERAPP; G_stAntSetupData.AntTxPower = ANT_TX_POWER_USERAPP; /* If good initialization, set state to Idle */ if( AntChannelConfig(ANT_SLAVE) ) { /* Channel is configured, so change LED to yellow */ #ifdef MPG1 LedOff(RED); LedOn(YELLOW); #endif /* MPG1 */ #ifdef MPG2 LedOn(GREEN0); #endif /* MPG2 */ UserApp_StateMachine = UserAppSM_Idle; } else { /* The task isn't properly initialized, so shut it down and don't run */ #ifdef MPG1 LedBlink(RED, LED_4HZ); #endif /* MPG1 */ #ifdef MPG2 LedBlink(RED0, LED_4HZ); #endif /* MPG2 */ UserApp_StateMachine = UserAppSM_Error; } } /* end UserAppInitialize() */