Ejemplo n.º 1
0
// Main Function
void main(void)
{ 
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  
  // establish baseline
  TI_CAPT_Init_Baseline(&slider);
  TI_CAPT_Update_Baseline(&slider,5);
  TI_CAPT_Init_Baseline(&menu);
  TI_CAPT_Update_Baseline(&menu,5);

  // Main loop starts here
  while (1)
  {
    // TI_CAPT_Raw(&slider,dCNT);
	// TI_CAPT_Custom(&slider,dCNT);
    position = TI_CAPT_Slider(&slider);
	direction = (struct Element*)TI_CAPT_Buttons(&menu); 
	if(direction == (struct Element*)&right)
	{
	    __no_operation();
	}
	if(direction == (struct Element*)&left);
	{
	    __no_operation();
	}
    if(position != ILLEGAL_SLIDER_WHEEL_POSITION)   
    {
        __no_operation();
    }
    __delay_cycles(100); 
  }
} // End Main
/* ----------------MeasureCapBaseLine--------------------------------------
 * Re-measure the baseline capacitance of the wheel elements & the center
 * button. To be called after each wake up event.
 * ------------------------------------------------------------------------*/
void MeasureCapBaseLine(void)
{
  P1OUT = BIT0;

	/* Set DCO to 8MHz */
	/* SMCLK = 8MHz/8 = 1MHz */
//	BCSCTL1 = CALBC1_8MHZ;
//	DCOCTL = CALDCO_8MHZ;
//	BCSCTL2 |= DIVS_3;

	/* SMCLK = 1MHz/4 = 250kHz */
//	BCSCTL1 = CALBC1_1MHZ;
//	DCOCTL = CALDCO_1MHZ;
//	BCSCTL2 |= DIVS_2;

	/* Set SMCLK to 1.5MHz */
	BCSCTL1 = CALBC1_12MHZ;
	DCOCTL = CALDCO_12MHZ;
//	BCSCTL2 |= DIVS_3;

  TI_CAPT_Init_Baseline(&wheel);
  TI_CAPT_Update_Baseline(&wheel,2);
  TI_CAPT_Init_Baseline(&middle_button);
  TI_CAPT_Update_Baseline(&middle_button,2);
}
Ejemplo n.º 3
0
// Main Function
void main(void)
{
    uint8_t i;
    WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer

    BCSCTL3 |= LFXT1S_2;                  // LFXT1 = VLO

    TI_CAPT_Init_Baseline(&keypad);
    TI_CAPT_Update_Baseline(&keypad,5);

    // Main loop starts here
    while (1)
    {
        keypressed = (struct Element *)TI_CAPT_Buttons(&keypad);
        if(keypressed)
        {
            for(i=0; i<NUM_SEN; i++)
            {
                if (keypressed == address_list[i])
                {
                    __no_operation();
                }
            }
        }
    }
} // End Main
Ejemplo n.º 4
0
// Main Function
void main(void)
{ 

  // Initialize System Clocks
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  
  //Clock Setting
  CSCTL1 &= ~(DCORSEL_7);                 // Clear DCO frequency select bits first
  CSCTL1 |= DCORSEL_3;                    // Set DCO = 8MHz, max in G6021
  CSCTL2 = FLLD_0 + 243;                  // DCODIV = 8MHz
  CSCTL3 |= SELREF__REFOCLK;              // Set REFO as FLL reference source
  CSCTL4 = SELMS__DCOCLKDIV | SELREF__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
  CSCTL5 |= DIVM_0 | DIVS_0;              // SMCLK = MCLK = DCODIV/1 = 8MHz

  // Initializing GPIO
  P8DIR |= BIT1;                         //Set the pin controlling the center LED P8.1  as output pin
  PM5CTL0 &= ~LOCKLPM5;


  // Initialize Baseline measurement
  TI_CAPT_Init_Baseline(&one_button);
  
  //TI_CAPT_Init_Baseline(&one_button);

   //Update baseline measurement (Average 100 measurements)
  
  TI_CAPT_Update_Baseline(&one_button,100);

  // Main loop starts here
  while (1)
  {
  	
  	#ifdef ELEMENT_CHARACTERIZATION_MODE
	// Get the raw delta counts for element characterization 
	TI_CAPT_Custom(&one_button,&dCnt);
	__no_operation(); 					// Set breakpoint here	
	#endif
	  	
	#ifndef ELEMENT_CHARACTERIZATION_MODE	  	
	// Check if the middle element sensor has been triggered. The API call
	// compares the value from the sensor against the threshold to determine
	// trigger condition

	if(TI_CAPT_Button(&one_button))
	{
		// Do something
		P8OUT |= BIT1;                            // Turn on center LED
	}
	else
	{
		P8OUT &= ~BIT1;                           // Turn off center LED
	}
	
    // Put the MSP430 into LPM3 for a certain DELAY period
    sleep(DELAY);
    #endif
  }
} // End Main
Ejemplo n.º 5
0
/*
 *  ======== main() ========
 */
uint16_t main(void)
{ 
	volatile uint8_t i;
    WDTCTL = WDTPW + WDTHOLD;   /* Stop watchdog timer */
    /* Initialize IO */
    P1DIR = 0xFF;
    P2DIR = 0xFF;
    P3DIR = 0xFF;
    P4DIR = 0xFF;
    PJDIR = 0xFF;
    P1OUT = 0;
    P2OUT = 0;
    P3OUT = 0;
    P4OUT = 0;
    PJOUT = 0;
    /* XT1 Setup taken from msp430fr59xx_CS_03.c code example. */
    PJSEL0 |= BIT4 + BIT5;
    CSCTL0 = CSKEY;
    CSCTL1 = DCOFSEL_6;                    /* Set DCO = 8MHz */
    CSCTL2 = SELA__LFXTCLK + SELS__DCOCLK + SELM__DCOCLK;
    CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0;     /* ACLK/1, SMCLK/1, MCLK/1 */
    CSCTL4 |= LFXTDRIVE_0;
    CSCTL4 &= ~LFXTOFF;
    do
    {
        CSCTL5 &= ~LFXTOFFG;   /* Clear XT1 fault flag */
        SFRIFG1 &= ~OFIFG;
    }while (SFRIFG1&OFIFG);    /* Test oscillator fault flag */   
    
    /* establish baseline */
    TI_CAPT_Init_Baseline(&keyPad);
    TI_CAPT_Update_Baseline(&keyPad,5);

    /* Main loop starts here */
    while (1)
    {
        activeKey = (struct Element *)TI_CAPT_Buttons(&keyPad);
        for(i=0;i<6;i++)
        {
            //if(activeKey == keyAddress[i])
            if(activeKey == keyPad.arrayPtr[i])
            {
                *(uint8_t *)ledPort[i] |= ledBit[i];
            }
        }
    	// TI_CAPT_Custom(&keyPad,dCnt);
        /* 
         * 32ms delay. This delay can be replaced with other application tasks. 
         */
        sleep(1000);
        /* Turn off all LEDs before next measurement */
        for(i=0;i<6;i++)
        {
            *(uint8_t *)ledPort[i] &= ~ledBit[i];
        }
    }
} /* End Main */
Ejemplo n.º 6
0
Archivo: main.c Proyecto: esmil/SLAA419
// Main Function
void main(void)
{ 

  // Initialize System Clocks
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  BCSCTL1 = CALBC1_1MHZ;                // Set DCO to 1, 8, 12 or 16MHz
  DCOCTL = CALDCO_1MHZ;
  BCSCTL2 |= DIVS_2;                    // divide SMCLK by 4 for 250khz      
  BCSCTL3 |= LFXT1S_2;                  // LFXT1 = VLO
  
  P1OUT = 0x00;							// Clear Port 1 bits
  P1DIR |= BIT0;						// Set P1.0 as output pin

  P2SEL &= ~(BIT6 + BIT7);				// Configure XIN (P2.6) and XOUT (P2.7) to GPIO
  P2OUT = 0x00;							// Drive all Port 2 pins low
  P2DIR = 0xFF;							// Configure all Port 2 pins outputs

  // Initialize Baseline measurement
  TI_CAPT_Init_Baseline(&one_button);
  
  // Update baseline measurement (Average 5 measurements)
  TI_CAPT_Update_Baseline(&one_button,5);  
  
  // Main loop starts here
  while (1)
  {
  	
  	#ifdef ELEMENT_CHARACTERIZATION_MODE
	// Get the raw delta counts for element characterization 
	TI_CAPT_Custom(&one_button,&dCnt);
	__no_operation(); 					// Set breakpoint here	
	#endif
	  	
	#ifndef ELEMENT_CHARACTERIZATION_MODE	  	
	// Check if the middle element sensor has been triggered. The API call
	// compares the value from the sensor against the threshold to determine
	// trigger condition  	
	if(TI_CAPT_Button(&one_button))
	{
		// Do something
		P1OUT |= BIT0;                            // Turn on center LED   
	}
	else
	{
		P1OUT &= ~BIT0;                           // Turn off center LED 
	}
	
    // Put the MSP430 into LPM3 for a certain DELAY period
    sleep(DELAY);		
    #endif

  }
} // End Main
Ejemplo n.º 7
0
// Main Function
void main(void)
{ 

  // Initialize System Clocks
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  
  //Clock Setting
  CSCTL0_H = 0xA5;                          // Unlock CS
  CSCTL1 = DCORSEL + DCOFSEL_5;             // Set DCO = 20MHz, use this clk when fRO
  CSCTL2 = SELA__VLOCLK + SELS_3 + SELM_3;  // set SMCLK = MCLK = DCO  LFXT1 = VLO
  CSCTL0_H = 0;                             // Lock CS registers

  P4DIR |= BIT2;						// Set the pin controlling the center LED P4.2  as output pin

  // Initialize Baseline measurement
  TI_CAPT_Init_Baseline(&one_button);
  
  // Update baseline measurement (Average 5 measurements)
  TI_CAPT_Update_Baseline(&one_button,5);  
  
  // Main loop starts here
  while (1)
  {
  	
  	#ifdef ELEMENT_CHARACTERIZATION_MODE
	// Get the raw delta counts for element characterization 
	TI_CAPT_Custom(&one_button,&dCnt);
	__no_operation(); 					// Set breakpoint here	
	#endif
	  	
	#ifndef ELEMENT_CHARACTERIZATION_MODE	  	
	// Check if the middle element sensor has been triggered. The API call
	// compares the value from the sensor against the threshold to determine
	// trigger condition

	if(TI_CAPT_Button(&one_button))
	{
		// Do something
		P4OUT |= BIT2;                            // Turn on center LED
	}
	else
	{
		P4OUT &= ~BIT2;                           // Turn off center LED
	}
	
    // Put the MSP430 into LPM3 for a certain DELAY period
    sleep(DELAY);
    #endif
  }
} // End Main
Ejemplo n.º 8
0
// Main Function
void main(void)
{ 
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer

  // establish baseline
  TI_CAPT_Init_Baseline(&slider);
  TI_CAPT_Update_Baseline(&slider,5);

  // Main loop starts here
  while (1)
  {
    position = TI_CAPT_Slider(&slider);
    //TI_CAPT_Custom(&slider,dCnt);
    if(position != ILLEGAL_SLIDER_WHEEL_POSITION)   
    {
        __no_operation();
    }
    __delay_cycles(100); 

  }
} // End Main
Ejemplo n.º 9
0
// Main Function
void main(void)
{ 
  
  uint8_t last = 0;
  
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  BCSCTL1 = CALBC1_16MHZ;               // Set DCO to 1, 8, 12 or 16MHz
  DCOCTL = CALDCO_16MHZ;
  BCSCTL1 |= DIVA_0;                    // ACLK/1 [ACLK/(0:1,1:2,2:4,3:8)]
  //BCSCTL2 |= DIVS_3;                  // SMCLK/8 [SMCLK/(0:1,1:2,2:4,3:8)]
  BCSCTL3 |= LFXT1S_2;                  // LFXT1 = VLO Clock Source
  
  P1OUT |= BIT0;				// P1.0 out
  P1DIR |= BIT0;				// P1.0 high
  
  P2DIR |= BIT0 | BIT1 | BIT4 | BIT5;			// Configure  Port 2 pins outputs

  // Initialize Baseline measurement
  TI_CAPT_Init_Baseline(&button_bar);
  
  // Update baseline measurement (Average 5 measurements)
  TI_CAPT_Update_Baseline(&button_bar,5);  
  
  SPISetup();                         // Initialize SPI Display
  //drawBitmap(blackbird_96_64, 96, 8, 0, 0);    
  
  clear();
  //setcharmode(1); //largechars
  //writeString(2,1,"Press button!");
  
  // Main loop starts here
  while (1)
  {
  	
  	#ifdef ELEMENT_CHARACTERIZATION_MODE
	// Get the raw delta counts for element characterization 
	TI_CAPT_Custom(&button_bar,wheelCnt);
	__no_operation(); 					// Set breakpoint here	
	#endif
	
	
	#ifndef ELEMENT_CHARACTERIZATION_MODE
	// Return the pointer to the element which has been touched
	keyPressed = (struct Element *)TI_CAPT_Buttons(&button_bar);
	
	// If a button has been touched, then take some action
	if(keyPressed)
	{
		// Up Element
		if(keyPressed == &a_element)
		{
			P1OUT |= BIT0;				// Turn on center LED
                        if (last != 2) {                        
                            clear();
                            last = 2;
                            drawBitmap(big_1, 32, 6, 32, 1);
                            //writeString(4,3,"A Pressed");
                        }
		}
		if(keyPressed == &b_element)
		{
			P1OUT |= BIT0;				// Turn on center LED
                        if (last != 3) {                        
                            clear();
                            last = 3;
                            drawBitmap(big_2, 32, 6, 32, 1);
                            //writeString(4,3,"B Pressed");
                        }
		}
		if(keyPressed == &c_element)
		{
			P1OUT |= BIT0;				// Turn on center LED
                        if (last != 1) {                        
                            clear();
                            last = 1;
                            drawBitmap(big_3, 32, 6, 32, 1);
                            //writeString(4,3,"C Pressed");
                        }
		}
		if(keyPressed == &d_element)
		{
			P1OUT |= BIT0;				// Turn on center LED
                        if (last != 4) {                        
                            clear();
                            last = 4;
                            drawBitmap(big_4, 32, 6, 32, 1);
                            //writeString(4,3,"D Pressed");
                        }
		}		
	  }
	  else
	  {
	      P1OUT &= ~(BIT0);				// Turn off center LED
              if (last != 0) 
              {
                drawBitmap(blackbird_96_64, 96, 8, 0, 0);  
                //writeString(4,4,"Press a button");
                last = 0;
              }
	  }      
        
    // Put the MSP430 into LPM3 for a certain DELAY period
    sleep(DELAY);
    #endif

  }
} // End Main
Ejemplo n.º 10
0
/**
 * Setup the capacitive buttons for reading.
 * This sets a baseline capacitance level when all buttons are unpressed
 * so that a chance in capacitance can be used to detect a button press.
 *
 */
void configCapButtons(void)
{
	/* establish baseline for cap touch monitoring */
	TI_CAPT_Init_Baseline(&keypad);
	TI_CAPT_Update_Baseline(&keypad,5);
}
//*****************************************************************************
//
// Main cap-touch example.
//
//*****************************************************************************
int
main(void)
{
    uint8_t ui8CenterButtonTouched;
    uint32_t ui32WheelTouchCounter;
    uint8_t ui8ConvertedWheelPosition;
    uint8_t ui8GestureDetected;
    uint8_t ui8Loop;

    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the clocking to run directly from the PLL at 80 MHz.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    //
    // Initialize a few GPIO outputs for the LEDs
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5);

    //
    // Turn on the Center LED
    //
    ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5);

    //
    // Initialize the UART.
    //
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioConfig(0, 9600, ROM_SysCtlClockGet());

    //
    // Configure the pins needed for capacitive touch sensing.  The capsense
    // driver assumes that these pins are already configured, and that they
    // will be accessed through the AHB bus
    //
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOA);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_2);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_3);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_4);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_6);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_7);

    //
    // Start up Systick to measure time.  This is also required by the capsense
    // drivers.
    //
    ROM_SysTickPeriodSet(0x00FFFFFF);
    ROM_SysTickEnable();

    //
    // Set the baseline capacitance measurements for our wheel and center
    // button.
    //
    TI_CAPT_Init_Baseline(&g_sSensorWheel);
    TI_CAPT_Update_Baseline(&g_sSensorWheel, 10);
    TI_CAPT_Init_Baseline(&g_sMiddleButton);
    TI_CAPT_Update_Baseline(&g_sMiddleButton, 10);

    //
    // Send the "sleep" code.  The TIVA C-series version of this app doesn't
    // actually sleep, but the MSP430-based GUI it interacts with expects to
    // see this code on startup, so we will provide it here.
    //
    UARTprintf("\0xDE\0xAD");

    //
    // Send the "awake" code.
    //
    UARTprintf("\0xBE\0xEF");

    //
    // Perform an LED startup sequence.
    //
    for(ui8Loop = 0; ui8Loop < 16; ui8Loop++)
    {
        LEDOutput(ui8Loop);
        DelayMs(10);
    }

    LEDOutput(0);


    //
    // Assume that the center button starts off "untouched", the wheel has no
    // position, and no gestures are in progress.
    //
    ui8CenterButtonTouched = 0;
    ui8ConvertedWheelPosition = INVALID_CONVERTED_POSITION;
    ui8GestureDetected = 0;

    //
    // This "wheel counter" gets incremented when a button on the wheel is held
    // down.  Every time it hits the value of WHEEL_TOUCH_DELAY, the device
    // sends a signal to the GUI reporting another button press.  We want this
    // delay normally, but we'll set the counter to just below the threshold
    // for now, so we'll avoid any percieved lag between the initial button
    // press and the first position report to the GUI.
    //
    ui32WheelTouchCounter = WHEEL_TOUCH_DELAY - 1;

    //
    // Begin the main capsense loop.
    //
    while(1)
    {
        //
        // Start by taking a fresh measurement from the wheel.  If it remains
        // set to ILLEGAL_SLIDER_WHEEL_POSITION, we will know it has not been
        // touched at all.  Otherwise we will have an updated position.
        //
        g_ui32WheelPosition = ILLEGAL_SLIDER_WHEEL_POSITION;
        g_ui32WheelPosition = TI_CAPT_Wheel(&g_sSensorWheel);

        //
        // If we registered a touch somewhere on the wheel, we will need to
        // figure out how to report that touch back to the GUI on the PC.
        //
        if(g_ui32WheelPosition != ILLEGAL_SLIDER_WHEEL_POSITION)
        {
            //
            // First, make sure we're not reporting center button touches while
            // the wheel is active.
            //
            ui8CenterButtonTouched = 0;

            //
            // We need to do a quick formatting change on the wheel position.
            // The "zero" postion as reported by the driver is about 40 degrees
            // off from "up" on the physical wheel.  We'll do that correction
            // here.
            //
            if(g_ui32WheelPosition < 8)
            {
                g_ui32WheelPosition += 64 - 8;
            }
            else
            {
                g_ui32WheelPosition -= 8;
            }

            //
            // We also need to reduce the effective number of positions on the
            // wheel.  The driver reports a wheel position from zero to
            // sixty-three, but the GUI only recognizes positions from zero to
            // sixteen.  Dividing our position by four accomplishes the
            // necessary conversion.
            //
            g_ui32WheelPosition = g_ui32WheelPosition >> 2;

            //
            // Now that we have a properly formatted wheel position, we will
            // use the GetGesture function to determine whether the user has
            // been sliding their finger around the wheel.  If so, this function
            // will return the magnitude and direction of the slide (Check the
            // function description for an example of how this is formated).
            // Otherwise, we will get back a zero.
            //
            ui8ConvertedWheelPosition = GetGesture(g_ui32WheelPosition);

            //
            // If the magnitude of our slide was one wheel position (of
            // sixteen) or less, don't register it.  This prevents excessive
            // reporting of toggles between two adjacent wheel positions.
            //
            if((ui8GestureDetected == 0) &&
               ((ui8ConvertedWheelPosition <= 1) ||
                (ui8ConvertedWheelPosition == 0x11) ||
                (ui8ConvertedWheelPosition == 0x10)))
            {
                //
                // If we obtained a valid wheel position last time we ran this
                // loop, keep our wheel position set to that instead of
                // updating it.  This prevents a mismatch between our recorded
                // absolute position and our recorded swipe magnitude.
                //
                if(g_ui32PreviousWheelPosition !=
                   ILLEGAL_SLIDER_WHEEL_POSITION)
                {
                    g_ui32WheelPosition = g_ui32PreviousWheelPosition;
                }

                //
                // Set the swipe magnitude to zero.
                //
                ui8ConvertedWheelPosition = 0;
            }

            //
            // We've made all of the position adjustments we're going to make,
            // so turn on LEDs to indicate that we've detected a finger on the
            // wheel.
            //
            LEDOutput(g_ui32WheelPosition);

            //
            // If the (adjusted) magnitude of the swipe we detected earlier is
            // valid and non-zero, we should alert the GUI that a gesture is
            // occurring.
            //
            if((ui8ConvertedWheelPosition != 0) &&
               (ui8ConvertedWheelPosition != 16) &&
               (ui8ConvertedWheelPosition != INVALID_CONVERTED_POSITION))
            {
                //
                // If this is a new gesture, we will need to send the gesture
                // start code.
                //
                if(ui8GestureDetected == 0)
                {
                    //
                    // Remember that we've started a gesture.
                    //
                    ui8GestureDetected = 1;

                    //
                    // Transmit gesture start status update & position via UART
                    // to PC.
                    //
                    ROM_UARTCharPut(UART0_BASE, GESTURE_START);
                    ROM_UARTCharPut(UART0_BASE, (g_ui32PreviousWheelPosition +
                                                 GESTURE_POSITION_OFFSET));
                }

                //
                // Transmit gesture & position via UART to PC
                //
                ROM_UARTCharPut(UART0_BASE, ui8ConvertedWheelPosition);
                ROM_UARTCharPut(UART0_BASE, (g_ui32WheelPosition +
                                             GESTURE_POSITION_OFFSET));
            }
            else
            {
                //
                // If we get here, the wheel has been touched, but there hasn't
                // been any sliding recently.  If there hasn't been any sliding
                // AT ALL, then this is a "press" event, and we need to start
                // sending press-style updates to the PC
                //
                if(ui8GestureDetected == 0)
                {
                    //
                    // Increment our wheel counter.
                    //
                    ui32WheelTouchCounter = ui32WheelTouchCounter + 1;

                    //
                    // If the user's finger is still in the same place...
                    //
                    if(ui32WheelTouchCounter >= WHEEL_TOUCH_DELAY)
                    {
                        //
                        // Transmit wheel position (twice) via UART to PC.
                        //
                        ui32WheelTouchCounter = 0;
                        ROM_UARTCharPut(UART0_BASE, (g_ui32WheelPosition +
                                                     WHEEL_POSITION_OFFSET));
                        ROM_UARTCharPut(UART0_BASE, (g_ui32WheelPosition +
                                                     WHEEL_POSITION_OFFSET));
                    }
                }
                else
                {
                    //
                    // We've received a slide input somewhat recently, but not
                    // during this loop instance.  This most likely means that
                    // the user started a gesture, but is currently just
                    // holding their finger in one spot.  This isn't really a
                    // "press" event, so there isn't anything to report.  We
                    // should, however, make sure the touch counter is primed
                    // for future press events.
                    //
                    ui32WheelTouchCounter = WHEEL_TOUCH_DELAY - 1;
                }
            }

            //
            // Regardless of all pressing, sliding, reporting, and LED events
            // that may have occurred, we need to record our measured
            // (adjusted) wheel position for reference for the next pass
            // through the loop.
            //
            g_ui32PreviousWheelPosition = g_ui32WheelPosition;
        }
        else
        {
            //
            // If we get here, there were no touches recorded on the slider
            // wheel.  We should check our middle button to see if it has been
            // pressed, and clean up our recorded state to prepare for future
            // possible wheel-touch events.
            //
            if(TI_CAPT_Button(&g_sMiddleButton))
Ejemplo n.º 12
0
//-----------------------------------------------------------------------------
int main(void)
{
    // Protect code from being overwritten
    MPU_createTwoSegments(__MSP430_BASEADDRESS_MPU__,0x0DC0,MPU_EXEC|MPU_READ,MPU_EXEC|MPU_READ|MPU_WRITE);
    MPU_start(__MSP430_BASEADDRESS_MPU__);


    // Check if a wakeup from LPMx.5 was detected and use a dedicated device-init flow and continue
    // previous program execution in that case.
    if (SYSRSTIV == SYSRSTIV_LPM5WU) {
        mode = APP_MAIN_MENU;
        select = 0;
    }
    else {              // Start up normally
        SystemInit();   // Initialize board

        // Display TI Logo
        LCD_drawPicture(1);
        TA1_sleep(8192);         // 2s
        TA1_sleep(8192);         // 2s
        // Write Title Screen on LCD
        LCD_introWrite();
        TA1_sleep(8192);         // 2s
        TA1_sleep(8192);         // 2s
    }

    // Init CapTouch Sliders
    TI_CAPT_Init_Baseline(&slider0);             //slider0 is the left capacitive touch slider (note right slider is not used)
 //   TI_CAPT_Init_Baseline(&slider1);

    TI_CAPT_Update_Baseline(&slider0, 10);
 //   TI_CAPT_Update_Baseline(&slider1, 10);


    InitMCU(); //initialize MCU for BMS
    BMSstart(); //start the BMS by searching for BQ76PL536 chips and addressing them

    while (1) {
        // Choose which app to enter based on mode variable
        switch (mode) {
        case APP_MAIN_MENU:
            mode = MainMenu();                                      //start main menu
            break;
        case APP_CELL_VOLTAGE:
        	CellVoltApp();                                          //run the cell voltage app
            break;
        case APP_PACK_VOLTAGE:
        	LCD_displayPackVoltage();                               //displays pack voltage
            break;
        case APP_STATE_OF_CHARGE:                                   //run state of charge app
        	StateOfChargeApp();
            break;
        case APP_TEMPERATURE:                                       //display pack temperatures
        	LCD_displayTemperature();
            break;
        case APP_CELL_BALANCE:                                      //run cell balance app
            //CellBalanceApp();
        	LCD_displayCellsImbalanced();
            break;
        default: break;
        }
    }
}