Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
onewire
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rust
onewire
Commits
87167e5f
Commit
87167e5f
authored
Jun 10, 2020
by
Michael Watzko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix compile and clippy errors (why the same again!?)
parent
1b1cd463
Pipeline
#174
passed with stage
in 5 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
30 deletions
+41
-30
src/ds18b20.rs
src/ds18b20.rs
+8
-4
src/lib.rs
src/lib.rs
+33
-26
No files found.
src/ds18b20.rs
View file @
87167e5f
...
...
@@ -33,10 +33,10 @@ pub enum MeasureResolution {
impl
MeasureResolution
{
pub
fn
time_ms
(
&
self
)
->
u16
{
match
self
{
&
MeasureResolution
::
TC8
=>
94
,
&
MeasureResolution
::
TC4
=>
188
,
&
MeasureResolution
::
TC2
=>
375
,
&
MeasureResolution
::
TC
=>
750
,
MeasureResolution
::
TC8
=>
94
,
MeasureResolution
::
TC4
=>
188
,
MeasureResolution
::
TC2
=>
375
,
MeasureResolution
::
TC
=>
750
,
}
}
}
...
...
@@ -58,6 +58,10 @@ impl DS18B20 {
}
}
/// # Safety
///
/// This is marked as unsafe because it does not check whether the given address
/// is compatible with a DS18B20 device. It assumes so.
pub
unsafe
fn
new_forced
(
device
:
Device
)
->
DS18B20
{
DS18B20
{
device
,
...
...
src/lib.rs
View file @
87167e5f
...
...
@@ -25,7 +25,7 @@ pub enum Command {
}
#[derive(Debug)]
pub
enum
Error
<
IO
E
:
Sized
+
Debug
>
{
pub
enum
Error
<
E
:
Sized
+
Debug
>
{
WireNotHigh
,
CrcMismatch
(
u8
,
u8
),
FamilyCodeMismatch
(
u8
,
u8
),
...
...
@@ -45,27 +45,31 @@ pub struct Device {
}
impl
Device
{
pub
fn
from_str
(
string
:
&
str
)
->
Result
<
Device
,
::
core
::
num
::
ParseIntError
>
{
if
string
.len
()
<
23
{
pub
fn
family_code
(
&
self
)
->
u8
{
self
.address
[
0
]
}
}
impl
core
::
str
::
FromStr
for
Device
{
type
Err
=
core
::
num
::
ParseIntError
;
fn
from_str
(
s
:
&
str
)
->
Result
<
Self
,
Self
::
Err
>
{
if
s
.len
()
<
23
{
let
_
=
u8
::
from_str_radix
(
""
,
16
)
?
;
// this causes a ParseIntError::Empty
}
Ok
(
Device
{
address
:
[
u8
::
from_str_radix
(
&
s
tring
[
0
..
2
],
16
)
?
,
u8
::
from_str_radix
(
&
s
tring
[
3
..
5
],
16
)
?
,
u8
::
from_str_radix
(
&
s
tring
[
6
..
8
],
16
)
?
,
u8
::
from_str_radix
(
&
s
tring
[
9
..
11
],
16
)
?
,
u8
::
from_str_radix
(
&
s
tring
[
12
..
14
],
16
)
?
,
u8
::
from_str_radix
(
&
s
tring
[
15
..
17
],
16
)
?
,
u8
::
from_str_radix
(
&
s
tring
[
18
..
20
],
16
)
?
,
u8
::
from_str_radix
(
&
s
tring
[
21
..
23
],
16
)
?
,
u8
::
from_str_radix
(
&
s
[
0
..
2
],
16
)
?
,
u8
::
from_str_radix
(
&
s
[
3
..
5
],
16
)
?
,
u8
::
from_str_radix
(
&
s
[
6
..
8
],
16
)
?
,
u8
::
from_str_radix
(
&
s
[
9
..
11
],
16
)
?
,
u8
::
from_str_radix
(
&
s
[
12
..
14
],
16
)
?
,
u8
::
from_str_radix
(
&
s
[
15
..
17
],
16
)
?
,
u8
::
from_str_radix
(
&
s
[
18
..
20
],
16
)
?
,
u8
::
from_str_radix
(
&
s
[
21
..
23
],
16
)
?
,
],
})
}
pub
fn
family_code
(
&
self
)
->
u8
{
self
.address
[
0
]
}
}
#[derive(Debug,
Clone,
Copy,
PartialEq)]
...
...
@@ -75,7 +79,13 @@ enum SearchState {
End
,
}
#[derive(Clone)]
impl
Default
for
SearchState
{
fn
default
()
->
Self
{
SearchState
::
Initialized
}
}
#[derive(Clone,
Default)]
pub
struct
DeviceSearch
{
address
:
[
u8
;
8
],
discrepancies
:
[
u8
;
8
],
...
...
@@ -84,11 +94,7 @@ pub struct DeviceSearch {
impl
DeviceSearch
{
pub
fn
new
()
->
DeviceSearch
{
DeviceSearch
{
address
:
[
0u8
;
ADDRESS_BYTES
as
usize
],
discrepancies
:
[
0u8
;
ADDRESS_BYTES
as
usize
],
state
:
SearchState
::
Initialized
,
}
DeviceSearch
::
default
()
}
pub
fn
new_for_family
(
family
:
u8
)
->
DeviceSearch
{
...
...
@@ -129,6 +135,7 @@ impl DeviceSearch {
DeviceSearch
::
reset_bit
(
&
mut
self
.discrepancies
,
bit
);
}
#[allow(unused)]
// useful method anyway?
fn
write_bit_in_discrepancy
(
&
mut
self
,
bit
:
u8
,
value
:
bool
)
{
if
value
{
self
.set_bit_in_discrepancy
(
bit
);
...
...
@@ -283,7 +290,7 @@ impl<E: core::fmt::Debug, ODO: OpenDrainOutput<Error = E>> OneWire<ODO> {
)
->
Result
<
(),
Error
<
E
>>
{
self
.reset
(
delay
)
?
;
self
.select
(
delay
,
device
)
?
;
self
.select
(
delay
,
device
);
self
.select
(
delay
,
device
)
?
;
self
.read_bytes
(
delay
,
read
)
?
;
Ok
(())
}
...
...
@@ -296,7 +303,7 @@ impl<E: core::fmt::Debug, ODO: OpenDrainOutput<Error = E>> OneWire<ODO> {
)
->
Result
<
(),
Error
<
E
>>
{
self
.reset
(
delay
)
?
;
self
.select
(
delay
,
device
)
?
;
self
.select
(
delay
,
device
);
self
.select
(
delay
,
device
)
?
;
self
.write_bytes
(
delay
,
write
)
?
;
Ok
(())
}
...
...
@@ -411,7 +418,7 @@ impl<E: core::fmt::Debug, ODO: OpenDrainOutput<Error = E>> OneWire<ODO> {
rom
.state
=
SearchState
::
DeviceFound
;
}
Ok
(
Some
(
Device
{
address
:
rom
.address
.clone
()
,
address
:
rom
.address
,
}))
}
...
...
@@ -455,8 +462,8 @@ impl<E: core::fmt::Debug, ODO: OpenDrainOutput<Error = E>> OneWire<ODO> {
}
pub
fn
read_bytes
(
&
mut
self
,
delay
:
&
mut
impl
DelayUs
<
u16
>
,
dst
:
&
mut
[
u8
])
->
Result
<
(),
E
>
{
for
i
in
0
..
dst
.len
()
{
dst
[
i
]
=
self
.read_byte
(
delay
)
?
;
for
d
in
dst
{
*
d
=
self
.read_byte
(
delay
)
?
;
}
Ok
(())
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment