コード例 #1
1
ファイル: ShiftPWM.c プロジェクト: ggaavv/Equinox-Clock
void LED_one_by_one(){
// Turn on then off every LED
	SetLED(LED_Loop,MAX_BRIGHTNESS);
	calulateLEDMIBAMBits();
	SetLED(LED_Loop,0);
	LED_Loop++;
	if(LED_Loop>LEDS)
		LED_Loop=0;
}
コード例 #2
0
//*****************************************************************************
//
// Change to a different SimpliciTI channel number (frequency).
//
//*****************************************************************************
static void ChangeChannel(void)
{
#ifdef FREQUENCY_AGILITY
    freqEntry_t sFreq;

    //
    // Cycle to the next channel, wrapping from the top of the table back
    // to the bottom if necessary.
    //
    if (++g_ucChannel >= NWK_FREQ_TBL_SIZE)
    {
        g_ucChannel = 0;
    }

    //
    // Set the radio frequency.
    //
    sFreq.logicalChan = g_ucChannel;
    SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SET, &sFreq);

    //
    // Turn both of the "LEDs" off and set the flag we use to tell the main
    // loop that it should blink the LEDs until a new message is received from
    // an end device.
    //
    SetLED(1, false);
    SetLED(2, false);
    g_ulBlinky = 1;
#endif
    return;
}
コード例 #3
0
ファイル: led_control.c プロジェクト: reillyeon/weblight
void StatusBlinkRed(uint8_t count) {
  uint8_t i;
  LEDsOff();
  for (i = 0; i < count; i++) {
    SetLED(0, 128, 0, 0);
    UpdateLEDs();
    _delay_ms(10);
    SetLED(0, 0, 0, 0);
    UpdateLEDs();
    _delay_ms(30);
  }
}
コード例 #4
0
ファイル: main.c プロジェクト: cjameshuff/stm32f4_base
void LED_InitGPIO(void)
{
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    
    GPIO_InitTypeDef gpioInit = {
        .GPIO_Pin = 0,
        .GPIO_Mode = GPIO_Mode_OUT,
        .GPIO_OType = GPIO_OType_PP,
        .GPIO_PuPd = GPIO_PuPd_UP,
        .GPIO_Speed = GPIO_Speed_50MHz
    };
    for(int j = 0; j < 4; ++j) {
        gpioInit.GPIO_Pin = LED_PIN[j];
        GPIO_Init(LED_PORT[j], &gpioInit);
    }
}

void SetLED(int led, bool state) {
    if(state)
        LED_PORT[led]->BSRRL = LED_PIN[led];
    else
        LED_PORT[led]->BSRRH = LED_PIN[led];
}

void ToggleLED(int led) {
    LED_PORT[led]->ODR ^= LED_PIN[led];
}

static void InitClocks(void);
// static void TIM4_Config(void);

int main(void)
{
    InitClocks();
    
    // Configure for millisecond system ticks
    if(SysTick_Config(SystemCoreClock/1000))
        while(1) {;}
    
    LED_InitGPIO();
    
    SetLED(0, true);
    SetLED(1, true);
    
    int led = 0;
    while(1)
    {
        delay_ms(1);
        ToggleLED(led);
        led = (led + 3)%4;
    }
} // main()
コード例 #5
0
ファイル: mainwindow.cpp プロジェクト: xuezeao/git_program
int IntoLED(int DID,int *send_positionNo,int send_LEDNum,int color)//color 1绿色
{
    STATE_RTN = STATE_NONE;

    char DataLED[6];
    memset(DataLED,0,6);
    for(int ledNo = 0;ledNo < send_LEDNum;ledNo++)
    {
    int i=send_positionNo[ledNo]%2;
    if (i==1)
    {
        if(color==1)
            DataLED[send_positionNo[ledNo]/2] = 0x10;
        else
            DataLED[send_positionNo[ledNo]/2] = 0x20;

    }
    else
    {
        if(color==1)
            DataLED[send_positionNo[ledNo]/2-1] = 0x01;
        else
            DataLED[send_positionNo[ledNo]/2-1] = 0x02;
    }
    }
    SetLED(myCom,DID,DataLED);
    for(int j=0;j<150;j++)
    {
    waitTaskInfo();
    if(STATE_RTN==STATE_SET_LED)
        return 0;
    }
}
コード例 #6
0
ファイル: main.c プロジェクト: ptLong/linux-code-collections
static portTASK_FUNCTION( Heartbeat_Task, parameters )
{
	(void)parameters;

	for(;;)
	{
		SetLED(1);
		vTaskDelay( 100 / portTICK_RATE_MS );
		SetLED(0);
		vTaskDelay( 100 / portTICK_RATE_MS );
		SetLED(1);
		vTaskDelay( 100 / portTICK_RATE_MS );
		SetLED(0);
		vTaskDelay( 700 / portTICK_RATE_MS );
	}
}
コード例 #7
0
ファイル: led_control.c プロジェクト: reillyeon/weblight
void LEDsOff() {
  uint8_t i;
  for (i = 0; i < LED_COUNT; ++i) {
    SetLED(i, 0, 0, 0);
  }
  UpdateLEDs();
}
コード例 #8
0
	void OpenNIMotorController::Release()
	{
		if( m_bOpened )
		{
			SetLED( LED_BLINK_GREEN );
			xnUSBCloseDevice( m_xDevice );
			m_bOpened = false;
		}
	}
コード例 #9
0
void Parameter_LED8x8_Form::mouseMoveEvent(QMouseEvent *event)
{
    mouse_posX_ = event->pos().x();
    mouse_posY_ = event->pos().y();

    if (mouse_press_ > 0){
        SetLED();
    }
}
コード例 #10
0
ファイル: wifi.c プロジェクト: Mindtribe/Leash-Debugger
void Task_WifiAP(void* params)
{
    (void)params; //avoid unused warning
    long retval;

    LOG(LOG_IMPORTANT, "Starting WiFi AP Mode.");
    SetLEDBlink(LED_1, LED_BLINK_PATTERN_WIFI_CONNECTING);

    if(WifiDefaultSettings() == RET_FAILURE)  {
        goto error;
    }

    if((retval = sl_Start(0,0,0)) < 0)  {
        goto error;
    }

    if(retval != ROLE_AP) {
        if(WifiSetModeAP() != ROLE_AP) {
            sl_Stop(SL_STOP_TIMEOUT);
            goto error;
        }
    }

    //Wait for an IP address to be acquired
    while(!IS_IP_ACQUIRED(wifi_state.status)) {};

    SetLEDBlink(LED_1, LED_BLINK_PATTERN_WIFI_AP);
    LOG(LOG_IMPORTANT, "AP Started - Ready for client.");

#ifdef DO_STACK_CHECK
    wifi_state.stack_watermark = uxTaskGetStackHighWaterMark(NULL);
#endif

    //start socket handler.
    xTaskCreate(Task_SocketServer,
                "Socket Server",
                SOCKET_TASK_STACK_SIZE/sizeof(portSTACK_TYPE),
                0,
                SOCKET_TASK_PRIORITY,
                0);

#ifdef DO_STACK_CHECK
    wifi_state.stack_watermark = uxTaskGetStackHighWaterMark(NULL);
#endif

    //exit (delete this task)
    WifiTaskEndCallback(&Task_WifiAP);
    vTaskDelete(NULL);

error:
    SetLED(LED_1, LED_BLINK_PATTERN_WIFI_FAILED);
    TASK_RETURN_ERROR(ERROR_UNKNOWN, "WIFI AP fail");
    return;

    return;
}
コード例 #11
0
/***    void ServerSetup()
 *
 *    Parameters:
 *          None
 *              
 *    Return Values:
 *          None
 *
 *    Description: 
 *    
 *      Initialized the Web Server Network parameters
 *      
 *      
 * ------------------------------------------------------------ */
void ServerSetup(void) 
{
    uint32_t i = 0;

    // Set the LED off, for not initialized
    //pinMode(PIN_LED_SAFE, OUTPUT);
    SetLED(SLED::NOTREADY);     

#if defined(USING_WIFI)
    state = WIFISCAN;          // Scan WiFi First, verify the WiFi connection
    xil_printf("Start WiFi Scan\r\n");
    RestartTimer();
    cNetworks = 0;
#else
    state = DYNAMICIPBEGIN;         // just start with the wired network
#endif

    SetTimeout(cSecDefault);
    stateNext = RESTARTREST;
    stateTimeOut = RESTARTREST;
    RestartTimer();

    cSecRest = cSecInitRest;

    // make sure no clients appear to be in use
    for(i=0; i<cMaxSocketsToListen; i++)
    {
        rgClient[i].pTCPClient = NULL;
        rgTCPClient[i].close();
    }
    cWorkingClients = 0;

    // initialize our temp DNS array
    // initialize them all to the Google NS
    // that way there is something in all of the slots
    // this will get over written if DHCP is used.
    for(i=0; i<sizeof(rgTempDNS)/sizeof(IPv4); i++)
    {
        if((i % 2) == 0)
        {
            rgTempDNS[i].u32 = 0x04040808; // Google public DNS server
        }
        else
        {
            rgTempDNS[i].u32 = 0x08080808; // Google public DNS server
        }
    }

    // now put in the ones that were requested
    memcpy(rgTempDNS, rgIpDNS, min(sizeof(rgTempDNS), sizeof(rgIpDNS)));

    if(sizeof(rgIpDNS) < sizeof(rgTempDNS))
    {
        rgTempDNS[sizeof(rgIpDNS)/sizeof(IPv4)] = ipGateway;
    }
 }
コード例 #12
0
void check_task()
{
	//Waiting for system finish initialize
	while (system.status != SYSTEM_INITIALIZED);

	while (remote_signal_check() == NO_SIGNAL);

	SetLED(LED_B, DISABLE);
	vTaskResume(correction_task_handle);

	while (system.status != SYSTEM_FLIGHT_CONTROL);

	vTaskDelay(2000);
	SetLED(LED_R, ENABLE);
	SetLED(LED_G, ENABLE);
	SetLED(LED_B, ENABLE);
	vTaskDelete(NULL);

}
コード例 #13
0
ファイル: wifi.c プロジェクト: Mindtribe/Leash-Debugger
void Task_WifiSTA(void* params)
{
    (void)params; //avoid unused warning
    long retval;

    LOG(LOG_IMPORTANT, "Starting WiFi Station Mode.");
    SetLEDBlink(LED_1, LED_BLINK_PATTERN_WIFI_CONNECTING);

    if(WifiDefaultSettings() == RET_FAILURE) {
        goto error;
    }

    if((retval = sl_Start(0,0,0)) < 0) {
        goto error;
    }
    if(retval != ROLE_STA) {
        goto error;
    }

    LOG(LOG_VERBOSE, "WiFi set to station mode.");

    if(WifiConnectSTA() == RET_FAILURE) {
        goto error;
    }

    SetLEDBlink(LED_1, LED_BLINK_PATTERN_WIFI_CONNECTED);

#ifdef DO_STACK_CHECK
    wifi_state.stack_watermark = uxTaskGetStackHighWaterMark(NULL);
#endif

    //start socket handler.
    xTaskCreate(Task_SocketServer,
                "Socket Server",
                SOCKET_TASK_STACK_SIZE/sizeof(portSTACK_TYPE),
                0,
                SOCKET_TASK_PRIORITY,
                0);

#ifdef DO_STACK_CHECK
    wifi_state.stack_watermark = uxTaskGetStackHighWaterMark(NULL);
#endif

    //exit (delete this task)
    WifiTaskEndCallback(&Task_WifiSTA);
    vTaskDelete(NULL);

    return;

error:
    SetLED(LED_1, LED_BLINK_PATTERN_WIFI_FAILED);
    TASK_RETURN_ERROR(ERROR_UNKNOWN, "WIFI Station fail");
    return;
}
コード例 #14
0
void system_init(void)
{
	LED_Config();
	Serial_Config(Serial_Baudrate);
	Motor_Config();
	PWM_Capture_Config();

	//IMU Config
	Sensor_Config();
	nRF24L01_Config();

	//SD Config
	if ((SD_status = SD_Init()) != SD_OK)
		system.status = SYSTEM_ERROR_SD;

	PID_Init(&PID_Pitch, 4.0, 0.0, 1.5);
	PID_Init(&PID_Roll, 4.0, 0.0, 1.5);
	PID_Init(&PID_Yaw, 5.0, 0.0, 15.0);

	Delay_10ms(10);

	Motor_Control(PWM_MOTOR_MIN, PWM_MOTOR_MIN, PWM_MOTOR_MIN, PWM_MOTOR_MIN);

	/* nRF Check */
	while (nRF_Check() == ERROR);

	/* Sensor Init */
	while (Sensor_Init() == ERROR);

	Delay_10ms(10);

	/* Lock */
	SetLED(LED_R, DISABLE);
	SetLED(LED_G, ENABLE);
	SetLED(LED_B, ENABLE);

	//Check if no error
	if (system.status != SYSTEM_ERROR_SD)
		system.status = SYSTEM_INITIALIZED;

}
コード例 #15
0
ファイル: StaticLED.cpp プロジェクト: Evangileon/IPC
void CStaticLED::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if(m_nTimerInterval==0)
		return;
	if(m_bShrink == FALSE)
		return;

	if(m_bBright = TRUE)
	{
		SetLED(ID_COLOR_GRAY, TRUE);
		m_bBright = FALSE;
	}
	else
	{
		SetLED(m_nColor, TRUE);
		m_bBright = TRUE;
	}

	CStatic::OnTimer(nIDEvent);
}
コード例 #16
0
ファイル: ShiftPWM.c プロジェクト: ggaavv/Equinox-Clock
void LED_one_by_one_smooth_all_on_all_off(uint8_t colour){
// All smooth on then all smooth off
	// red = 0
	// green = 1
	// blue = 2
	// LED_Loop = led no
	// LED_Loop_v1 = (0 = getting brigher)
	//				(1 = getting duller)
	//getting brighter
	if( ((LED_Loop%3)==0) && (LED_Loop_v1==0) ){
		SetLED(LED_Loop+colour,LED_Loop_v2);
		calulateLEDMIBAMBits();
		LED_Loop_v2++;
		if(LED_Loop_v2>MAX_BRIGHTNESS){
			LED_Loop_v2=0;
			LED_Loop+=3;
		}
		if(LED_Loop>LEDS){
			LED_Loop_v1=1;
			LED_Loop_v2=MAX_BRIGHTNESS;
			LED_Loop=0;
		}
	}
	//getting duller
	if( ((LED_Loop%3)==0) && (LED_Loop_v1==1) ){
		SetLED(LED_Loop+colour,LED_Loop_v2);
		calulateLEDMIBAMBits();
		LED_Loop_v2--;
		if(LED_Loop_v2<0){
			LED_Loop_v2=MAX_BRIGHTNESS;
			LED_Loop+=3;
		}
		if(LED_Loop>LEDS){
			LED_Loop=0;
			LED_Loop_v1=0;
			LED_Loop_v2=0;
			LED_Loop_v3=0;
		}
	}
}
コード例 #17
0
//--------------------------------------------------------------------------------------------------------
void System_Init(void)
{
  GPIO_Init();
  UART_Init();
  ADC_Init();
  PIT_Init();
  PWM_Init();
  LED_Init();
  InitFlashLed();
  //----------进入按键调参--------
  SetLED();
  
  //---------初始化全局变量-------
  CarControlStop();
  

  
  
  g_nCarCount=0;
  g_nSpeedControlCount=0;
  g_nSpeedControlPeriod=0;
  g_nDirectionControlCount=0;
  g_nDirectionControlPeriod=0;
  
  g_fAngleControlOut=0;
  
  g_nLeftMotorPulse=0;
  g_nRightMotorPulse=0;
  g_fCarSpeed=0;
  g_fSpeedControlOutNew=0;
  g_fSpeedControlOutOld=0;
  g_fSpeedControlIntegral=0;
  g_fSpeedControlOut=0;
  
  VOLTAGE_RIGHT=0;
  VOLTAGE_LEFT=0; 
  DIR_LEFT_OFFSET=0;
  DIR_RIGHT_OFFSET=0;
  g_fDirectionControlOutP=0;
  g_fDirectionControlOutD=0;
  g_fDirectionControlOutOld=0;
  g_fDirectionControlOutNew=0;
  g_fDirection=0;
  g_nDirectionGyro=0;
  g_fDirectionControlOut=0;
  
  g_fLeftMotorOut=0;
  g_fRightMotorOut=0;
}
コード例 #18
0
void Parameter_LED8x8_Form::mousePressEvent(QMouseEvent *event)
{
    event->button();
    mouse_posX_ = event->pos().x();
    mouse_posY_ = event->pos().y();

    if (event->button() == Qt::LeftButton){
        mouse_press_ = 1;
    }else if (event->button() == Qt::RightButton){
        mouse_press_ = 2;
    }

    ///////////////////鼠标按下的瞬间就先来一次/////////////
    SetLED();
}
コード例 #19
0
ファイル: ws28xx.cpp プロジェクト: vanvught/rpidmx512
WS28xx::WS28xx (CInterruptSystem *pInterruptSystem, TWS28XXType Type, uint16_t nLEDCount, uint32_t nClockSpeed)
:	m_tLEDType (Type),
	m_nLEDCount (nLEDCount),
	m_nClockSpeedHz(nClockSpeed),
	m_nGlobalBrightness(0xFF),
	m_bUpdating (FALSE),
	m_nHighCode(Type == WS2812B ? 0xF8 : (((Type == UCS1903) || (Type == UCS2903)) ? 0xFC : 0xF0)),
	m_SPIMaster (pInterruptSystem, ((m_tLEDType == WS2801) || (m_tLEDType == APA102)) ? (nClockSpeed == 0 ? WS2801_SPI_SPEED_DEFAULT_HZ : nClockSpeed) : 6400000, 0, 0)
{
	assert(m_tLEDType <= UCS2903);
	assert(m_nLEDCount > 0);

	if ((m_tLEDType == SK6812W) || (m_tLEDType == APA102)) {
		m_nBufSize = m_nLEDCount * 4;
	} else {
		m_nBufSize = m_nLEDCount * 3;
	}

	if (m_tLEDType == WS2811 || m_tLEDType == WS2812 || m_tLEDType == WS2812B || m_tLEDType == WS2813 || m_tLEDType == WS2815 || m_tLEDType == SK6812 || m_tLEDType == SK6812W || m_tLEDType == UCS1903 || m_tLEDType == UCS2903) {
		m_nBufSize *= 8;
	}

	if (m_tLEDType == APA102) {
		m_nBufSize += 8;
	}

	m_pBuffer = new u8[m_nBufSize];
	assert(m_pBuffer != 0);

	if (m_tLEDType == APA102) {
		memset(m_pBuffer, 0, 4);
		for (uint32_t i = 0; i < m_nLEDCount; i++) {
			SetLED(i, 0, 0, 0);
		}
		memset(&m_pBuffer[m_nBufSize - 4], 0xFF, 4);
	} else {
		memset(m_pBuffer, m_tLEDType == WS2801 ? 0 : 0xC0, m_nBufSize);
	}

	m_pReadBuffer = new u8[m_nBufSize];
	assert(m_pReadBuffer != 0);

	m_pBlackoutBuffer = new u8[m_nBufSize];
	assert(m_pBlackoutBuffer != 0);
	memcpy(m_pBlackoutBuffer, m_pBuffer, m_nBufSize);
}
コード例 #20
0
void MSInit()
{
    //turn off A lot of crap
    CM1CON0bits.C1ON=0;
    CM1CON0=0;
    CM2CON0=0;
    SRCON0bits.SRLEN=0;
    //disable analog
    ANSEL=0;
    ANSELH=0;
    ADCON0bits.ADON=0;

    UARTInit();
    RTCInit();
    EPInit();
    USBInit();
    I2CInit();

    LED_LATCH=0;
    LED_TRIS=0;

    SetLED(0);
    EnableOperation();
}
コード例 #21
0
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bRetcode;
    smplStatus_t eRetcode;
    ioctlScanChan_t sScan;
    freqEntry_t pFreq[NWK_FREQ_TBL_SIZE];
    tBoolean bFirstTimeThrough;
    unsigned long ulLoop;
    uint8_t ucLast;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus("Initializing...");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();

    //
    // Did we have a problem with the address?
    //
    if(!bRetcode)
    {
        //
        // Yes - make sure the display is updated then hang the app.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // Turn on both our LEDs
    //
    SetLED(1, true);
    SetLED(2, true);

    UpdateStatus("Joining network...");

    //
    // Initialize the SimpliciTI stack but don't set any receive callback.
    //
    while(1)
    {
        eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0);

        if(eRetcode == SMPL_SUCCESS)
        {
            break;
        }

        ToggleLED(1);
        ToggleLED(2);
        SPIN_ABOUT_A_SECOND;
    }

    //
    // Tell the user what's up.
    //
    UpdateStatus("Sniffing...");

    //
    // Set up for our first sniff.
    //
    sScan.freq = pFreq;
    bFirstTimeThrough = true;
    ucLast = 0xFF;

    //
    // Keep sniffing forever.
    //
    while (1)
    {
        //
        // Wait a while.
        //
        SPIN_ABOUT_A_QUARTER_SECOND;

        //
        // Scan for the active channel.
        //
        SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SCAN, &sScan);

        //
        // Did we find a signal?
        //
        if (1 == sScan.numChan)
        {
            if (bFirstTimeThrough)
            {
                //
                // Set the initial LED state.
                //
                SetLED(1, false);
                SetLED(2, true);

                //
                // Wait a while.
                //
                for(ulLoop = 0; ulLoop < 15; ulLoop--)
                {
                    //
                    // Toggle both LEDs and wait a bit.
                    //
                    ToggleLED(1);
                    ToggleLED(2);
                    SPIN_ABOUT_A_QUARTER_SECOND;
                }
                bFirstTimeThrough = false;
            }

            //
            // Has the channel changed since the last time we updated the
            // display?
            //
            if(pFreq[0].logicalChan != ucLast)
            {
                //
                // Remember the channel we just detected.
                //
                ucLast = pFreq[0].logicalChan;

                //
                // Tell the user which channel we found to be active.
                //
                UpdateStatus("Active channel is %d.", pFreq[0].logicalChan);

                //
                // Set the "LEDs" to mimic the behavior of the MSP430 versions
                // of this application.
                //
                switch(pFreq[0].logicalChan)
                {
                    case 0:
                    {
                        /* GREEN OFF */
                        /* RED   OFF */
                        SetLED(1, false);
                        SetLED(2, false);
                        break;
                    }

                    case 1:
                    {
                        /* GREEN OFF */
                        /* RED   ON */
                        SetLED(1, false);
                        SetLED(2, true);
                        break;
                    }

                    case 2:
                    {
                        /* GREEN ON */
                        /* RED   OFF */
                        SetLED(1, true);
                        SetLED(2, false);
                        break;
                    }

                    case 3:
                    {
                        /* GREEN ON */
                        /* RED   ON */
                        SetLED(1, true);
                        SetLED(2, true);
                        break;
                    }

                    case 4:
                    {
                        /* blink them both... */
                        SetLED(1, false);
                        SetLED(2, false);
                        SPIN_ABOUT_A_QUARTER_SECOND;
                        SetLED(1, true);
                        SetLED(2, true);
                        SPIN_ABOUT_A_QUARTER_SECOND;
                        SetLED(1, false);
                        SetLED(2, false);
                    }
                }
            }
        }
    }
}
コード例 #22
0
ファイル: player.c プロジェクト: solokacher/iCandle
void HandleEvent()
{
	U8 RefrashCounter;
	EVENT Evt = Player.Event;

	ClearEvent();
	switch(Evt)
	{
		case EV_NULL:
			break;

		case EV_DREQ:
			if(BufCnt>=32)
			{
				VS_Send32Byte(DataPtr);
				DataPtr += 32;
				BufCnt -= 32;
			}
			else
				GenerateEvent(EV_BUFEMPTY);
			break;

		case EV_BUFEMPTY:
			if(f_eof(Player.currFile))
				GenerateEvent(EV_END);
			else
			{
				f_read((Player.currFile), DataBuf, BUFSIZE, &BufCnt);
				DataPtr = DataBuf;
			}
			RefrashCounter++;
			if(RefrashCounter == Refrash){
			LCDClean();
			LCDPutString("Now Playing #");
			LCDPutUInt(Player.SongNum);}
			break;

		case EV_NEXT:
			VS_CancelDecoding();
			if(++Player.SongNum  > Player.TotalSongNum)
				Player.SongNum= 1;
			scan_files_open (Player.currFile,"/",Player.SongNum);
			GenerateEvent(EV_BUFEMPTY);
			RefrashCounter = Reset;
			break;

		case EV_PREVIOUS:
			VS_CancelDecoding();
			if(--Player.SongNum  == 0)
				Player.SongNum= Player.TotalSongNum;
			scan_files_open (Player.currFile,"/",Player.SongNum);
			GenerateEvent(EV_BUFEMPTY);
			RefrashCounter = Reset;
			break;

		case EV_MODE:
			Player.Mode++;
			Player.Mode %= 3;
			SetLED(Player.Mode);
			LCDClean();
			LCDPutString("Mode: ");
			if(Player.Mode==SM_BASS)
			LCDPutString("Bass");
			if(Player.Mode==SM_TREBLE)
			LCDPutString("Treble");
			if(Player.Mode==SM_SONG)
			LCDPutString("Song");
			RefrashCounter = Reset;
			break;

		case EV_BASSTREB:
			VS_SetBassTreble(Player.Bass,Player.Treble);
			LCDClean();
			LCDPutString("Bass: ");
			LCDPutUInt(Player.Bass);
			if(Player.Mode==SM_BASS)
			LCDPutString(" <--");
			LCDChangeLine();
			LCDPutString("Treble: ");
			LCDPutInt(Player.Treble);
			if(Player.Mode==SM_TREBLE)
			LCDPutString(" <--");
			RefrashCounter = Reset;
			break;

		case EV_VOLUME:
			VS_SetVol(Player.Volume);
			LCDClean();
			LCDPutString("Now Playing #");
			LCDPutUInt(Player.SongNum);
			LCDChangeLine();
			LCDPutString("Volume: ");
			LCDPutUInt(((ADC0+48)/41));//0~100
			LCD_DataWrite('%');
			RefrashCounter = Reset;
			break;

		case EV_PAUSE:
//			ConsoleWrite("Paused.\n");
			Player.Status = PS_PAUSED;
			LCDClean();
			LCDPutString("|| Paused....");
			break;

		case EV_PLAY:
//			ConsoleWrite("Resume Playing...\n");
			Player.Status = PS_PLAYING;
			LCDClean();
			LCDPutString("Now Playing: #");
			LCDPutUInt(Player.SongNum);
			break;

		case EV_END:
			Player.Event = EV_NEXT;
			LCDClean();
			LCDPutString("End.");
			break;

		default:
			break;
	}
}
コード例 #23
0
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bSuccess, bRetcode, bInitialized;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();
    if(!bRetcode)
    {
        //
        // The Ethernet MAC address can't have been set so hang here since we
        // don't have an address to use for SimpliciTI.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // First time through, we need to initialize the SimpliciTI stack.
    //
    bInitialized = false;

    //
    // The main loop starts here now that we have joined the network.
    //
    while(1)
    {
        //
        // Tell the user what to do.
        //
        UpdateStatus(true, "Please choose the operating mode.");

        //
        // Now wait until the user selects whether we should run as the sender
        // or the receiver.
        //
        while(g_ulMode == MODE_UNDEFINED)
        {
            //
            // Just spin, processing UI messages and waiting for someone to
            // press one of the mode buttons.
            //
            WidgetMessageQueueProcess();
        }

        //
        // At this point, the mode is set so remove the buttons from the
        // display and replace them with the LEDs.
        //
        WidgetRemove((tWidget *)&g_sBtnContainer);
        WidgetAdd((tWidget *)&g_sBackground,
                  (tWidget *)&g_sLEDContainer);
        WidgetPaint((tWidget *)&g_sBackground);

        //
        // Tell the user what we're doing now.
        //
        UpdateStatus(false, "Joining network...");

        if(!bInitialized)
        {
            //
            // Initialize the SimpliciTI stack  We keep trying to initialize until
            // we get a success return code.  This indicates that we have also
            // successfully joined the network.
            //
            while(SMPL_SUCCESS != SMPL_Init((uint8_t (*)(linkID_t))0))
            {
                ToggleLED(1);
                ToggleLED(2);
                SPIN_ABOUT_A_SECOND;
            }

            //
            // Now that we are initialized, remember not to call this again.
            //
            bInitialized = true;
        }

        //
        // Once we have joined, turn both LEDs on and tell the user what we want
        // them to do.
        //
        SetLED(1, true);
        SetLED(2, true);

        //
        // Now call the function that initiates communication in
        // the desired mode.  Note that these functions will not return
        // until communication is established or an error occurs.
        //
        if(g_ulMode == MODE_SENDER)
        {
            bSuccess = LinkTo();
        }
        else
        {
            bSuccess = LinkFrom();
        }

        //
        // If we were unsuccessfull, go back to the mode selection
        // display.
        //
        if(!bSuccess)
        {
            //
            // Remove the LEDs and show the buttons again.
            //
            WidgetRemove((tWidget *)&g_sLEDContainer);
            WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sBtnContainer);
            WidgetPaint((tWidget *)&g_sBackground);

            //
            // Tell the user what happened.
            //
            UpdateStatus(false, "Error establishing communication!");

            //
            // Remember that we don't have an operating mode chosen.
            //
            g_ulMode = MODE_UNDEFINED;
        }
    }
}
コード例 #24
0
//*****************************************************************************
//
// This function attempts to link to another SimpliciTI device by sending a
// link request.
//
//*****************************************************************************
tBoolean
LinkTo(void)
{
    linkID_t linkID1;
    uint8_t  pucMsg[2], ucWrap;
    unsigned long ulCount;
    smplStatus_t eRetcode;

    //
    // Our message counter hasn't wrapped.
    //
    ucWrap = 0;

    //
    // Turn on LED 2
    //
    SetLED(2, true);

    //
    // Tell the user what we're doing.
    //
    UpdateStatus(false, "Attempting to link...");

    //
    // Try to link for about 10 seconds.
    //
    for(ulCount = 0; ulCount < LINK_TIMEOUT_SECONDS; ulCount++)
    {
        //
        // Try to link.
        //
        eRetcode = SMPL_Link(&linkID1);

        //
        // Did we succeed?
        //
        if(eRetcode == SMPL_SUCCESS)
        {
            //
            // Yes - drop out of the loop.
            //
            break;
        }

        //
        // We didn't link so toggle the LEDs, wait a bit then try again.
        //
        ToggleLED(1);
        ToggleLED(2);
        SPIN_ABOUT_A_SECOND;
    }

    //
    // Did the link succeed?
    //
    if(eRetcode != SMPL_SUCCESS)
    {
        //
        // No - return an error code.
        //
        UpdateStatus(false, "Failed to link!");
        return(false);
    }
    else
    {
        UpdateStatus(false, "Link succeeded.");
    }

    //
    // Turn off the second LED now that we have linked.
    //
    SetLED(2, false);

#ifdef FREQUENCY_AGILITY
    //
    // The radio comes up with Rx off. If Frequency Agility is enabled we need
    // it to be on so we don't miss a channel change broadcast.  We need to
    // hear this since this application has no ack.  The broadcast from the AP
    // is, therefore, the only way to find out about a channel change.
    //
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0);
#endif

    //
    // Set up the initial message and message counter.
    //
    pucMsg[0] = 2;
    pucMsg[1] = ++g_ucTid;
    ulCount = 0;

    //
    // We've linked successfully so drop into an infinite loop during which
    // we send messages to the receiver every 5 seconds or so.
    //
    while (1)
    {
        //
        // Send a message every 5 seconds. This could be emulating a sleep.
        //
#ifndef FREQUENCY_AGILITY
        //
        // If Frequency Agility is disabled we don't need to listen for the
        // broadcast channel change command.
        //
        SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);
#endif

        //
        // Kill about 5 seconds.
        //
        SPIN_ABOUT_A_SECOND;
        SPIN_ABOUT_A_SECOND;
        SPIN_ABOUT_A_SECOND;
        SPIN_ABOUT_A_SECOND;
        SPIN_ABOUT_A_SECOND;

#ifndef FREQUENCY_AGILITY
        //
        // See comment above...If Frequency Agility is not enabled we never
        // listen so it is OK if we just awaken leaving Rx off.
        //
        SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
#endif

        //
        // Send a message.
        //
        eRetcode = SMPL_Send(linkID1, pucMsg, sizeof(pucMsg));
        if (SMPL_SUCCESS == eRetcode)
        {
            //
            // Toggle LED 1 to indicate that we sent something.
            //
            ToggleLED(1);

            //
            // Set up the next message.  Every 8th message toggle LED 1 instead
            // of LED 2 on the receiver.
            //
            pucMsg[0] = (++ucWrap & 0x7) ? 2 : 1;
            pucMsg[1] = ++g_ucTid;
        }

        //
        // Tell the user what we did.
        //
        UpdateStatus(false, "Sent msg %d (%s).", ++ulCount,
                     MapSMPLStatus(eRetcode));
    }
}
コード例 #25
0
//*****************************************************************************
//
// This function listens for a link request from another SimpliciTI device.
//
//*****************************************************************************
tBoolean
LinkFrom(void)
{
    linkID_t linkID1;
    uint8_t  pucMsg[MAX_APP_PAYLOAD], ucLen, ucLtid;
    unsigned long ulCount;
    smplStatus_t eRetcode;

    //
    // Tell the user what we're doing.
    //
    UpdateStatus(false, "Listening for link...");

    //
    // Keep the compiler happy.
    //
    eRetcode = SMPL_TIMEOUT;

    //
    // Turn on LED 1 to indicate that we are listening.
    //
    SetLED(1, true);

    //
    // Listen for link for 10 seconds or so.  This logic may fail if you
    // happen to have sat around for about 13.6 years between starting the
    // example and pressing the mode selection button.  I suspect I will be
    // forgiven for this.
    //
    ulCount = g_ulSysTickCount + (LINK_TIMEOUT_SECONDS * TICKS_PER_SECOND);
    while (ulCount > g_ulSysTickCount)
    {
        //
        // Process our message queue to keep the widget library happy.
        //
        WidgetMessageQueueProcess();

        //
        // Listen for a link.  This call takes quite some time to return.
        //
        eRetcode = SMPL_LinkListen(&linkID1);

        //
        // Was the link successful?
        //
        if (SMPL_SUCCESS == eRetcode)
        {
            //
            // Yes - drop out of the loop.
            //
            break;
        }
    }

    //
    // Did we link successfully?
    //
    if(eRetcode != SMPL_SUCCESS)
    {
        //
        // No - Tell the user what happened and return an error.
        //
        UpdateStatus(false, "Failed to link!");
        return(false);
    }

    //
    // Turn off LED 1 to indicate that our listen succeeded.
    //
    UpdateStatus(false, "Link succeeded.");
    SetLED(1, false);

    //
    // Clear our message counter.
    //
    ulCount = 0;

    //
    // Enter an infinite loop polling for messages.
    //
    while (1)
    {
        //
        // Turn the radio off and pretend to sleep for a second or so.
        //
        SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);
        SPIN_ABOUT_A_SECOND;  /* emulate MCU sleeping */

        //
        // Turn the radio back on again.
        //
        SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);

        //
        // Were any messages "received"?
        //
        // The receive call results in polling the Access Point.  The success
        // case occurs when a payload is actually returned.  When there is no
        // frame waiting for the device a frame with no payload is returned by
        // the Access Point.  Note that this loop will retrieve any and all
        // frames that are waiting for this device on the specified link ID.
        // This call will also return frames that were received directly.  It
        // is possible to get frames that were repeated either from the initial
        // transmission from the peer or via a Range Extender.  This is why we
        // implement the TID check.
        //
        do
        {
            //
            // Receive whatever the AP has for us.
            //
            eRetcode = SMPL_Receive(linkID1, pucMsg, &ucLen);

            //
            // Did we get a real frame?
            //
            if((eRetcode == SMPL_SUCCESS) && ucLen)
            {
                //
                // Tell the user what's going on.
                //
                UpdateStatus(false, "Received msg %d", ++ulCount);

                //
                // Process our message queue to keep the widget library happy.
                //
                WidgetMessageQueueProcess();

                //
                // Check the application sequence number to detect late or missing
                // frames.
                //
                ucLtid = *(pucMsg+1);
                if (ucLtid)
                {
                    //
                    // If the current TID is non-zero and the last one we saw was
                    // less than this one assume we've received the 'next' one.
                    //
                    if (g_ucTid < ucLtid)
                    {
                        //
                        // 'Next' frame.  We may have missed some but we don't
                        // care.
                        //
                        if ((*pucMsg == 1) || (*pucMsg == 2))
                        {
                            //
                            // We're good. Toggle the requested LED.
                            //
                            ToggleLED(*pucMsg);
                        }

                        //
                        // Remember the last TID.
                        //
                        g_ucTid = ucLtid;
                    }

                    //
                    // If current TID is non-zero and less than or equal to the last
                    // one we saw assume we received a duplicate.  Just ignore it.
                    //
                }
                else
                {
                    //
                    // Current TID is zero so the count wrapped or we just started.
                    // Let's just accept it and start over.
                    //
                    if ((*pucMsg == 1) || (*pucMsg == 2))
                    {
                        //
                        // We're good. Toggle the requested LED.
                        //
                        ToggleLED(*pucMsg);
                    }

                    //
                    // Remember the last TID.
                    //
                    g_ucTid = ucLtid;
                }
            }
        } while ((eRetcode == SMPL_SUCCESS) & ucLen);
    }
}
コード例 #26
0
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bRetcode;
    bspIState_t intState;
    uint8_t ucLastChannel;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus(true, "Initializing...");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();

    //
    // Did we have a problem with the address?
    //
    if(!bRetcode)
    {
        //
        // Yes - make sure the display is updated then hang the app.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // Turn on both our LEDs
    //
    SetLED(1, true);
    SetLED(2, true);

    UpdateStatus(true, "Waiting for a device...");

    //
    // Initialize the SimpliciTI stack and register our receive callback.
    //
    SMPL_Init(ReceiveCallback);

    //
    // Tell the user what's up.
    //
    UpdateStatus(true, "Access point active.");

    //
    // Do nothing after this - the SimpliciTI stack code handles all the
    // access point function required.
    //
    while(1)
    {
        //
        // Wait for the Join semaphore to be set by the receipt of a Join
        // frame from a device that supports an end device.
        //
        // An external method could be used as well. A button press could be
        // connected to an ISR and the ISR could set a semaphore that is
        // checked by a function call here, or a command shell running in
        // support of a serial connection could set a semaphore that is
        // checked by a function call.
        //
        if (g_ucJoinSem && (g_ucNumCurrentPeers < NUM_CONNECTIONS))
        {
            //
            // Listen for a new incoming connection.
            //
            while (1)
            {
                if (SMPL_SUCCESS == SMPL_LinkListen(&g_sLID[g_ucNumCurrentPeers]))
                {
                    //
                    // The connection attempt succeeded so break out of the
                    // loop.
                    //
                    break;
                }

                //
                // Process our widget message queue.
                //
                WidgetMessageQueueProcess();

                //
                // A "real" application would implement its fail-to-link
                // policy here.  We go back and listen again.
                //
            }

            //
            // Increment our peer counter.
            //
            g_ucNumCurrentPeers++;

            //
            // Decrement the join semaphore.
            //
            BSP_ENTER_CRITICAL_SECTION(intState);
            g_ucJoinSem--;
            BSP_EXIT_CRITICAL_SECTION(intState);

            //
            // Tell the user how many devices we are now connected to.
            //
            UpdateStatus(false, "%d devices connected.", g_ucNumCurrentPeers);
        }

        //
        // Have we received a frame on one of the ED connections? We don't use
        // a critical section here since it doesn't really matter much if we
        // miss a poll.
        //
        if (g_ucPeerFrameSem)
        {
            uint8_t     pucMsg[MAX_APP_PAYLOAD], ucLen, ucLoop;

            /* process all frames waiting */
            for (ucLoop = 0; ucLoop < g_ucNumCurrentPeers; ucLoop++)
            {
                //
                // Receive the message.
                //
                if (SMPL_SUCCESS == SMPL_Receive(g_sLID[ucLoop], pucMsg,
                                                 &ucLen))
                {
                    //
                    // ...and pass it to the function that processes it.
                    //
                    ProcessMessage(g_sLID[ucLoop], pucMsg, ucLen);

                    //
                    // Decrement our frame semaphore.
                    //
                    BSP_ENTER_CRITICAL_SECTION(intState);
                    g_ucPeerFrameSem--;
                    BSP_EXIT_CRITICAL_SECTION(intState);
                }
            }
        }

        //
        // Have we been asked to change channel?
        //
        ucLastChannel = g_ucChannel;
        if (g_bChangeChannel)
        {
            //
            // Yes - go ahead and change to the next radio channel.
            //
            g_bChangeChannel = false;
            ChangeChannel();
        }
        else
        {
            //
            // No - check to see if we need to automatically change channel
            // due to interference on the current one.
            //
            CheckChangeChannel();
        }

        //
        // If the channel changed, update the display.
        //
        if(g_ucChannel != ucLastChannel)
        {
            UpdateStatus(false, "Changed to channel %d.", g_ucChannel);
        }

        //
        // If required, blink the "LEDs" to indicate we are waiting for a
        // message following a channel change.
        //
        BSP_ENTER_CRITICAL_SECTION(intState);
        if (g_ulBlinky)
        {
            if (++g_ulBlinky >= 0xF)
            {
                g_ulBlinky = 1;
                ToggleLED(1);
                ToggleLED(2);
            }
        }
        BSP_EXIT_CRITICAL_SECTION(intState);

        //
        // Process our widget message queue.
        //
        WidgetMessageQueueProcess();
    }
}
コード例 #27
0
//*****************************************************************************
//
// This function attempts to link to another SimpliciTI device by sending a
// link request.
//
//*****************************************************************************
tBoolean
LinkTo(void)
{
    smplStatus_t eRetcode;
    unsigned long ulCount;

    //
    // Turn both "LEDs" on.
    //
    SetLED(1, true);
    SetLED(2, true);

    //
    // Tell SimpliciTI to try to link to an access point.
    //
    for(ulCount = 1; ulCount <= 10; ulCount++)
    {
        //
        // Update the displayed count.  Note that we must process the widget
        // message queue here to ensure that the change makes it onto the
        // display.
        //
        UpdateStatus(false, "Link request %d (%s)", ulCount,
                     (ulCount > 1) ? MapSMPLStatus(eRetcode) : "Waiting");
        WidgetMessageQueueProcess();

        //
        // Try to link to the access point.
        //
        eRetcode = SMPL_Link(&sLinkID);
        if(eRetcode == SMPL_SUCCESS)
        {
            break;
        }

        //
        // Wait a bit before trying again.
        //
        NWK_DELAY(1000);

        //
        // Toggle both the LEDs
        //
        ToggleLED(1);
        ToggleLED(2);
    }

    //
    // Did we manage to link to the access point?
    //
    if(eRetcode == SMPL_SUCCESS)
    {
        //
        // Tell the user how we got on.
        //
        UpdateStatus(false, "Link successful.");
        SetLED(2, false);

        //
        // Turn on RX. Default is off.
        //
        SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0);

        //
        // Set the time at which we have to send the next packet to our peer to
        // one second in the future.
        //
        g_ulNextPacketTick = g_ulSysTickCount + TICKS_PER_SECOND;

        //
        // Tell the main loop that we established communication successfully.
        //
        return(true);
    }
    else
    {
        UpdateStatus(false, "Failed to link.");

        //
        // Tell the main loop that we failed to establish communication.
        //
        return(false);
    }
}
コード例 #28
0
ファイル: barebones.c プロジェクト: BronsonD/cm530
int main(void)
{
// Must include this line in all programs using "cm530.h/.c"
	SysInit();

	while(1)
	{
		// Reset the LEDs
		SetLED(TXD, 0);
		SetLED(RXD, 0);
		SetLED(AUX, 0);

		SetLED(MANAGE, 0);
		SetLED(PROGRAM, 0);
		SetLED(PLAY, 0);

		mDelay(1000);

		SetLED(TXD, 1);
		SetLED(RXD, 1);
		SetLED(AUX, 1);

		SetLED(MANAGE, 1);
		SetLED(PROGRAM, 1);
		SetLED(PLAY, 1);

		mDelay(1000);
	}

	return 0;
}
コード例 #29
0
//*****************************************************************************
//
// This is the main monitoring function for the applicaiton. It "sleeps" for
// 5 seconds or so then checks to see if there are any alerts being broadcast.
// If not, it toggles a LED and goes back to "sleep".  If an alert is received
// it switches into "babbling" mode where it retransmits the alert every 100mS
// to propagate the alert through the network.
//
// This function does not return.
//
//*****************************************************************************
void
MonitorForBadNews(void)
{
    uint8_t pucMsg[1], ucLen;
    unsigned long ulLoop;

    //
    // Turn off LEDs. Check for bad news will toggle one LED.  The other LED will
    // toggle when bad news message is sent.
    //
    SetLED(2, false);
    SetLED(1, false);

    //
    // Start with radio sleeping.
    //
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);

    while (1)
    {
        //
        // Spoof MCU sleeping...
        //
        for (ulLoop = 0; ulLoop < CHECK_RATE; ulLoop++)
        {
            SPIN_ABOUT_A_SECOND;
        }

        ToggleLED(1);

        //
        // Check the "sensor" to see if we need to send an alert.
        //
        if (g_bAlarmRaised)
        {
            //
            // The sensor has been activated. Start babbling.  This function
            // will not return.
            //
            Start2Babble();
        }

        //
        // Wake up the radio and receiver so that we can listen for others
        // babbling.
        //
        SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
        SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0);

        //
        // Stay on "long enough" to see if someone else is babbling
        //
        SPIN_ABOUT_A_QUARTER_SECOND;

        //
        // We're done with the radio so shut it down.
        //
        SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);

        //
        // Did we receive a message while the radio was on?
        //
        if (SMPL_SUCCESS == SMPL_Receive(SMPL_LINKID_USER_UUD, pucMsg, &ucLen))
        {
            //
            // Did we receive something and, if so, is it bad news?
            //
            if (ucLen && (pucMsg[0] == BAD_NEWS))
            {
                //
                // Bad news has been received so start babbling to pass the
                // alert on to the other devices in the network.
                //
                UpdateStatus(true, "Alarm received!");
                Start2Babble();
            }
        }
    }
}
コード例 #30
0
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bRetcode;
    smplStatus_t eRetcode;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus("Initializing...");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();

    //
    // Did we have a problem with the address?
    //
    if(!bRetcode)
    {
        //
        // Yes - make sure the display is updated then hang the app.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // Turn on both our LEDs
    //
    SetLED(1, true);
    SetLED(2, true);

    UpdateStatus("Waiting...");

    //
    // Initialize the SimpliciTI stack but don't set any receive callback.
    //
    while(1)
    {
        eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0);

        if(eRetcode == SMPL_SUCCESS)
        {
            break;
        }

        ToggleLED(1);
        ToggleLED(2);
        SPIN_ABOUT_A_SECOND;
    }

    //
    // Tell the user what's up.
    //
    UpdateStatus("Range Extender active.");

    //
    // Do nothing after this - the SimpliciTI stack code handles all the
    // access point function required.
    //
    while(1)
    {
        //
        // Process the widget message queue.
        //
        WidgetMessageQueueProcess();
    }
}