Commit b772e496 authored by TechnoElf's avatar TechnoElf
Browse files

Multiple screens + warcrimes

parent ced93bee
......@@ -112,6 +112,27 @@ dependencies = [
"void",
]
[[package]]
name = "embedded-layout"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7adbc16ba694006a121bce08a8935186d16cb008a4c9e20c5e346517ad1e0ac8"
dependencies = [
"embedded-graphics",
"embedded-layout-macros",
]
[[package]]
name = "embedded-layout-macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "352186cee85e4cf9104c42b4dfd0295a22901c5d2bf0c26efd47265adcf1c52d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "float-cmp"
version = "0.8.0"
......@@ -141,6 +162,12 @@ dependencies = [
"stable_deref_trait",
]
[[package]]
name = "json"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
[[package]]
name = "kraken"
version = "0.1.0"
......@@ -148,6 +175,8 @@ dependencies = [
"display-interface",
"display-interface-spi",
"embedded-graphics",
"embedded-layout",
"json",
"rppal",
"st7789",
]
......@@ -194,6 +223,24 @@ dependencies = [
"autocfg",
]
[[package]]
name = "proc-macro2"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rppal"
version = "0.12.0"
......@@ -250,6 +297,23 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "syn"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "vcell"
version = "0.1.3"
......
......@@ -4,8 +4,10 @@ version = "0.1.0"
edition = "2018"
[dependencies]
json = "0.12.4"
rppal = { version = "0.12.0", features = ["hal"] }
st7789 = "0.6.1"
display-interface-spi = "0.4.1"
display-interface = "0.4.1"
embedded-graphics = "0.7.1"
embedded-layout = "0.2.0"
use std::net::{TcpListener};
use std::net::{TcpListener, TcpStream};
use std::io::{Read, Write};
use std::mem;
use rppal::hal::Delay;
use rppal::spi::{Spi, Bus, SlaveSelect, Mode};
use rppal::gpio::Gpio;
use rppal::gpio::{Gpio, OutputPin};
use st7789::{ST7789, Orientation};
use display_interface_spi::SPIInterfaceNoCS;
use embedded_graphics::prelude::*;
......@@ -12,23 +13,40 @@ use embedded_graphics::draw_target::DrawTarget;
use embedded_graphics::mono_font::ascii::FONT_9X18_BOLD;
use embedded_graphics::mono_font::MonoTextStyle;
use embedded_graphics::text::{Text, Alignment};
use embedded_graphics::primitives::{Circle, Rectangle, PrimitiveStyle};
use embedded_layout::prelude::*;
use embedded_layout::layout::linear::LinearLayout;
const GATEWAY: &str = "192.168.254.1:80";
fn main() {
let spi_bus = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 5000000, Mode::Mode0).unwrap();
let dc = Gpio::new().unwrap().get(12).unwrap().into_output();
let rst = Gpio::new().unwrap().get(13).unwrap().into_output();
let spi_bus_0 = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 5000000, Mode::Mode0).unwrap();
let spi_bus_1 = Spi::new(Bus::Spi0, SlaveSelect::Ss1, 5000000, Mode::Mode0).unwrap();
let dc_0 = Gpio::new().unwrap().get(12).unwrap().into_output();
let dc_1: OutputPin = unsafe { mem::transmute_copy(&dc_0) };
let rst_0 = Gpio::new().unwrap().get(13).unwrap().into_output();
let rst_1: OutputPin = unsafe { mem::transmute_copy(&rst_0) };
let display_bus = SPIInterfaceNoCS::new(spi_bus, dc);
let display_bus_0 = SPIInterfaceNoCS::new(spi_bus_0, dc_0);
let display_bus_1 = SPIInterfaceNoCS::new(spi_bus_1, dc_1);
let mut display = ST7789::new(display_bus, rst, 240, 240);
let mut display_0 = ST7789::new(display_bus_0, rst_0, 240, 240);
let mut display_1 = ST7789::new(display_bus_1, rst_1, 240, 240);
display.init(&mut Delay::new()).unwrap();
display.set_orientation(Orientation::Landscape).unwrap();
display_0.init(&mut Delay::new()).unwrap();
display_1.init(&mut Delay::new()).unwrap();
display_0.set_orientation(Orientation::Portrait).unwrap();
display_1.set_orientation(Orientation::Portrait).unwrap();
display_0.clear(Rgb565::new(255, 255, 255)).unwrap();
display_1.clear(Rgb565::new(255, 255, 255)).unwrap();
let style = MonoTextStyle::new(&FONT_9X18_BOLD, Rgb565::new(0, 0, 0));
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();
Text::with_alignment("Release the Kraken!", Point::new(120, 120), style, Alignment::Center).draw(&mut display_0).unwrap();
Text::with_alignment("Release the Kraken!", Point::new(120, 120), style, Alignment::Center).draw(&mut display_1).unwrap();
//let mut gateway = TcpStream::connect(GATEWAY).unwrap();
//gateway.write("test".as_bytes()).unwrap();
let listener = TcpListener::bind("0.0.0.0:80").unwrap();
for stream in listener.incoming() {
......@@ -41,15 +59,29 @@ fn main() {
let (req, _headers) = head.split_once("\r\n").unwrap();
let (method, rem) = req.split_once(" ").unwrap();
let (uri, _ver) = rem.split_once(" ").unwrap();
let (path, _query) = uri.split_once("?").unwrap_or((uri, ""));
let resp = match (method, path) {
("POST", "/state") => {
display_0.clear(Rgb565::new(255, 255, 255)).unwrap();
display_1.clear(Rgb565::new(255, 255, 255)).unwrap();
LinearLayout::horizontal(Chain::new(
LinearLayout::vertical(
Chain::new(Rectangle::new(Point::zero(), Size::new(120, 1)).into_styled(PrimitiveStyle::with_fill(Rgb565::new(255, 255, 255)))).append(Circle::new(Point::zero(), 40).into_styled(PrimitiveStyle::with_fill(Rgb565::new(0, 255, 0)))).append(Text::new(&body, Point::zero(), style))
).with_alignment(horizontal::Center).arrange()).append(LinearLayout::vertical(
Chain::new(Rectangle::new(Point::zero(), Size::new(120, 1)).into_styled(PrimitiveStyle::with_fill(Rgb565::new(255, 255, 255)))).append(Circle::new(Point::zero(), 40).into_styled(PrimitiveStyle::with_fill(Rgb565::new(0, 255, 0)))).append(Text::new(&body, Point::zero(), style))
).with_alignment(horizontal::Center).arrange()
)).with_alignment(vertical::Center).arrange().align_to(&display_0.bounding_box(), horizontal::Center, vertical::Center).draw(&mut display_0).unwrap();
LinearLayout::horizontal(Chain::new(
LinearLayout::vertical(
Chain::new(Rectangle::new(Point::zero(), Size::new(120, 1)).into_styled(PrimitiveStyle::with_fill(Rgb565::new(255, 255, 255)))).append(Circle::new(Point::zero(), 40).into_styled(PrimitiveStyle::with_fill(Rgb565::new(0, 255, 0)))).append(Text::new(&body, Point::zero(), style))
).with_alignment(horizontal::Center).arrange()).append(LinearLayout::vertical(
Chain::new(Rectangle::new(Point::zero(), Size::new(120, 1)).into_styled(PrimitiveStyle::with_fill(Rgb565::new(255, 255, 255)))).append(Circle::new(Point::zero(), 40).into_styled(PrimitiveStyle::with_fill(Rgb565::new(0, 255, 0)))).append(Text::new(&body, Point::zero(), style))
).with_alignment(horizontal::Center).arrange()
)).with_alignment(vertical::Center).arrange().align_to(&display_0.bounding_box(), horizontal::Center, vertical::Center).draw(&mut display_1).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) => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment