-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge in chux0519/raspi-oled as sample
- Loading branch information
Showing
9 changed files
with
385 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Build It | ||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Build for Raspberry Pi 2/3/4 32 bit | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
use-cross: true | ||
command: build | ||
args: --target armv7-unknown-linux-gnueabihf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
**/*.rs.bk |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "raspi-oled" | ||
version = "0.1.0" | ||
authors = ["chux0519 <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
embedded-graphics = "0.6.0-alpha.2" | ||
linux-embedded-hal = "0.2.2" | ||
machine-ip = "0.2.1" | ||
ssd1306 = "0.3.0-alpha.2" | ||
ctrlc = { version = "3.0", features = ["termination"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# raspi demo for oled(ssd1306) | ||
|
||
in rust | ||
|
||
## Quick start | ||
|
||
The easiest way to build this sample is with [Cross](https://github.com/rust-embedded/cross). | ||
|
||
``` | ||
cross build --release --target armv7-unknown-linux-gnueabihf | ||
``` | ||
|
||
> That assumes Raspberry Pi 2/3/4 running a 32 bit kernel | ||
After the build finishes, copy it to your Raspberry Pi | ||
|
||
``` | ||
scp target/armv7-unknown-linux-gnueabihf/release/raspi-oled user@ip:/home/user | ||
``` | ||
|
||
Then SSH to your Pi and run it | ||
|
||
``` | ||
sudo ./raspi-oled | ||
``` | ||
|
||
## Example | ||
|
||
![picture](./images/01.jpg) | ||
|
||
![primitive](./images/02.jpg) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use embedded_graphics::fonts::Font6x8; | ||
use embedded_graphics::image::Image; | ||
use embedded_graphics::pixelcolor::BinaryColor; | ||
use embedded_graphics::prelude::*; | ||
use embedded_graphics::primitives::{Circle, Line, Rectangle}; | ||
use embedded_graphics::Drawing; | ||
use linux_embedded_hal::I2cdev; | ||
use machine_ip; | ||
use ssd1306::{mode::GraphicsMode, Builder}; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
extern crate ctrlc; | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
use std::sync::Arc; | ||
|
||
fn main() { | ||
let running = Arc::new(AtomicBool::new(true)); | ||
let r = running.clone(); | ||
ctrlc::set_handler(move || { | ||
r.store(false, Ordering::SeqCst); | ||
}) | ||
.expect("Error setting Ctrl-C handler"); | ||
|
||
let i2c = I2cdev::new("/dev/i2c-1").unwrap(); | ||
|
||
let mut disp: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into(); | ||
|
||
disp.init().unwrap(); | ||
disp.flush().unwrap(); | ||
|
||
while running.load(Ordering::SeqCst) { | ||
disp.draw( | ||
Line::new(Point::new(8, 16 + 16), Point::new(8 + 16, 16 + 16)) | ||
.stroke(Some(BinaryColor::On)) | ||
.into_iter(), | ||
); | ||
disp.draw( | ||
Line::new(Point::new(8, 16 + 16), Point::new(8 + 8, 16)) | ||
.stroke(Some(BinaryColor::On)) | ||
.into_iter(), | ||
); | ||
disp.draw( | ||
Line::new(Point::new(8 + 16, 16 + 16), Point::new(8 + 8, 16)) | ||
.stroke(Some(BinaryColor::On)) | ||
.into_iter(), | ||
); | ||
|
||
disp.draw( | ||
Rectangle::new(Point::new(48, 16), Point::new(48 + 16, 16 + 16)) | ||
.stroke(Some(BinaryColor::On)) | ||
.into_iter(), | ||
); | ||
|
||
disp.draw( | ||
Circle::new(Point::new(96, 16 + 8), 8) | ||
.stroke(Some(BinaryColor::On)) | ||
.into_iter(), | ||
); | ||
|
||
let local_addr = machine_ip::get().unwrap(); | ||
|
||
disp.draw( | ||
Font6x8::render_str(&format!("IP: {}", local_addr.to_string())) | ||
.translate(Point::new(0, 56)) | ||
.into_iter(), | ||
); | ||
disp.flush().unwrap(); | ||
|
||
sleep(Duration::from_secs(2)); | ||
|
||
disp.clear(); | ||
|
||
let im: Image<BinaryColor> = | ||
Image::new(include_bytes!("../rust.raw"), 64, 64).translate(Point::new(32, 0)); | ||
disp.draw(im.into_iter()); | ||
disp.flush().unwrap(); | ||
|
||
sleep(Duration::from_secs(2)); | ||
disp.clear(); | ||
} | ||
disp.clear(); | ||
disp.flush().unwrap(); | ||
} |