use classic::GamepadButtons;
use byteorder::{
ByteOrder,
LittleEndian
};
use super::{
HasStandardButtons,
PollCommand,
};
#[derive(Clone)]
pub enum JogControl {
Stop = 0x00,
Hold = 0x30,
Left = 0x20,
Right = 0x10,
DropRevolutions = 0x80,
DropAndHold = 0xb0,
NewHold = 0xc0,
}
pub enum JogState {
TurnedLeft,
TurnedRight,
AtMaximum
}
#[repr(C)]
pub struct JogCon {
pub buttons: GamepadButtons,
jog_position: [u8; 2],
pub jog_state: u8,
}
impl JogCon {
pub fn jog_position(&self) -> i16 {
LittleEndian::read_i16(&self.jog_position)
}
}
impl HasStandardButtons for JogCon {
fn buttons(&self) -> GamepadButtons {
self.buttons.clone()
}
}
pub struct ControlJC {
pub mode: JogControl,
pub strength: u8,
}
impl ControlJC {
pub fn new(mode: JogControl, strength: u8) -> Self {
Self {
mode: mode,
strength: strength,
}
}
}
impl PollCommand for ControlJC {
fn set_command(&self, command: &mut [u8]) {
command[0] = self.mode.clone() as u8;
command[0] |= self.strength & 0x0f;
}
}