Skip to content

Commit

Permalink
Fix the angular wheel detection
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbaunwall committed Feb 23, 2024
1 parent f343cfb commit 2ca719d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "Apache-2.0"
authors = ["Lars Baunwall"]
documentation = "https://github.com/larsbaunwall/beolyd5"
repository = "https://github.com/larsbaunwall/beolyd5"
version = "1.0.1"
version = "1.0.2"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion src/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
┌─┴─────┐ │
┌─────────────┐ ┌─────────┐ │ .───. │)│
│ .┴. │ Pi 5/ │ │( )│ │
│ BS5 ( = )◀──USB+HDMI──│HifiBerry│◀──PowerLink──│ `───' │ │
│ BS5 ( = )◀──USB+HDMI──│HifiBerry│◀──PowerLink──│ `───' │ │
│ `┬' │ │ │BeoLab ├─┘
└─────────────┘ └─────────┘ └───────┘
```
Expand Down
12 changes: 11 additions & 1 deletion src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,17 @@ impl Beolyd5Controller {
//uint8_t bar [2] = { 0xc0, 0x00 }; // turns on LED
//uint8_t bar [2] = { 0x80, 0x00 }; // turns off screen, on LED
//uint8_t bar [2] = { 0xd0, 0x00 }; // blinking
fn send(&self, data: [u8; 2]) -> Result<(), Box<dyn Error>> {

/// Sends a command to the device to turn on the LCD backlight or the LED.
/// Commands _could_ be:
/// - `[0x00, 0x00]` to turn off the LCD backlight and the LED
/// - `[0x40, 0x00]` to turn on the LCD backlight
/// - `[0xc0, 0x00]` to turn on the LED
/// - `[0x80, 0x00]` to turn off the LCD backlight and turn on the LED
/// - `[0xd0, 0x00]` to make the LED blink
/// - `[0x01, 0x00]` to make a click sound
/// Returns `Ok(())` if the command was sent successfully, or an `Err` if there was a problem sending the command.
pub fn send(&self, data: [u8; 2]) -> Result<(), Box<dyn Error>> {
let device_clone = self.device.clone().ok_or_else(|| {
Box::new(std::io::Error::new(
ErrorKind::NotFound,
Expand Down
25 changes: 25 additions & 0 deletions src/rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Use of this source code is governed by an Apache 2.0 license that can be found in the LICENSE file.
*/

use std::fmt;

/// `Button` represents one of the four buttons on the BeoSound 5 controller.
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum Button {
Expand All @@ -13,6 +15,18 @@ pub enum Button {
Standby,
}

impl fmt::Display for Button {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Button::None => write!(f, "None"),
Button::Left => write!(f, "Left"),
Button::Right => write!(f, "Right"),
Button::Go => write!(f, "Go"),
Button::Standby => write!(f, "Standby"),
}
}
}

/// `Wheel` represents one of the three wheels on the BeoSound 5 controller.
#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum Wheel {
Expand All @@ -22,6 +36,17 @@ pub enum Wheel {
None,
}

impl fmt::Display for Wheel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Wheel::Front => write!(f, "Front"),
Wheel::Angular => write!(f, "Angular"),
Wheel::Back => write!(f, "Back"),
Wheel::None => write!(f, "None"),
}
}
}

/// `SystemEvent` represents a system event (any event) from the BeoSound 5 controller.
/// It includes the event bytes, the last read bytes, the positions of the wheels, and the button pressed.
#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize)]
Expand Down

0 comments on commit 2ca719d

Please sign in to comment.