-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmix_v3.3_backup.ino
1419 lines (1293 loc) · 31.5 KB
/
cosmix_v3.3_backup.ino
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
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <EEPROM.h>
#include <TinyGPS.h>
#include <Serial1.h>
#include <RTClib.h>
#include <SD.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
// Référence shield //
// Mega 2560 Rev3 //
// GPS Shield Sparfun //
// Datalogging Arduino Shield CS L2 L1 //
// ------- //
// defines //
// ------- //
#define COINC_LINE 4
#define VERSION "m3.3s"
#define SERIALNUM "0-0"
// BMP085 pressure sensor
#define BMP085_ADDRESS 0x77 // I2C address of BMP085
// AdaFruit LCD RGB 16x2 Shield
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
#define BLANK_LINE " "
#define WELCOME_BKGCOLOR WHITE
#define ACQ_STOPPED_BKGCOLOR VIOLET
#define ACQ_STARTING_BKGCOLOR RED
#define ACQ_RUNNING_BKGCOLOR GREEN
#define WARNING1_BKGCOLOR RED
#define WARNING2_BKGCOLOR YELLOW
#define CFG_ACQ_BKGCOLOR TEAL
#define CFG_GPS_BKGCOLOR BLUE
#define DISP_TEMP_BKGCOLOR YELLOW
#define DISP_GPS_BKGCOLOR BLUE
#define ABOUT_BKGCOLOR TEAL
#define TITLE_MENU_ACQ ""
#define TITLE_MENU_CFG_ACQ "Cfg Acquisition"
#define TITLE_MENU_CFG_GPS "Cfg GPS"
#define TITLE_MENU_DISP_TP "Temp/Press Info"
#define TITLE_MENU_DISP_GPS "GPS Info"
#define TITLE_MENU_ABOUT "COSMIX Info"
#define RTC_DISPLAY_POS 15
// Buttons Pad
#define BUTTONSPAD_AI 0
#define BUTTON_UP 0x1
#define BUTTON_DOWN 0x2
#define BUTTON_LEFT 0x3
#define BUTTON_RIGHT 0x4
#define BUTTON_SELECT 0x5
#define BUTTON_NOTHING 0x0
#define BUTTON_NEXT 0x6
// GPS
/*
* GPS RX: pin 19
TX: pin 18
*/
#define RXPIN 19
#define TXPIN 18
#define GPSBAUD 4800
// SD
#define SD_LINE 10
/*
place #define MEGA_SOFT_SPI 1 in libraries/SD/utility/Sd2Card.h
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 10
*/
/*
* Interrupt pin 2 .
* BMP085 SDA 20
SCL 21
*/
// Display
#define NB_CFG_ACQ_DIGI 4
#define MAX_DURATION 9999
#define NB_MENU 6
#define MENU_ACQ 0
#define MENU_CFG_ACQ 1
#define MENU_CFG_GPS 2
#define MENU_DISP_TP 3
#define MENU_DISP_GPS 4
#define MENU_ABOUT 5
#define RTC_UNSET 0
#define RTC_PC 1
#define RTC_LOCAL 2
#define RTC_GPS 3
// --------- //
// Constants //
// --------- //
// SD Card
const int chipSelect = SD_LINE;
// BMP085
const unsigned char OSS = 0; // Oversampling Setting
// -------- //
// Globals //
// -------- //
// Config
bool continuousmode = true;
int duration = 0;
bool acqrunning = false;
char filename[15];
File dataFile;
char gpsfilename[15];
File gpsFile;
char serialnum[10];
// Event Counter
volatile long countPulse1=0;
volatile long countPulse2=0;
volatile long countCoinc=0;
volatile boolean event1=false;
volatile boolean event2=false;
volatile boolean eventc=false;
volatile long time0;
// module independant variables
short temperature;
long pressure;
// you can change the overall brightness by range 0 -> 255
int brightness = 255;
char cmode[2]={
'D',char(243)};
char RTCmodeDisplay[4]={
char(255),'\3','\4','\2'};
int RTCmode = RTC_UNSET;
char mess[80];
char longmess[200];
int longmessstart;
char cfg_acq_selindex = 0;
boolean acqdisplay = true;
boolean gpsmode = false;
boolean gpsset = false;
int gpstry = 0;
int selmenu = MENU_ACQ;
int localtime = 2;
char slatitude[15], slongitude[15];
float gpsaltitude = -999;
float latitude = -999;
float longitude = -999;
int lannee;
byte lemois;
byte lejour;
byte lheure;
byte laminute;
byte laseconde;
byte lescentiemes;
unsigned long lesmillis;
char lestatus[5];
char ascdate[100];
int about_index = 0;
DateTime now;
//ADKeyboard Module
int adc_key_val[5] ={
50, 200, 400, 600, 800 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;
// Serial comm data
char serialbuffer[20];
boolean stringComplete = false;
char datamess[200];
boolean serialcom = false;
byte newChar[8] = {
//4,14,31,0,0,0,0}; "^"
B00100,
B01110,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte newChar1[8] = {
//4,14,31,0,0,0,0}; "intersection"
B00000,
B01110,
B11011,
B10001,
B10001,
B10001,
B10001,
B00000
};
byte newChar2[8] = {
// antenne GPS
B00000,
B10001,
B10010,
B01100,
B01100,
B10011,
B10000,
B10000
};
byte newChar3[8] = {
//"PC"
B11000,
B10100,
B11000,
B10011,
B00100,
B00100,
B00011,
B00000
};
byte newChar4[8] = {
//"LC"
B10000,
B10000,
B10000,
B11011,
B00100,
B00100,
B00011,
B00000
};
byte newChar5[8] = {
//"��"
B00010,
B00100,
B01110,
B10001,
B11111,
B10000,
B01110,
B00000
};
byte newChar6[8] = {
//"��"
B01000,
B00100,
B01110,
B00001,
B01111,
B10001,
B01111,
B00000
};
char *menu[NB_MENU] = {
TITLE_MENU_ACQ,
TITLE_MENU_CFG_ACQ,
TITLE_MENU_CFG_GPS,
TITLE_MENU_DISP_TP,
TITLE_MENU_DISP_GPS,
TITLE_MENU_ABOUT
};
// BMP085 Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;
// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;
// --------------- //
// Globals Objects //
// --------------- //
RTC_DS1307 RTC;
//RTC_Millis RTC_m;
TinyGPS gps;
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// Stores all of the bmp085's calibration values into global variables
// Calibration values are required to calculate temp and pressure
// This function should be called at the beginning of the program
void bmp085Calibration()
{
ac1 = bmp085ReadInt(0xAA);
ac2 = bmp085ReadInt(0xAC);
ac3 = bmp085ReadInt(0xAE);
ac4 = bmp085ReadInt(0xB0);
ac5 = bmp085ReadInt(0xB2);
ac6 = bmp085ReadInt(0xB4);
b1 = bmp085ReadInt(0xB6);
b2 = bmp085ReadInt(0xB8);
mb = bmp085ReadInt(0xBA);
mc = bmp085ReadInt(0xBC);
md = bmp085ReadInt(0xBE);
}
// Calculate temperature given ut.
// Value returned will be in units of 0.1 deg C
short bmp085GetTemperature(unsigned int ut)
{
long x1, x2;
x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
x2 = ((long)mc << 11)/(x1 + md);
b5 = x1 + x2;
return ((b5 + 8)>>4);
}
// Calculate pressure given up
// calibration values must be known
// b5 is also required so bmp085GetTemperature(...) must be called first.
// Value returned will be pressure in units of Pa.
long bmp085GetPressure(unsigned long up)
{
long x1, x2, x3, b3, b6, p;
unsigned long b4, b7;
b6 = b5 - 4000;
// Calculate B3
x1 = (b2 * (b6 * b6)>>12)>>11;
x2 = (ac2 * b6)>>11;
x3 = x1 + x2;
b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
// Calculate B4
x1 = (ac3 * b6)>>13;
x2 = (b1 * ((b6 * b6)>>12))>>16;
x3 = ((x1 + x2) + 2)>>2;
b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
b7 = ((unsigned long)(up - b3) * (50000>>OSS));
if (b7 < 0x80000000)
p = (b7<<1)/b4;
else
p = (b7/b4)<<1;
x1 = (p>>8) * (p>>8);
x1 = (x1 * 3038)>>16;
x2 = (-7357 * p)>>16;
p += (x1 + x2 + 3791)>>4;
return p;
}
// Read 1 byte from the BMP085 at 'address'
char bmp085Read(unsigned char address)
{
unsigned char data;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 1);
while(!Wire.available());
return Wire.read();
}
// Read 2 bytes from the BMP085
// First byte will be from 'address'
// Second byte will be from 'address'+1
int bmp085ReadInt(unsigned char address)
{
unsigned char msb, lsb;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 2);
while(Wire.available()<2);
msb = Wire.read();
lsb = Wire.read();
return (int) msb<<8 | lsb;
}
// Read the uncompensated temperature value
unsigned int bmp085ReadUT()
{
unsigned int ut;
// Write 0x2E into Register 0xF4
// This requests a temperature reading
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF4);
Wire.write(0x2E);
Wire.endTransmission();
// Wait at least 4.5ms
delay(5);
// Read two bytes from registers 0xF6 and 0xF7
ut = bmp085ReadInt(0xF6);
return ut;
}
// Read the uncompensated pressure value
unsigned long bmp085ReadUP()
{
unsigned char msb, lsb, xlsb;
unsigned long up = 0;
// Write 0x34+(OSS<<6) into register 0xF4
// Request a pressure reading w/ oversampling setting
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF4);
Wire.write(0x34 + (OSS<<6));
Wire.endTransmission();
// Wait for conversion, delay time dependent on OSS
delay(2 + (3<<OSS));
// Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF6);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 3);
// Wait for data to become available
while(Wire.available() < 3)
;
msb = Wire.read();
lsb = Wire.read();
xlsb = Wire.read();
up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
return up;
}
//======================================================
// Stop Acquisition (VIOLET BackGround color = Acq stopped)
// --------------------------------
// Detach interrupts
// Close datafile
// Display final counts
//======================================================
void stopAcquisition()
{
detachInterrupt(0);
detachInterrupt(1);
event1 = false;
event2 = false;
eventc = false;
if(dataFile)dataFile.close();
lcd.setBacklight(ACQ_STOPPED_BKGCOLOR);
acqrunning = false;
if(serialcom)Serial.println("stopped");
if(selmenu==MENU_ACQ)displaycount();
return;
}
//======================================================
// Start Acquisition (GREEN BackGround = Acq running)
// --------------------------------
// Get initial time
// Open datafile
// attach interrupts
// Display counts
//======================================================
void startAcquisition()
{
event1 = false;
event2 = false;
eventc = false;
lcd.setBacklight(ACQ_STARTING_BKGCOLOR);
now= RTC.now();
sprintf(filename,"COSMIX.TXT");
dataFile = SD.open(filename, FILE_WRITE);
if (dataFile)
{
dataFile.println("----==== Nouvelle Acquisition ====---");
if (continuousmode)
sprintf(mess,"Mod: infini Heure locale : UTC%+i",localtime);
else
sprintf(mess,"Mod:%curee %04dmn Heure locale : UTC%+i",cmode[continuousmode],duration,localtime);
dataFile.println(mess);
}
if (gpsFile)gpsFile.println("----==== Nouvelle Acquisition ====---");
attachInterrupt(0, gestionINT01, RISING);
attachInterrupt(1, gestionINT02, RISING);
lcd.setBacklight(ACQ_RUNNING_BKGCOLOR);
time0 = millis();
displaycount();
acqrunning = true;
if(serialcom)Serial.println("started");
return;
}
//======================================================
// Acquisition Display setting
// BackGround GREEN when acquisition is running, VIOLET when stopped
// -------------------------------
// Set Acquisition Display header
// Display RTC status
// Display Counts
// Manage Buttons
// * RIGHT : Start/Stop Acquisition
// * LEFT : Reset (or Stop and Reset if running)
// * SELECT : Next menu
//======================================================
void acquisition_display(uint8_t buttons)
{
switch(buttons)
{
case BUTTON_NEXT:
lcd.clear();
(acqrunning)?lcd.setBacklight(ACQ_RUNNING_BKGCOLOR):lcd.setBacklight(ACQ_STOPPED_BKGCOLOR);
lcd.setCursor(0, 0);
sprintf(mess,"%c C1 C2 C1\1C2",cmode[continuousmode]);
lcd.print(mess);
displayRTC();
displaycount();
break;
case BUTTON_LEFT:
if(acqrunning)
{
stopAcquisition();
}
InitCounters();
displaycount();
acquisition_display(BUTTON_NOTHING);
break;
case BUTTON_RIGHT:
if(acqrunning)
{
stopAcquisition();
}
else
{
startAcquisition();
}
acquisition_display(BUTTON_NOTHING);
break;
case BUTTON_SELECT:
selmenu = (selmenu+1)%NB_MENU;
buttons = BUTTON_NEXT;
selectdisplay(false,buttons);
return;
}
buttons = BUTTON_NOTHING;
return;
}
//======================================================
// Config Acquisition
// BackGround CYAN
// -------------------------------
// Set Config Acquisition Display header
// Acquisition mode
// - continuous (infinity symbol)
// - finite (run duration limited to selected mn)
// Manage Buttons
// * RIGHT/LEFT : Change cursor position
// * UP/DOWN : change mode or change duration if finite mode selected
// * SELECT : Next menu
//======================================================
void menu_cfg_acq(uint8_t buttons)
{
int factor[NB_CFG_ACQ_DIGI] = {1000,100,10,1 };
switch(buttons)
{
case BUTTON_NEXT:
lcd.clear();
lcd.setBacklight(CFG_ACQ_BKGCOLOR);
lcd.setCursor(0,0);
lcd.print(menu[selmenu]);
cfg_acq_selindex = 0;
break;
case BUTTON_UP:
if(acqrunning)stopAcquisition();
InitCounters();
if (cfg_acq_selindex)
{
duration += factor[cfg_acq_selindex-1];
if(duration>MAX_DURATION)duration=MAX_DURATION;
}
else
{
continuousmode = !continuousmode;
}
break;
case BUTTON_DOWN:
if(acqrunning)stopAcquisition();
InitCounters();
if (cfg_acq_selindex)
{
duration -= factor[cfg_acq_selindex-1];
if(duration<0)duration = 0;
}
else
{
continuousmode = !continuousmode;
}
break;
case BUTTON_LEFT:
if(!continuousmode){
cfg_acq_selindex = ((cfg_acq_selindex+NB_CFG_ACQ_DIGI)%(NB_CFG_ACQ_DIGI+1));
}
break;
case BUTTON_RIGHT:
if(!continuousmode){
cfg_acq_selindex = ((cfg_acq_selindex+1)%(NB_CFG_ACQ_DIGI+ 1));
}
break;
case BUTTON_SELECT:
if(duration==0)
{
continuousmode = true;
}
selmenu = (selmenu+1)%NB_MENU;
buttons = BUTTON_NEXT;
selectdisplay(false,buttons);
return;
}
config_acq_display();
buttons = BUTTON_NOTHING;
return;
}
//======================================================
// Config GPS mode
// BackGround PINK
// -------------------------------
// Set Config GPS Display header
// Acquisition gpsmode
// - false (default)
// acquisition can start without GPS lock
// local time (from RTC) is used until
//
// - true
// Manage Buttons
// * RIGHT/LEFT : Change cursor position
// * UP/DOWN : change mode or change duration if finite mode selected
// * SELECT : Next menu
//======================================================
void menu_cfg_GPS(uint8_t buttons)
{
switch(buttons)
{
case BUTTON_NEXT:
lcd.clear();
lcd.setBacklight(CFG_GPS_BKGCOLOR);
lcd.setCursor(0,0);
lcd.print(menu[selmenu]);
longmessstart = 0;
break;
case BUTTON_UP:
gpsmode = !gpsmode;
break;
case BUTTON_DOWN:
gpsmode = !gpsmode;
break;
case BUTTON_SELECT:
selmenu = (selmenu+1)%NB_MENU;
buttons = BUTTON_NEXT;
selectdisplay(false,buttons);
return;
}
config_GPS_display();
buttons = BUTTON_NOTHING;
return;
}
void menu_disp_TP(uint8_t buttons)
{
switch(buttons)
{
case BUTTON_NEXT:
lcd.clear();
lcd.setBacklight(DISP_TEMP_BKGCOLOR);
lcd.setCursor(0,0);
lcd.print(menu[selmenu]);
break;
case BUTTON_UP:
break;
case BUTTON_DOWN:
break;
case BUTTON_LEFT:
break;
case BUTTON_RIGHT:
break;
case BUTTON_SELECT:
selmenu = (selmenu+1)%NB_MENU;
buttons = BUTTON_NEXT;
selectdisplay(false,buttons);
return;
}
buttons = BUTTON_NOTHING;
return;
}
void menu_disp_GPS(uint8_t buttons)
{
switch(buttons)
{
case BUTTON_NEXT:
lcd.clear();
lcd.setBacklight(DISP_GPS_BKGCOLOR);
lcd.setCursor(0,0);
lcd.print(menu[selmenu]);
break;
case BUTTON_UP:
break;
case BUTTON_DOWN:
break;
case BUTTON_LEFT:
break;
case BUTTON_RIGHT:
break;
case BUTTON_SELECT:
selmenu = (selmenu+1)%NB_MENU;
buttons = BUTTON_NEXT;
selectdisplay(false,buttons);
return;
}
buttons = BUTTON_NOTHING;
return;
}
void menu_about(uint8_t buttons)
{
switch(buttons)
{
case BUTTON_NEXT:
about_index = 0;
lcd.clear();
lcd.setBacklight(ABOUT_BKGCOLOR);
lcd.setCursor(0,0);
lcd.print(menu[selmenu]);
break;
case BUTTON_UP:
about_index += 1;
lcd.setCursor(0, 1);
lcd.print(BLANK_LINE);
break;
case BUTTON_DOWN:
about_index -= (about_index>0)?1:0;
lcd.setCursor(0, 1);
lcd.print(BLANK_LINE);
break;
case BUTTON_LEFT:
break;
case BUTTON_RIGHT:
break;
case BUTTON_SELECT:
selmenu = (selmenu+1)%NB_MENU;
buttons = BUTTON_NEXT;
selectdisplay(false,buttons);
return;
}
about_display();
buttons = BUTTON_NOTHING;
return;
}
void selectdisplay(bool init,uint8_t buttons)
{
if (init)
{
lcd.clear();
lcd.setBacklight(CFG_ACQ_BKGCOLOR);
cfg_acq_selindex = 0;
}
switch(selmenu)
{
case MENU_ACQ:
acquisition_display(buttons);
break;
case MENU_CFG_ACQ:
menu_cfg_acq(buttons);
break;
case MENU_CFG_GPS:
menu_cfg_GPS(buttons);
break;
case MENU_DISP_TP:
menu_disp_TP(buttons);
break;
case MENU_DISP_GPS:
menu_disp_GPS(buttons);
break;
case MENU_ABOUT:
menu_about(buttons);
break;
}
delay(200);
}
void config_acq_display()
{
char selindexpos[NB_CFG_ACQ_DIGI+1] = {4,10,11,12,13};
lcd.setCursor(0, 0);
if (continuousmode)
sprintf(mess,"Mod:%c ",cmode[continuousmode]);
else
sprintf(mess,"Mod:%cur\5e %04dmn",cmode[continuousmode],duration);
lcd.print(mess);
lcd.setCursor(4,1);
lcd.print(" ");
lcd.setCursor(selindexpos[cfg_acq_selindex],1);
lcd.print('\0');
}
void config_GPS_display()
{
lcd.setCursor(0, 0);
char cursormess[10];
if (gpsmode)
{
sprintf(mess,"Mod : GPS requis");
sprintf(cursormess,"----");
}
else
{
sprintf(mess,"Mod : GPS option");
sprintf(cursormess,"----");
}
lcd.print(mess);
lcd.setCursor(4,1);
lcd.print(" ");
lcd.setCursor(10,1);
lcd.print('\0');
lcd.print(cursormess);
lcd.print('\0');
}
void config_GPS_refresh_display()
{
getGPSInfo();
displayRTC();
}
void GPS_display()
{
getGPSInfo();
char slat[30];
char slong[30];
float2string(latitude,slat,4);
float2string(longitude,slong,4);
sprintf(mess,"%s/%s",slat,slong);
lcd.setCursor(0,1);
lcd.print(mess);
displayRTC();
}
void TP_display()
{
temperature = bmp085GetTemperature(bmp085ReadUT());
pressure = bmp085GetPressure(bmp085ReadUP());
lcd.setCursor(0,0);
sprintf(mess,"Temp: %d.%d %cC ",(int)((float)temperature/10.),(temperature<0)?(int)((-temperature)%10):(int)(temperature%10),char(223));
lcd.print(mess);
sprintf(mess,"Press: %lu Pa",(long)pressure);
lcd.setCursor(0,1);
lcd.print(mess);
}
void about_display()
{
char mess[16];
now = RTC.now();
switch (about_index%4)
{
case 0:
sprintf(mess,"%04d/%02d/%02d",now.year(),now.month(),now.day());
break;
case 1:
sprintf(mess,"%02d:%02d:%02d",now.hour(),now.minute(),now.second());
break;
case 2:
sprintf(mess,"Rel : %s",VERSION);
break;
case 3:
sprintf(mess,"S/N : %s",serialnum);
break;
}
lcd.setCursor(0, 1);
lcd.print(mess);
}
int get_key(unsigned int input)
{
int k;
for (k = 0; k < NUM_KEYS; k++)
if (input < adc_key_val[k])break;
if (k >= NUM_KEYS)k = -1; // No valid key pressed
return k;
}
int readButtons()
{
adc_key_in = analogRead(BUTTONSPAD_AI);
switch(get_key(adc_key_in))
{
case 0:
return BUTTON_SELECT;
case 1:
return BUTTON_UP;
case 2:
return BUTTON_RIGHT;
case 3:
return BUTTON_LEFT;
case 4:
return BUTTON_DOWN;
}
return BUTTON_NOTHING;
}
void ddmmssff(char *sval,float val, float invalid)
{
char sign =' ';
int ddval,mmval,ssval,ffval;
float dum;
if (val==invalid)
{
sprintf(sval,"**%c**'**.**%c",char(223),char(34));
return;
}
if (val<0)
{
sign = '-';
val = -val;
}
ddval = int(val);
dum = (val-ddval)*60;
mmval = int(dum);
dum = (dum-mmval)*60;
ssval = int(dum);
dum = (dum-ssval)*100;
ffval = int(dum);
sprintf(sval,"%c%d%c%02d'%02d.%02d%c",sign,ddval,char(223),mmval,ssval,ffval,char(34));
return;
}
void getGPSInfo()
{
boolean gpsvalid = false;
unsigned long age;
char sdiff[50];
char lmess[4];
lesmillis = millis();
now = RTC.now();
lannee = now.year();
lemois = now.month();
lejour = now.day();
lheure = now.hour();
laminute = now.minute();
laseconde = now.second();