Пример #1
0
void cmd_tswait(uint8_t argc, char **argv)
{
  tsTouchData_t data;
  int32_t delay;
  int32_t error = 0;

  if (argc == 1)
  {
    getNumber (argv[0], &delay);
  }
  else
  {
    delay = 0;
  }

  // Validate delay
  if (delay < 0)
  {
    printf("Invalid timeout%s", CFG_PRINTF_NEWLINE);
    return;
  }

  // Blocking delay until a valid touch event occurs
  error = tsWaitForEvent(&data, delay > 0 ? (uint32_t)delay : 0);

  if (error == TS_ERROR_NONE)
  {
    // A valid touch event occurred ... parse data
    printf("%d, %d%s",(int)data.xlcd, (int)data.ylcd, CFG_PRINTF_NEWLINE);
  }
  else
  {
    // Display error code
    printf("%d %s", (int)error, CFG_PRINTF_NEWLINE);
  }

  return;
}
Пример #2
0
char alphaHandleTouchEvent(void)
{
  tsTouchData_t data;
  char result = '\0';
  uint8_t row, col;
  int32_t tsError = -1;

  // Blocking delay until a valie touch event occurs
  while (tsError)
  {
    tsError = tsWaitForEvent(&data, 0);
  }

  // Attempt to convert touch data to char
  if ((data.y < ALPHA_ROW1_TOP) || (data.y > ALPHA_ROW6_TOP + ALPHA_BTN_HEIGHT))
  {
    return result;
  }

  // Get column
  if ((data.x > alphaBtnX[0]) && (data.x < alphaBtnX[0] + ALPHA_BTN_WIDTH))
    col = 0;
  else if ((data.x > alphaBtnX[1]) && (data.x < alphaBtnX[1] + ALPHA_BTN_WIDTH))
    col = 1;
  else if ((data.x > alphaBtnX[2]) && (data.x < alphaBtnX[2] + ALPHA_BTN_WIDTH))
    col = 2;
  else if ((data.x > alphaBtnX[3]) && (data.x < alphaBtnX[3] + ALPHA_BTN_WIDTH))
    col = 3;
  else if ((data.x > ALPHA_COL5_LEFT) && (data.x < ALPHA_COL5_LEFT + ALPHA_BTN_WIDTH))
    col = 4;
  else
    return result;

  // Get row
  if ((data.y > ALPHA_ROW1_TOP) && (data.y < ALPHA_ROW1_TOP + ALPHA_BTN_HEIGHT))
    row = 0;
  else if ((data.y > ALPHA_ROW2_TOP) && (data.y < ALPHA_ROW2_TOP + ALPHA_BTN_HEIGHT))
    row = 1;
  else if ((data.y > ALPHA_ROW3_TOP) && (data.y < ALPHA_ROW3_TOP + ALPHA_BTN_HEIGHT))
    row = 2;
  else if ((data.y > ALPHA_ROW4_TOP) && (data.y < ALPHA_ROW4_TOP + ALPHA_BTN_HEIGHT))
    row = 3;
  else if ((data.y > ALPHA_ROW5_TOP) && (data.y < ALPHA_ROW5_TOP + ALPHA_BTN_HEIGHT))
    row = 4;
  else if ((data.y > ALPHA_ROW6_TOP) && (data.y < ALPHA_ROW6_TOP + ALPHA_BTN_HEIGHT))
    row = 5;
  else
    return result;

  // Match found ... update button and process the results
  alphaRenderButton(alphaPage, col, row, true);
  result = alphaKeys[alphaPage][row][col];
  
  if (result == '<')
  {
    // Trim character if backspace was pressed
    if (alphaString_ptr > alphaString)
    {
      alphaString_ptr--;
      *alphaString_ptr = '\0';
    }
  }
  else if (result == '*')
  {
    // Switch page if the shift button was pressed
    alphaPage++;
    if (alphaPage > 3)
    {
      alphaPage = 0;
    }
    // Update the UI
    alphaRefreshScreen();
  }
  else if (result == '>')
  {
    // OK button
    systickDelay(CFG_TFTLCD_TS_KEYPADDELAY);
    return '>';
  }
  else
  {
    // Add text to string buffer
    *alphaString_ptr++ = result;
  }

  // Brief delay
  systickDelay(CFG_TFTLCD_TS_KEYPADDELAY);

  // Return button to deselected state
  alphaRefreshScreen();
  return result;
}
Пример #3
0
int main(void)
{
  #if !defined CFG_TFTLCD
    #error "CFG_TFTLCD must be enabled in projectconfig.h for this test"
  #endif
  #if defined CFG_INTERFACE
    #error "CFG_INTERFACE must be disabled in projectconfig.h for this test (to save space)"
  #endif

  // Configure cpu and mandatory peripherals
  systemInit();
  
  /* Set P2.0 to GPIO input (just in case) */
  gpioSetDir(2, 0, 0);

  /* Set P1.4/AD5 to analog input (only AD0..3 are configured by adcInit) */
  IOCON_PIO1_4 &= ~(IOCON_PIO1_4_ADMODE_MASK |
                    IOCON_PIO1_4_FUNC_MASK |
                    IOCON_PIO1_4_MODE_MASK);
  IOCON_PIO1_4 |=  (IOCON_PIO1_4_FUNC_AD5 &
                    IOCON_PIO1_4_ADMODE_ANALOG);

  // Rotate the screen and render the area around the data grid
  lcdSetOrientation(LCD_ORIENTATION_LANDSCAPE);
  renderLCDFrame();

  tsTouchData_t touch;

  // Start reading
  while (1)
  {
    // Wait up to 5ms for a touch event
    tsTouchError_t error = tsWaitForEvent(&touch, 5);
    if (!error)
    {
      if (touch.x > 25 && touch.x < 100 && touch.y > 210)
      {
        // Analog switch selected
        adcEnabled = adcEnabled ? false : true;
      }
      if (touch.x > 125 && touch.x < 200 && touch.y > 210)
      {
        // Digital switch selected
        digEnabled = digEnabled ? false : true;
      }
      // Refresh the frame
      renderLCDFrame();
    }

    // Read pins
    if (adcEnabled)
      addToBuffer(adcBuffer, adcRead(5) / 4); // 10-bit value converted to 8-bits
    if (digEnabled)
      addToBuffer(digBuffer, gpioGetValue(2, 0) ? 0xFF : 0x00);

    // Update the LCD is required
    renderLCDGrid();

    // Note, this will actually mean the timing is ~100mS + the amount of
    // time it took to get the readings and update the LCD
    // A timer interrupt could be used to get much more accurate results,
    // filling the buffer inside the IRQ and rendering the screen updates
    // every x milliseconds
    systickDelay(100);
  }

  return 0;
}