Skip to content

Commit a822a98

Browse files
committed
init example
also add build script
0 parents  commit a822a98

File tree

5 files changed

+250
-0
lines changed

5 files changed

+250
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
**/*.rs.bk

Cargo.lock

Lines changed: 195 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "raspi-oled"
3+
version = "0.1.0"
4+
authors = ["chux0519 <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
embedded-graphics = "0.6.0-alpha.2"
11+
linux-embedded-hal = "0.2.2"
12+
machine-ip = "0.2.1"
13+
ssd1306 = "0.3.0-alpha.2"

build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/sh
2+
docker run \
3+
--volume $PWD:/home/cross/project \
4+
--volume $HOME/.cargo/registry:/home/cross/.cargo/registry \
5+
ragnaroek/rust-raspberry:1.39.0 \
6+
build --release

src/main.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use embedded_graphics::fonts::Font6x8;
2+
use embedded_graphics::prelude::*;
3+
use embedded_graphics::primitives::{Circle, Line, Rectangle};
4+
use embedded_graphics::Drawing;
5+
use linux_embedded_hal::I2cdev;
6+
use machine_ip;
7+
use ssd1306::{mode::GraphicsMode, Builder};
8+
9+
fn main() {
10+
let i2c = I2cdev::new("/dev/i2c-1").unwrap();
11+
12+
let mut disp: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into();
13+
14+
disp.init().unwrap();
15+
disp.flush().unwrap();
16+
17+
disp.draw(Line::new(Point::new(8, 16 + 16), Point::new(8 + 16, 16 + 16)).into_iter());
18+
disp.draw(Line::new(Point::new(8, 16 + 16), Point::new(8 + 8, 16)).into_iter());
19+
disp.draw(Line::new(Point::new(8 + 16, 16 + 16), Point::new(8 + 8, 16)).into_iter());
20+
21+
disp.draw(Rectangle::new(Point::new(48, 16), Point::new(48 + 16, 16 + 16)).into_iter());
22+
23+
disp.draw(Circle::new(Point::new(96, 16 + 8), 8).into_iter());
24+
25+
let local_addr = machine_ip::get().unwrap();
26+
27+
disp.draw(
28+
Font6x8::render_str(&format!("IP: {}", local_addr.to_string()))
29+
.translate(Point::new(0, 56))
30+
.into_iter(),
31+
);
32+
33+
disp.flush().unwrap();
34+
}

0 commit comments

Comments
 (0)