use super::HasStandardButtons;
#[repr(C)]
#[derive(Clone)]
pub struct GamepadButtons {
data: u16,
}
impl GamepadButtons {
const PS_SELECT: u16 = 0x0001;
const PS_L3: u16 = 0x0002;
const PS_R3: u16 = 0x0004;
const PS_START: u16 = 0x0008;
const PS_UP: u16 = 0x0010;
const PS_RIGHT: u16 = 0x0020;
const PS_DOWN: u16 = 0x0040;
const PS_LEFT: u16 = 0x0080;
const PS_L2: u16 = 0x0100;
const PS_R2: u16 = 0x0200;
const PS_L1: u16 = 0x0400;
const PS_R1: u16 = 0x0800;
const PS_TRIANGLE: u16 = 0x1000;
const PS_CIRCLE: u16 = 0x2000;
const PS_CROSS: u16 = 0x4000;
const PS_SQUARE: u16 = 0x8000;
pub fn select(&self) -> bool {
self.data & Self::PS_SELECT == 0
}
pub fn l3(&self) -> bool {
self.data & Self::PS_L3 == 0
}
pub fn r3(&self) -> bool {
self.data & Self::PS_R3 == 0
}
pub fn start(&self) -> bool {
self.data & Self::PS_START == 0
}
pub fn up(&self) -> bool {
self.data & Self::PS_UP == 0
}
pub fn right(&self) -> bool {
self.data & Self::PS_RIGHT == 0
}
pub fn down(&self) -> bool {
self.data & Self::PS_DOWN == 0
}
pub fn left(&self) -> bool {
self.data & Self::PS_LEFT == 0
}
pub fn l2(&self) -> bool {
self.data & Self::PS_L2 == 0
}
pub fn r2(&self) -> bool {
self.data & Self::PS_R2 == 0
}
pub fn l1(&self) -> bool {
self.data & Self::PS_L1 == 0
}
pub fn r1(&self) -> bool {
self.data & Self::PS_R1 == 0
}
pub fn triangle(&self) -> bool {
self.data & Self::PS_TRIANGLE == 0
}
pub fn circle(&self) -> bool {
self.data & Self::PS_CIRCLE == 0
}
pub fn cross(&self) -> bool {
self.data & Self::PS_CROSS == 0
}
pub fn square(&self) -> bool {
self.data & Self::PS_SQUARE == 0
}
pub fn bits(&self) -> u16 {
self.data
}
}
#[repr(C)]
pub struct Classic {
pub buttons: GamepadButtons,
}
impl HasStandardButtons for Classic {
fn buttons(&self) -> GamepadButtons {
self.buttons.clone()
}
}