Fixes to slash merge

This commit is contained in:
Luke D. Jones
2024-04-10 09:13:26 +12:00
parent a737d240be
commit 564992719e
15 changed files with 194 additions and 174 deletions

View File

@@ -17,6 +17,7 @@ pub enum SlashType {
impl FromStr for SlashType {
type Err = SlashError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Ok(match s {
"ga403" | "GA403" => Self::GA403,
@@ -32,8 +33,8 @@ pub enum SlashMode {
Bounce = 0x10,
Slash = 0x12,
Loading = 0x13,
BitStream = 0x1D,
Transmission = 0x1A,
BitStream = 0x1d,
Transmission = 0x1a,
Flow = 0x19,
Flux = 0x25,
Phantom = 0x24,
@@ -77,7 +78,6 @@ impl FromStr for SlashMode {
}
}
impl Display for SlashMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match &self {
@@ -102,7 +102,6 @@ impl Display for SlashMode {
}
impl SlashMode {
pub fn list() -> [String; 15] {
[
SlashMode::Bounce.to_string(),
@@ -134,4 +133,3 @@ pub struct DeviceState {
pub slash_interval: u8,
pub slash_mode: SlashMode,
}

View File

@@ -9,4 +9,4 @@ pub mod error;
/// Provides const methods to create the USB HID control packets
pub mod usb;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

View File

@@ -9,18 +9,18 @@
//! Step 1 needs to be applied only on fresh system boot.
use dmi_id::DMIID;
#[cfg(feature = "dbus")]
use crate::error::SlashError;
use crate::{SlashMode, SlashType};
const PACKET_SIZE: usize = 128;
const DEV_PAGE: u8 = 0x5e;
pub const VENDOR_ID: u16 = 0x0B05;
pub const PROD_ID: u16 = 0x193B;
pub const VENDOR_ID: u16 = 0x0b05;
pub const PROD_ID: u16 = 0x193b;
pub const PROD_ID_STR: &str = "193B";
pub type SlashUsbPacket = [u8;PACKET_SIZE];
pub type SlashUsbPacket = [u8; PACKET_SIZE];
/// `get_anime_type` is very broad, matching on part of the laptop board name
/// only. For this reason `find_node()` must be used also to verify if the USB
@@ -43,53 +43,53 @@ pub fn get_slash_type() -> Result<SlashType, SlashError> {
/// start after the laptop boots.
#[inline]
pub const fn pkts_for_init() -> [SlashUsbPacket; 2] {
let mut pkt1 = [0;PACKET_SIZE];
let mut pkt1 = [0; PACKET_SIZE];
pkt1[0] = DEV_PAGE;
pkt1[1] = 0xD7;
pkt1[1] = 0xd7;
pkt1[2] = 0x00;
pkt1[3] = 0x00;
pkt1[4] = 0x01;
pkt1[5] = 0xAC;
pkt1[5] = 0xac;
let mut pkt2 = [0;PACKET_SIZE];
let mut pkt2 = [0; PACKET_SIZE];
pkt2[0] = DEV_PAGE;
pkt2[1] = 0xD2;
pkt2[1] = 0xd2;
pkt2[2] = 0x02;
pkt2[3] = 0x01;
pkt2[4] = 0x08;
pkt2[5] = 0xAB;
pkt2[5] = 0xab;
[pkt1, pkt2]
}
#[inline]
pub const fn pkt_save() -> SlashUsbPacket {
let mut pkt = [0;PACKET_SIZE];
let mut pkt = [0; PACKET_SIZE];
pkt[0] = DEV_PAGE;
pkt[1] = 0xD4;
pkt[1] = 0xd4;
pkt[2] = 0x00;
pkt[3] = 0x00;
pkt[4] = 0x01;
pkt[5] = 0xAB;
pkt[5] = 0xab;
pkt
}
#[inline]
pub const fn pkt_set_mode(mode: SlashMode) -> [SlashUsbPacket; 2] {
let mut pkt1 = [0;PACKET_SIZE];
let mut pkt1 = [0; PACKET_SIZE];
pkt1[0] = DEV_PAGE;
pkt1[1] = 0x02;
pkt1[2] = 0x03;
pkt1[3] = 0x00;
pkt1[4] = 0x0C;
pkt1[4] = 0x0c;
let mut pkt2 = [0;PACKET_SIZE];
let mut pkt2 = [0; PACKET_SIZE];
pkt2[0] = DEV_PAGE;
pkt2[1] = 0xD3;
pkt2[1] = 0xd3;
pkt2[2] = 0x04;
pkt2[3] = 0x00;
pkt2[4] = 0x0C;
pkt2[4] = 0x0c;
pkt2[5] = 0x01;
pkt2[6] = mode as u8;
pkt2[7] = 0x02;
@@ -110,19 +110,19 @@ pub const fn pkt_set_mode(mode: SlashMode) -> [SlashUsbPacket; 2] {
pub const fn pkt_set_options(enabled: bool, brightness: u8, interval: u8) -> SlashUsbPacket {
let status_byte = if enabled { 0x01 } else { 0x00 };
let mut pkt = [0;PACKET_SIZE];
let mut pkt = [0; PACKET_SIZE];
pkt[0] = DEV_PAGE;
pkt[1] = 0xD3;
pkt[1] = 0xd3;
pkt[2] = 0x03;
pkt[3] = 0x01;
pkt[4] = 0x08;
pkt[5] = 0xAB;
pkt[6] = 0xFF;
pkt[5] = 0xab;
pkt[6] = 0xff;
pkt[7] = 0x01;
pkt[8] = status_byte;
pkt[9] = 0x06;
pkt[10] = brightness;
pkt[11] = 0xFF;
pkt[11] = 0xff;
pkt[12] = interval;
pkt