-
Notifications
You must be signed in to change notification settings - Fork 994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #3074 and some other minor issues, improves battery level #3163
Closed
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
21886cf
heltec tracker Screen timeout bug
Gabrielerusso c206aec
Merge remote-tracking branch 'upstream/master'
Gabrielerusso d0db7fb
Update protobufs
Gabrielerusso 39878cf
fixed screen offsets and i2c pins
Gabrielerusso 95ba7b0
Merge remote-tracking branch 'upstream/master'
Gabrielerusso 1e2f4c9
fixes heltec tracker width/heigth labels
Gabrielerusso bd0cfad
Merge remote-tracking branch 'upstream/master'
Gabrielerusso e9f8675
Added battery level lookup table
Gabrielerusso 714108a
Fixed formatting for trunk
Gabrielerusso edd5bd7
Merge remote-tracking branch 'upstream/master'
Gabrielerusso 116ffaf
Added LiFePO4 and PB battery table
Gabrielerusso 3cce370
Fixes possible position leak when location is disabled
Gabrielerusso 0def5cd
Merge remote-tracking branch 'upstream/master'
Gabrielerusso bc53fcc
Version name corrections
Gabrielerusso b2084c0
Removed delay, added voltage filter
Gabrielerusso e7947a6
Merge remote-tracking branch 'upstream/master'
Gabrielerusso aabc979
Merge remote-tracking branch 'upstream/master'
Gabrielerusso 58acd28
Fixed ADC_CTRL , Checks for valid ADC readings
Gabrielerusso 11d78be
Fixed ESP32 ADC resolution bug introduced by #3184
Gabrielerusso 9d83e52
Trunk fmt
Gabrielerusso 940897a
added possibility to completely disable DEBUG LOG
Gabrielerusso cb59600
Merge remote-tracking branch 'upstream/master'
Gabrielerusso 10205d2
Update protobufs
Gabrielerusso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,7 +182,7 @@ class AnalogBatteryLevel : public HasBatteryLevel | |
|
||
#ifndef BATTERY_SENSE_SAMPLES | ||
#define BATTERY_SENSE_SAMPLES \ | ||
30 // Set the number of samples, it has an effect of increasing sensitivity in complex electromagnetic environment. | ||
15 // Set the number of samples, it has an effect of increasing sensitivity in complex electromagnetic environment. | ||
#endif | ||
|
||
#ifdef BATTERY_PIN | ||
|
@@ -208,12 +208,10 @@ class AnalogBatteryLevel : public HasBatteryLevel | |
raw = raw / BATTERY_SENSE_SAMPLES; | ||
scaled = operativeAdcMultiplier * ((1000 * AREF_VOLTAGE) / pow(2, BATTERY_SENSE_RESOLUTION_BITS)) * raw; | ||
#endif | ||
// LOG_DEBUG("battery gpio %d raw val=%u scaled=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled)); | ||
last_read_value += (scaled - last_read_value) * 0.5; // Virtual LPF | ||
return scaled; | ||
} else { | ||
return last_read_value; | ||
//LOG_DEBUG("battery gpio %d raw val=%u scaled=%u filtered=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled), (uint32_t) (last_read_value)); | ||
} | ||
return last_read_value; | ||
#endif // BATTERY_PIN | ||
return 0; | ||
} | ||
|
@@ -226,19 +224,24 @@ class AnalogBatteryLevel : public HasBatteryLevel | |
{ | ||
|
||
uint32_t raw = 0; | ||
uint8_t raw_c = 0; //raw reading counter | ||
|
||
#ifndef BAT_MEASURE_ADC_UNIT // ADC1 | ||
#ifdef ADC_CTRL | ||
#ifdef ADC_CTRL //enable adc voltage divider when we need to read | ||
pinMode(ADC_CTRL, OUTPUT); | ||
digitalWrite(ADC_CTRL, HIGH); | ||
digitalWrite(ADC_CTRL, ADC_CTRL_ENABLED); | ||
delay(10); | ||
#endif | ||
for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { | ||
raw += adc1_get_raw(adc_channel); | ||
int val_ = adc1_get_raw(adc_channel); | ||
if(val_ >= 0){ //save only valid readings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check for valid readings, invalid should give -1 but could be usefull to use strictly greather than 0 instead of >= ? |
||
raw += val_; | ||
raw_c ++; | ||
} | ||
// delayMicroseconds(100); | ||
} | ||
#ifdef ADC_CTRL | ||
digitalWrite(ADC_CTRL, LOW); | ||
#ifdef ADC_CTRL //disable adc voltage divider when we need to read | ||
digitalWrite(ADC_CTRL, !ADC_CTRL_ENABLED); | ||
#endif | ||
#else // ADC2 | ||
int32_t adc_buf = 0; | ||
|
@@ -249,10 +252,10 @@ class AnalogBatteryLevel : public HasBatteryLevel | |
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DATA_INV); | ||
adc2_get_raw(adc_channel, ADC_WIDTH_BIT_12, &adc_buf); | ||
raw += adc_buf; | ||
raw_c ++; | ||
} | ||
#endif // BAT_MEASURE_ADC_UNIT | ||
raw = raw / BATTERY_SENSE_SAMPLES; | ||
return raw; | ||
return (raw / (raw_c < 1 ? 1 : raw_c)); | ||
} | ||
#endif | ||
|
||
|
@@ -383,10 +386,6 @@ bool Power::analogInit() | |
} else { | ||
LOG_INFO("ADCmod: ADC characterization based on default reference voltage\n"); | ||
} | ||
#if defined(HELTEC_V3) || defined(HELTEC_WSL_V3) | ||
pinMode(37, OUTPUT); // needed for P channel mosfet to work | ||
digitalWrite(37, LOW); | ||
#endif | ||
#endif // ARCH_ESP32 | ||
|
||
#ifdef ARCH_NRF52 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there aren't filter caps with the resistor value i've seen the fet should saturate in less than 3ms