Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Janis Heims
kraken
Commits
ced93bee
Commit
ced93bee
authored
Aug 13, 2021
by
TechnoElf
Browse files
Control over HTTP
parent
9e4ba00a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main.rs
View file @
ced93bee
use
std
::
net
::{
TcpListener
};
use
std
::
io
::
Read
;
use
std
::
io
::
{
Read
,
Write
}
;
use
rppal
::
hal
::
Delay
;
use
rppal
::
spi
::{
Spi
,
Bus
,
SlaveSelect
,
Mode
};
...
...
@@ -30,13 +30,36 @@ fn main() {
display
.clear
(
Rgb565
::
new
(
255
,
255
,
255
))
.unwrap
();
Text
::
with_alignment
(
"Release the Kraken!"
,
Point
::
new
(
120
,
120
),
style
,
Alignment
::
Center
)
.draw
(
&
mut
display
)
.unwrap
();
let
listener
=
TcpListener
::
bind
(
"0.0.0.0:80
80
"
)
.unwrap
();
let
listener
=
TcpListener
::
bind
(
"0.0.0.0:80"
)
.unwrap
();
for
stream
in
listener
.incoming
()
{
if
let
Ok
(
mut
stream
)
=
stream
{
let
mut
text
=
String
::
new
();
stream
.read_to_string
(
&
mut
text
)
.unwrap
();
display
.clear
(
Rgb565
::
new
(
255
,
255
,
255
))
.unwrap
();
Text
::
with_alignment
(
&
text
,
Point
::
new
(
120
,
20
),
style
,
Alignment
::
Center
)
.draw
(
&
mut
display
)
.unwrap
();
let
mut
buf
=
[
0
;
1024
];
let
len
=
stream
.read
(
&
mut
buf
)
.unwrap
();
let
buf
=
String
::
from_utf8_lossy
(
&
buf
[
0
..
len
]);
let
(
head
,
body
)
=
buf
.split_once
(
"
\r\n\r\n
"
)
.unwrap
();
let
(
req
,
_headers
)
=
head
.split_once
(
"
\r\n
"
)
.unwrap
();
let
(
method
,
rem
)
=
req
.split_once
(
" "
)
.unwrap
();
let
(
uri
,
_ver
)
=
rem
.split_once
(
" "
)
.unwrap
();
let
resp
=
match
(
method
,
uri
)
{
(
"PUT"
,
"/id"
)
=>
{
display
.clear
(
Rgb565
::
new
(
255
,
255
,
255
))
.unwrap
();
Text
::
with_alignment
(
&
body
,
Point
::
new
(
120
,
20
),
style
,
Alignment
::
Center
)
.draw
(
&
mut
display
)
.unwrap
();
"200 OK"
},
(
"PUT"
,
"/status"
)
=>
{
display
.clear
(
Rgb565
::
new
(
0
,
255
,
0
))
.unwrap
();
"200 OK"
},
(
m
,
u
)
=>
{
eprintln!
(
"Invalid request: {} {}"
,
m
,
u
);
"404 NOT FOUND"
}
};
stream
.write
(
format!
(
"HTTP/1.1 {}
\r\n\r\n
"
,
resp
)
.as_bytes
())
.unwrap
();
stream
.flush
()
.unwrap
();
}
}
}
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