📄 mouse_emulation.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006
Part of BlueLab 3.6.2-release
FILE NAME
mouse_emulation.c
DESCRIPTION
For test
NOTES
*/
/****************************************************************************
Header files
*/
/* #include "hid_mouse.h"
#include "snut_stream_util.h"
*/
#include <pio.h>
#include <message.h>
#include <string.h>
#include <sink.h>
#include <source.h>
#include <stream.h>
#include <vm.h>
#include <panic.h>
#include <stdio.h>
#include "app_private.h"
void mouseEmulationInit(Sink left, Sink right);
/* Internal messages */
enum
{
TEST_PERF_MOUSE
};
#define HANDTEST_CFG
#ifdef HANDTEST_CFG
/* LED 捞亥?勤甸矾 */
typedef struct REPORT_TAG
{
/* uint8 repid; */
/* uint8 l_button:1;
uint8 r_button:1;
uint8 m_button:1;
*/
uint8 button;
uint8 wheel;
uint8 x;
uint8 y;
} T_REPORT;
#define INPUT_SIZE 4 /*5*/
#define LBUTTON_POS 0x01
#define RBUTTON_POS 0x02
#define MBUTTON_POS 0x04
/*static T_REPORT mouse_report = {0x02, 0x00, 0x00, 0x00, 0x00};*/
/* USB REPORT 绰 ID 甫 荤侩窍瘤 臼绊 郴侩父 焊晨 */
static T_REPORT mouse_report = {0x00, 0x00, 0x00, 0x00};
#endif
/* Packet types */
#define HID_HANDSHAKE 0
#define HID_CONTROL 1
#define HID_GET_REPORT 4
#define HID_SET_REPORT 5
#define HID_GET_PROTOCOL 6
#define HID_SET_PROTOCOL 7
#define HID_GET_IDLE 8
#define HID_SET_IDLE 9
#define HID_DATA 10
#define HID_DATC 11
#if 0
typedef enum
{
hid_report_other = 0,
hid_report_input = 1,
hid_report_output = 2,
hid_report_feature = 3
} hid_report_type;
#endif
struct {
TaskData task;
Sink left_sink;
Sink right_sink;
} me;
static int TestHidInterruptReport(Sink sink, hid_report_type report_type,
uint16 report_length, const uint8 *data)
{
uint8 *ptr;
uint16 offset;
if(!sink) return 0; /* 俊矾惯积凳 */
/* Get pointer to stream */
ptr = SinkMap(sink);
#if 0
uint16 offset = SinkClaim(sink, report_length + 1);
if (offset == 0xFFFF)
return -1;
/* Store header */
ptr[offset] = (HID_DATA << 4) | (report_type & 0x03);
/* Copy data into packet */
memcpy(&ptr[offset + 1], data, report_length);
/* Flush packet */
SinkFlush(sink, report_length + 1);
#else
offset = SinkClaim(sink, report_length);
if (offset == 0xFFFF)
return -1;
memcpy(&ptr[offset], data, report_length);
/* Flush packet */
SinkFlush(sink, report_length);
#endif
return 0;
}
static void mouseEmulationHandler(Task task, MessageId id, Message message)
{
#ifdef HANDTEST_CFG
static int dir = 1;
static int count = 0;
static int big_count = 0;
uint8 marker[10];
#endif
#ifdef HANDTEST_CFG
if(id == TEST_PERF_MOUSE){
mouse_report.button = mouse_report.wheel = mouse_report.x = mouse_report.y = 0;
if(count == 100)
if((big_count & 0x0F) == 0x00){
DEBUG((" == big count =%d\n", bigcount));
marker[0] = marker[1] = (uint8)'*';
/* SendNtoSink(StreamUartSink(), marker, 1); */
}
switch (dir)
{
case 0:
mouse_report.x = 2;
TestHidInterruptReport(me.left_sink, hid_report_input,INPUT_SIZE, (const uint8 *)&mouse_report );
if(count++ > 100){
count = 0;
dir = 1;
big_count++;
}
break;
case 1:
mouse_report.y = 2;
TestHidInterruptReport(me.right_sink, hid_report_input,INPUT_SIZE, (const uint8 *)&mouse_report );
if(count++ > 100){
count = 0;
dir = 2;
big_count++;
}
break;
case 2:
mouse_report.x = 0xFE;
TestHidInterruptReport(me.left_sink, hid_report_input,INPUT_SIZE, (const uint8 *)&mouse_report );
if(count++ > 100){
count = 0;
dir = 3;
big_count++;
}
break;
case 3:
mouse_report.y = 0xFE;
TestHidInterruptReport(me.right_sink, hid_report_input,INPUT_SIZE, (const uint8 *)&mouse_report );
if(count++ > 100){
count = 0;
dir = 0;
big_count++;
}
break;
default:
break;
} /* switch */
/*if(big_count != 2){*/ /* 滴锅噶 倒绊 吝瘤 窃 */
MessageSendLater(&me.task, TEST_PERF_MOUSE, 0, 1);
/*} */
}
#endif
}
/* 悼累窍瘤 臼绰 惑怕肺 弥扁拳 凳 */
void mouseEmulationInit(Sink left, Sink right)
{
me.task.handler = mouseEmulationHandler;
me.left_sink = left;
me.right_sink = right;
MessageSendLater(&me.task, TEST_PERF_MOUSE, 0,1000);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -