/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	//RFCOMM_SendFrame(0x10003000,0x10003004,4,4,130,0x10003200);
	uint16_t tick;
	SetupHardware();

	LPC_TIM0->TCR = 1;
	Led1On();
	Led2On();
	Led1Off();
	Led2Off();

	EVENT_USB_Host_DeviceUnattached();
		
	for (;;)
	{
		//uint8_t ButtonStatus = Buttons_GetStateMask();

	
		/* Check if the system update interval has elapsed */
		if(LPC_TIM0->IR &0x01)
		{
			/* Clear the timer compare flag */
			LPC_TIM0->IR |= 0x01;
			if (RFCOMM_SensorStream){
				Led1On();
			}
			else{
				if(tick++>=50)
				{
					tick = 0;
					Led1Not();
				}
			}
			/* If the bluetooth stack is active, manage timeouts within each layer */
			BluetoothAdapter_TickElapsed();
			KeyScan();
			if(sendFlag){
				rfcomm_send_data();
			}	
		}
		
		BluetoothAdapter_USBTask();
		USB_USBTask();
	}
}
void Led2Not(void)
{
	static uint8_t tog;
	if(tog){
		Led1On();
		tog = 0;
	}else{
		Led1Off();
		tog = 1;
	}
}
Exemple #3
0
/******************************************************************************
* LED_TurnOnLed
*
* Turn on one or more LEDs. Doesn't check/affect flashing states.
*******************************************************************************/
void LED_TurnOnLed(LED_t LEDNr)
{
  if (LEDNr & LED1)
    Led1On();
  if (LEDNr & LED2)
    Led2On();
  if (LEDNr & LED3)
    Led3On();
  if (LEDNr & LED4)
    Led4On();
}
Exemple #4
0
/******************************************************************************
* LED_StartSerialFlash
*
* Serial flashing lights
******************************************************************************/
void LED_StartSerialFlash(void)
{
  /* indicate going into flashing mode (must be done first) */
  LED_StartFlash(0);

  /* set up for serial lights */
  LED_TurnOffAllLeds();
  Led1On();
  mLedFlashingLEDs = LED1 | LED2; /* toggle these to on first flash */

  /* indicate in serial flash mode */
  mfLedInSerialMode = TRUE;
}
//----------------------------------------------------------------------------
void task_led1_func (void *par)
{
  unsigned int Blink = 1;

  while(1){
    if (Blink & 1) Led1On();
    else           Led1Off();

    Blink = Blink ^ 1;

    tn_task_sleep(250); // Sleep 250 ticks.
  }
}
void  Speaker_SetInterface(void)
{
  {
    if(pInformation->USBwValue == 0x0000){
      // Turn off LED
      Led1Off();
      bCameraOn = 0;
      //GPIOF->BSRR = GPIO_Pin_6;
    }else{
      // Turn ON LED
      //GPIOF->BRR = GPIO_Pin_6;
      Led1On();
      bCameraOn = 1;
    }
  }
}
/* ------------------------------------------------------------------ */
int main (void)
{
	uint8_t state = ST_TOP_MENU;
	uint8_t nextstate = ST_TOP_MENU;
	uint8_t key = KEY_NONE;
	func_p pStateFunc = states[state];
	
	
	/* disable watchdog */
	wdt_reset();
	Wdt_clear_flag();
	Wdt_change_enable();
	Wdt_stop();
		
	Clear_prescaler();
	InitLED();
	Led1On();
	
	Timer0_Init();
	SPEAKER_Init();
	BUTTON_Init();
	LCD_Init();
	
	sei();
	
	while (1)
	{
		key = BUTTON_GetKey();
		nextstate = pStateFunc(key);
		
		if (nextstate != state) {
			pStateFunc = states[nextstate];
			state = nextstate;
		}
		
	} /* end of while(1) */
	return 0;
}
RET_MAIN main(void)
{
#ifdef MTOUCH_DEBUG
    DEBUGDELAY* pDelay;
#endif
    // Board hardware initialization.
    SysBoardInit();

    // STEP 1
    // mTouch library initialization.
    MTouchInit();

    // STEP 2
    // Sensors initialization. All sensors must be initialized (see MTOUCH_SENSORS_NUMBER in mTouchConfig.h).
    // PLEASE READ "SENSOR OPTIMIZATION (DEBUG MODULE)" CHAPTER IN THE HELP FILE TO SELECT OPTIMAL PARAMETERS.
    // For example if sensor is connected to RB1/AN2 pin
    // MTouchSetSensor(0,      // sensor number
    //                 &TRISB, // port B
    //                 &LATB,
    //                 1,      // IO bit number
    //                 2,      // analog channel number
    //                 -1,     // press detection threshold by default (see MTOUCH_DEFAULT_THRESHOLD in mTouchConfig.h)
    //                 -1,     // oversampling by default (see MTOUCH_DEFAULT_OVERSAMPLING in mTouchConfig.h)
    //                 -1 );   // CTMU charge delay by default (see MTOUCH_DEFAULT_CHARGE_DELAY in mTouchConfig.h, not used for CVD acquisition)


    // sensor #0
    MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1);
    // sensor #1
    MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1);

#ifdef MTOUCH_DEBUG
    // Debug log initialization (allows streaming data to PC GUI). PC GUI helps to
    // choose right values for sensors' oversampling factors and thresholds.
    SysLogInit();

    // MTouchDebugDelay(sensorNumber) function calculates CTMU charge delay value
    // to provide charging sensor about 75% of AVdd.
    pDelay = MTouchDebugDelay(0);
    // Set adjusted CTMU charge delay value for the sensor.
    MTouchSetChargeDelay(0, pDelay->delay);
    pDelay = MTouchDebugDelay(1);
    MTouchSetChargeDelay(1, pDelay->delay);
#endif

    // STEP 3
    // Slider initialization. All sliders must be initialized (see MTOUCH_2CHSLIDERS_NUMBER in mTouchConfig.h).
    // For example if slider is connected to sensor 5 and sensor 11
    // MTouchSet2ChSlider(0,           // slider number
    //                    5,           // first sensor number
    //                    11);         // second sensor number

    // slider #0
    MTouchSet2ChSlider(0, 0, 1);

    // STEP 4
    // Timer interrupt initialization to call mTouch acquisition pereodically.
    SysTimerInit();


    while(1)
    {

        // STEP 5
        // Decode all controls.
        MTouchDecode();


        // STEP 6
        // Get current value of the slider.

        if(MTouchGet2ChSliderState(0) == CONTROL_PRESSED)
        {
            Led_ALLOff();

            if(MTouchGet2ChSliderValue(0) > 15*1000/16) {
                Led15On();
            }

            else if(MTouchGet2ChSliderValue(0) > 14*1000/16) {
                Led14On();
            }

            else if(MTouchGet2ChSliderValue(0) > 13*1000/16) {
                Led13On();
            }

            else if(MTouchGet2ChSliderValue(0) > 12*1000/16) {
                Led12On();
            }

            else if(MTouchGet2ChSliderValue(0) > 11*1000/16) {
                Led11On();
            }

            else if(MTouchGet2ChSliderValue(0) > 10*1000/16) {
                Led10On();
            }

            else if(MTouchGet2ChSliderValue(0) > 9*1000/16)  {
                Led9On();
            }

            else if(MTouchGet2ChSliderValue(0) > 8*1000/16)  {
                Led8On();
            }

            else if(MTouchGet2ChSliderValue(0) > 7*1000/16)  {
                Led7On();
            }

            else if(MTouchGet2ChSliderValue(0) > 6*1000/16)  {
                Led6On();
            }

            else if(MTouchGet2ChSliderValue(0) > 5*1000/16)  {
                Led5On();
            }

            else if(MTouchGet2ChSliderValue(0) > 4*1000/16)  {
                Led4On();
            }

            else if(MTouchGet2ChSliderValue(0) > 3*1000/16)  {
                Led3On();
            }

            else if(MTouchGet2ChSliderValue(0) > 2*1000/16)  {
                Led2On();
            }

            else if(MTouchGet2ChSliderValue(0) > 1*1000/16)  {
                Led1On();
            }

            else if(MTouchGet2ChSliderValue(0) > 0)          {
                Led0On();
            }
        }

#ifdef MTOUCH_DEBUG
        // Log data from sensors to PC GUI.
        MTouchDebugLogDeltas();

#endif


    }

}
RET_MAIN main(void)
{
#ifdef MTOUCH_DEBUG
DEBUGDELAY* pDelay;
#endif
UINT8  i;

    // Board hardware initialization.
    SysBoardInit();

    // Clear sleep timeout counter.
    SleepResetTimeoutCounter();

    // Clear sleep mode flag.
    SleepSetRunMode();


    // mTouch library initialization.
    MTouchInit();

    // Sensors initialization. All sensors must be initialized (see MTOUCH_SENSORS_NUMBER in mTouchConfig.h).
	// PLEASE READ "SENSOR OPTIMIZATION (DEBUG MODULE)" CHAPTER IN THE HELP FILE TO SELECT OPTIMAL PARAMETERS.
    // For example if sensor is connected to RB1/AN2 pin
    // MTouchSetSensor(0,      // sensor number
    //                 &TRISB, // port B
    //                 &LATB,
    //                 1,      // IO bit number
    //                 2,      // analog channel number
    //                 -1,     // press detection threshold by default (see MTOUCH_DEFAULT_THRESHOLD in mTouchConfig.h)
    //                 -1,     // oversampling by default (see MTOUCH_DEFAULT_OVERSAMPLING in mTouchConfig.h)
    //                 -1 );   // CTMU charge delay by default (see MTOUCH_DEFAULT_CHARGE_DELAY in mTouchConfig.h, not used for CVD acquisition)

                  
    // sensor #0
    MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1);
    // sensor #1
    MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1); 
    // sensor #2
    MTouchSetSensor(2, CH2_TRIS, CH2_LAT, CH2_IO_BIT, CH2_AN_NUM, -1, -1, -1);  
    // sensor #3
    MTouchSetSensor(3, CH3_TRIS, CH3_LAT, CH3_IO_BIT, CH3_AN_NUM, -1, -1, -1);  
    // sensor #4
    MTouchSetSensor(4, CH4_TRIS, CH4_LAT, CH4_IO_BIT, CH4_AN_NUM, -1, -1, -1);  
    // sensor #5
    MTouchSetSensor(5, CH5_TRIS, CH5_LAT, CH5_IO_BIT, CH5_AN_NUM, -1, -1, -1);  
    // sensor #6
    MTouchSetSensor(6, CH6_TRIS, CH6_LAT, CH6_IO_BIT, CH6_AN_NUM, -1, -1, -1);  
    // sensor #7
    MTouchSetSensor(7, CH7_TRIS, CH7_LAT, CH7_IO_BIT, CH7_AN_NUM, -1, -1, -1);

#ifdef MTOUCH_DEBUG
    // MTouchDebugDelay(sensorNumber) function calculates CTMU charge delay value
    // to provide charging sensor about 75% of AVdd.
    pDelay = MTouchDebugDelay(0);
    // Set adjusted CTMU charge delay value for the sensor.
    MTouchSetChargeDelay(0, pDelay->delay);
    pDelay = MTouchDebugDelay(1);
    MTouchSetChargeDelay(1, pDelay->delay);
    pDelay = MTouchDebugDelay(2);
    MTouchSetChargeDelay(2, pDelay->delay);
    pDelay = MTouchDebugDelay(3);
    MTouchSetChargeDelay(3, pDelay->delay);
    pDelay = MTouchDebugDelay(4);
    MTouchSetChargeDelay(4, pDelay->delay);
    pDelay = MTouchDebugDelay(5);
    MTouchSetChargeDelay(5, pDelay->delay);
    pDelay = MTouchDebugDelay(6);
    MTouchSetChargeDelay(6, pDelay->delay);
    pDelay = MTouchDebugDelay(7);
    MTouchSetChargeDelay(7, pDelay->delay);

#endif

    // Timer interrupt initialization to call mTouch acquisition pereodically.
    SysTimerInit();

    while(1)
    {
        // Get current states of the buttons.
        // If any sensor is pressed then reset sleep mode timeout counter.
        Led_ALLOff();
        // sensor #0
        if(MTouchGetSensorState(0) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led0On();} 
        // sensor #1
        if(MTouchGetSensorState(1) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led1On();}
        // sensor #2
        if(MTouchGetSensorState(2) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led2On();}
        // sensor #3
        if(MTouchGetSensorState(3) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led3On();}
        // sensor #4
        if(MTouchGetSensorState(4) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led4On();}
        // sensor #5
        if(MTouchGetSensorState(5) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led5On();}
        // sensor #6
        if(MTouchGetSensorState(6) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led6On();}
        // sensor #7
        if(MTouchGetSensorState(7) == SENSOR_PRESSED) { SleepResetTimeoutCounter(); Led7On();}


        // If the timeout counter transition is from sleep to run value then
        // change mode for normal operation.
        if(SleepIsWakeUpEvent())
        {
             
            // Disable watchdog timer.
            SysDisableWDT();

            // Initialize sensors
            MTouchInitializeSensor(0);
            MTouchInitializeSensor(1);
            MTouchInitializeSensor(2);
            MTouchInitializeSensor(3);
            MTouchInitializeSensor(4);
            MTouchInitializeSensor(5);
            MTouchInitializeSensor(6);
            MTouchInitializeSensor(7);

            // Enable timer interrupt
            SysEnableTimerInterrupt();

            // Clear sleep mode flag.
            SleepSetRunMode();

        }

        // If the timeout counter transition is from run to sleep value then
        // change mode for power save operation.
        if(SleepIsTimeoutEvent())
        {

            // Disable timer interrupt
            SysDisableTimerInterrupt();

            // Enable watchdog timer to wakeup.
            SysEnableWDT();

            // Set sleep mode flag.
            SleepSetSleepMode();
           
        }


        // Check sleep mode flag.
        if(SleepIsSleepMode())
        {

            // Indicate power saving mode.
            Led15On();
            
            // Enter device sleep mode (sleep time is 1024 mS).
            // Device will wake up from watchdog timer.
            Sleep();

            // Reset watchdog timer.
            ClrWdt();

            for(i=0; i<4*MTOUCH_DEFAULT_OVERSAMPLING; i++)
            {
                // Run acquisition.
                MTouchAcquisition();

                // Reset watchdog timer.
                ClrWdt();
            }


        }else{

            SleepIncrementTimeoutCounter();

        }
            
    }

}
RET_MAIN main(void)
{
#ifdef MTOUCH_DEBUG
DEBUGDELAY*   pDelay;
#endif
    // Board hardware initialization.
    SysBoardInit();

    // STEP 1
    // mTouch library initialization.
    MTouchInit();

    // STEP 2
    // Sensors initialization. All sensors must be initialized (see MTOUCH_SENSORS_NUMBER in mTouchConfig.h).
	// PLEASE READ "SENSOR OPTIMIZATION (DEBUG MODULE)" CHAPTER IN THE HELP FILE TO SELECT OPTIMAL PARAMETERS.
    // For example if sensor is connected to RB1/AN2 pin
    // MTouchSetSensor(0,      // sensor number
    //                 &TRISB, // port B
    //                 &LATB,
    //                 1,      // IO bit number
    //                 2,      // analog channel number
    //                 -1,     // press detection threshold by default (see MTOUCH_DEFAULT_THRESHOLD in mTouchConfig.h)
    //                 -1,     // oversampling by default (see MTOUCH_DEFAULT_OVERSAMPLING in mTouchConfig.h)
    //                 -1 );   // CTMU charge delay by default (see MTOUCH_DEFAULT_CHARGE_DELAY in mTouchConfig.h, not used for CVD acquisition)

                  
    // sensor #0
    MTouchSetSensor(0, CH0_TRIS, CH0_LAT, CH0_IO_BIT, CH0_AN_NUM, -1, -1, -1);
    // sensor #1
    MTouchSetSensor(1, CH1_TRIS, CH1_LAT, CH1_IO_BIT, CH1_AN_NUM, -1, -1, -1);  
    // sensor #2
    MTouchSetSensor(2, CH2_TRIS, CH2_LAT, CH2_IO_BIT, CH2_AN_NUM, -1, -1, -1);  
    // sensor #3
    MTouchSetSensor(3, CH3_TRIS, CH3_LAT, CH3_IO_BIT, CH3_AN_NUM, -1, -1, -1);  
    // sensor #4
    MTouchSetSensor(4, CH4_TRIS, CH4_LAT, CH4_IO_BIT, CH4_AN_NUM, -1, -1, -1);  
    // sensor #5
    MTouchSetSensor(5, CH5_TRIS, CH5_LAT, CH5_IO_BIT, CH5_AN_NUM, -1, -1, -1);  
    // sensor #6
    MTouchSetSensor(6, CH6_TRIS, CH6_LAT, CH6_IO_BIT, CH6_AN_NUM, -1, -1, -1);  
    // sensor #7
    MTouchSetSensor(7, CH7_TRIS, CH7_LAT, CH7_IO_BIT, CH7_AN_NUM, -1, -1, -1);

#ifdef MTOUCH_DEBUG
    // Debug log initialization (allows streaming data to PC GUI). PC GUI helps to
    // choose right values for sensors' oversampling factors and thresholds.
    SysLogInit();

	// MTouchDebugDelay(sensorNumber) function calculates an optimal CTMU charge delay value
    // to provide charging sensor about 75% of AVdd.
    pDelay = MTouchDebugDelay(0);
    // Set the adjusted optimal CTMU charge delay value for the sensor.
    MTouchSetChargeDelay(0, pDelay->delay);

    pDelay = MTouchDebugDelay(1);
    MTouchSetChargeDelay(1, pDelay->delay);
    pDelay = MTouchDebugDelay(2);
    MTouchSetChargeDelay(2, pDelay->delay);
    pDelay = MTouchDebugDelay(3);
    MTouchSetChargeDelay(3, pDelay->delay);
    pDelay = MTouchDebugDelay(4);
    MTouchSetChargeDelay(4, pDelay->delay);
    pDelay = MTouchDebugDelay(5);
    MTouchSetChargeDelay(5, pDelay->delay);
    pDelay = MTouchDebugDelay(6);
    MTouchSetChargeDelay(6, pDelay->delay);
    pDelay = MTouchDebugDelay(7);
    MTouchSetChargeDelay(7, pDelay->delay);

#endif

    // STEP 3
    // Timer interrupt initialization to call mTouch acquisition pereodically.
    SysTimerInit();


    while(1)
    {

        // STEP 4
        // Get current states of the basic buttons.

        Led_ALLOff();
        // button #0
        if(MTouchGetSensorState(0) == SENSOR_PRESSED) { Led0On(); }
        // button #1
        if(MTouchGetSensorState(1) == SENSOR_PRESSED) { Led1On(); }
        // button #2
        if(MTouchGetSensorState(2) == SENSOR_PRESSED) { Led2On(); }
        // button #3
        if(MTouchGetSensorState(3) == SENSOR_PRESSED) { Led3On(); }
        // button #4
        if(MTouchGetSensorState(4) == SENSOR_PRESSED) { Led4On(); }
        // button #5
        if(MTouchGetSensorState(5) == SENSOR_PRESSED) { Led5On(); }
        // button #6
        if(MTouchGetSensorState(6) == SENSOR_PRESSED) { Led6On(); }
        // button #7
        if(MTouchGetSensorState(7) == SENSOR_PRESSED) { Led7On(); }


        #ifdef MTOUCH_DEBUG
           // Log data from sensors to PC GUI.
           MTouchDebugLogDeltas();

        #endif

     
    }

}