Skip to content

Commit

Permalink
Implement PartialEq and Eq wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
eldruin committed Sep 15, 2022
1 parent a764732 commit eb5fcff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.1.1] - 2022-09-15

### Added
- Implement `PartialEq` and `Eq` on public structs.

### Fixed
- Fixed bit changes not being written to the driver struct in the functions `set_data_rate`, `set_wake_power_mode`, `set_sleep_power_mode` and `set_auto_sleep_data_rate`.

Expand Down
40 changes: 20 additions & 20 deletions src/types.rs
Expand Up @@ -39,7 +39,7 @@ pub mod mode {
}

/// Unscaled acceleration measurement
#[derive(Debug, Default, Clone, PartialEq)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct UnscaledMeasurement {
/// X-axis acceleration.
pub x: i16,
Expand All @@ -61,7 +61,7 @@ pub struct Measurement {
}

/// G scale
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GScale {
/// Range: +/-2g
G2,
Expand All @@ -72,7 +72,7 @@ pub enum GScale {
}

/// Read mode
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ReadMode {
/// Normal read mode (default)
Normal,
Expand All @@ -81,7 +81,7 @@ pub enum ReadMode {
}

/// Output data rate
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OutputDataRate {
/// 800 Hz (default)
Hz800,
Expand All @@ -102,7 +102,7 @@ pub enum OutputDataRate {
}

/// Sampling rate used in auto-sleep/wake mode
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AutoSleepDataRate {
/// 50 Hz (default)
Hz50,
Expand All @@ -115,7 +115,7 @@ pub enum AutoSleepDataRate {
}

/// Power mode
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PowerMode {
/// Normal (default)
Normal,
Expand All @@ -128,7 +128,7 @@ pub enum PowerMode {
}

/// Current system mode
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SystemMode {
/// Standby mode
Standby,
Expand All @@ -139,7 +139,7 @@ pub enum SystemMode {
}

/// Current data status
#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct DataStatus {
/// X,Y,Z-axis data overwrite
pub xyz_overwrite: bool,
Expand All @@ -160,7 +160,7 @@ pub struct DataStatus {
}

/// Portrait/landscape debounce counter mode
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DebounceCounterMode {
/// Decrements debounce whenever the condition of interest is no longer valid.
Decrement,
Expand All @@ -169,7 +169,7 @@ pub enum DebounceCounterMode {
}

/// Current portrait/landscape status
#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct PortraitLandscapeStatus {
/// True if any of the other fields changed
pub something_changed: bool,
Expand All @@ -182,7 +182,7 @@ pub struct PortraitLandscapeStatus {
}

/// Portrait/Landscape orientation
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PortraitLandscapeOrientation {
/// Equipment is standing vertically in the normal orientation (default)
PortraitUp,
Expand All @@ -201,7 +201,7 @@ impl Default for PortraitLandscapeOrientation {
}

/// Front/Back orientation
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FrontBackOrientation {
/// Equipment is in front-facing orientation (default)
Front,
Expand All @@ -216,7 +216,7 @@ impl Default for FrontBackOrientation {
}

/// Current interrupt status
#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct InterruptStatus {
/// Auto-sleep/wake interrupt occurred
pub auto_sleep: bool,
Expand All @@ -237,7 +237,7 @@ pub struct InterruptStatus {
/// Interrupt source enable/disable
///
/// Unavailable interrupt sources on a device are ignored.
#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct EnabledInterrupts {
/// Auto-sleep/wake interrupt enabled
pub auto_sleep: bool,
Expand All @@ -256,7 +256,7 @@ pub struct EnabledInterrupts {
}

/// Physical interrupt pin polarity
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InterruptPinPolarity {
/// Low state when active (default)
ActiveLow,
Expand All @@ -265,7 +265,7 @@ pub enum InterruptPinPolarity {
}

/// Physical interrupt pin configuration
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InterruptPinConfiguration {
/// Push-pull configuration (default)
PushPull,
Expand All @@ -274,7 +274,7 @@ pub enum InterruptPinConfiguration {
}

/// Interrupt source pin route
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InterruptSourcePinRoute {
/// Source is routed to pin INT1
Int1,
Expand All @@ -291,7 +291,7 @@ impl Default for InterruptSourcePinRoute {
/// Interrupt source pin route
///
/// Unavailable interrupt sources on a device are ignored.
#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct InterruptPinRoutes {
/// Auto-sleep/wake interrupt pin route (INT1/INT2)
pub auto_sleep: InterruptSourcePinRoute,
Expand All @@ -310,7 +310,7 @@ pub struct InterruptPinRoutes {
}

/// Interrupts that wake the device from sleep
#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct WakeInterrupts {
/// Acceleration transient interrupt
pub transient: bool,
Expand All @@ -323,7 +323,7 @@ pub struct WakeInterrupts {
}

/// Possible slave addresses
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SlaveAddr {
/// Default slave address
Default,
Expand Down

0 comments on commit eb5fcff

Please sign in to comment.