示例#1
0
// System Control
//  k is one of the SYSTEM_CONTROL defines which come from the HID usage table "Generic Desktop Page (0x01)"
// in "HID Usage Tables" (HUT1_12v2.pdf)
size_t Keyboard_::systemControl(uint8_t k) 
{
	if(k <= 16)
	{
		u16 mask = 0;
		u8 m[2];

		if(k > 0)
		{
			mask = 1 << (k - 1);
		}

		m[0] = LSB(mask);
		m[1] = MSB(mask);
		HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m));

		// these are all OSCs, so send a clear to make it possible to send it again later
		m[0] = 0;
		m[1] = 0;
		HID_SendReport(HID_REPORTID_SYSTEMCONTROL,m,sizeof(m));
		return 1;
	}
	else
	{
		setWriteError();
		return 0;
	}
}
示例#2
0
void Remote_::next(void)
{
    uint8_t m[2];
    m[0] = REMOTE_NEXT;
    m[1] = 0;
    HID_SendReport(4,m,2);
}
示例#3
0
void Remote_::pause(void)
{
    uint8_t m[2];
    m[0] = REMOTE_PAUSE;
    m[1] = 0;
    HID_SendReport(4,m,2);
}
示例#4
0
void Remote_::stop(void)
{
    uint8_t m[2];
    m[0] = REMOTE_STOP;
    m[1] = 0;
    HID_SendReport(4,m,2);
}
示例#5
0
void Remote_::mute(void)
{
    uint8_t m[2];
    m[0] = VOLUME_MUTE;
    m[1] = 0;
    HID_SendReport(4,m,2);
}
示例#6
0
void Remote_::play(void)
{
    uint8_t m[2];
    m[0] = REMOTE_PLAY;
    m[1] = 0;
    HID_SendReport(4,m,2);
}
示例#7
0
void Remote_::increase(void)
{
    uint8_t m[2];
    m[0] = VOLUME_UP;
    m[1] = 0;
    HID_SendReport(4,m,2);
}
示例#8
0
void Remote_::decrease(void)
{
    uint8_t m[2];
    m[0] = VOLUME_DOWN;
    m[1] = 0;
    HID_SendReport(4,m,2);
}
示例#9
0
void Joystick_::setState(JoyState_t *joySt)
{
	uint8_t data[joyBytes];
	uint32_t buttonTmp;
	buttonTmp = joySt->buttons;

	data[0] = buttonTmp & 0xFF;		// Break 32 bit button-state out into 4 bytes, to send over USB
	buttonTmp >>= 8;
	data[1] = buttonTmp & 0xFF;
	buttonTmp >>= 8;
	data[2] = buttonTmp & 0xFF;
	buttonTmp >>= 8;
	data[3] = buttonTmp & 0xFF;

	data[4] = joySt->throttle;		// Throttle
	data[5] = joySt->rudder;		// Steering

	data[6] = (joySt->hatSw2 << 4) | joySt->hatSw1;		// Pack hat-switch states into a single byte

	data[7] = joySt->xAxis;		// X axis
	data[8] = joySt->yAxis;		// Y axis
	data[9] = joySt->zAxis;		// Z axis
	data[10] = joySt->xRotAxis;		// rX axis
	data[11] = joySt->yRotAxis;		// rY axis
	data[12] = joySt->zRotAxis;		// rZ axis

	//HID_SendReport(Report number, array of values in same order as HID descriptor, length)
	HID_SendReport(3, data, joyBytes);
	// The joystick is specified as using report 3 in the descriptor. That's where the "3" comes from
}
示例#10
0
void Remote_::rewind(void)
{
    uint8_t m[2];
    m[0] = 0;
    m[1] = REMOTE_REWIND >> 8;
    HID_SendReport(4,m,2);
}
示例#11
0
void Remote_::clear(void)
{
    uint8_t m[2];
    m[0] = 0;
    m[1] = 0;
    HID_SendReport(4,m,2);
}
示例#12
0
void Remote_::forward(void)
{
    uint8_t m[2];
    m[0] = 0;
    m[1] = REMOTE_FAST_FORWARD >> 8;
    HID_SendReport(4,m,2);
}
示例#13
0
void Remote_::previous(void)
{
    uint8_t m[2];
    m[0] = REMOTE_PREVIOUS;
    m[1] = 0;
    HID_SendReport(4,m,2);
}
示例#14
0
void Joystick_::setState(JoyState_t *joySt)
{
	uint8_t data[joyBytes];
	uint32_t buttonTmp;
	buttonTmp = joySt->buttons;

	data[0] = buttonTmp & 0xFF;		// Break 32 bit button-state out into 4 bytes, to send over USB
	buttonTmp >>= 8;
	data[1] = buttonTmp & 0xFF;
	buttonTmp >>= 8;
	
	// unpacking the orb data is trickier
	unsigned char high;
	unsigned char low;
	unsigned char temp;

	high = joySt->xAxis >> 8;
	low = joySt->xAxis & 255;
	data[2] = low;
	temp = high;

	high = joySt->yAxis >> 6;
	low = joySt->yAxis & 63;
	data[3] = (low << 2) + temp;
	temp = high;
	
	high = joySt->zAxis >> 4;
	low = joySt->zAxis & 15;
	data[4] = (low << 4) + temp;
	temp = high;

	high = joySt->xRotAxis >> 2;
	low = joySt->xRotAxis & 3;
	data[5] = (low << 6) + temp;
	temp = high;

	high = 0;
	low = 0;
	data[6] = temp;
	temp = high;

	high = joySt->yRotAxis >> 8;
	low = joySt->yRotAxis & 255;
	data[7] = low;
	temp = high;

	high = joySt->zRotAxis >> 6;
	low = joySt->zRotAxis & 63;
	data[8] = (low << 2) + temp;
	temp = high;

	high = 0;
	low = 0;
	data[9] = (low << 4) + temp;

	//HID_SendReport(Report number, array of values in same order as HID descriptor, length)
	HID_SendReport(3, data, joyBytes);
	// The joystick is specified as using report 3 in the descriptor. That's where the "3" comes from
}
示例#15
0
void Thumbstick_::setState(ThumbState_t *thumbSt)
{
	int16_t data[2];
	data[0] = thumbSt->xAxis;	// X axis
	data[1] = thumbSt->yAxis;	// Y axis
	//HID_SendReport(Report number, array of values in same order as HID descriptor, length)
	HID_SendReport(4, data, 4);
}
示例#16
0
void Mouse_::move(signed char x, signed char y, signed char wheel)
{
        MouseReport.Button = _buttons;
        MouseReport.X = x;
        MouseReport.Y = y;
        //m[3] = wheel;
        HID_SendReport(HID_REPORTID_MouseReport);
}
示例#17
0
void Joystick_::setState(JoyState_t * JoySt)
{
	uint8_t data[joyBytes];
	uint8_t dataX[3];
	uint8_t buttonTmp;
	buttonTmp = JoySt -> Buttons;

	data[0] = buttonTmp;           // Buttons
	data[1] = JoySt -> XAxis;      // X Axis
	data[2] = JoySt -> YAxis;      // Y Axis
	data[3] = JoySt -> ZAxis;
	dataX[0] = JoySt -> Buttons2;
	dataX[1] = JoySt -> XAxis2;
	dataX[2] = JoySt -> YAxis2;

	HID_SendReport(3, data, joyBytes);
	HID_SendReport(4, dataX, joyBytes);
}
示例#18
0
void Mouse_::move(signed char x, signed char y, signed char wheel)
{
	u8 m[4];
	m[0] = _buttons;
	m[1] = x;
	m[2] = y;
	m[3] = wheel;
	HID_SendReport(HID_REPORTID_MOUSE,m,sizeof(m));
}
示例#19
0
void Mouse_::move(signed char x, signed char y, signed char wheel)
{
	u8 m[4];
	m[0] = _buttons;
	m[1] = x;
	m[2] = y;
	m[3] = wheel;
	HID_SendReport(1,m,4);
}
示例#20
0
void Joystick_::move(uint8_t x, uint8_t y, uint8_t throttle, uint8_t buttons)
{
    u8 j[4];
    j[0] = x;
    j[1] = y;
    j[2] = throttle;
    j[3] = buttons;
    //HID_SendReport(Report number, array of values in same order as HID descriptor, length)
    HID_SendReport(4, j, 4);
}
示例#21
0
// all parameters have the range of -32768 to 32767 and must be scaled to screen pixels
// some examples:
//   x=0,y=0 is the middle of the screen
//   x=-32768,y=-32768 is the top left corner
//   x=32767,y=-32768 is the top right corner
//   x=32767,y=32767 is the bottom right corner
//   x=-32768,y=32767 is the bottom left corner
void Mouse_::moveAbs(int16_t x, int16_t y, int16_t wheel)
{
	u8 m[7];
	m[0] = _buttons; // TODO: is it a good idea to take over the _buttons from relative report here or should it be left out?
	m[1] = LSB(x);
	m[2] = MSB(x);
	m[3] = LSB(y);
	m[4] = MSB(y);
	m[5] = LSB(wheel);
	m[6] = MSB(wheel);
	HID_SendReport(HID_REPORTID_MOUSE_ABS,m,sizeof(m));
}
示例#22
0
void Joystick_::sendState()
{
	uint8_t data[joystickStateSize];
	uint32_t buttonTmp = buttons;

	// Split 32 bit button-state into 4 bytes
	data[0] = buttonTmp & 0xFF;		
	buttonTmp >>= 8;
	data[1] = buttonTmp & 0xFF;
	buttonTmp >>= 8;
	data[2] = buttonTmp & 0xFF;
	buttonTmp >>= 8;
	data[3] = buttonTmp & 0xFF;

	data[4] = throttle;
	data[5] = rudder;

	// Calculate hat-switch values
	uint8_t convertedHatSwitch[2];
	for (int hatSwitchIndex = 0; hatSwitchIndex < 2; hatSwitchIndex++)
	{
		if (hatSwitch[hatSwitchIndex] < 0)
		{
			convertedHatSwitch[hatSwitchIndex] = 8;
		}
		else
		{
			convertedHatSwitch[hatSwitchIndex] = (hatSwitch[hatSwitchIndex] % 360) / 45;
		}
	}

	// Pack hat-switch states into a single byte
	data[6] = (convertedHatSwitch[1] << 4) | (B00001111 & convertedHatSwitch[0]);

	data[7] = xAxis + 127;
	data[8] = yAxis + 127;
	data[9] = zAxis + 127;

	//data[10] = (xAxisRotation % 360) * 0.708;
	data[10] = (xAxisRotation % 360);
	data[11] = (yAxisRotation % 360) * 0.708;
	data[12] = (zAxisRotation % 360) * 0.708;

	// HID_SendReport(Report number, array of values in same order as HID descriptor, length)
	HID_SendReport(JOYSTICK_REPORT_ID, data, joystickStateSize);
}
示例#23
0
void Media_::press(uint16_t command) {
    HID_SendReport(4,&command,sizeof(command)); //reportid (4), consumer control command, size in bytes (2)
}
示例#24
0
void Keyboard_::sendReport(KeyReport* keys)
{
	HID_SendReport(HID_REPORTID_KEYBOARD,keys,sizeof(*keys));
}
示例#25
0
void Keyboard_::sendReport(KeyReport* keys)
{
	HID_SendReport(2,keys,sizeof(KeyReport));
}
示例#26
0
void MicroJoy::sendReport(JoystickReport* joyReport)
{
	HID_SendReport(MICROJOY_1_REPORT_ID,joyReport,sizeof(JoystickReport));
}
示例#27
0
void Media_::pressRawKeyboard(uint8_t modifiers, uint8_t key) {
    uint8_t keys[8] = {
        modifiers,0,key,0,0,0,0,0
    }; //modifiers, reserved, key[0]
    HID_SendReport(2,&keys,8);
}
示例#28
0
void Joystick_::sendReport(JoystickReport* joyReport)
{
	HID_SendReport(3,joyReport,sizeof(JoystickReport));
}
示例#29
0
void HIDBridge_::proceedCommand(void){
#ifdef DEBUG
	debug->print("c");
	debug->println(nhp_read.command);
#endif

#ifdef HIDBRIDGE_RX
	// proceed a possible end flag
	if (nhp_read.command == HIDBRIDGE_COMMAND_END) {

		// we've got a correct USB protocol received. Write it to the host now.
		if (reportID && (recvLength == reportLength)) {
			rxReady = false; //TODO not needed?
#ifdef USB_DEBUG
			// debug print HID reports
			debug->print("USBk ");
			debug->print(reportID, DEC);
			for (uint8_t i = 0; i < reportLength; i++) {
				debug->print(", 0x");
				debug->print(hidReport[i], HEX);
			}
			debug->println();
#endif
			HID_SendReport(reportID, hidReport, reportLength);

			// acknowledge signal
			rxReady = true;
			writeState();
		}
		// log an error
		else
			err(HIDBRIDGE_ERR_CMD_END);

		// reset reportID in any case
		reportID = 0;
	}

	// proceed a possible new reportID lead
	else {
		// flag an error if we have a pending report
		if (reportID)
			err(HIDBRIDGE_ERR_CMD_RID);

		// determine the new report length
		switch (nhp_read.command) { //TODO progmem lookup table
#ifdef HID_MOUSE_ENABLE
		case HID_REPORTID_MOUSE:
			reportLength = sizeof(HID_MouseReport_Data_t);
			break;
#endif

#ifdef HID_MOUSE_ABSOLUTE_ENABLE
		case HID_REPORTID_MOUSE_ABSOLUTE:
			reportLength = sizeof(HID_MouseAbsoluteReport_Data_t);
			break;
#endif

#ifdef HID_KEYBOARD_ENABLE
		case HID_REPORTID_KEYBOARD:
			reportLength = sizeof(HID_KeyboardReport_Data_t);
			break;
#endif

#ifdef HID_CONSUMERCONTROL_ENABLE
		case HID_REPORTID_CONSUMERCONTROL:
			reportLength = sizeof(HID_ConsumerControlReport_Data_t);
			break;
#endif

#ifdef HID_SYSTEMCONTROL_ENABLE
		case HID_REPORTID_SYSTEMCONTROL:
			reportLength = sizeof(HID_SystemControlReport_Data_t);
			break;
#endif

#ifdef HID_GAMEPAD_ENABLE
		case HID_REPORTID_GAMEPAD:
			reportLength = sizeof(HID_GamepadReport_Data_t);
			break;
#endif

		default:
			// error
			reportLength = 0;
			break;
		}

		if (reportLength) {
			// save new report properties
			reportID = nhp_read.command;
			recvLength = 0;
		}
		else {
			// new reportID is not supported
			//TODO recv length =0?
			reportID = 0;
			err(HIDBRIDGE_ERR_COMMAND);
		}
	}
#else // ifdef HIDBRIDGE_RX
	err(HIDBRIDGE_ERR_COMMAND);
#endif
}
示例#30
0
void Media_::releaseAll() {
    HID_SendReport(4,0,2); //release the keypress
}