-
Notifications
You must be signed in to change notification settings - Fork 1
/
lcd.cpp
221 lines (192 loc) · 4.49 KB
/
lcd.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include <wiringPi.h> //WiringPi headers
#include <lcd.h> //LCD headers from WiringPi
#include <stdio.h> //Needed for the printf function below
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <wiringSerial.h>
//gcc lcd.c -o lcd -lwiringPi -lwiringPiDev
#define LCD_RS 3 //Register select pin
#define LCD_E 0 //Enable Pin
#define LCD_D4 6 //Data pin 4
#define LCD_D5 1 //Data pin 5
#define LCD_D6 5 //Data pin 6
#define LCD_D7 4 //Data pin 7
// ------------------------ GPS
//RPI-------------->GPS
//RX--------------->Tx
//TX--------------->Rx
//GND-------------->Gnd
//oczekiwanie na sygnal
//1 - czeka
//0 - znalazl sygnal
int waitingForSingal(){
return 1;
}
//pobranie szerokosci z GPS
float getLatitude(){
return 51.4234;
}
//pobranie dlugosci z GPS
float getLongitude(){
return 17.4333;
}
void testGPS(){
char gps[65];
int fd,flag=0; //uchwyt dla UART
char arr[]="$GPGGA";
if((fd = serialOpen("/dev/ttyAMA0",9600)) < 0)
{
printf("%s\n", "Nie udalo sie podlaczyc do UART");
return;
} else {
printf("Podlaczono UART\n");
}
while(1)
{
int i=0;
int c;
if(c=serialGetchar(fd)==13||10)
{
for(i=0; i<6; i++)
{
if(serialGetchar(fd) == arr[i])
flag++;
}
}
if(flag==6)
{
flag=0;
for(i=0; i<=65; i++)
gps[i] = serialGetchar(fd);
}
printf("%d\n",gps);
}
}
void testPars(){
FILE *file = fopen("gg.txt", "r");
char Buffer[1024] = {0};
while(fgets(Buffer,1024,file) != NULL)
{
if(Buffer[0] == '$')
{
if (memcmp(Buffer+1,"GPGGA",5) == 0)
{
char *token = strtok(Buffer+6,",");
int i = 0;
while(token != NULL)
{
switch(i)
{
case 0:
// cout <<"Universal Time Coordinated (UTC): " <<token << endl;
break;
case 1:
printf("Lat: %f\n", token);
break;
case 2:
// cout << "North or South :" <<token << endl;
break;
case 3:
printf("Lng: %f\n", token);
break;
case 4:
// cout <<"East or West :" <<token << endl;
break;
case 5:
// cout << "GPS Quality Indicator :"<<token << endl;
break;
case 6:
// cout << "Number of satellites in view, 00 - 12 :"<<token << endl;
break;
case 7:
// cout << "Horizontal Dilution of precision :"<<token << endl;
break;
case 8:
//printf("Lat: %d\n", token);
break;
case 9:
// cout << "Units of antenna altitude, meters :"<<token << endl;
break;
case 10:
// cout << "Geoidal separation :"<<token << endl;
break;
case 11:
// cout << "Units of geoidal separation :"<<token << endl;
break;
case 12:
// cout << "Age of differential GPS data :"<<token << endl;
break;
case 13:
// cout << "Differential reference station ID :"<<token << endl;
break;
case 14:
// cout << "Checksum :"<<token << endl;
break;
default:
break;
}
i++;
token = strtok(NULL,",");
}
}
}
}
}
//inicjalizacja GPS
int initGPS(){
return 0;
}
// ------------------------ LCD
//inicjalizacja wyswietlacza
int initLCD(){
int lcd;
if (lcd = lcdInit (2, 16,4, LCD_RS, LCD_E ,LCD_D4 , LCD_D5, LCD_D6,LCD_D7,0,0,0,0)){
printf ("Nie udana inicjalizacja LCD! \n");
return -1;
}
return lcd;
}
//wyswietlenie napisu oczekiwania
void displayWaiting(int lcd){
lcdClear(lcd);
lcdPosition(lcd,0,0);
lcdPuts(lcd, "Czekanie na sygnal");
}
//wyswietlanie wspolrzednych na wyswieltaczu
void displayCoords(int lcd, float lat, float lng){
lcdClear(lcd);
lcdPuts(lcd, "Lat: ");
lcdPosition(lcd,0,1);
lcdPuts(lcd, "Lng: ");
}
//zapis wspolrzednych do pliku csv
void saveCoords(float lat, float lng){
//save to file
FILE *f = fopen("coords.csv", "w");
if (f == NULL)
{
printf("Nie mozna otworzyc pliku!\n");
}
fprintf(f, "%f,%f\n", lat, lng);
fclose(f);
}
//-------------------------------------------------------------------------------
int main()
{
//inicjalizacja
wiringPiSetup();
int lcd = initLCD();
int gps = initGPS();
//testGPS();
testPars();
int hasSignal = waitingForSingal();
while(hasSignal){
sleep(1);
float lat = getLatitude();
float lng = getLongitude();
displayCoords(lcd, lat, lng);
saveCoords(lat, lng);
}
getchar();
}