use core::fmt::Debug;
pub mod kempston;
bitflags! {
#[derive(Default)]
pub struct MouseButtons: u8 {
const LEFT = 0b0000_0001;
const RIGHT = 0b0000_0010;
const MIDDLE = 0b0000_0100;
const FOURTH = 0b0001_0000;
const FIFTH = 0b0010_0000;
const SIXTH = 0b0100_0000;
const SEVENTH = 0b1000_0000;
}
}
#[derive(Clone, Copy, Default, Debug)]
pub struct MouseMovement {
pub horizontal: i16,
pub vertical: i16
}
pub trait MouseInterface {
fn set_buttons(&mut self, buttons: MouseButtons);
fn get_buttons(&self) -> MouseButtons;
fn move_mouse(&mut self, mov: MouseMovement);
}
pub trait MouseDevice: Debug {
fn port_read(&self, port: u16) -> u8;
fn port_write(&mut self, _port: u16, _data: u8) -> bool { false }
}
#[derive(Clone, Copy, Default, Debug)]
pub struct NullMouseDevice;
impl From<(i16, i16)> for MouseMovement {
fn from((x, y): (i16, i16)) -> Self {
MouseMovement {
horizontal: x,
vertical: y
}
}
}
impl From<[i16;2]> for MouseMovement {
fn from([x, y]: [i16;2]) -> Self {
(x, y).into()
}
}
impl MouseInterface for NullMouseDevice {
fn set_buttons(&mut self, _buttons: MouseButtons) {}
fn get_buttons(&self) -> MouseButtons {
MouseButtons::empty()
}
fn move_mouse(&mut self, _mov: MouseMovement) {}
}
impl MouseDevice for NullMouseDevice {
fn port_read(&self, _port: u16) -> u8 {
u8::max_value()
}
}