diff --git a/apex-ctl/Cargo.toml b/apex-ctl/Cargo.toml index a1037b2..e920470 100644 --- a/apex-ctl/Cargo.toml +++ b/apex-ctl/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] anyhow = "1.0.44" -clap = "3.0.0-beta.5" +clap = { version = "4.0.26", features = ["derive"] } log = "0.4.14" simplelog = "0.10.2" apex-hardware = { path = "../apex-hardware", features= ["usb"] } \ No newline at end of file diff --git a/apex-ctl/src/main.rs b/apex-ctl/src/main.rs index 70b590a..6107d65 100644 --- a/apex-ctl/src/main.rs +++ b/apex-ctl/src/main.rs @@ -1,6 +1,6 @@ use anyhow::Result; -use apex_hardware::{Device, FrameBuffer, USBDevice}; -use clap::Parser; +use apex_hardware::{Device, USBDevice}; +use clap::{ArgAction, Parser, Subcommand}; use log::{info, LevelFilter}; use simplelog::{Config as LoggerConfig, SimpleLogger}; @@ -8,13 +8,13 @@ use simplelog::{Config as LoggerConfig, SimpleLogger}; #[clap(version = "1.0", author = "not-jan")] struct Opts { /// A level of verbosity, and can be used multiple times - #[clap(short, long, parse(from_occurrences))] - verbose: i32, - #[clap(subcommand)] + #[arg(short, long, action = ArgAction::Count)] + verbose: u8, + #[command(subcommand)] subcmd: SubCommand, } -#[derive(Parser)] +#[derive(Subcommand)] enum SubCommand { /// Clear the OLED screen Clear, diff --git a/apex-engine/src/engine.rs b/apex-engine/src/engine.rs index b782153..b428455 100644 --- a/apex-engine/src/engine.rs +++ b/apex-engine/src/engine.rs @@ -75,7 +75,7 @@ impl AsyncDevice for Engine { #[allow(clippy::needless_lifetimes)] fn draw<'this>(&'this mut self, display: &'this FrameBuffer) -> Self::DrawResult<'this> { async { - let screen = display.framebuffer.as_buffer(); + let screen = display.framebuffer.as_raw_slice(); let event = GameEvent { game: GAME, diff --git a/apex-engine/src/lib.rs b/apex-engine/src/lib.rs index cf95082..e4447ba 100644 --- a/apex-engine/src/lib.rs +++ b/apex-engine/src/lib.rs @@ -1,3 +1,3 @@ -#![feature(generic_associated_types, type_alias_impl_trait)] +#![feature(type_alias_impl_trait)] mod engine; pub use engine::{Engine, HEARTBEAT, REMOVE_EVENT, REMOVE_GAME}; diff --git a/apex-hardware/Cargo.toml b/apex-hardware/Cargo.toml index 5235496..01262c5 100644 --- a/apex-hardware/Cargo.toml +++ b/apex-hardware/Cargo.toml @@ -12,7 +12,7 @@ async = [] [dependencies] anyhow = "1.0.44" -bitvec = "0.22.3" +bitvec = "1.0.1" embedded-graphics = "0.7.1" hidapi = { version = "1.2.6", optional = true } num_enum = "0.5.4" diff --git a/apex-hardware/src/device.rs b/apex-hardware/src/device.rs index 26eda67..6847eec 100644 --- a/apex-hardware/src/device.rs +++ b/apex-hardware/src/device.rs @@ -4,6 +4,8 @@ use embedded_graphics::{pixelcolor::BinaryColor, prelude::*}; #[cfg(feature = "async")] use std::future::Future; +const FB_SIZE: usize = 40 * 128 / 8 + 2; + #[derive(Copy, Clone, Debug)] pub struct FrameBuffer { /// The framebuffer with one bit value per pixel. @@ -11,13 +13,13 @@ pub struct FrameBuffer { /// trailing null byte. This is done to prevent superfluous copies when /// sending the image to a display device. The implementations of /// `Drawable` and `DrawTarget` take this quirk into account. - pub framebuffer: BitArray, + pub framebuffer: BitArray<[u8; FB_SIZE], Msb0>, } impl Default for FrameBuffer { fn default() -> Self { - let mut framebuffer = BitArray::::zeroed(); - framebuffer.as_mut_buffer()[0] = 0x61; + let mut framebuffer = BitArray::<[u8; FB_SIZE], Msb0>::ZERO; + framebuffer.as_raw_mut_slice()[0] = 0x61; FrameBuffer { framebuffer } } } @@ -121,18 +123,15 @@ impl AsyncDevice for T where T: 'static, { - type ClearResult<'a> + type ClearResult<'a> = impl Future> + 'a where - Self: 'a, - = impl Future> + 'a; - type DrawResult<'a> + Self: 'a; + type DrawResult<'a> = impl Future> + 'a where - Self: 'a, - = impl Future> + 'a; - type ShutdownResult<'a> + Self: 'a; + type ShutdownResult<'a> = impl Future> + 'a where - Self: 'a, - = impl Future> + 'a; + Self: 'a; #[allow(clippy::needless_lifetimes)] fn draw<'this>(&'this mut self, display: &'this FrameBuffer) -> Self::DrawResult<'this> { diff --git a/apex-hardware/src/lib.rs b/apex-hardware/src/lib.rs index ae9f957..affec0a 100644 --- a/apex-hardware/src/lib.rs +++ b/apex-hardware/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(generic_associated_types, type_alias_impl_trait)] +#![feature(type_alias_impl_trait)] mod device; #[cfg(feature = "usb")] mod usb; diff --git a/apex-hardware/src/usb.rs b/apex-hardware/src/usb.rs index 5355d48..3041c22 100644 --- a/apex-hardware/src/usb.rs +++ b/apex-hardware/src/usb.rs @@ -66,7 +66,7 @@ impl Device for USBDevice { fn draw(&mut self, display: &FrameBuffer) -> Result<()> { Ok(self .handle - .send_feature_report(display.framebuffer.as_buffer())?) + .send_feature_report(display.framebuffer.as_raw_slice())?) } fn clear(&mut self) -> Result<()> { diff --git a/apex-mpris2/src/lib.rs b/apex-mpris2/src/lib.rs index eac9f8b..83ba129 100644 --- a/apex-mpris2/src/lib.rs +++ b/apex-mpris2/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(generic_associated_types, type_alias_impl_trait, async_iterator)] +#![feature(type_alias_impl_trait, async_iterator)] mod generated; mod player; pub use player::{Metadata, Player, MPRIS2}; diff --git a/apex-mpris2/src/player.rs b/apex-mpris2/src/player.rs index 05edc92..48e8500 100644 --- a/apex-mpris2/src/player.rs +++ b/apex-mpris2/src/player.rs @@ -195,22 +195,18 @@ impl<'a> Player<'a> { impl<'a> AsyncPlayer for Player<'a> { type Metadata = Metadata; - type MetadataFuture<'b> + type MetadataFuture<'b> = impl Future> + 'b where - Self: 'b, - = impl Future> + 'b; - type NameFuture<'b> + Self: 'b; + type NameFuture<'b> = impl Future + 'b where - Self: 'b, - = impl Future + 'b; - type PlaybackStatusFuture<'b> + Self: 'b; + type PlaybackStatusFuture<'b> = impl Future> + 'b where - Self: 'b, - = impl Future> + 'b; - type PositionFuture<'b> + Self: 'b; + type PositionFuture<'b> = impl Future> + 'b where - Self: 'b, - = impl Future> + 'b; + Self: 'b; #[allow(clippy::needless_lifetimes)] fn metadata<'this>(&'this self) -> Self::MetadataFuture<'this> { diff --git a/apex-music/src/lib.rs b/apex-music/src/lib.rs index 794833b..bd167a2 100644 --- a/apex-music/src/lib.rs +++ b/apex-music/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(generic_associated_types, type_alias_impl_trait)] +#![feature(type_alias_impl_trait)] mod player; pub use player::{ AsyncMetadata, AsyncPlayer, Metadata, PlaybackStatus, Player, PlayerEvent, Progress, diff --git a/apex-music/src/player.rs b/apex-music/src/player.rs index 344a057..424cb3a 100644 --- a/apex-music/src/player.rs +++ b/apex-music/src/player.rs @@ -9,7 +9,6 @@ pub enum PlaybackStatus { Playing, } - #[derive(Clone, Debug)] pub enum PlayerEvent { Seeked, @@ -72,22 +71,18 @@ pub trait AsyncPlayer { impl AsyncPlayer for T { type Metadata = ::Metadata; - type MetadataFuture<'a> + type MetadataFuture<'a> = impl Future> + 'a where - T: 'a, - = impl Future> + 'a; - type NameFuture<'a> + T: 'a; + type NameFuture<'a> = impl Future where - T: 'a, - = impl Future; - type PlaybackStatusFuture<'a> + T: 'a; + type PlaybackStatusFuture<'a> = impl Future> where - T: 'a, - = impl Future>; - type PositionFuture<'a> + T: 'a; + type PositionFuture<'a> = impl Future> where - T: 'a, - = impl Future>; + T: 'a; #[allow(clippy::needless_lifetimes)] fn metadata<'this>(&'this self) -> Self::MetadataFuture<'this> { @@ -137,18 +132,15 @@ pub trait AsyncMetadata { /// Blanket implementation for non-async Metadata sources impl AsyncMetadata for T { - type ArtistsFuture<'a> + type ArtistsFuture<'a> = impl Future> + 'a where - T: 'a, - = impl Future> + 'a; - type LengthFuture<'a> + T: 'a; + type LengthFuture<'a> = impl Future> + 'a where - T: 'a, - = impl Future> + 'a; - type TitleFuture<'a> + T: 'a; + type TitleFuture<'a> = impl Future> + 'a where - T: 'a, - = impl Future> + 'a; + T: 'a; #[allow(clippy::needless_lifetimes)] fn title<'this>(&'this self) -> Self::TitleFuture<'this> { diff --git a/apex-windows/src/lib.rs b/apex-windows/src/lib.rs index a8b0dfc..812e774 100644 --- a/apex-windows/src/lib.rs +++ b/apex-windows/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(generic_associated_types, type_alias_impl_trait,async_iterator)] +#![feature(type_alias_impl_trait, async_iterator)] mod music; -pub use music::Player; -pub use music::Metadata; +pub use music::{Metadata, Player}; diff --git a/apex-windows/src/music.rs b/apex-windows/src/music.rs index fea0e15..eb45b59 100644 --- a/apex-windows/src/music.rs +++ b/apex-windows/src/music.rs @@ -1,10 +1,10 @@ use anyhow::{anyhow, Result}; use apex_music::{AsyncPlayer, Metadata as MetadataTrait, PlaybackStatus, PlayerEvent, Progress}; -use std::future::Future; use futures_core::stream::Stream; +use std::future::Future; -use std::time::Duration; use async_stream::stream; +use std::time::Duration; use tokio::time::MissedTickBehavior; use windows::Media::{ Control, @@ -82,7 +82,7 @@ impl Player { pub async fn stream(&self) -> Result> { let mut timer = tokio::time::interval(Duration::from_millis(100)); timer.set_missed_tick_behavior(MissedTickBehavior::Skip); - Ok(stream!{ + Ok(stream! { loop { timer.tick().await; yield PlayerEvent::Timer; @@ -93,34 +93,29 @@ impl Player { impl AsyncPlayer for Player { type Metadata = Metadata; - type MetadataFuture<'b> + type MetadataFuture<'b> = impl Future> + 'b where - Self: 'b, - = impl Future> + 'b; - type NameFuture<'b> + Self: 'b; + type NameFuture<'b> = impl Future + 'b where - Self: 'b, - = impl Future + 'b; - type PlaybackStatusFuture<'b> + Self: 'b; + type PlaybackStatusFuture<'b> = impl Future> + 'b where - Self: 'b, - = impl Future> + 'b; - type PositionFuture<'b> + Self: 'b; + type PositionFuture<'b> = impl Future> + 'b where - Self: 'b, - = impl Future> + 'b; + Self: 'b; + #[allow(clippy::needless_lifetimes)] fn metadata<'this>(&'this self) -> Self::MetadataFuture<'this> { async { let session = self.media_properties().await?; let title = session.Title()?.to_string_lossy(); let artists = session.Artist()?.to_string_lossy(); - Ok(Metadata { - title, - artists - }) + Ok(Metadata { title, artists }) } } + #[allow(clippy::needless_lifetimes)] fn playback_status<'this>(&'this self) -> Self::PlaybackStatusFuture<'this> { async { @@ -146,12 +141,14 @@ impl AsyncPlayer for Player { }) } } + #[allow(clippy::needless_lifetimes)] fn name<'this>(&'this self) -> Self::NameFuture<'this> { // There might be a Windows API to find the name of the player but the user most // likely will never see this anyway async { String::from("windows-api") } } + #[allow(clippy::needless_lifetimes)] fn position<'this>(&'this self) -> Self::PositionFuture<'this> { // TODO: Find the API for this? diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..5d56faf --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly" diff --git a/settings.toml b/settings.toml index 34097cf..6afe98c 100644 --- a/settings.toml +++ b/settings.toml @@ -3,7 +3,7 @@ enabled = true # Set this to the highest priority so it will start with the clock # priority = 1 # Enables a twelve hour clock instead of the 24hr one -# Defaults to your lcoal format if unset +# Defaults to your local format if unset # twelve_hour = false [mpris2] @@ -12,7 +12,7 @@ enabled = true # You can check what to put here by using tools like D-Feet # preferred_player = "Lollypop" -[crypto] +[coindesk] enabled = true # Valid choices are "gbp", "usd" and "eur" # Default is USD diff --git a/src/main.rs b/src/main.rs index 9c8c4c0..e620d4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ #![allow(incomplete_features)] #![feature( - generic_associated_types, type_alias_impl_trait, try_blocks, const_fn_floating_point_arithmetic, diff --git a/src/providers/mod.rs b/src/providers/mod.rs index e3b0605..7bdaf64 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -2,4 +2,4 @@ pub(crate) mod clock; #[cfg(feature = "crypto")] pub(crate) mod coindesk; #[cfg(any(feature = "dbus-support", target_os = "windows"))] -pub(crate) mod music; \ No newline at end of file +pub(crate) mod music; diff --git a/src/render/debug.rs b/src/render/debug.rs index 9b5cf06..2e07bae 100644 --- a/src/render/debug.rs +++ b/src/render/debug.rs @@ -4,6 +4,7 @@ use crate::render::{ }; use anyhow::Result; use async_stream::try_stream; +use config::Config; use embedded_graphics::{ pixelcolor::BinaryColor, prelude::Point, @@ -22,7 +23,7 @@ use tokio::{ static PROVIDER_INIT: fn(&Config) -> Result> = register_callback; #[allow(clippy::unnecessary_wraps)] -fn register_callback() -> Result> { +fn register_callback(_config: &Config) -> Result> { info!("Registering dummy display source."); let provider = Box::new(DummyProvider {}); Ok(provider) diff --git a/src/render/display.rs b/src/render/display.rs index d98cbf3..2d4145d 100644 --- a/src/render/display.rs +++ b/src/render/display.rs @@ -1,6 +1,6 @@ use anyhow::Result; -use apex_hardware::FrameBuffer; +pub use apex_hardware::FrameBuffer; use futures_core::Stream; pub trait ContentProvider { diff --git a/src/render/text.rs b/src/render/text.rs index 0f55170..89c2b4a 100644 --- a/src/render/text.rs +++ b/src/render/text.rs @@ -56,7 +56,7 @@ impl DrawTarget for ScrollableCanvas { } fn clear(&mut self, color: Self::Color) -> Result<(), Self::Error> { - self.canvas.set_all(color.is_on()); + self.canvas.fill(color.is_on()); Ok(()) } } @@ -98,7 +98,7 @@ impl StatefulScrollable { /// * `text`: the new text /// /// returns: Result - /// + /// /// # Examples /// /// ```