Struct Mouse

Source
pub struct Mouse<'c> { /* private fields */ }
Expand description

A PS/2 mouse.

This provides the functionality of a typical PS/2 mouse, as well as PS/2 devices that act like mice, such as touchpads or wireless mouse receivers.

§Examples

use ps2::Controller;

let mut controller = unsafe { Controller::new() };
let mut mouse = controller.mouse();

Implementations§

Source§

impl<'c> Mouse<'c>

Source

pub fn set_scaling_one_to_one(&mut self) -> Result<(), MouseError>

Set the scaling of reported data to be 1:1.

Read more about scaling here.

Source

pub fn set_scaling_two_to_one(&mut self) -> Result<(), MouseError>

Set the scaling of reported data to be 2:1.

Read more about scaling here.

Source

pub fn set_resolution(&mut self, resolution: u8) -> Result<(), MouseError>

Set mouse resolution.

Valid values are 0 for 1 count/mm, 1 for 2 counts/mm, 2 for 4 counts/mm, or 3 for 8 counts/mm.

Source

pub fn get_status_packet( &mut self, ) -> Result<(MouseStatusFlags, u8, u8), MouseError>

Request a status packet from the mouse and reset the movement counters.

The first byte returned is a bitfield, the second byte is the mouse resolution, and the third is the sample rate.

Source

pub fn set_stream_mode(&mut self) -> Result<(), MouseError>

Reset mouse movement counters and enter streaming mode.

Read more about modes here.

Source

pub fn request_data_packet( &mut self, ) -> Result<(MouseMovementFlags, i16, i16), MouseError>

Request a movement data packet from the mouse and reset the movement counters.

The first byte returned is a bitfield, and the other two bytes are 9-bit two’s complement integers for the horizontal and vertical movement offset relative to the position at which the last packet was sent.

If you’re writing an interrupt handler, see Mouse::read_data_packet.

Source

pub fn read_data_packet( &mut self, ) -> Result<(MouseMovementFlags, i16, i16), MouseError>

Read an existing movement data packet directly from the data buffer.

The first byte returned is a bitfield, and the other two bytes are 9-bit two’s complement integers for the horizontal and vertical movement offset relative to the position at which the last packet was sent.

This does not send any commands to the mouse. This is useful in interrupt handlers when we just want to read the data sent by the mouse.

Source

pub fn reset_wrap_mode(&mut self) -> Result<(), MouseError>

Reset mouse movement counters and exit wrap mode, entering the mode the mouse was in previously.

Read more about modes here.

Source

pub fn set_wrap_mode(&mut self) -> Result<(), MouseError>

Reset mouse movement counters and enter wrap mode.

Read more about modes here.

Source

pub fn set_remote_mode(&mut self) -> Result<(), MouseError>

Reset mouse movement counters and enter remote mode.

Read more about modes here.

Source

pub fn get_mouse_type(&mut self) -> Result<MouseType, MouseError>

Attempt to obtain a device identifier for this mouse.

Source

pub fn set_sample_rate(&mut self, sample_rate: u8) -> Result<(), MouseError>

Set the mouse sample rate and reset the movement counters.

Valid rates are 10, 20, 40, 60, 80, 100, and 200, in samples per second.

Source

pub fn enable_data_reporting(&mut self) -> Result<(), MouseError>

Enable data reporting and reset the movement counters.

This only affects data reporting in stream mode.

Source

pub fn disable_data_reporting(&mut self) -> Result<(), MouseError>

Disable data reporting and reset the movement counters.

This only affects data reporting in stream mode. Note that this only disables reporting, not sampling. Movement packets may still be read using Mouse::request_data_packet.

Source

pub fn set_defaults(&mut self) -> Result<(), MouseError>

Set defaults, clear movement counters, and enter stream mode.

Default settings are as follows: sampling rate = 100 samples/second, resolution = 4 counts/mm, scaling = 1:1, data reporting disabled.

Source

pub fn resend_last_packet(&mut self) -> Result<(), MouseError>

Request that the mouse resend the last transmitted byte or packet.

Currently, this does not return any data, since the resent data may be one or more bytes in length. It is the responsibility of the caller to consume these bytes using Controller::read_data.

Source

pub fn reset_and_self_test(&mut self) -> Result<(), MouseError>

Reset the mouse and perform a Basic Assurance Test.

Returns MouseError::SelfTestFailed if the test fails.

Trait Implementations§

Source§

impl<'c> Debug for Mouse<'c>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'c> Freeze for Mouse<'c>

§

impl<'c> RefUnwindSafe for Mouse<'c>

§

impl<'c> Send for Mouse<'c>

§

impl<'c> Sync for Mouse<'c>

§

impl<'c> Unpin for Mouse<'c>

§

impl<'c> !UnwindSafe for Mouse<'c>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.