//Includes and definitions
#include "SdFat.h"
#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_GFX.h>  
#include <MCUFRIEND_kbv.h>
#include "TouchScreen_kbv.h"

#define DEBUG 
//Rutiner, der er pakket ind som nedenfor, bliver udført , når DEBUG er defineret.
//Udkommenteres linien, vil rutinerne ikke blive udført. Og der spares hukommelse og procestid.
/* Use as copy paste routine
  #ifdef DEBUG
    // Write debug routine here
  #endif
 */
//#define TEST
MCUFRIEND_kbv tft;
RTC_DS1307 RTC;
int XP = 6, YP = A1, XM = A2, YM = 7;
TouchScreen_kbv ts(XP, YP, XM, YM, 300);
TSPoint_kbv tp; 

#define SD_CS 53 //Ben 53 bruges til at vælge SDkortet
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY 0x5AEB 
#define PALETTEDEPTH   0 
#define BMPIMAGEOFFSET 54
#define BUFFPIXEL      20
//SD Card code start................................
const byte chipSelect = SS;
#define error(msg) sd.errorHalt(F(msg))
SdFat sd;
SdFile file;
char logFileName[11] = "logfil.txt";
char back1FileName[10] = "back1.txt";
char back2FileName[10] = "back2.txt";
//ArduinoOutStream cout(Serial);
//End SD Card code ...................................

const int fwdpin = A15; //FWD pin
const int rflpin = A14; //RFL pin
const int inppin = A13; //Input pin
const int patpin = A12; //PA temp pin
const int pstpin = A11; //PSU temp pin
const int vpin = A10; //PSU volt pin
const int apin = A9; //PSU ampere pin

//meter variables
float ltx = 0;    // Saved x coord of bottom of needle
uint16_t osx = 120, osy = 120; // Saved x & y coords
int old_analog =  -999; // Value last displayed
int value[8] = {0, 0, 0, 0, 0, 0, 0, 0}; 
int old_value[8] = { -1, -1, -1, -1, -1, -1, -1};
int mvalue;
int meterStart = 0;  // Calc value to fit meter scale start
double swrValue;
//Global variables
int TimeZone = 0;
unsigned long zTime = 0;
char* stationName = "Not set";
byte bandSelectType = 0;
char buf[5];
int portValue = 0; //Set-value to LP filter
char* transieverType = "None";