-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholedParkingV4.c
805 lines (722 loc) · 20 KB
/
oledParkingV4.c
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdbool.h>
#include <oled-exp.h>
#include <ugpio/ugpio.h>
#define NUMSPB 3 //Number of Parking Space Boundaries (# of rows)
#define NUMPARKSPACE 11 //Total number of parking spaces in array
#define NUMPSCOL 4 //Number of columns in parking space array
#define NUMPSROW 3 //Number of rows in parking space array
#define NUMENTRANCE 2 //Number of enterances
#define E0 0 //Pin number for Entrance 0
#define E1 6 //Pin number for Entrance 1
#define P0 45 //Pin number for Parking Space 0
#define P1 46 //Pin number for Parking Space 1
#define P2 2 //Pin number for Parking Space 2
#define P4 18 //Pin number for Parking Space 4
#define P5 19 //Pin number for Parking Space 5
#define P6 3 //Pin number for Parking Space 6
//Enumerated types for status of parking spaces
typedef enum status {UNOCCUPIED, RESERVED, OCCUPIED} PSTATUS;
//Structure for positional x, y coordinates defined TYPE POSITION
typedef struct pos
{
uint8_t x;
uint8_t y;
} TPOS;
//Structure for positional corners of desired blocks to be drawn made up of coordinates
//Defined by type TYPE BLOCK
typedef struct block
{
TPOS startpos;
TPOS endpos;
} TBLOCK;
TBLOCK startPB[NUMSPB]; //Array of coordinates for the initial NUMSPB boundaries
TBLOCK parkSpacePB[NUMPARKSPACE]; //Array of coordinates for Parking Space Boundaries
TBLOCK parkSpace[NUMPARKSPACE]; //Array of coordinates for Parking Space 'filled' area
TBLOCK entrance[NUMENTRANCE]; //Array of coordinates for entrances
TPOS entPos[NUMENTRANCE]; //Array of the coordinates of the center of the entrances
TPOS psPos[NUMPARKSPACE]; //Array of the coordinates of the center of the Parking Spaces
typedef struct oled
{
PSTATUS PLArray [NUMPARKSPACE];
bool ENTArray [NUMENTRANCE];
uint8_t PLStatus [NUMPARKSPACE];
uint8_t distance[NUMENTRANCE][NUMPARKSPACE];
uint8_t tempDist;
uint8_t tempPS;
uint8_t spot[NUMENTRANCE];
int spotCounter[NUMENTRANCE];
} TDISPLAY;
TDISPLAY display;
uint8_t bitMask[8]; //bitMask used to define specific bit within a byte through hexidecimal
uint8_t tBuffer[1028]; //Buffer required for OLED to write bytes to OLED display
//Custom Functions
uint8_t min (uint8_t a, uint8_t b) //Simple Min function
{
if(a<b)
{
return a;
}
return b;
}
uint8_t max (uint8_t a, uint8_t b) //Simple Max function
{
if(a>b)
{
return a;
}
return b;
}
/* Draws specific pixel to the buffer to draw to OLED
* @param *dbuffer the buffer for the OLED
* @param aCol integer of x co-ordinate
* @param aRow integer of y co-ordinate
*/
void drawPixel(uint8_t *dbuffer, uint8_t aCol, uint8_t aRow)
{
uint8_t byteRow = aRow/8; //OLED display divided into 8 rows of bytes, divide by 8 to get target row
uint16_t targetByte = 128*byteRow + aCol; //127 columns per row, multiply row number by 128 and add column for target Byte
uint8_t targetBit = aRow % 8; //taking modulus will define the bit within the target byte that needs to changed
*(dbuffer + targetByte) |= bitMask[targetBit]; //Or's in bit to the target byte
}
/* Remove specific pixel from the buffer to draw to OLED
* @param *dbuffer the buffer for the OLED
* @param aCol integer of x co-ordinate
* @param aRow integer of y co-ordinate
*/
void removePixel(uint8_t *dbuffer, uint8_t aCol, uint8_t aRow)
{
uint8_t byteRow = aRow / 8; //Refer Above
uint16_t targetByte = 128*byteRow + aCol; //Refer Above
uint8_t targetBit = aRow % 8; //Refer Above
*(dbuffer+targetByte) = (*(dbuffer+targetByte)&(~bitMask[targetBit])); //Bitwise 'and' with the complement of the target bit to //remove given pixel
}
//Draws the left initial parking boundaries to buffer
void drawStartPB()
{
for(uint8_t i = 0; i < NUMSPB; i++)
{
for(uint8_t x=startPB[i].startpos.x; x <= startPB[i].endpos.x; x++) //Draws each column for boundary
{
for(uint8_t y=startPB[i].startpos.y; y <= startPB[i].endpos.y; y++)
{
drawPixel(tBuffer, x, y);
}
}
}
}
//Writes the boundaries around a given parking space to the buffer
void drawPB(uint8_t aParkSpace)
{
uint8_t x1 = parkSpacePB[aParkSpace].startpos.x;
uint8_t x2 = parkSpacePB[aParkSpace].endpos.x;
uint8_t y1 = parkSpacePB[aParkSpace].startpos.y;
uint8_t y2 = parkSpacePB[aParkSpace].endpos.y;
for(uint8_t x = x1; x <= x2; x++)
{
if(x< x2-1) //Draws Horizontal bar
{
for(uint8_t y = y1; y< y1+2; y++)
{
drawPixel(tBuffer, x, y);
}
}
else //Draws Vertical bar
{
for(uint8_t y = y1; y <= y2; y++)
{
drawPixel(tBuffer, x, y);
}
}
}
}
//Writes the given parking space to the buffer
void drawPS(uint8_t aParkSpace)
{
uint8_t x1 = parkSpace[aParkSpace].startpos.x;
uint8_t x2 = parkSpace[aParkSpace].endpos.x;
uint8_t y1 = parkSpace[aParkSpace].startpos.y;
uint8_t y2 = parkSpace[aParkSpace].endpos.y;
for(uint8_t x=x1; x <= x2; x++) //Writes rectangle from corner to corner
{
for(uint8_t y=y1; y <= y2; y++)
{
drawPixel(tBuffer, x, y);
}
}
}
//Removes the given Parking space from the buffer
void removePS(uint8_t aParkSpace)
{
uint8_t x1 = parkSpace[aParkSpace].startpos.x;
uint8_t x2 = parkSpace[aParkSpace].endpos.x;
uint8_t y1 = parkSpace[aParkSpace].startpos.y;
uint8_t y2 = parkSpace[aParkSpace].endpos.y;
for(uint8_t x=x1; x <= x2; x++) //Removes rectangle from corner to corner
{
for(uint8_t y=y1; y <= y2; y++)
{
removePixel(tBuffer, x, y);
}
}
}
//Writes the given entrance to the buffer
void drawEntrance(uint8_t anEntrance)
{
uint8_t x1 = entrance[anEntrance].startpos.x;
uint8_t x2 = entrance[anEntrance].endpos.x;
uint8_t y1 = entrance[anEntrance].startpos.y;
uint8_t y2 = entrance[anEntrance].endpos.y;
for(uint8_t x=x1; x <= x2; x++) //Draws from corner to corner
{
for(uint8_t y=y1; y <= y2; y++)
{
drawPixel(tBuffer, x, y);
}
}
}
/* Writes the path from enterance to parking space
* @param anEntrance the entrance to start path from
* @param aParkSpace the Parking space to go to
*/
void drawReserve(uint8_t anEntrance, uint8_t aParkSpace)
{
uint8_t x1 = entPos[anEntrance].x; //Gets centers of Entrance
uint8_t y1 = entPos[anEntrance].y;
uint8_t x2 = psPos[aParkSpace].x; //Gets center of Parking Space
uint8_t y2 = psPos[aParkSpace].y;
uint8_t x = x1;
for(uint8_t y = min(y1, y2)+5; y<=max(y1,y2); y++) //Writes vertical line up from entrance
{
drawPixel(tBuffer, x, y);
}
x = x2;
for(uint8_t y = min(y1, y2); y<=min(y1,y2)+4; y++) //Writes vertical line up to Parking Space center
{
drawPixel(tBuffer, x, y);
}
uint8_t y = y2+5;
for(uint8_t x = min(x1, x2); x<=max(x1,x2); x++) //Writes Horizontal line connecting two vertical lines
{
drawPixel(tBuffer, x, y);
}
}
/* Removes the path from enterance to parking space
* @param anEntrance the entrance to start path from
* @param aParkSpace the Parking space to go to
*/
void removeReserve(uint8_t anEntrance, uint8_t aParkSpace)
{
uint8_t x1 = entPos[anEntrance].x; //Refer Above
uint8_t y1 = entPos[anEntrance].y;
uint8_t x2 = psPos[aParkSpace].x; //Refer Above
uint8_t y2 = psPos[aParkSpace].y;
uint8_t x = x1;
for(uint8_t y = min(y1, y2)+5; y<=max(y1,y2); y++) //Refer Above
{
removePixel(tBuffer, x, y);
}
x = x2;
for(uint8_t y = min(y1, y2); y<=min(y1,y2)+4; y++) //Refer Above
{
removePixel(tBuffer, x, y);
}
uint8_t y = y2+5;
for(uint8_t x = min(x1, x2); x<=max(x1,x2)+4; x++) //Refer Above
{
removePixel(tBuffer, x, y);
}
}
//Displays written text to OLED, Function created due to buffer overwriting text
void displayText()
{
oledSetTextColumns(); //Writes text in top right corner
oledSetCursorByPixel(0,97);
oledWrite("Smart");
oledSetTextColumns();
oledSetCursorByPixel(1,85);
oledWrite("Parking");
oledSetTextColumns(); //Writes y-coordinates of Parking Spaces
oledSetCursorByPixel(1,28);
oledWrite("C");
oledSetTextColumns();
oledSetCursorByPixel(3,28);
oledWrite("B");
oledSetTextColumns();
oledSetCursorByPixel(5,28);
oledWrite("A");
oledSetTextColumns(); //Writes x-coordinates of Parking Spaces
oledSetCursorByPixel(7,42);
oledWrite("1");
oledSetTextColumns();
oledSetCursorByPixel(7,55);
oledWrite("2");
oledSetTextColumns();
oledSetCursorByPixel(7,68);
oledWrite("3");
oledSetTextColumns();
oledSetCursorByPixel(7,81);
oledWrite("4");
oledSetTextColumns(); //Labels Entrances
oledSetCursorByPixel(7,16);
oledWrite("E0");
oledSetTextColumns();
oledSetCursorByPixel(7,106);
oledWrite("E1");
}
//Initialize Parking lot with given parameters
void initializePL()
{
oledDriverInit(); //Initialize OLED
oledSetDisplayPower(0);
oledClear();
bitMask[0] = 0x01; //Declare bitMask 00000001
bitMask[1] = 0x02; //Declare bitMask 00000010
bitMask[2] = 0x04; //Declare bitMask 00000100
bitMask[3] = 0x08; //Declare bitMask 00001000
bitMask[4] = 0x10; //Declare bitMask 00010000
bitMask[5] = 0x20; //Declare bitMask 00100000
bitMask[6] = 0x40; //Declare bitMask 01000000
bitMask[7] = 0x80; //Declare bitMask 10000000
for(uint16_t i = 0; i < 1024; i++) //Initialize the buffer to 0
{
tBuffer[i] = 0x0;
}
for(uint8_t i = 0; i < NUMSPB; i++) //Coordinates of initial Parking Space boundaries
{
startPB[i].startpos.x = 37;
startPB[i].startpos.y = i*16 + 4;
startPB[i].endpos.x = 38;
startPB[i].endpos.y = i*16 + 15;
}
for(uint8_t i = 0; i < NUMPSROW; i++) //Coordinates of parking Space Boundaries, 'filled area', and centers
{
for(uint8_t j = 0; j < NUMPSCOL; j++)
{
uint8_t k = i*NUMPSCOL + j;
if(k < NUMPARKSPACE)
{
parkSpacePB[k].startpos.x = j*13 + 39;
parkSpacePB[k].startpos.y = 36 - i*16;
parkSpacePB[k].endpos.x = j*13 + 51;
parkSpacePB[k].endpos.y = 47 - i*16;
parkSpace[k].startpos.x = parkSpacePB[k].startpos.x + 2;
parkSpace[k].startpos.y = parkSpacePB[k].startpos.y + 4;
parkSpace[k].endpos.x = parkSpacePB[k].endpos.x - 4;
parkSpace[k].endpos.y = parkSpacePB[k].endpos.y;
psPos[k].x = parkSpace[k].startpos.x + 3;
psPos[k].y = parkSpace[k].startpos.y + 4;
}
}
}
for(uint8_t i = 0; i <NUMENTRANCE; i++) //Coordinates of Entrance boundaries and centers
{
entrance[i].startpos.x = 4 + i*111;
entrance[i].startpos.y = 60;
entrance[i].endpos.x = entrance[i].startpos.x + 8;
entrance[i].endpos.y = 63;
entPos[i].x = 8 + i*111;
entPos[i].y = 59;
}
drawStartPB(); //Draws initial boundaries
for(uint8_t i = 0; i<NUMPARKSPACE; i++) //Draws each parking space
{
drawPB(i);
}
for(uint8_t i = 0; i<NUMENTRANCE; i++) //Draws each entrance
{
drawEntrance(i);
}
oledDraw(tBuffer, 1024); //Display Buffer to OLED
displayText(); //Write text on top of buffer
oledSetDisplayPower(1); //Turn display on
}
//Draws given Parking space
void setPS(uint8_t aParkSpace)
{
oledSetCursorByPixel(0,0);
drawPS(aParkSpace);
oledDraw(tBuffer, 1024);
displayText();
}
//Clears given Parking space
void clearPS(uint8_t aParkSpace)
{
oledSetCursorByPixel(0,0);
removePS(aParkSpace);
oledDraw(tBuffer, 1024);
displayText();
}
//Draws given path
void setPath(uint8_t anEntrance, uint8_t aParkSpace)
{
oledSetCursorByPixel(0,0);
drawReserve(anEntrance, aParkSpace);
oledDraw(tBuffer, 1024);
displayText();
}
//Clears given path
void clearPath(uint8_t anEntrance, uint8_t aParkSpace)
{
oledSetCursorByPixel(0,0);
removeReserve(anEntrance, aParkSpace);
oledDraw(tBuffer, 1024);
displayText();
}
//Declaration of gpio's and direction (All inputs)
int gpioDeclare ()
{
uint8_t rv;
uint8_t rq;
// check if gpio is already exported
if ((rq = gpio_is_requested(1)) < 0)
{
perror("gpio_is_requested");
return EXIT_FAILURE;
}
if ((rq = gpio_is_requested(E0)) < 0)
{
perror("gpio_is_requested");
return EXIT_FAILURE;
}
if ((rq = gpio_is_requested(E1)) < 0)
{
perror("gpio_is_requested");
return EXIT_FAILURE;
}
if ((rq = gpio_is_requested(P0)) < 0)
{
perror("gpio_is_requested");
return EXIT_FAILURE;
}
if ((rq = gpio_is_requested(P1)) < 0)
{
perror("gpio_is_requested");
return EXIT_FAILURE;
}
if ((rq = gpio_is_requested(P2)) < 0)
{
perror("gpio_is_requested");
return EXIT_FAILURE;
}
if ((rq = gpio_is_requested(P4)) < 0)
{
perror("gpio_is_requested");
return EXIT_FAILURE;
}
if ((rq = gpio_is_requested(P5)) < 0)
{
perror("gpio_is_requested");
return EXIT_FAILURE;
}
if ((rq = gpio_is_requested(P6)) < 0)
{
perror("gpio_is_requested");
return EXIT_FAILURE;
}
//Declare gpio
if ((rv = gpio_request(1, NULL)) < 0)
{
perror("gpio_request");
return EXIT_FAILURE;
}
if ((rv = gpio_request(E0, NULL)) < 0)
{
perror("gpio_request");
return EXIT_FAILURE;
}
if ((rv = gpio_request(E1, NULL)) < 0)
{
perror("gpio_request");
return EXIT_FAILURE;
}
if ((rv = gpio_request(P0, NULL)) < 0)
{
perror("gpio_request");
return EXIT_FAILURE;
}
if ((rv = gpio_request(P1, NULL)) < 0)
{
perror("gpio_request");
return EXIT_FAILURE;
}
if ((rv = gpio_request(P2, NULL)) < 0)
{
perror("gpio_request");
return EXIT_FAILURE;
}
if ((rv = gpio_request(P4, NULL)) < 0)
{
perror("gpio_request");
return EXIT_FAILURE;
}
if ((rv = gpio_request(P5, NULL)) < 0)
{
perror("gpio_request");
return EXIT_FAILURE;
}
if ((rv = gpio_request(P6, NULL)) < 0)
{
perror("gpio_request");
return EXIT_FAILURE;
}
// set to input direction
printf("> setting to input\n");
if ((rv = gpio_direction_input(1)) < 0)
{
perror("gpio_direction_input");
}
if ((rv = gpio_direction_input(E0)) < 0)
{
perror("gpio_direction_input");
}
if ((rv = gpio_direction_input(E1)) < 0)
{
perror("gpio_direction_input");
}
if ((rv = gpio_direction_input(P0)) < 0)
{
perror("gpio_direction_input");
}
if ((rv = gpio_direction_input(P1)) < 0)
{
perror("gpio_direction_input");
}
if ((rv = gpio_direction_input(P2)) < 0)
{
perror("gpio_direction_input");
}
if ((rv = gpio_direction_input(P4)) < 0)
{
perror("gpio_direction_input");
}
if ((rv = gpio_direction_input(P5)) < 0)
{
perror("gpio_direction_input");
}
if ((rv = gpio_direction_input(P6)) < 0)
{
perror("gpio_direction_input");
}
return 0;
}
//OLED Display Data to track positions
void initializeDisplayInfo()
{
for(uint8_t i = 0; i < NUMPARKSPACE; i++) //Calculates distance from each entrance to parking space
{
display.distance[0][i] = ((i)%NUMPSCOL)+1 + i/NUMPSCOL;
display.distance[1][i] = NUMPSCOL-(i%NUMPSCOL) + i/NUMPSCOL;
//printf(">DISTANCE %d: %d\n", i, distance[0][i]);
//printf(">DISTANCE %d: %d\n", i, distance[1][i]);
}
for(uint8_t i = 0; i < NUMPARKSPACE; i++) //Initialize available parking spaces due to limitations in reed switches
{
display.PLStatus[i] = 1;
if(i == 0 || i == 1 || i == 2 || i == 4 || i == 5 || i == 6)
{
display.PLArray[i] = UNOCCUPIED;
}
else
{
setPS(i);
display.PLArray[i] = OCCUPIED;
}
}
for(uint8_t i = 0; i < NUMENTRANCE; i++) //Initialize entrances as empty
{
display.spotCounter[i] = 0;
display.ENTArray[i] = false;
}
}
//Parking Space input (input > 0)
void PSInput(int input)
{
if(display.PLArray[input-1] == UNOCCUPIED || display.PLArray[input-1] == RESERVED) //Occupies given parking space if empty or
{ //reserved
for(uint8_t i = 0; i < NUMENTRANCE; i++)
{
if(display.spot[i] == input-1) //If reserved remove reservation line
{
oledSetDisplayPower(0);
clearPath(i, input-1);
display.spotCounter[input-1] = 0;
display.ENTArray[i] = false;
}
}
setPS(input-1);
display.PLArray[input-1] = OCCUPIED;
oledSetDisplayPower(1);
}
else //Empties parking space
{
oledSetDisplayPower(0);
clearPS(input-1);
display.PLArray[input-1] = UNOCCUPIED;
oledSetDisplayPower(1);
}
bool flag = true;
for(uint8_t i = 0; i < NUMPARKSPACE; i++) //Checks if parking lot is full
{
if(display.PLArray[i] == UNOCCUPIED)
{
flag = false;
}
}
if(flag) //Indicates full parkinglot
{
oledSetTextColumns();
oledSetCursorByPixel(0,5);
oledWrite("FULL");
}
}
//Entrance input (input > 0)
void EInput(int input)
{
if(!(display.ENTArray[input-1])) //If the entrance isn't being used yet run code
{
display.tempDist = 0;
display.tempPS = 0;
for(uint8_t i = 0; i < NUMPARKSPACE; i++) //Check all available parking spaces and their distances from entrance
{
if(display.PLArray[i] == UNOCCUPIED)
{
if(!display.tempDist)
{
display.tempDist = display.distance[input-1][i];
display.tempPS = i;
}
else if (display.distance[input-1][i] < display.tempDist)
{
display.tempDist = display.distance[input-1][i];
display.tempPS = i;
}
}
}
if(display.tempDist == 0) //If no parking space found, parking lot is full
{
oledSetTextColumns();
oledSetCursorByPixel(0,5);
oledWrite("FULL");
}
else //Draw path to closest parking space
{
oledSetDisplayPower(0);
setPath(input-1, display.tempPS);
display.spot[input-1] = display.tempPS;
display.ENTArray[input-1] = true;
display.PLArray[display.tempPS] = RESERVED;
oledSetDisplayPower(1);
}
}
else
{
clearPath(input-1, 3);
display.ENTArray[input-1] = false;
}
}
int main ()
{
initializePL(); //Initialize Parking Lot (OLED And Co-ordinates)
initializeDisplayInfo(); //Initialize OLED Display info
int input = 1;
if(gpioDeclare()) //Declare GPIOS
{
perror("ERROR");
return -1;
}
while(input != 0) //Loop until Exited
{
bool loop = true;
while(loop) //Loops for valid input
{
usleep(10000);
for(uint8_t i = 0; i < NUMENTRANCE; i++) //Removes path to Parking space if beyond given threshold
{
if(display.ENTArray[i])
{
display.spotCounter[i] ++;
}
if(display.spotCounter[i] > 500)
{
clearPath(i, display.spot[i]);
display.PLArray[display.spot[i]] = UNOCCUPIED;
display.spotCounter[i] = 0;
display.ENTArray[i] = false;
}
}
if(gpio_get_value(1) == 1) //If overwrite button pressed, manual input
{
printf("> Please give an input: ");
fflush(stdout);
if(gpio_get_value(1) == 1)
{
scanf("%d", &input);
printf("\n");
loop = false;
}
}
if((!display.ENTArray[0]) && gpio_get_value(E0) == 0) //Inputs from Reed Switches (Must be declared individually)
{
input = -1;
loop = false;
}
else if((!display.ENTArray[1]) && gpio_get_value(E1) == 0)
{
input = -2;
loop = false;
}
else if(gpio_get_value(P0) != display.PLStatus[0])
{
input = 1;
display.PLStatus[0] = gpio_get_value(P0);
loop = false;
}
else if(gpio_get_value(P1) != display.PLStatus[1])
{
input = 2;
display.PLStatus[1] = gpio_get_value(P1);
loop = false;
}
else if(gpio_get_value(P2) != display.PLStatus[2])
{
input = 3;
display.PLStatus[2] = gpio_get_value(P2);
loop = false;
}
else if(gpio_get_value(P4) != display.PLStatus[4])
{
input = 5;
display.PLStatus[4] = gpio_get_value(P4);
loop = false;
}
else if(gpio_get_value(P5) != display.PLStatus[5])
{
input = 6;
display.PLStatus[5] = gpio_get_value(P5);
loop = false;
}
else if(gpio_get_value(P6) != display.PLStatus[6])
{
input = 7;
display.PLStatus[6] = gpio_get_value(P6);
loop = false;
}
}
if(input > 0) //If Parking Space Input
{
PSInput(input);
}
if(input < 0) //If Entrance Input
{
input = -input;
EInput(input);
}
}
oledClear(); //Clear OLED information
oledSetDisplayPower(0);
}