Subversion Repositories svnkaklik

Rev

Blame | Last modification | View Log | Download

//#DEFINE  AD_OSA_X          0           // adresa A/D prevodniku pro osu X
//#DEFINE  AD_OSA_Y          1           // adresa A/D prevodniku pro osu Y
//#DEFINE  TL1           PIN_A2          // tlacitka
//#DEFINE  TL2           PIN_A4

//#DEFINE  EEleve_x           0
//#DEFINE  EEprave_x          1          //adresovani EEPROM
//#DEFINE  EEhorni_y          2
//#DEFINE  EEdolni_y          3

//#DEFINE  EEmin_x            4          // ulozeni hodnot (adresy)
//#DEFINE  EEmax_x            5
//#DEFINE  EEmin_y            6
//#DEFINE  EEmax_y            7
//#DEFINE  EEstred_x          8
//#DEFINE  EEstred_y          9


unsigned int min_x;
unsigned int max_x;
unsigned int min_y;
unsigned int max_y;
unsigned int stred_x;
unsigned int stred_y;
unsigned int leve_x;
unsigned int prave_x;
unsigned int horni_y;
unsigned int dolni_y;


/*#DEFINE  TEXT0    "Joy set to cent"
#DEFINE  TEXT1    "er and press OK"
#DEFINE  TEXT2    "Joy move in some "
#DEFINE  TEXT3    "full circle"
#DEFINE  TEXT4    "Calib. complete"*/

#DEFINE  TEXT0    " Dejte paku do "
#DEFINE  TEXT1    "prostøed"
#DEFINE  TEXT2    "Udelajte par"
#DEFINE  TEXT3    "kruhù"
#DEFINE  TEXT4    "hotovo"


void Joystick (int *ted_x, int *ted_y, int8 *ted_tl1, int8 *ted_tl2)
{
   set_adc_channel(AD_OSA_X);
   delay_us(10);
   *ted_x=read_adc();
   set_adc_channel(AD_OSA_Y);
   delay_us(10);
   *ted_y=read_adc();


 if (!input(TL1))
  {
  delay_us(500);
  if (!input(TL1)) *ted_tl1=True;
  }
  else *ted_TL1=False;

 if (!input(TL2))
  {
  delay_us(500);
  if (!input(TL2)) *ted_tl2=True;
  }
  else *ted_tl2=False;
}



void kalibrace()
{

int  x,y;
int8 tlac1,tlac2;

   min_x = max_x = min_y = max_y = stred_x = stred_y = 128;

// ROZSACH JOYSTIKU
   printf(lcd_putc,"\f");
   printf(lcd_putc,TEXT2);
   lcd_gotoxy(1,2);
   printf(lcd_putc,TEXT3);

   while(input(TL1))
   {
      if (0x17 == klavesa()) return;         // escape
      
      Joystick(&x,&y,&tlac1,&tlac2);

      if (max_x < x )max_x=x;
      if (min_x > x )min_x=x;
      if (max_y < y )max_y=y;                //zjisteni meznich hodnot
      if (min_y > y )min_y=y;
   };

   Delay_ms(500);
   printf(lcd_putc,"\f");
   printf(lcd_putc,TEXT0);
   lcd_gotoxy(1,2);
   printf(lcd_putc,TEXT1);

   while(input(TL1))
   joystick(&stred_x,&stred_y,&tlac1,&tlac2);            //nastaveni stredu



    leve_x=max_x - stred_x;
    prave_x=stred_x - min_x;
    horni_y=max_y - stred_y;
    dolni_y=stred_x - min_x;

    leve_x = leve_x / 8;                     //vypocet parametru
    prave_x = prave_x / 8;
    horni_y = horni_y / 8;
    dolni_y = dolni_y / 8;

   write_eeprom(EEleve_x,leve_x);
   write_eeprom(EEprave_x,prave_x);
   write_eeprom(EEstred_x,stred_x);
   write_eeprom(EEstred_y,stred_y);
   write_eeprom(EEhorni_y,horni_y);
   write_eeprom(EEdolni_y,dolni_y);
  
   //write_eeprom(EEmin_x,min_x);              //zapis
   //write_eeprom(EEmax_x,max_x);
   //write_eeprom(EEmin_y,min_y);
   //write_eeprom(EEmax_y,max_y);
}