/*=============================================================================
                    Programa de teste de libsk_access.so
                    Compilar com:
 #gcc -L(caminho para o pacote) -Wall -o foobar foobar.c -lsk_access                    
                    
   V1.0 - 09/09/2011
   V1.1 - 19/12/2013  - Utiliza Header
==============================================================================*/
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <curses.h>
#include <string.h>
#include "sk_access.h"

	 void *lib;
	 char *error;
/*=============================================================================
                             Le entrada do usuario
==============================================================================*/
int Get_User_Input(){
  char ch[10];
  int c;
  
  for(c=0;c<5;c++)
	 printf("\n");
  
  printf(" 1=Send_Data(0x41)       2=Send_Disp_Ctrl     3=Clear_Disp         4=Clear_L1\n");
  printf(" 5=Clear_L2              6=Cursor_Off         7=Cursor_On          8=Cursor_Blink\n");
  printf(" 9=Back_Space           10=Line_Feed         11=Carriage_Return   12=Gotoxy(20,2)\n");
  printf("13=Disp_Char(""A"")		14=Disp(""Teste Teclado Smak"");              15=Get_Cursor\n");
  printf("16=Get_Status           17=Set_Page0         18=Set_Page1         19=GetOperatingSystem\n");
  printf("20=Set_Eco_On           21=Set_Eco_Off       22=Set_Psw_On        23=Set_Psw_Off\n");
  printf("24=Get_Dll_Version      25=Get_Firmware_Version                   26=Get_Serial_Number\n");
  printf("27=Enable_keyboard      28=Disable_keyboard  29=Log_On            30=Log_Off\n");
  printf("31=Keyb_Reset           32=Reset_Interface   33=Redirect\n");
  printf("34=Exit\n");
  
  
  gets(ch);
  
  return(atoi(ch));
}
/*=============================================================================
                            Executa funçõao da So
==============================================================================*/
void Exec_So(int func){
  
  unsigned char a,b,c;
  int i;
  char s[100];
  
  
  switch (func){
	 case 1:Send_Data((char)0x41);break;
	 case 2:Send_Disp_Ctrl((char)0x01);break;
	 case 3:Clear_Disp(); break;
	 case 4:Clear_L1();break;
	 case 5:Clear_L2();break;
	 case 6:Cursor_Off();break;
	 case 7:Cursor_On();break;
	 case 8:Cursor_Blink();break;
	 case 9:Back_Space();break;
	 case 10:Line_Feed();break;
	 case 11:Carriage_Return();break;
	 case 12:Gotoxy(20,2);break;
	 case 13:Disp_Char((char)0x41);break;
	 case 14:Disp("Teste Teclado Smak");break;
	 case 15:a = Get_Cursor(&b , &c);
		 printf("Cursor em x=%d e y=%d, index=%d\n",b,c,a); break;
	 case 16:a = Get_Status();
	         switch(a){
		   case(0):printf("Status = OK");break;
		   case(1):printf("Status = Err"); break;
		   case(0xff):printf("Status = Time_Out");break;
		 } break;				
	 case 17:Set_Page0();break;
	 case 18:Set_Page1(); break;
	 case 19:i = GetOperatingSystem();
		 printf("Operating System = %d",i); break;
	 case 20:Set_Eco_On();break;
	 case 21:Set_Eco_Off();break;
	 case 22:Set_Psw_On();break;
	 case 23:Set_Psw_Off();break;
	 case 24:Get_Dll_Version(s);
		 printf("Dll Version = %s",s);break;
	 case 25:Get_Firmware_Version(s);
	 	 printf("Firmware Version = %s",s);break;
	 case 26:Get_Serial_Number(s);
	 	 printf("Serial Number = %s",s);break;
	 case 27:Enable_Keyboard();break;
	 case 28:Disable_Keyboard();break;
	 case 29:Log_On(3);break;
	 case 30:Log_Off();break;
	 case 31:Keyb_Reset();break;
	 case 32:Reset_Interface();break;				
	 case 33:Redirect();break;
	 case 34:Free_Sk_Access();break;
  }//Switch
}
/*=============================================================================
                             Programa principal
==============================================================================*/

int main(int argc, char **argv) {
  
    int x;
	 
	 (*Log_On)(3);
	 do{
	   x = Get_User_Input();
		Exec_So(x);
	 }while (x!=34);
    return 0;	 
}