Cause great pain to self with cargo-deny + cargo-cranky

This commit is contained in:
Luke D. Jones
2022-12-04 21:49:47 +13:00
parent 2fca7a09c4
commit 2705b08dca
60 changed files with 622 additions and 339 deletions

View File

@@ -47,8 +47,7 @@ impl AnimeType {
/// The width of diagonal images
pub fn width(&self) -> usize {
match self {
AnimeType::GA401 => 74,
AnimeType::GA402 => 74,
AnimeType::GA401 | AnimeType::GA402 => 74,
}
}
@@ -103,8 +102,8 @@ impl AnimeDataBuffer {
/// Create from a vector of bytes
///
/// # Panics
/// Will panic if the vector length is not `ANIME_DATA_LEN`
/// # Errors
/// Will error if the vector length is not `ANIME_DATA_LEN`
#[inline]
pub fn from_vec(anime: AnimeType, data: Vec<u8>) -> Result<Self> {
if data.len() != anime.data_length() {
@@ -147,10 +146,7 @@ impl TryFrom<AnimeDataBuffer> for AnimePacketType {
/// This runs the animations as a blocking loop by using the `callback` to write data
///
/// If `callback` is `Ok(true)` then `run_animation` will exit the animation loop early.
pub fn run_animation(
frames: &AnimeGif,
callback: &dyn Fn(AnimeDataBuffer) -> Result<bool>,
) -> Result<()> {
pub fn run_animation(frames: &AnimeGif, callback: &dyn Fn(AnimeDataBuffer) -> Result<bool>) {
let mut count = 0;
let start = Instant::now();
@@ -215,9 +211,10 @@ pub fn run_animation(
}
}
// TODO: Log this error
if matches!(callback(output), Ok(true)) {
info!("rog-anime: frame-loop callback asked to exit early");
return Ok(());
return;
}
if timed && Instant::now().duration_since(start) > run_time {
@@ -232,5 +229,4 @@ pub fn run_animation(
}
}
}
Ok(())
}

View File

@@ -52,39 +52,43 @@ impl AnimeDiagonal {
let mut matrix = AnimeDiagonal::new(anime_type, duration);
match raster {
match &raster {
png_pong::PngRaster::Gray8(ras) => {
Self::pixels_from_8bit(ras, &mut matrix, bright, true)
Self::pixels_from_8bit(ras, &mut matrix, bright, true);
}
png_pong::PngRaster::Graya8(ras) => {
Self::pixels_from_8bit(ras, &mut matrix, bright, true)
Self::pixels_from_8bit(ras, &mut matrix, bright, true);
}
png_pong::PngRaster::Rgb8(ras) => {
Self::pixels_from_8bit(ras, &mut matrix, bright, false)
Self::pixels_from_8bit(ras, &mut matrix, bright, false);
}
png_pong::PngRaster::Rgba8(ras) => {
Self::pixels_from_8bit(ras, &mut matrix, bright, false)
Self::pixels_from_8bit(ras, &mut matrix, bright, false);
}
png_pong::PngRaster::Gray16(ras) => {
Self::pixels_from_16bit(ras, &mut matrix, bright, true)
Self::pixels_from_16bit(ras, &mut matrix, bright, true);
}
png_pong::PngRaster::Rgb16(ras) => {
Self::pixels_from_16bit(ras, &mut matrix, bright, false)
Self::pixels_from_16bit(ras, &mut matrix, bright, false);
}
png_pong::PngRaster::Graya16(ras) => {
Self::pixels_from_16bit(ras, &mut matrix, bright, true)
Self::pixels_from_16bit(ras, &mut matrix, bright, true);
}
png_pong::PngRaster::Rgba16(ras) => {
Self::pixels_from_16bit(ras, &mut matrix, bright, false)
Self::pixels_from_16bit(ras, &mut matrix, bright, false);
}
_ => return Err(AnimeError::Format),
png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format),
};
Ok(matrix)
}
fn pixels_from_8bit<P>(ras: pix::Raster<P>, matrix: &mut AnimeDiagonal, bright: f32, grey: bool)
where
fn pixels_from_8bit<P>(
ras: &pix::Raster<P>,
matrix: &mut AnimeDiagonal,
bright: f32,
grey: bool,
) where
P: pix::el::Pixel<Chan = pix::chan::Ch8>,
{
let width = ras.width();
@@ -105,7 +109,7 @@ impl AnimeDiagonal {
}
fn pixels_from_16bit<P>(
ras: pix::Raster<P>,
ras: &pix::Raster<P>,
matrix: &mut AnimeDiagonal,
bright: f32,
grey: bool,
@@ -136,7 +140,7 @@ impl AnimeDiagonal {
}
}
/// Do conversion from the nested Vec in AnimeMatrix to the two required
/// Do conversion from the nested Vec in `AnimeMatrix` to the two required
/// packets suitable for sending over USB
fn to_ga401_packets(&self) -> Result<AnimeDataBuffer> {
let mut buf = vec![0u8; AnimeType::GA401.data_length()];

View File

@@ -26,7 +26,7 @@ pub enum AnimeError {
impl fmt::Display for AnimeError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AnimeError::NoFrames => write!(f, "No frames in PNG"),
AnimeError::Io(e) => write!(f, "Could not open: {}", e),

View File

@@ -93,7 +93,7 @@ impl AnimeGrid {
impl TryFrom<AnimeGrid> for AnimeDataBuffer {
type Error = AnimeError;
/// Do conversion from the nested Vec in AniMeMatrix to the two required
/// Do conversion from the nested Vec in anime matrix to the two required
/// packets suitable for sending over USB
fn try_from(anime: AnimeGrid) -> Result<Self> {
let mut buf = vec![0u8; anime.anime_type.data_length()];

View File

@@ -30,7 +30,7 @@ impl Default for Pixel {
/// is to be used to sample an image and set the LED brightness.
///
/// The position of the Led in `LedPositions` determines the placement in the final
/// data packets when written to the AniMe.
/// data packets when written to the `AniMe`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Led(f32, f32, u8);
@@ -58,7 +58,7 @@ impl Led {
/// Container of `Led`, each of which specifies a position within the image
/// The main use of this is to position and sample colours for the final image
/// to show on AniMe
/// to show on `AniMe`
pub struct AnimeImage {
pub scale: Vec2,
/// Angle in radians
@@ -294,8 +294,8 @@ impl AnimeImage {
let x0 = led_from_px.mul_vec3(pos + Vec3::new(0.0, -0.5, 0.0));
const GROUP: [f32; 4] = [0.0, 0.5, 1.0, 1.5];
for u in GROUP.iter() {
for v in GROUP.iter() {
for u in &GROUP {
for v in &GROUP {
let sample = x0 + *u * du + *v * dv;
let x = sample.x as i32;
@@ -399,7 +399,7 @@ impl AnimeImage {
let png_pong::Step { raster, delay: _ } = decoder.last().ok_or(AnimeError::NoFrames)??;
let width;
let pixels = match raster {
let pixels = match &raster {
png_pong::PngRaster::Gray8(ras) => {
width = ras.width();
Self::pixels_from_8bit(ras, true)
@@ -432,7 +432,7 @@ impl AnimeImage {
width = ras.width();
Self::pixels_from_16bit(ras, false)
}
_ => return Err(AnimeError::Format),
png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format),
};
let mut matrix = AnimeImage::new(
@@ -449,7 +449,7 @@ impl AnimeImage {
Ok(matrix)
}
fn pixels_from_8bit<P>(ras: pix::Raster<P>, grey: bool) -> Vec<Pixel>
fn pixels_from_8bit<P>(ras: &pix::Raster<P>, grey: bool) -> Vec<Pixel>
where
P: pix::el::Pixel<Chan = pix::chan::Ch8>,
{
@@ -468,7 +468,7 @@ impl AnimeImage {
.collect()
}
fn pixels_from_16bit<P>(ras: pix::Raster<P>, grey: bool) -> Vec<Pixel>
fn pixels_from_16bit<P>(ras: &pix::Raster<P>, grey: bool) -> Vec<Pixel>
where
P: pix::el::Pixel<Chan = pix::chan::Ch16>,
{
@@ -491,7 +491,7 @@ impl AnimeImage {
impl TryFrom<&AnimeImage> for AnimeDataBuffer {
type Error = AnimeError;
/// Do conversion from the nested Vec in AnimeDataBuffer to the two required
/// Do conversion from the nested Vec in `AnimeDataBuffer` to the two required
/// packets suitable for sending over USB
fn try_from(leds: &AnimeImage) -> Result<Self> {
let mut l: Vec<u8> = leds

View File

@@ -7,11 +7,11 @@ pub use data::*;
mod grid;
pub use grid::*;
/// Transform a PNG image for displaying on AniMe matrix display
/// Transform a PNG image for displaying on `AniMe` matrix display
mod image;
pub use image::*;
/// A grid of data that is intended to be read out and displayed on the ANiMe as
/// A grid of data that is intended to be read out and displayed on the `AniMe` as
/// a diagonal
mod diagonal;
pub use diagonal::*;

View File

@@ -7,7 +7,7 @@ use crate::{
error::Result, AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType,
};
/// All the possible AniMe actions that can be used. This enum is intended to be
/// All the possible `AniMe` actions that can be used. This enum is intended to be
/// a helper for loading up `ActionData`.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum ActionLoader {
@@ -44,7 +44,7 @@ pub enum ActionLoader {
Pause(Duration),
}
/// All the possible AniMe actions that can be used. The enum is intended to be
/// All the possible `AniMe` actions that can be used. The enum is intended to be
/// used in a array allowing the user to cycle through a series of actions.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum ActionData {
@@ -194,7 +194,7 @@ impl Sequences {
None
}
pub fn iter(&self) -> ActionIterator {
pub fn iter(&self) -> ActionIterator<'_> {
ActionIterator {
actions: self,
next_idx: 0,

View File

@@ -1,4 +1,4 @@
//! Utils for writing to the AniMe USB device
//! Utils for writing to the `AniMe` USB device
//!
//! Use of the device requires a few steps:
//! 1. Initialise the device by writing the two packets from `get_init_packets()`
@@ -63,7 +63,7 @@ pub const fn pkt_for_flush() -> [u8; PACKET_SIZE] {
}
/// Get the packet required for setting the device to on, on boot. Requires
/// pkt_for_apply()` to be written after.
/// `pkt_for_apply()` to be written after.
#[inline]
pub const fn pkt_for_set_boot(status: bool) -> [u8; PACKET_SIZE] {
let mut pkt = [0; PACKET_SIZE];