26
26
#include " Esp.h"
27
27
#include < FS.h>
28
28
#include " SPIFFS.h"
29
+
30
+ #include " config.h"
29
31
#include " ElocConfig.hpp"
30
32
31
33
const char * TAG = " CONFIG" ;
@@ -83,7 +85,10 @@ void readMicInfo() {
83
85
file2.close ();
84
86
Serial.println (" micinfo: " + gMicInfo .MicType + " " + gMicInfo .MicBitShift + " " + gMicInfo .MicGPSCoords + " " + gMicInfo .MicPointingDirectionDegrees + " " + gMicInfo .MicHeight + " " + gMicInfo .MicMountType + " " + gMicInfo .MicBluetoothOnOrOff );
85
87
}
88
+ /* *************************************************************************************************/
89
+
86
90
91
+ /* ************************** Global settings via BT Config ****************************************/
87
92
// BUGME: encapsulate these in a struct & implement a getter
88
93
uint32_t gSampleRate ;
89
94
int gSecondsPerFile = 60 ;
@@ -330,3 +335,216 @@ void readSettings() {
330
335
331
336
file2.close ();
332
337
}
338
+
339
+
340
+
341
+ /* *************************************************************************************************/
342
+
343
+
344
+ /* ************************** Global settings via config file **************************************/
345
+ // BUGME: handle this through file system
346
+ extern bool gMountedSDCard ;
347
+
348
+ // BUGME: encapsulate these in a struct & implement a getter
349
+ int gbitShift;
350
+ bool TestI2SClockInput=false ;
351
+ bool gTimingFix =false ;
352
+ bool gListenOnly =true ;
353
+ bool gUseAPLL =true ;
354
+ int gMaxFrequencyMHZ =80 ; // SPI this fails for anyting below 80 //
355
+ int gMinFrequencyMHZ =10 ;
356
+ bool gEnableLightSleep =true ; // only for AUTOMATIC light leep.
357
+
358
+ void readConfig () {
359
+
360
+ char line[128 ] = " " ;
361
+ char *position;
362
+ if (gMountedSDCard ) {
363
+ FILE *f = fopen (" /sdcard/eloctest.txt" , " r" );
364
+ if (f == NULL ) {
365
+ ESP_LOGI (TAG, " no eloc testing file on root of SDCARD " );
366
+ // return;
367
+ } else {
368
+ ESP_LOGI (TAG, " \n\n\n " );
369
+ while (!feof (f)) {
370
+ fgets (line, sizeof (line), f);
371
+ // ESP_LOGI(TAG, "%s", line);
372
+
373
+ position = strstr (line, " SampleRate:" );
374
+ if (position != NULL ) {
375
+ position = strstr (line, " :" );
376
+ gSampleRate = atoi (position + 1 );
377
+ ESP_LOGI (TAG, " sample rate override %u" , gSampleRate );
378
+ }
379
+
380
+ position = strstr (line, " MaxFrequencyMHZ:" );
381
+ if (position != NULL ) {
382
+ position = strstr (line, " :" );
383
+ gMaxFrequencyMHZ = atoi (position + 1 );
384
+ ESP_LOGI (TAG, " Max Frequency MHZ override %d" , gMaxFrequencyMHZ );
385
+ }
386
+ position = strstr (line, " MinFrequencyMHZ:" );
387
+ if (position != NULL ) {
388
+ position = strstr (line, " :" );
389
+ gMinFrequencyMHZ = atoi (position + 1 );
390
+ ESP_LOGI (TAG, " Min Frequency MHZ override %d" , gMinFrequencyMHZ );
391
+ }
392
+
393
+ position = strstr (line, " gain:" );
394
+ if (position != NULL ) {
395
+ position = strstr (line, " :" );
396
+ gbitShift = atoi (position + 1 );
397
+ ESP_LOGI (TAG, " gain override: %d" , gbitShift);
398
+ }
399
+
400
+ position = strstr (line, " SecondsPerFile:" );
401
+ if (position != NULL ) {
402
+ position = strstr (line, " :" );
403
+ gSecondsPerFile = atoi (position + 1 );
404
+ ESP_LOGI (TAG, " Seconds per File override: %d" , gSecondsPerFile );
405
+ }
406
+
407
+ position = strstr (line, " UseAPLL:no" );
408
+ if (position != NULL ) {
409
+ gUseAPLL = false ;
410
+ }
411
+ position = strstr (line, " UseAPLL:yes" );
412
+ if (position != NULL ) {
413
+ gUseAPLL = true ;
414
+ }
415
+ position = strstr (line, " TryLightSleep?:yes" );
416
+ if (position != NULL ) {
417
+ gEnableLightSleep = true ;
418
+ }
419
+ position = strstr (line, " TryLightSleep?:no" );
420
+ if (position != NULL ) {
421
+ gEnableLightSleep = false ;
422
+ }
423
+ position = strstr (line, " ListenOnly?:no" );
424
+ if (position != NULL ) {
425
+ gListenOnly = false ;
426
+ }
427
+ position = strstr (line, " ListenOnly?:yes" );
428
+ if (position != NULL ) {
429
+ gListenOnly = true ;
430
+ }
431
+ position = strstr (line, " TimingFix:no" );
432
+ if (position != NULL ) {
433
+ gTimingFix = false ;
434
+ }
435
+ position = strstr (line, " TimingFix:yes" );
436
+ if (position != NULL ) {
437
+ gTimingFix = true ;
438
+ }
439
+ position = strstr (line, " TestI2SClockInput:no" );
440
+ if (position != NULL ) {
441
+ TestI2SClockInput = false ;
442
+ }
443
+ position = strstr (line, " TestI2SClockInput:yes" );
444
+ if (position != NULL ) {
445
+ TestI2SClockInput = true ;
446
+ }
447
+ }
448
+ ESP_LOGI (TAG, " Use APLL override: %d" , gUseAPLL );
449
+ ESP_LOGI (TAG, " Enable light Sleep override: %d" , gEnableLightSleep );
450
+ ESP_LOGI (TAG, " Listen Only override: %d" , gListenOnly );
451
+ ESP_LOGI (TAG, " Timing fix override: %d" , gTimingFix );
452
+ ESP_LOGI (TAG, " Test i2sClockInput: %d" , TestI2SClockInput);
453
+ ESP_LOGI (TAG, " \n\n\n " );
454
+
455
+ fclose (f);
456
+ }
457
+ }
458
+
459
+ i2s_mic_Config.sample_rate = gSampleRate ;
460
+ if (gSampleRate <= 32000 ) { // my wav files sound wierd if apll clock raate is > 32kh. So force non-apll clock if >32khz
461
+ i2s_mic_Config.use_apll = gUseAPLL ;
462
+ ESP_LOGI (TAG, " Sample Rate is < 32khz USE APLL Clock %d" , gUseAPLL );
463
+ } else {
464
+ i2s_mic_Config.use_apll = false ;
465
+ ESP_LOGI (TAG, " Sample Rate is > 32khz Forcing NO_APLL " );
466
+ }
467
+ }
468
+
469
+ void readCurrentSession () {
470
+ char line[128 ] = " " ;
471
+ char *position;
472
+
473
+ FILE *f = fopen (" /spiffs/currentsession.txt" , " r" );
474
+ if (f == NULL ) {
475
+ // gSessionFolder="";
476
+ ESP_LOGI (TAG, " Failed to open file for reading" );
477
+ // return;
478
+ } else {
479
+
480
+ // char *test=line;
481
+
482
+ while (!feof (f)) {
483
+ fgets (line, sizeof (line), f);
484
+ // ESP_LOGI(TAG, "%s", line);
485
+ // char *test2;
486
+ // int start,finish;
487
+ position = strstr (line, " Session ID" );
488
+ if (position != NULL ) {
489
+ position = strstr (line, " _" ); // need to ad one memory location
490
+ //
491
+ // the long epoch will be in the first 10 digits. int microseconds the last 3
492
+
493
+ gStartupTime = atoll (position + 1 );
494
+
495
+ char epoch[10 ] = " " ;
496
+ epoch[0 ] = *(position + 1 );
497
+ epoch[1 ] = *(position + 2 );
498
+ epoch[2 ] = *(position + 3 );
499
+ epoch[3 ] = *(position + 4 );
500
+ epoch[4 ] = *(position + 5 );
501
+ epoch[5 ] = *(position + 6 );
502
+ epoch[6 ] = *(position + 7 );
503
+ epoch[7 ] = *(position + 8 );
504
+ epoch[8 ] = *(position + 9 );
505
+ epoch[9 ] = *(position + 10 );
506
+
507
+ char ms[3 ] = " " ;
508
+ ms[0 ] = *(position + 11 );
509
+ ms[1 ] = *(position + 12 );
510
+ ms[2 ] = *(position + 13 );
511
+
512
+ // ESP_LOGI(TAG, "epoch %s", epoch);
513
+ // ESP_LOGI(TAG, "ms %s", ms);
514
+
515
+ setTime (atol (epoch), atoi (ms));
516
+ ESP_LOGI (TAG, " startup time %lld" , gStartupTime );
517
+ // ESP_LOGI(TAG, "testing atol %ld", atol("1676317685250"));
518
+ // ESP_LOGI(TAG, "testing atoll %lld", atoll("1676317685250"));
519
+ position = strstr (line, " : " );
520
+ ESP_LOGI (TAG, " session FOLDER 1 %s" , position + 3 );
521
+ strncat (gSessionFolder , position + 3 , 63 );
522
+ gSessionFolder [strcspn (gSessionFolder , " \n " )] = ' \0 ' ;
523
+ ESP_LOGI (TAG, " gSessionFolder %s" , gSessionFolder );
524
+ }
525
+ position = strstr (line, " Sample Rate:" );
526
+ if (position != NULL ) {
527
+ position = strstr (line, " : " ); // need to ad one memory location
528
+ gSampleRate = atoi (position + 3 );
529
+ // gSampleRate=4000;
530
+ ESP_LOGI (TAG, " sample rate %u" , gSampleRate );
531
+ }
532
+
533
+ position = strstr (line, " Mic Gain:" );
534
+ if (position != NULL ) {
535
+ position = strstr (line, " : " ); // need to ad one memory location
536
+ gbitShift = atol (position + 3 );
537
+ ESP_LOGI (TAG, " bit shift %d" , gbitShift);
538
+ }
539
+
540
+ position = strstr (line, " Seconds Per File:" );
541
+ if (position != NULL ) {
542
+ position = strstr (line, " : " ); // need to ad one memory location
543
+ gSecondsPerFile = atol (position + 3 );
544
+ ESP_LOGI (TAG, " seconds per file %d" , gSecondsPerFile );
545
+ }
546
+ }
547
+ }
548
+
549
+ fclose (f);
550
+ }
0 commit comments