//GPS icon
static const unsigned char gps_data[] PROGMEM = {
0x07,0x80
,0x0f,0xe0
,0x1f,0xf0
,0x3c,0x70
,0x38,0x78
,0x78,0x38
,0x38,0x78
,0x3c,0xf0
,0x1f,0xf0
,0x1f,0xe0
,0x0f,0xe0
,0x0f,0xc0
,0x07,0x80
,0x03,0x80
,0x01,0x00
};

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

void Disp_Title() {//2022
  u8g2.begin();
  u8g2.clearBuffer();                    // clear the internal memory

  //u8g2.setFont(u8g2_font_finderskeepers_tf);
  u8g2.drawBitmap(75, 25, 2, 15, logo_bmp);
  u8g2.drawBitmap(94, 25, 2, 15, logo_bmp);
  u8g2.drawBitmap(112, 25, 2, 15, logo_bmp);
//    u8g2.drawBitmap(5, 25, 2, 19, WIFI);
  u8g2.setFont(u8g2_font_fub14_tf);
  u8g2.drawStr(10,20,"AlthibaPRO");    // write something to the internal memory
  u8g2.setFont(u8g2_font_finderskeepers_tf);
  u8g2.drawStr(10,40,"Ver6.02");    // write something to the internal memory
  u8g2.setFont(u8g2_font_fub11_tf);
  u8g2.drawStr(10,55,"MachinakaOBS");    // write something to the internal memory
  u8g2.sendBuffer();                    // transfer internal memory to the display
  u8g2.setFont(u8g2_font_finderskeepers_tf);
}

void Disp_Start() {//2022

//  u8g2.begin();
  u8g2.clearBuffer();                    // clear the internal memory
  u8g2.setFont(u8g2_font_fub14_tf);
  u8g2.drawStr(5,20," S T A R T");    // write something to the internal memory
  u8g2.setFont(u8g2_font_fub11_tf);
  u8g2.drawStr(20,50,"AlthibaPRO");    // write something to the internal memory
  u8g2.sendBuffer();                    // transfer internal memory to the display
  u8g2.setFont(u8g2_font_finderskeepers_tf);
}

void Disp_Reset() {//2022
//  u8g2.begin();
  u8g2.clearBuffer();                    // clear the internal memory
  u8g2.setFont(u8g2_font_fub14_tf);
  u8g2.drawStr(20,20,"All Reset");    // write something to the internal memory
  u8g2.setFont(u8g2_font_finderskeepers_tf);
  u8g2.drawStr(0,50,"Please turn the power off and then on again");    // write something to the internal memory
  u8g2.sendBuffer();                    // transfer internal memory to the display
}

void Disp_SetOK() {//2022
//  u8g2.begin();
  u8g2.clearBuffer();                    // clear the internal memory
  u8g2.setFont(u8g2_font_fub14_tf);
  u8g2.drawStr(10,20,"AllStep SET!");    // write something to the internal memory
  u8g2.setFont(u8g2_font_finderskeepers_tf);
  u8g2.drawStr(0,50,"Please turn the power off and then on again");    // write something to the internal memory
  u8g2.sendBuffer();                    // transfer internal memory to the display
}

void Disp_Accesspoint(){//2022
//  u8g2.begin();
  u8g2.clearBuffer();                    // clear the internal memory
  u8g2.setFont(u8g2_font_fub14_tf);
  u8g2.drawStr(10,20,"WIFI MODE");    // write something to the internal memory
  u8g2.setFont(u8g2_font_fub11_tf);
  u8g2.drawStr(15,40,"Access point");    // write something to the internal memory
  u8g2.setFont(u8g2_font_finderskeepers_tf);
  u8g2.drawStr(0,60,"Please turn the power off and then on again");    // write something to the internal memory
  u8g2.sendBuffer();                    // transfer internal memory to the display
}

void Disp_Station(){//2022
//  u8g2.begin();
  u8g2.clearBuffer();                    // clear the internal memory
  u8g2.setFont(u8g2_font_fub14_tf);
  u8g2.drawStr(10,20,"WIFI MODE");    // write something to the internal memory
  u8g2.setFont(u8g2_font_fub11_tf);
  u8g2.drawStr(10,40,"Station mode");    // write something to the internal memory
  u8g2.setFont(u8g2_font_finderskeepers_tf);
  u8g2.drawStr(0,60,"Please turn the power off and then on again");    // write something to the internal memory
  u8g2.sendBuffer();                    // transfer internal memory to the display
}

void Disp_AP(){//2022
//  u8g2.begin();
  u8g2.clearBuffer();                    // clear the internal memory
  u8g2.setFont(u8g2_font_finderskeepers_tf);
  u8g2.drawStr(5,10,"WIFI:");    // write something to the internal memory
  u8g2.drawStr(50,10,"Access Point");    // write something to the internal memory
  u8g2.drawStr(5,20,"SSID:");    // write something to the internal memory
  u8g2.setCursor(60, 20);
  u8g2.print(wifi_ap_ssid);
  u8g2.drawStr(5,30,"PASSWORD:");    // write something to the internal memory
  u8g2.setCursor(60, 30);
  u8g2.print(wifi_ap_pwd);
  u8g2.drawStr(5,40,"Channel:");    // write something to the internal memory
  u8g2.setCursor(60, 40);
  u8g2.print(wifi_ap_ch);
  //HOMEPALT=EEPROM_readLong(EE_HOMEALT);
  //HOMEPAZM=EEPROM_readLong(EE_HOMEAZM);  
  //u8g2.drawStr(5,50,"HOME ALT:");    // write something to the internal memory
  //u8g2.setCursor(60, 50);
  //u8g2.print(HOMEPALT);
  //u8g2.drawStr(5,60,"HOME AZM:");    // write something to the internal memory
  //u8g2.setCursor(60, 60);
  //u8g2.print(HOMEPAZM);
  u8g2.sendBuffer();                    // transfer internal memory to the display
}

void Disp_ST(){//2022
//  u8g2.begin();
  u8g2.clearBuffer();                    // clear the internal memory
  u8g2.setFont(u8g2_font_finderskeepers_tf);
  u8g2.drawStr(5,10,"WIFI:");    // write something to the internal memory
  u8g2.drawStr(60,10,"Station");    // write something to the internal memory
  u8g2.drawStr(5,20,"SSID:");    // write something to the internal memory
  u8g2.setCursor(60, 20);
  u8g2.print(wifi_ap_ssid);
  u8g2.drawStr(5,30,"PASSWORD:");    // write something to the internal memory
  u8g2.setCursor(60, 30);
  u8g2.print(wifi_ap_pwd);
  u8g2.drawStr(5,40,"Channel:");    // write something to the internal memory
  u8g2.setCursor(60, 40);
  u8g2.print(wifi_ap_ch);
  //HOMEPALT=EEPROM_readLong(EE_HOMEALT);
  //HOMEPAZM=EEPROM_readLong(EE_HOMEAZM);  
  //u8g2.drawStr(5,50,"HOME ALT:");    // write something to the internal memory
  //u8g2.setCursor(60, 50);
  //u8g2.print(HOMEPALT);
  //u8g2.drawStr(5,60,"HOME AZM:");    // write something to the internal memory
  //u8g2.setCursor(60, 60);
  //u8g2.print(HOMEPAZM);
  u8g2.sendBuffer();                    // transfer internal memory to the display
}

void Disp_Status() {//2022

  char Dispreply[50];
  double f,f1,f2,f3; 
  int    i,i1,i2;
  long   ii;
  byte   b;
  unsigned long _coord_t=0;
  double _dec,_ra;
  unsigned int i3; 

//  u8g2.begin();
  u8g2.clearBuffer();                    // clear the internal memory
  u8g2.setFont(u8g2_font_roentgen_nbp_h_all);

  //Telescope Declination
  if (millis()-_coord_t<100)
  { f=_ra; f1=_dec; } else {
    getEqu(&f,&f1,false); f/=15.0;
    _ra=f; _dec=f1; _coord_t=millis(); 
  }
  doubleToDms(Dispreply,&f1,false,true,PM_HIGH);
  u8g2.drawStr(5,32,"DEC:");
  u8g2.setCursor(35, 32);
  u8g2.print(Dispreply);

  //Telescope RA
  if (millis()-_coord_t<100)
  { f=_ra; f1=_dec; } else {
    getEqu(&f,&f1,false); f/=15.0;
    _ra=f; _dec=f1; _coord_t=millis(); 
  }
  doubleToHms(Dispreply,&f,PM_HIGH);
  u8g2.drawStr(5,22,"RA:");
  u8g2.setCursor(45, 22);
  u8g2.print(Dispreply);

//  if (generalError == ERR_NONE){
      if (currentGuideRate==d_GuideRate1x){
        //Telescope Altitude
        getHor(&f,&f1); doubleToDms(Dispreply,&f,false,true,precision);
        u8g2.drawStr(5,55,"ALT:");
        u8g2.setCursor(35, 55);
        u8g2.print(Dispreply);
      
        //telescope azimuth
        getHor(&f,&f1); f1=degRange(f1); doubleToDms(Dispreply,&f1,true,false,precision);
        u8g2.drawStr(5,45,"AZ:");
        u8g2.setCursor(35, 45);
        u8g2.print(Dispreply);
      }else{

       // UTC Date
        LMT=UT1-timeZone;
        double J=JD;
        int y,m,d;

        while (LMT >= 24.0) { LMT=LMT-24.0; J=J-1.0; } 
        if    (LMT<0.0)   { LMT=LMT+24.0; J=J+1.0; }
        greg(J,&y,&m,&d); y-=2000; if (y >= 100) y-=100;
        sprintf(Dispreply,"%02d/%02d/%02d",y,m,d); 

        u8g2.drawStr(5,46,"DATE");
        u8g2.setCursor(45, 46);
        u8g2.print(Dispreply);
      
        // UTC Time
        f=timeRange(UT1); 
        doubleToHms(Dispreply,&f,PM_HIGH);
        u8g2.drawStr(5,57,"UTC:");
        u8g2.setCursor(45, 57);
        u8g2.print(Dispreply);
        
      }
 // }

  //GPS
  if (GPSf ==1){
  //u8g2.drawBitmap(65, 0, 2, 15, gps_data);
      u8g2.setFont(u8g2_font_open_iconic_all_1x_t);
      u8g2.setFontDirection(0);
      u8g2.drawGlyph(70, 8, 0x91);
      u8g2.setFont(u8g2_font_finderskeepers_tf);
  }

  //Track
  if (trackingState==TrackingSidereal){
      u8g2.setFont(u8g2_font_open_iconic_arrow_1x_t);
      u8g2.setFontDirection(0);
      u8g2.drawGlyph(100, 8, 0x56);
      u8g2.setFont(u8g2_font_finderskeepers_tf);
  }
  
  //GOTO
//  if (generalError == ERR_NONE){
      if (trackingState==TrackingMoveTo){
          u8g2.setFont(u8g2_font_open_iconic_other_1x_t);
          u8g2.setFontDirection(0);
          u8g2.drawGlyph(100, 8, 0x46);
        
          u8g2.setFont(u8g2_font_finderskeepers_tf);
          u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
          u8g2.drawStr(5,8,"Slew");
      } else {
     
          //Speed
          switch (currentGuideRate) {
          case 0://0.25
              u8g2.setFont(u8g2_font_open_iconic_check_1x_t);
              u8g2.drawGlyph(5, 8, 0x44);
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
              u8g2.drawStr(17,8,"0.25");
              break;
          case 1://0.5
              u8g2.setFont(u8g2_font_open_iconic_check_1x_t);
              u8g2.drawGlyph(5, 8, 0x44);
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
              u8g2.drawStr(17,8,"0.5");
              break;
          case 2://*1
              u8g2.setFont(u8g2_font_open_iconic_check_1x_t);
              u8g2.drawGlyph(5, 8, 0x44);
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
              u8g2.drawStr(12,8," 1");
              break;
          case 3://*2
              u8g2.setFont(u8g2_font_open_iconic_check_1x_t);
              u8g2.drawGlyph(5, 8, 0x44);
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
              u8g2.drawStr(12,8," 2");
              break;
          case 4://*4
              u8g2.setFont(u8g2_font_open_iconic_check_1x_t);
              u8g2.drawGlyph(5, 8, 0x44);
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
              u8g2.drawStr(12,8," 4");
              break;
          case 5://*8
              u8g2.setFont(u8g2_font_open_iconic_check_1x_t);
              u8g2.drawGlyph(5, 8, 0x44);
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
              u8g2.drawStr(12,8," 8");
              break;
          case 6://*24
              u8g2.setFont(u8g2_font_open_iconic_check_1x_t);
              u8g2.drawGlyph(5, 8, 0x44);
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
              u8g2.drawStr(17,8,"24");
              break;
          case 7://*48
              u8g2.setFont(u8g2_font_open_iconic_check_1x_t);
              u8g2.drawGlyph(5, 8, 0x44);
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
              u8g2.drawStr(17,8,"48");
              break;
          case 8://*MAX
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
              u8g2.drawStr(10,8,"Max");
              break;
          case 9://*Slew
//              u8g2.setFont(u8g2_font_finderskeepers_tf);
              u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
               u8g2.drawStr(5,8,"Slew");
              break;
          }
      }
//   }

  //WIFI
  if (WIFIf ==1){
      u8g2.setFont(u8g2_font_open_iconic_www_1x_t);
      u8g2.setFontDirection(0);
      u8g2.drawGlyph(115, 8, 0x48);
      u8g2.setFont(u8g2_font_finderskeepers_tf);
    }

  //SOUND
  if (soundEnabled == 1){
      u8g2.setFont(u8g2_font_open_iconic_all_1x_t);
      u8g2.setFontDirection(0);
      u8g2.drawGlyph(85, 8, 0x115);
      u8g2.setFont(u8g2_font_finderskeepers_tf);
  }
  
  //ERROR
  //ERR_NONE, ERR_MOTOR_FAULT, ERR_ALT_MIN, ERR_LIMIT_SENSE, ERR_DEC, ERR_AZM,
  //ERR_UNDER_POLE, ERR_MERIDIAN, ERR_SYNC, ERR_PARK, ERR_GOTO_SYNC, ERR_UNSPECIFIED,
  //ERR_ALT_MAX, ERR_WEATHER_INIT, ERR_SITE_INIT, ERR_NV_INIT}
    
  if (generalError==ERR_LIMIT_SENSE){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(20,46,"ERR_");
    u8g2.drawStr(5,57,"LIMIT_SENSE");}

  if (generalError==ERR_MOTOR_FAULT){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(20,46,"ERR_");
    u8g2.drawStr(5,57,"MOTOR_FAULT");}

  if (generalError==ERR_ALT_MAX){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_ALT_MAX");}
    
  if (generalError==ERR_ALT_MIN){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_ALT_MIN");}

  if (generalError==ERR_SYNC){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_SYNC");}
    
  if (generalError==ERR_PARK){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_PARK");}

  if (generalError==ERR_WEATHER_INIT){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_WEATHER");}

  if (generalError==ERR_SITE_INIT){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_SITE");}

//  if (generalError==ERR_NV_INIT){
//    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
//    u8g2.drawStr(5,46,"            ");
//    u8g2.drawStr(5,57,"            ");
//    u8g2.drawStr(5,57,"ERR_NV_INIT");}

  if (generalError==ERR_UNSPECIFIED){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_UNSPECIFIED");}

  if (generalError==ERR_MERIDIAN){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_MERIDIAN");}
    
  if (generalError==ERR_UNDER_POLE){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(20,46,"ERR_");
    u8g2.drawStr(5,57,"UNDER_POLE");}
    
  if (generalError==ERR_AZM){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_AZM");}
    
  if (generalError==ERR_DEC){
    u8g2.setFont(u8g2_font_roentgen_nbp_h_all);
    u8g2.drawStr(5,46,"            ");
    u8g2.drawStr(5,57,"            ");
    u8g2.drawStr(5,57,"ERR_DEC");}
    
  u8g2.sendBuffer(); // transfer internal memory to the display
  
}
