#oled #waveshare #driver #raspberry-pi #display #hat #devices

ws-oled-driver

Raspberry Pi Waveshare OLED 显示帽驱动程序

4 个版本

0.0.5 2023 年 3 月 7 日
0.0.4 2023 年 3 月 6 日
0.0.3 2023 年 3 月 6 日
0.0.2 2023 年 3 月 6 日

#1247硬件支持

MIT 许可证

16KB
285

用 Rust 编写的 Raspberry Pi Waveshare OLED (SH1106) HAT 驱动程序

设备(正面) 设备(背面) 设备(通电)

设备: https://www.waveshare.com/wiki/1.3inch_OLED_HAT

用法

cargo add ws-oled-driver

-- 或 --

[dependencies]
ws-oled-driver = "0.0.5"

为 Raspberry Pi Zero 跨编译

  cargo build --target arm-unknown-linux-gnueabihf --release 

示例

显示

注意:THE ws_oled_driver::gfx 库仍在开发中。由于可以直接访问 Display { memory: Vec<u8> } 字段,即显示缓冲区,您可以直接修改缓冲区以创建视觉效果,并使用 display.render()? 函数将其渲染到显示。

use ws_oled_driver::Device;  /* HAT Device */
use ws_oled_driver::gfx;     /* Graphics */
use anyhow::Result;

fn main() -> Result<()> {
   let mut device = Device::new()?;
   device.initialize_components()?;

   /* FILL DISPLAY */
   gfx::fill(&mut device.display, 0xFF);
   device.display.render()?; 

   /* DRAW POINT at (x, y) == (10, 10) */
   gfx::draw_point(&mut device.display, (10, 10), 0xFF);

   /* DRAW LINE */

   gfx::draw_line(&mut device.display, (0, 0), (127, 63));
   device.display.render()?; 

   Ok(())
}

摇杆

use anyhow::Result;
use ws_oled_driver::joystick;
use ws_oled_driver::Device; /* HAT Device */

fn main() -> Result<()> {
    let mut device = Device::new()?;
    device.initialize_components()?;

    loop {
        if let Some(joystick_state) = device.joystick.read() {
            match joystick_state {
                joystick::State::Up => {
                    println!("You Pressed Up");
                }
                joystick::State::Down => {
                    println!("You Pressed Down");
                }
                joystick::State::Left => {
                    println!("You Pressed Left");
                }
                joystick::State::Right => {
                    println!("You Pressed Right");
                }
                joystick::State::Click => {
                    println!("You Clicked!");
                }
            }
        }
    }
}

按钮

use ws_oled_driver::Device;  /* HAT Device */
use ws_oled_driver::button::State;
use anyhow::Result;

fn main() -> Result<()> {
  let mut device = Device::new()?;
  device.initialize_components()?;

  loop {
    if let Some(button_state) = device.button_controller.read() {
      match button_state {
        State::Key1 => println!("Key1 pressed"),
        State::Key2 => println!("Key2 pressed"),
        State::Key3 => println!("Key3 pressed"),
      }
    }
    else {
      println!("Nothing Pressed!")
    }
  }
}

路线图

  1. 改进图形库

依赖关系

~505KB