Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Astro
rust-card10
Commits
16d5d0b1
Commit
16d5d0b1
authored
Aug 22, 2019
by
Astro
⚙
Browse files
light_sensor
parent
6a50161e
Changes
3
Hide whitespace changes
Inline
Side-by-side
example/src/main.rs
View file @
16d5d0b1
...
...
@@ -9,6 +9,7 @@ fn main() {
writeln!
(
UART
,
"Hello from Rust
\r
"
)
.unwrap
();
let
display
=
Display
::
open
();
let
light
=
LightSensor
::
start
();
for
t
in
0
..
Display
::
W
{
display
.clear
(
Color
::
yellow
());
display
.print
(
160
-
t
,
10
,
b"Hello Rust
\0
"
,
Color
::
white
(),
Color
::
black
());
...
...
@@ -29,6 +30,7 @@ fn main() {
if
b
.right_top
()
{
display
.print
(
80
,
30
,
b"Reset
\0
"
,
Color
::
red
(),
Color
::
black
());
}
writeln!
(
UART
,
"Light: {:?}
\r
"
,
light
.get
());
display
.update
();
}
...
...
l0dable/src/lib.rs
View file @
16d5d0b1
...
...
@@ -67,9 +67,10 @@ mod display;
pub
use
display
::{
Display
,
Color
,
LineStyle
};
mod
buttons
;
pub
use
buttons
::
Buttons
;
pub
mod
uart
;
pub
const
UART
:
uart
::
Uart
=
uart
::
Uart
;
mod
light_sensor
;
pub
use
light_sensor
::
LightSensor
;
pub
fn
exit
(
ret
:
i32
)
->
!
{
unsafe
{
...
...
l0dable/src/light_sensor.rs
0 → 100644
View file @
16d5d0b1
use
super
::
bindings
::
*
;
pub
struct
LightSensor
;
impl
LightSensor
{
pub
fn
start
()
->
Self
{
if
unsafe
{
epic_light_sensor_run
()
}
!=
0
{
panic!
(
"Cannot start light sensor"
);
}
LightSensor
}
pub
fn
get
(
&
self
)
->
Option
<
u16
>
{
let
mut
result
=
0
;
if
unsafe
{
epic_light_sensor_get
(
&
mut
result
)
}
==
0
{
Some
(
result
)
}
else
{
None
}
}
}
impl
Drop
for
LightSensor
{
fn
drop
(
&
mut
self
)
{
unsafe
{
epic_light_sensor_stop
();
}
}
}
Write
Preview
Supports
Markdown
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