void cmd_orientation(uint8_t argc, char **argv)
{
  int32_t value;
  
  if (argc == 0)
  {    
    printf("%d%s", lcdGetOrientation(), CFG_PRINTF_NEWLINE);
    return;
  }

  // Convert supplied parameters
  getNumber (argv[0], &value);

  switch (value)
  {
    case 0:
      lcdSetOrientation(LCD_ORIENTATION_PORTRAIT);
      break;
    case 1:
      lcdSetOrientation(LCD_ORIENTATION_LANDSCAPE);
      break;
    default:
      printf("Invalid value: Enter 0 or 1%s", CFG_PRINTF_NEWLINE);
      return;
  }

  return;
}
Example #2
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;
}