@@ -60,7 +60,6 @@ int gRawSampleBlockSize=1000;
60
60
int gSampleBlockSize =16000 ; // must be factor of 1000 in samples
61
61
int gBufferLen =1000 ; // in samples
62
62
int gBufferCount =18 ; // so 6*4000 = 24k buf len
63
- float gVoltage [] = {0 .0f , 0 .0f , 0 .0f , 0 .0f };
64
63
// always keep these in same order
65
64
int gbitShift;
66
65
bool gDisableBluetoothWhenRecording =false ;
@@ -77,12 +76,6 @@ int64_t gTotalUPTimeSinceReboot=esp_timer_get_time(); //esp_timer_get_time retu
77
76
int64_t gTotalRecordTimeSinceReboot =0 ;
78
77
int64_t gSessionRecordTime =0 ;
79
78
80
- // voltage
81
- bool gVoltageCalibrationDone =false ;
82
- float gVoltageOffset =10.0 ; // read this in on startup
83
- float gvOff=2.7 ;
84
- float gvFull=3.3 ;
85
- float gvLow=3.18 ;
86
79
int gMinutesWaitUntilDeepSleep =60 ; // change to 1 or 2 for testing
87
80
88
81
@@ -132,7 +125,6 @@ void readSettings();
132
125
void writeSettings (String settings);
133
126
void freeSpace ();
134
127
void doDeepSleep ();
135
- float getVoltage ();
136
128
void setTime (long epoch, int ms);
137
129
138
130
// idf-wav-sdcard/lib/sd_card/src/SDCard.cpp m_host.max_freq_khz = 18000;
@@ -194,14 +186,6 @@ void readConfig() {
194
186
ESP_LOGI (TAG, " gain override: %d" , gbitShift);
195
187
}
196
188
197
- position = strstr (line, " VoltageOffset:" );
198
- if (position != NULL )
199
- {
200
- position = strstr (line, " :" );
201
- gVoltageOffset = atof (position + 1 );
202
- ESP_LOGI (TAG, " voltage offset override: %f" , gVoltageOffset );
203
- }
204
-
205
189
position = strstr (line, " SecondsPerFile:" );
206
190
if (position != NULL )
207
191
{
@@ -574,14 +558,14 @@ void wait_for_button_push()
574
558
// digitalWrite(BATTERY_LED,LOW);
575
559
// bool gBatteryLEDToggle=false;
576
560
float currentvolts;
577
- currentvolts= getVoltage ()+ gVoltageOffset ;
561
+ currentvolts= Battery::GetInstance (). getVoltage ();
578
562
579
563
gRecording =false ;
580
- // getVoltage();
564
+ // Battery::GetInstance(). getVoltage();
581
565
boolean sentElocStatus=false ;
582
566
int loopcounter=0 ;
583
567
Serial.println ( " waiting for button or bluetooth" );
584
- Serial.println ( " voltage is " +String (getVoltage ()+ gVoltageOffset ));
568
+ Serial.println ( " voltage is " +String (Battery::GetInstance (). getVoltage ()));
585
569
586
570
587
571
int64_t timein= getSystemTimeMS ();
@@ -599,7 +583,7 @@ void wait_for_button_push()
599
583
600
584
while (!gotrecord)
601
585
{
602
- // getVoltage();
586
+ // Battery::GetInstance(). getVoltage();
603
587
// gotrecord=false;
604
588
// Serial.println( "waiting for buttonpress");
605
589
// btwrite("Waiting for record button");
@@ -791,8 +775,9 @@ void wait_for_button_push()
791
775
vTaskDelay (pdMS_TO_TICKS (30 )); // so if we get record, max 10ms off
792
776
793
777
778
+ /* *************** NOTE: Status LED blinking must be handled in a separate task
794
779
if (loopcounter==0) {
795
- currentvolts= getVoltage ()+ gVoltageOffset ;
780
+ currentvolts= Battery::GetInstance(). getVoltage();
796
781
//currentvolts=0.1;
797
782
if ((getSystemTimeMS()-timein) > (60000*gMinutesWaitUntilDeepSleep)) doDeepSleep(); // one hour to deep sleep
798
783
if (currentvolts <= gvOff) doDeepSleep();
@@ -807,6 +792,7 @@ void wait_for_button_push()
807
792
if (!SerialBT.connected()) digitalWrite(STATUS_LED,LOW);
808
793
if (currentvolts <= gvLow) digitalWrite(BATTERY_LED,LOW);
809
794
}
795
+ ****************************************************************************/
810
796
}
811
797
812
798
// mountSDCard();
@@ -891,67 +877,6 @@ String getProperDateTime() {
891
877
892
878
}
893
879
894
-
895
- float IRAM_ATTR getVoltage () {
896
- // Statements;
897
- // printf(" two following are heap size, total and max alloc ");
898
- // Note: ADC2 pins cannot be used when Wi-Fi is used. So, if you’re using Wi-Fi and you’re having trouble
899
- // getting the value from an ADC2 GPIO, you may consider using an ADC1 GPIO instead, that should solve your problem.
900
-
901
-
902
- // we want to measure up to 4 volts.
903
- // ed's stuff https://www.youtube.com/watch?v=5srvxIm1mcQ 470k 1.47meg
904
-
905
- // so the new vrange = 3.96v
906
-
907
-
908
- // 3.25v on en pin corresponds to 1.83v on gpio34
909
- // so voltage = pinread/4095 *X where x is the multiplier varies from device to device and on input current.
910
- // 3.29v =2979
911
- // so 3.29= 2979/4095 *3.96*X 3.29 =2.88*X so X = 1.142
912
- // pinMode(VOLTAGE_PIN,INPUT);
913
- // analogSetPinAttenuation(VOLTAGE_PIN, ADC_11db);
914
- // vTaskDelay(pdMS_TO_TICKS(500));
915
- // analogRead(VOLTAGE_PIN)
916
-
917
- // return(2.6);
918
-
919
- // uint16_t value=analogRead(VOLTAGE_PIN);
920
-
921
- float accum=0.0 ;
922
- float avg;
923
- for (int i=0 ; i<5 ;i++) {
924
- accum+= gpio_get_level (VOLTAGE_PIN);
925
- }
926
- // return((float)accum/5.0);
927
- avg=accum/5.0 ;
928
-
929
-
930
- // printf("voltage raw, calc" );
931
- // printf(value);
932
- // printf(" ");
933
- // printf(((float)value/4095)*3.96*1.142 ); //see above calc
934
- // printf(" ");
935
-
936
- // printf(analogReadMilliVolts(VOLTAGE_PIN));
937
- // delay(500);
938
-
939
- return (10.0 ); // comment
940
- // return((avg/4095)*3.96*1.142); //uncomment for field versions
941
-
942
- }
943
-
944
-
945
- float calculateVoltageOffset () {
946
- // gvoltageoffset will always be ADDED
947
- // assume battery is currently at voff =2.7
948
- //
949
- float temp= getVoltage ()-gvLow; // if v = 2.6 offset will be neg so need to be added if 2.8, pos, so need to be sub
950
- gVoltageOffset =temp*-1.0 ;
951
- Serial.println (" voltage offset is " +String (gVoltageOffset ));
952
- return gVoltageOffset ;
953
- }
954
-
955
880
void doDeepSleep (){
956
881
957
882
esp_sleep_enable_ext0_wakeup (OTHER_GPIO_BUTTON, 0 ); // then try changing between 0 and 1.
@@ -1086,8 +1011,9 @@ void record(I2SSampler *input) {
1086
1011
1087
1012
// voltage check
1088
1013
if ((loopCounter % 50 )==0 ) {
1089
- ESP_LOGI (TAG, " LOOPCOUNTER MOD 50 is 0" );
1090
- if ((getVoltage ()+gVoltageOffset )<gvOff) {
1014
+ ESP_LOGI (TAG, " Checking battery state" );
1015
+ Battery::GetInstance ().getVoltage ();
1016
+ if ((Battery::GetInstance ().isEmpty ())) {
1091
1017
stopit=true ; loopCounter=10000001L ;
1092
1018
ESP_LOGI (TAG, " Voltage LOW-OFF. Stopping record. " );
1093
1019
deepSleep=true ;
@@ -1357,13 +1283,13 @@ void sendElocStatus() { //compiles and sends eloc config
1357
1283
1358
1284
sendstring=sendstring+ " !1!" + gFirmwareVersion + " \n " ; // firmware
1359
1285
1360
- float tempvolts= getVoltage ()+ gVoltageOffset ;
1286
+ float tempvolts= Battery::GetInstance (). getVoltage ();
1361
1287
String temptemp= " FULL" ;
1362
- if (tempvolts <gvFull ) temptemp=" " ;
1363
- if (tempvolts <gvLow ) temptemp=" !!! LOW !!!" ;
1364
- if (tempvolts <gvOff ) temptemp=" turn off" ;
1288
+ if (! Battery::GetInstance (). isFull () ) temptemp=" " ;
1289
+ if (Battery::GetInstance (). isLow () ) temptemp=" !!! LOW !!!" ;
1290
+ if (Battery::GetInstance (). isEmpty () ) temptemp=" turn off" ;
1365
1291
1366
- if (gVoltageCalibrationDone ) {
1292
+ if (Battery::GetInstance (). isCalibrationDone () ) {
1367
1293
sendstring=sendstring+ " !2!" +String (tempvolts)+ " v # " +temptemp+" \n " ; // battery voltage
1368
1294
} else {
1369
1295
sendstring=sendstring+ " !2!" +String (tempvolts)+ " v " +temptemp+" \n " ;
@@ -1515,25 +1441,7 @@ readMicInfo();
1515
1441
1516
1442
1517
1443
readCurrentSession ();
1518
-
1519
-
1520
-
1521
- // read the voltage offset
1522
- FILE* f = fopen (" /spiffs/voltageoffset.txt" , " r" );
1523
- char line[128 ]=" " ;
1524
- if (f == NULL ) {
1525
- ESP_LOGI (TAG, " no voltage offset" );
1526
- // return;
1527
- } else {
1528
- fgets (line, sizeof (line), f);
1529
- gVoltageOffset =atof (line);
1530
- ESP_LOGI (TAG, " voltage offset %f" , gVoltageOffset );
1531
- }
1532
-
1533
- fclose (f);
1534
-
1535
-
1536
-
1444
+
1537
1445
1538
1446
1539
1447
0 commit comments