Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flow3r
flow3r firmware
Commits
6e79447f
Verified
Commit
6e79447f
authored
1 year ago
by
dos
Browse files
Options
Downloads
Patches
Plain Diff
py,st3m: power: Explicitly handle uninitialized battery percentage
parent
7353d73e
No related branches found
No related tags found
1 merge request
!569
py,st3m: power: Explicitly handle uninitialized battery percentage
Pipeline
#9236
passed
1 year ago
Stage: check
Stage: build
Stage: deploy
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_payload/st3m/power.py
+6
-3
6 additions, 3 deletions
python_payload/st3m/power.py
with
6 additions
and
3 deletions
python_payload/st3m/power.py
+
6
−
3
View file @
6e79447f
...
@@ -28,8 +28,8 @@ class Power:
...
@@ -28,8 +28,8 @@ class Power:
self
.
_adc
=
machine
.
ADC
(
self
.
_adc_pin
,
atten
=
machine
.
ADC
.
ATTN_11DB
)
self
.
_adc
=
machine
.
ADC
(
self
.
_adc_pin
,
atten
=
machine
.
ADC
.
ATTN_11DB
)
self
.
_battery_voltage
=
self
.
_battery_voltage_sample
()
self
.
_battery_voltage
=
self
.
_battery_voltage_sample
()
self
.
_prev_battery_percentages
=
[
1
,
1
,
1
]
self
.
_prev_battery_percentages
=
[
-
1
,
-
1
,
-
1
]
self
.
_battery_percentage
=
1
self
.
_battery_percentage
=
-
1
# LUT created from Joulescope measurement of "official" 2Ah Battery at 650mW discharge at 26°C and decimated from ~42k samples
# LUT created from Joulescope measurement of "official" 2Ah Battery at 650mW discharge at 26°C and decimated from ~42k samples
self
.
_batLUT
=
[
self
.
_batLUT
=
[
(
99
,
4.114
),
(
99
,
4.114
),
...
@@ -138,7 +138,7 @@ class Power:
...
@@ -138,7 +138,7 @@ class Power:
# speeding up the process to get an intial settled value because recursion is hard
# speeding up the process to get an intial settled value because recursion is hard
for
i
in
range
(
5
):
for
i
in
range
(
5
):
self
.
_approximate_battery_percentage
()
self
.
_battery_percentage
=
self
.
_approximate_battery_percentage
()
self
.
_ts
=
time
.
ticks_ms
()
self
.
_ts
=
time
.
ticks_ms
()
def
_battery_voltage_sample
(
self
)
->
float
:
def
_battery_voltage_sample
(
self
)
->
float
:
...
@@ -207,6 +207,9 @@ class Power:
...
@@ -207,6 +207,9 @@ class Power:
# log.debug("prev: " + str(self._prev_battery_percentages) + " %")
# log.debug("prev: " + str(self._prev_battery_percentages) + " %")
percent_list
=
self
.
_prev_battery_percentages
percent_list
=
self
.
_prev_battery_percentages
if
-
1
in
percent_list
:
return
percentage
# avoid division by zero in weird edge cases
# avoid division by zero in weird edge cases
listsum
=
sum
(
percent_list
)
listsum
=
sum
(
percent_list
)
if
(
listsum
==
0
)
or
(
percent_list
[
0
]
==
0
):
if
(
listsum
==
0
)
or
(
percent_list
[
0
]
==
0
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment