Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mobile-transceiver-software
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
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Will Sloan
mobile-transceiver-software
Compare revisions
master to 05c4114c645bb0dabc4710e34f8872c36371eaee
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
xanarin/mobile-transceiver-software
Select target project
No results found
05c4114c645bb0dabc4710e34f8872c36371eaee
Select Git revision
Swap
Target
cats/mobile-transceiver-software
Select target project
cats/mobile-transceiver-software
Reed/mobile-transceiver-software
xanarin/mobile-transceiver-software
3 results
master
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (1)
add analog sensors
· 05c4114c
Stephen D
authored
4 months ago
05c4114c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main.rs
+20
-2
20 additions, 2 deletions
src/main.rs
src/shell.rs
+10
-0
10 additions, 0 deletions
src/shell.rs
src/voltage.rs
+30
-1
30 additions, 1 deletion
src/voltage.rs
with
60 additions
and
3 deletions
src/main.rs
View file @
05c4114c
...
...
@@ -21,6 +21,9 @@ pub type MyInstant = Instant<u64, 1, { SYS_TICK_FREQ }>;
#[rtic::app(device
=
stm32f4xx_hal::pac,
peripherals
=
true
,
dispatchers
=
[
USART1,
USART6]
)]
mod
app
{
use
core
::
fmt
::
Write
;
use
arrayvec
::
ArrayString
;
use
cortex_m
::
singleton
;
use
hal
::{
adc
::{
config
::
AdcConfig
,
Adc
},
...
...
@@ -129,8 +132,18 @@ mod app {
// setup volt meter
let
volt_pin
=
gpioc
.pc0
.into_analog
();
let
sensor1
=
gpioc
.pc2
.into_analog
();
let
sensor2
=
gpioc
.pc3
.into_analog
();
let
sensor3
=
gpioc
.pc4
.into_analog
();
let
volt_adc
=
Adc
::
adc1
(
dp
.ADC1
,
true
,
AdcConfig
::
default
());
let
mut
volt_meter
=
VoltMeter
::
new
(
volt_pin
,
volt_adc
,
config
.min_voltage
.into
());
let
mut
volt_meter
=
VoltMeter
::
new
(
volt_pin
,
sensor1
,
sensor2
,
sensor3
,
volt_adc
,
config
.min_voltage
.into
(),
);
// Detect if we're connected to USB or not
let
usb_detect
=
gpioa
.pa5
.into_pull_down_input
();
...
...
@@ -306,7 +319,10 @@ mod app {
let
mut
buf
=
[
0
;
MAX_PACKET_LEN
];
let
mut
cats
=
Packet
::
new
(
&
mut
buf
);
let
voltage
=
ctx
.shared.volt_meter
.lock
(|
vm
|
vm
.voltage
());
let
(
sensors
,
voltage
)
=
ctx
.shared
.volt_meter
.lock
(|
vm
|
(
vm
.sensors
(),
vm
.voltage
()));
let
temp
=
ctx
.shared
.radio
...
...
@@ -332,6 +348,8 @@ mod app {
.unwrap
();
if
!
config
.comment
.is_empty
()
{
let
mut
buf
:
ArrayString
<
64
>
=
ArrayString
::
new
();
write!
(
&
mut
buf
,
"{} {} {}"
,
sensors
[
0
],
sensors
[
1
],
sensors
[
2
])
.unwrap
();
cats
.add_comment
(
&
config
.comment
)
.unwrap
();
}
...
...
This diff is collapsed.
Click to expand it.
src/shell.rs
View file @
05c4114c
...
...
@@ -256,6 +256,16 @@ impl Shell {
write!
(
ushell
,
"
\r\n
{volts:.2} V
\r\n
"
)
.ok
();
}
"sensors"
=>
{
let
sensors
=
volt_meter
.lock
(|
vm
|
vm
.sensors
());
write!
(
ushell
,
"
\r\n
S1: {} mV
\r\n
S2: {} mV
\r\n
S3: {} mV
\r\n
"
,
sensors
[
0
],
sensors
[
1
],
sensors
[
2
]
)
.ok
();
}
"help"
=>
{
write!
(
ushell
,
"{}"
,
HELP_TEXT
)
.ok
();
}
...
...
This diff is collapsed.
Click to expand it.
src/voltage.rs
View file @
05c4114c
...
...
@@ -8,20 +8,49 @@ const FACTOR: f64 = 1.0 / 0.0757856;
pub
struct
VoltMeter
{
pin
:
Pin
<
'C'
,
0
,
Analog
>
,
sensor1
:
Pin
<
'C'
,
2
,
Analog
>
,
sensor2
:
Pin
<
'C'
,
3
,
Analog
>
,
sensor3
:
Pin
<
'C'
,
4
,
Analog
>
,
adc
:
Adc
<
ADC1
>
,
threshold
:
Option
<
f32
>
,
}
impl
VoltMeter
{
pub
fn
new
(
pin
:
Pin
<
'C'
,
0
,
Analog
>
,
mut
adc
:
Adc
<
ADC1
>
,
threshold
:
Option
<
f32
>
)
->
Self
{
pub
fn
new
(
pin
:
Pin
<
'C'
,
0
,
Analog
>
,
sensor1
:
Pin
<
'C'
,
2
,
Analog
>
,
sensor2
:
Pin
<
'C'
,
3
,
Analog
>
,
sensor3
:
Pin
<
'C'
,
4
,
Analog
>
,
mut
adc
:
Adc
<
ADC1
>
,
threshold
:
Option
<
f32
>
,
)
->
Self
{
adc
.calibrate
();
Self
{
pin
,
sensor1
,
sensor2
,
sensor3
,
adc
,
threshold
,
}
}
pub
fn
sensors
(
&
mut
self
)
->
[
u16
;
3
]
{
let
samples
=
[
self
.adc
.convert
(
&
self
.sensor1
,
SampleTime
::
Cycles_480
),
self
.adc
.convert
(
&
self
.sensor2
,
SampleTime
::
Cycles_480
),
self
.adc
.convert
(
&
self
.sensor3
,
SampleTime
::
Cycles_480
),
];
let
mut
out
=
[
0
;
3
];
for
(
i
,
s
)
in
samples
.iter
()
.enumerate
()
{
out
[
i
]
=
self
.adc
.sample_to_millivolts
(
*
s
);
}
out
}
pub
fn
voltage
(
&
mut
self
)
->
f64
{
let
sample
=
self
.adc
.convert
(
&
self
.pin
,
SampleTime
::
Cycles_480
);
let
mv
=
self
.adc
.sample_to_millivolts
(
sample
);
...
...
This diff is collapsed.
Click to expand it.