summaryrefslogtreecommitdiffstats
path: root/common.h
blob: ba105e7d3ae7d508d50757fa13636ea0632714d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef COMMON_H
#define COMMON_H

#if !defined _WIN32 && !defined __CYGWIN__
//linux:
	#include <sys/ioctl.h>
	#include <sys/types.h>
	#include <sys/stat.h>
	#include <asm/types.h>
	#include <fcntl.h>
	#include <linux/hiddev.h>
	#include <linux/hidraw.h>
	#include <linux/input.h>
	#include <sys/timeb.h>
	#include <stdint.h>
	#include <errno.h>
#else
//windows
	#include <windows.h>
	#include <setupapi.h>
	#include <hidusage.h>
	#include <hidpi.h>
	#include <math.h>
	#include <sys/timeb.h>
	#include <wchar.h>
#endif

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <getopt.h>
#include <string.h>
#include <stdbool.h>
#include "strings.h"
#include "instructions.h"

typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned char BYTE;

#ifdef OPGUI
	#define _APPNAME "OPGUI"
	#include <gtk/gtk.h>

	//to use the same code of windows version
	#define PrintMessage1(s,p) {sprintf(str,s,p); PrintMessage(str);}
	#define PrintMessage2(s,p1,p2) {sprintf(str,s,p1,p2); PrintMessage(str);}
	#define PrintMessage3(s,p1,p2,p3) {sprintf(str,s,p1,p2,p3); PrintMessage(str);}
	#define PrintMessage4(s,p1,p2,p3,p4) {sprintf(str,s,p1,p2,p3,p4); PrintMessage(str);}
	#define PrintStatus(s,p1,p2) {sprintf(str,s,p1,p2); gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,str);while (gtk_events_pending ()) gtk_main_iteration();}
	#define	PrintStatusSetup() //only needed for console version
	#define	PrintStatusEnd() //only needed for console version
	#define	PrintStatusClear() gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,"");

	extern int statusID;
	extern GtkWidget *status_bar;
	void PrintMessage(const char *msg);

#else
	#define _APPNAME "OP"
	#define _CMD

	//to use the same code of windows version
	#define PrintMessage printf
	#define PrintMessage1 printf
	#define PrintMessage2 printf
	#define PrintMessage3 printf
	#define PrintMessage4 printf
	#define PrintStatus(s,p1,p2) printf("\b\b\b\b%3d%%",p1); fflush(stdout);
	#define	PrintStatusSetup() printf("    ");
	#define	PrintStatusEnd() printf("\b\b\b\b");
	#define	PrintStatusClear() //only for GUI

#endif

#define COL 16
//Version defined in makefile
#if !defined VERSION
  #define VERSION "unknown"
#endif
#define G (12.0/34*1024/5)		//=72,2823529412
#define LOCK	1
#define FUSE	2
#define FUSE_H  4
#define FUSE_X	8
#define CAL 	16
#define SLOW	256

#if !defined _WIN32 && !defined __CYGWIN__		//Linux
	#define SYSNAME "Linux"
	#define DIMBUF 64
	DWORD GetTickCount();
	extern unsigned char bufferU[128],bufferI[128];
#else	//Windows
	#define SYSNAME "Windows"
	#define DIMBUF 64
	extern unsigned char bufferU0[128],bufferI0[128];
	extern unsigned char *bufferU,*bufferI;
	extern DWORD NumberOfBytesRead,BytesWritten;
	extern ULONG Result;
	extern HANDLE WriteHandle,ReadHandle;
	extern OVERLAPPED HIDOverlapped;
	extern HANDLE hEventObject;
#endif

extern char str[4096];
extern int saveLog;
extern char** strings;
extern int fd;
extern int saveLog,programID,MinDly,load_osccal,load_BKosccal;
extern int use_osccal,use_BKosccal;
extern int load_calibword,max_err;
extern int AVRlock,AVRfuse,AVRfuse_h,AVRfuse_x;
extern int ICDenable,ICDaddr;
extern int FWVersion,HwID;
extern FILE* logfile;
extern char LogFileName[512];
extern char loadfile[512],savefile[512];
extern WORD *memCODE_W;
extern int size,sizeW,sizeEE,sizeCONFIG,sizeUSERID;
extern unsigned char *memCODE,*memEE,memID[64],memCONFIG[48],memUSERID[8];
extern double hvreg;
extern int RWstop;

int StartHVReg(double V);
void msDelay(double delay);
void DisplayEE();
void PrintMessageI2C(const char *msg);
int CheckV33Regulator(void);
void OpenLogFile(void);
void WriteLogIO();
void CloseLogFile();
unsigned int htoi(const char *hex, int length);
void PacketIO(double delay);

#endif // COMMON_H