Ejemplo n.º 1
0
/*
** This function resolves the coordinates of the location on the 
** touch screen being touched.
*/
void ResolveCoordinates(int *pX, int *pY)
{
    unsigned short xpos, ypos;
    char x = 0, y =1;
    char rx1 = 0, rx2 = 0;
    char ry1 = 0, ry2 = 0;
    unsigned int xDpos = 0;
    int yDpos = 0;

    /* read x-cordinates */
    ReadAxis(x, &rx1, &rx2);
          
    /* read y cordinates */
    ReadAxis(y, &ry1, &ry2);
    /*To collect the 10 bits of digital data, 8 present in rx1 and 2 in rx2.*/
    xpos = rx1 + ((unsigned short int)rx2 << 8);

    /*To collect the 10 bits of digital data, 8 present in ry1 and 2 in ry2.*/
    ypos = ry1 + ((unsigned short int)ry2 << 8);

    xDpos = (unsigned int)xpos*DEFAULT_XSCALE + XOFFSET; 
    yDpos = (int)ypos*DEFAULT_YSCALE + YOFFSET;

    yDpos = LCD_HEIGHT - yDpos;

    if(yDpos < 0)
    {
        yDpos = 0;
    }

    /* put touch screen in stand by mode.So that next
     * can be detected 
     */          
    TSCStandByMode();
    
    *pX =(int)xDpos;
    *pY = yDpos;
}
Ejemplo n.º 2
0
int main(void)
{
    int xCoOd = 0, yCoOd = 0;
    char pressure = 0, touched = 0;
    unsigned int i = 0;
    unsigned char *dest;
    unsigned char *src;

    SetupIntc();

    SetUpLCD();
  
    /* configuring the base ceiling */
    RasterDMAFBConfig(SOC_LCDC_0_REGS, 
                      (unsigned int)(g_pucBuffer+PALETTE_OFFSET),
                      (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 -
					  PALETTE_OFFSET, FRAME_BUFFER_0);

    RasterDMAFBConfig(SOC_LCDC_0_REGS, 
                      (unsigned int)(g_pucBuffer+PALETTE_OFFSET),
                      (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - 
					  PALETTE_OFFSET, FRAME_BUFFER_1);

    src = (unsigned char *) palette_32b;
    dest = (unsigned char *) (g_pucBuffer+PALETTE_OFFSET);

    // Copy palette info into buffer
    for( i = PALETTE_OFFSET; i < (PALETTE_SIZE+PALETTE_OFFSET); i++)
	{
		*dest++ = *src++;
	}

	// copy splash screen
	/*src = (unsigned char *)&splash[40];
	for(; i < LCD_SIZE; i++)
	{
		*dest++ = *src++;
	}*/
		
	GrOffScreen16BPPInit(&g_sSHARP480x272x16Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT);
	
	// Initialize a drawing context.
	GrContextInit(&sContext, &g_sSHARP480x272x16Display);

    /* enable End of frame interrupt */
    RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS);

    /* enable raster */
    RasterEnable(SOC_LCDC_0_REGS);

    /* Enable display panel backlight and power */
    ConfigRasterDisplayEnable();

    DisplayGR();
	
	SoundInit();

    // TS init
    PeripheralsSetup();
    InitTouchScreen();
	
    // Loop forever handling widget messages.    
    while(1)
	{
		while(!touched)
		{
			ReadAxis(2, &pressure, &touched);
		}
		
        /* Resolving the coordinates of the touched location.*/
        ResolveCoordinates(&xCoOd, &yCoOd);
		
		do
		{
			WidgetPointerMessage(WIDGET_MSG_PTR_DOWN, xCoOd, yCoOd);
			
			// Process any messages in the widget message queue.
			WidgetMessageQueueProcess();

            ResolveCoordinates(&xCoOd, &yCoOd);
			ReadAxis(2, &pressure, &touched);
        }while(touched);
		
		WidgetPointerMessage(WIDGET_MSG_PTR_UP, xCoOd, yCoOd);
		WidgetMessageQueueProcess();
	}
	
}
Ejemplo n.º 3
0
void loop()
{
  int xRaw = ReadAxis(xInput);
  int yRaw = ReadAxis(yInput);
  int zRaw = ReadAxis(zInput);

  if (digitalRead(buttonPin) == LOW)
  {
    Serial.println();
    Serial.print(xRaw);
    Serial.print(", ");
    Serial.print(yRaw);
    Serial.print(", ");
    Serial.print(zRaw);

    AutoCalibrate(xRaw, yRaw, zRaw);
  }
  else
  {
    Serial.print("Raw Ranges: X: ");
    Serial.print(xRawMin);
    Serial.print("-");
    Serial.print(xRawMax);

    Serial.print(", Y: ");
    Serial.print(yRawMin);
    Serial.print("-");
    Serial.print(yRawMax);

    Serial.print(", Z: ");
    Serial.print(zRawMin);
    Serial.print("-");
    Serial.print(zRawMax);
    Serial.println();
    Serial.print(xRaw);
    Serial.print(", ");
    Serial.print(yRaw);
    Serial.print(", ");
    Serial.print(zRaw);

    // Convert raw values to 'milli-Gs"
    long xScaled = map(xRaw, xRawMin, xRawMax, -1000, 1000);
    long yScaled = map(yRaw, yRawMin, yRawMax, -1000, 1000);
    long zScaled = map(zRaw, zRawMin, zRawMax, -1000, 1000);

    // re-scale to fractional Gs
    float xAccel = xScaled / 1000.0;
    float yAccel = yScaled / 1000.0;
    float zAccel = zScaled / 1000.0;

    Serial.print(" :: ");
    Serial.print(xAccel);
    Serial.print("G, ");
    Serial.print(yAccel);
    Serial.print("G, ");
    Serial.print(zAccel);
    Serial.println("G");

  delay(500);
  }
}