
#include <stdio.h>
#include "grlcm.h"

void main()
{
  char cType;
  int  nLcmType, nLcmSize;
  int  nMaxX, nMaxY;
  /*
  Bitmap buffer to display. One bit to one pixel.
  for this 8x8 buffer:
  10000001
  01000010
  00100100
  00011000
  00011000
  00100100
  01000010
  10000001
  Note: The width of bitmap must be byte boundary.
  If you want to define a 20x15 image. You should define a
  ((20+8)/8)*15 = 3*15 bytes buffer.
  */
  char pcImage[] = { 0x81,0x42,0x24,0x18,0x18,0x24,0x42,0x81 };

  printf("\nDM&P Graphic LCM Library Demo Program, %s %s.\n\n",__DATE__,__TIME__);
  printf("GrLCM Library Version %s\n\n",GrLcm_Version());

  /* Select LCM type */
  printf("1. 122X32 \n");
  printf("2. 128X64 \n");
  printf("3. 320X240\n");
  printf("4. 128X128\n");
  printf("5. 240X128\n");
  printf("6. 240X64 \n");
  printf("Your LCM type: ");
  cType = getch();
  printf("%c\n",cType);
  switch(cType)
  {
    case '1': nLcmSize = LCM_122X32;  break;
    case '2': nLcmSize = LCM_128X64;  break;
    case '3': nLcmSize = LCM_320X240; break;
    case '4': nLcmSize = LCM_128X128; break;
    case '5': nLcmSize = LCM_240X128; break;
    case '6': nLcmSize = LCM_240X64;  break;
  }

  /* Select LCM interface */
  printf("\n");
  printf("1. GPIO\n");
  printf("2. Printer port\n");
  printf("3. VGA emulator\n");
  printf("Your interface type: ");
  cType = getch();
  printf("%c\n",cType);
  switch(cType)
  {
    case '1': nLcmType = LCM_GPIO; break;
    case '2': nLcmType = LCM_PRN;  break;
    case '3': nLcmType = LCM_VGA;  break;
  }

  /* Initialize graphic LCM library */
  if(GrLcm_Init(nLcmType,nLcmSize)==0)
  {
    printf("Unable to initialize LCM library.\n");
    return;
  }

  /* Select font size */
  GrLcm_SetFontType(LCM_FONT_5X7);

  /* Clear LCM. Show DM&P logo and text "Hello" */
  GrLcm_ClearScreen();
  GrLcm_DisplayBitmapFile(0,0,"dmp.bmp");
  GrLcm_printf(70,0,"Hello");

  /* Display bitmap buffer */
  GrLcm_DisplayBitmap(70,10,8,8,pcImage);

  /* Line function test */
  nMaxX = GrLcm_GetMaxX() - 1;
  nMaxY = GrLcm_GetMaxY() - 1;
  GrLcm_DrawLine(    0,    0,nMaxX,    0);
  GrLcm_DrawLine(nMaxX,    0,nMaxX,nMaxY);
  GrLcm_DrawLine(nMaxX,nMaxY,    0,nMaxY);
  GrLcm_DrawLine(    0,nMaxY,    0,    0);
  GrLcm_DrawLine(    0,    0,nMaxX,nMaxY);
  GrLcm_DrawLine(nMaxX,    0,    0,nMaxY);

  getch();

  /* Close GrLCM library */
  GrLcm_Close();
  printf("Program terminated.\n");
}

