Skip to content

Commit

Permalink
删除smart-leds-matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleGuest committed May 13, 2024
1 parent c6875e3 commit 2b64b7a
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 522 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
members = ["cube", "smart-leds-matrix", "cube_rand", "maze", "ws2812-spi-rs"]
members = ["cube", "cube_rand", "maze", "ws2812-spi-rs"]
4 changes: 3 additions & 1 deletion cube/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ embedded-graphics-core = "0.4.0"
# "spin_no_std",
# ] }
ws2812-spi = { path = "../ws2812-spi-rs/" }
smart-leds-matrix = { path = "../smart-leds-matrix/" }
# smart-leds-matrix = { path = "../smart-leds-matrix/" }
cube_rand = { path = "../cube_rand/" }
maze = { path = "../maze" }
esp-storage = { version = "0.3.0", features = ["esp32c3"] }
embedded-storage = "0.3.1"
smart-leds-matrix = "0.2.0"
smart-leds = "0.4.0"

[profile.dev]
opt-level = "s"
Expand Down
55 changes: 19 additions & 36 deletions cube/src/ledc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use esp_hal::{
spi::{master::Spi, FullDuplexMode},
};
use heapless::Vec;
use log::error;
use smart_leds_matrix::{
layout::{invert_axis::NoInvert, Rectangular},
SmartLedMatrix,
Expand All @@ -16,59 +17,40 @@ use crate::mapping;
const NUM_LEDS: usize = 64;

pub struct LedControl<'d> {
/// 最终上传的数据
buf: [u8; 8],
// gd: Gd,
/// 亮度
// brightness: u8,
ws: Ws2812<Spi<'d, SPI2, FullDuplexMode>>,
matrix: SmartLedMatrix<Rectangular<NoInvert>, NUM_LEDS>,
matrix: SmartLedMatrix<Ws2812<Spi<'d, SPI2, FullDuplexMode>>, Rectangular<NoInvert>, NUM_LEDS>,
}

impl<'d> LedControl<'d> {
pub fn new(spi: Spi<'d, SPI2, FullDuplexMode>) -> Self {
let brightness = 10;

let ws = Ws2812::new(spi);
let mut matrix = SmartLedMatrix::<_, { 8 * 8 }>::new(Rectangular::new(8, 8));
matrix.set_brightness(brightness);
let mut matrix = SmartLedMatrix::<_, _, { 8 * 8 }>::new(ws, Rectangular::new(8, 8));
matrix.set_brightness(1);
matrix.clear(Rgb888::new(0, 0, 0)).unwrap();

Self {
buf: [0; 8],
// gd: Gd::default(),
// brightness,
ws,
matrix,
}
Self { matrix }
}

pub fn shutdown(&mut self) {
// self.led.power_off();
pub fn off(&mut self) {
self.matrix.set_brightness(0);
}

// 设置亮度
pub fn set_brightness(&mut self, b: u8) {
self.matrix.set_brightness(b)
self.matrix.set_brightness(b);
}

/// 清屏
pub fn clear(&mut self) {
for i in 0..self.buf.len() {
self.buf[i] = 0;
}
self.upload();
self.write_bytes([0; 8]);
}

/// 清屏
pub fn clear_with_color(&mut self, color: Rgb888) {
if let Err(e) = self.matrix.clear(color) {
log::error!("clear_with_color error {e:?}");
error!("clear_with_color error {e:?}");
}
}

pub fn upload(&mut self) {
self.write_bytes(self.buf);
}

pub fn write_bytes(&mut self, data: [u8; 8]) {
let mut pixels = Vec::<Pixel<Rgb888>, NUM_LEDS>::new();
for (y, _) in data.iter().enumerate() {
Expand All @@ -79,9 +61,7 @@ impl<'d> LedControl<'d> {
BinaryColor::Off
};

pixels
.push(Pixel((x, y as i32).into(), on_off.into()))
.unwrap();
pixels.push(Pixel((x, y as i32).into(), on_off.into()));
}
}
self.write_pixels(pixels);
Expand All @@ -91,16 +71,19 @@ impl<'d> LedControl<'d> {
where
I: IntoIterator<Item = Pixel<Rgb888>>,
{
self.matrix.draw_iter(pixels).unwrap();
if let Err(e) = self.matrix.flush_with_gamma(&mut self.ws) {
log::error!("write_rgb {e:?}");
if let Err(e) = self.matrix.draw_iter(pixels) {
error!("write pixels error: {e:?}");
}
if let Err(e) = self.matrix.flush() {
error!("write pixels error: {e:?}");
}
}

pub fn write_pixel(&mut self, pixel: Pixel<Rgb888>) {
self.write_pixels([pixel]);
}

/// 绘制分数
pub fn draw_score(&mut self, score: u8) {
self.clear();

Expand Down
13 changes: 13 additions & 0 deletions cube/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ use core::mem::MaybeUninit;
use cube::buzzer::Buzzer;
use cube::ledc::LedControl;
use embassy_executor::Spawner;
use embassy_time::Timer;
use embedded_graphics::draw_target::DrawTarget;
use embedded_graphics::geometry::{Point, Size};
use embedded_graphics::pixelcolor::{Rgb888, RgbColor};
use embedded_graphics::primitives::{
Circle, Line, Primitive, PrimitiveStyle, PrimitiveStyleBuilder, Rectangle,
};
use embedded_graphics::transform::Transform;
use embedded_graphics::Drawable;
use esp_backtrace as _;
use esp_hal::delay::Delay;
use esp_hal::gpio::IO;
Expand All @@ -16,6 +25,10 @@ use esp_hal::timer::TimerGroup;
use esp_hal::{clock::ClockControl, i2c::I2C, peripherals::Peripherals, prelude::*};
use mpu6050_dmp::address::Address;
use mpu6050_dmp::sensor::Mpu6050;
use smart_leds::RGB8;
use smart_leds_matrix::layout::Rectangular;
use smart_leds_matrix::SmartLedMatrix;
use ws2812_spi::Ws2812;

extern crate alloc;

Expand Down
3 changes: 0 additions & 3 deletions smart-leds-matrix/.gitignore

This file was deleted.

22 changes: 0 additions & 22 deletions smart-leds-matrix/Cargo.toml

This file was deleted.

201 changes: 0 additions & 201 deletions smart-leds-matrix/LICENSE

This file was deleted.

Loading

0 comments on commit 2b64b7a

Please # to comment.