📄 hid.c
字号:
//
// MOUSE MOUSE MOUSE MOUSE MOUSE MOUSE MOUSE MOUSE MOUSE MOUSE MOUSE MOUSE
//
device_instance *dvi_ptr;
unsigned long status;
short x;
short y;
unsigned char button;
// mprintf( WHITE, CONTINUE, "hid_callback_mouse \r\n" );
if ( atlmix_is_fatal_error( (transfer_instance *)(epi_ptr->transfer_instance) ) )
{
// Device may be detached
atlmix_free_transfer( (transfer_instance *)(epi_ptr->transfer_instance) );
return;
}
dvi_ptr = devep_find_device( epi_ptr->dev_addr );
status = *((unsigned long *)(((transfer_instance *)(epi_ptr->transfer_instance))->data_ptr_base));
atlmix_re_enable_interrupt_transfer( epi_ptr->transfer_instance );
if ( hid_class_interface.idVendor == (dvi_ptr->dev_descriptor).idVendor )
{
if ( hid_class_interface.idProduct == (dvi_ptr->dev_descriptor).idProduct )
{
(*(hid_class_interface.hid_callback_function))( dvi_ptr, status );
return;
}
}
#if 0
x = mouse.x + ((signed char)((status & 0x0000FF00) >> 8) >> 1);
y = mouse.y + ((signed char)((status & 0x00FF0000) >> 16) >> 1);
#else
x = (signed char)((status & 0x0000FF00) >> 8);
y = (signed char)((status & 0x00FF0000) >> 16);
x = (x < 0) ? -1 : x;
x = (0 < x) ? 1 : x;
y = (y < 0) ? -1 : y;
y = (0 < y) ? 1 : y;
x += mouse.x;
y += mouse.y;
#endif
x = ( x < 1 ) ? 1 : x;
x = ( 78 < x ) ? 78 : x;
y = ( y < 1 ) ? 1 : y;
y = ( 14 < y ) ? 14 : y;
button = (signed char)(status & 0x000000FF);
p_mouse = mouse;
mouse.x = x;
mouse.y = y;
mouse.button = button;
if ( mouse.button & p_mouse.button & 0x02 )
audio_volume_set_delta( p_mouse.x - mouse.x );
else
gene_install_asynchronous_periodic_process( 4, display_mouse_status );
}
#if 0
void display_mouse_status( void )
{
gene_install_asynchronous_periodic_process( 4, NULL );
mprintf( WHITE, CONTINUE, " mouse event [x = %2d, y = %2d] ", mouse.x, mouse.y );
mprintf( (mouse.button & 0x01) ? WHITE : DARKGRAY, CONTINUE, "[Left] " );
mprintf( (mouse.button & 0x02) ? WHITE : DARKGRAY, CONTINUE, "[Right]\r\n" );
}
#else
void display_mouse_status( void )
{
unsigned char color;
unsigned char p_color;
unsigned char message_on;
int x;
int y;
static int px;
static int py;
gene_install_asynchronous_periodic_process( 4, NULL );
x = wherex();
y = wherey();
if ( (p_mouse.button | mouse.button) & 0x02 )
{
message_on = mouse.button & 0x02;
if ( message_on )
{
px = ((78 - 17) < mouse.x) ? (78 - 17) : mouse.x;
py = mouse.y;
}
gotoxy( px, py );
if ( is_audio_exist() )
mprintf( message_on ? LIGHTRED : DARKGRAY, CONTINUE, "[Volume control!]" );
else
mprintf( message_on ? LIGHTRED : DARKGRAY, CONTINUE, "[No Audio device!]" );
gotoxy( x, y );
return;
}
if ( mouse.x )
{
switch ( p_mouse.button )
{
case 0x01 :
color = LIGHTRED;
break;
case 0x03 :
color = YELLOW;
break;
default :
color = DARKGRAY;
break;
}
gotoxy( p_mouse.x, p_mouse.y );
mprintf( color, CONTINUE, "*" );
}
switch ( mouse.button )
{
case 0x01 :
color = LIGHTRED;
break;
case 0x03 :
color = YELLOW;
break;
default :
color = WHITE;
break;
}
gotoxy( mouse.x, mouse.y );
// mprintf( color , CONTINUE, "%c", 219 );
mprintf( color , CONTINUE, "%c", 16 );
gotoxy( x, y );
}
#endif
unsigned char hid_usb_key_buffer( void )
{
return ( g_keyboard_buffer_ptr_out - g_keyboard_buffer_ptr_in );
}
int hid_usb_key_buffer_pop( void )
{
int buffer;
if ( g_keyboard_buffer_ptr_out != g_keyboard_buffer_ptr_in )
{
buffer = g_keyboard_buffer[ g_keyboard_buffer_ptr_out ];
g_keyboard_buffer_ptr_out = keyboard_buffer_pointer_increment( g_keyboard_buffer_ptr_out );
return( buffer );
}
return( 0 );
}
void hid_usb_key_buffer_push( int buffer )
{
unsigned char p;
p = keyboard_buffer_pointer_increment( g_keyboard_buffer_ptr_in );
if ( g_keyboard_buffer_ptr_out != p )
{
g_keyboard_buffer[ g_keyboard_buffer_ptr_in ] = buffer;
g_keyboard_buffer_ptr_in = p;
}
}
unsigned char keyboard_buffer_pointer_increment( unsigned char p )
{
return ( ((p + 1) < KEYBOARD_BUFFER_DEPTH) ? ++p : 0 );
}
void hid_keyboard_main( void )
{
char s[80];
mprintf( LIGHTGREEN, CONTINUE, "\r\n\r\n KeyboardTest started\r\n\r\n" );
mprintf( LIGHTGRAY, CONTINUE, " Keyboard test!! Please input from your USB keyboard. \r\n Hit " );
mprintf( LIGHTRED, CONTINUE, "[Return]" );
mprintf( LIGHTGRAY, CONTINUE, " to exit from this test routine.\r\n\r\n" );
ui_get_string_from_console( s, 80, WHITE, " >> ", YELLOW, 0, "Hit keys to test.", NULL );
mprintf( YELLOW, CONTINUE, "\r\n" );
ui_soft_blink(s, 150, 2);
mprintf( YELLOW, CONTINUE, "\r\n\r\n\r\n" );
}
/*************************************************
**
** Write the each charactor on mojitable[i]
**
*************************************************/
void moji_init( void )
{
int i;
for(i = 4; i<30; i++)
{
mojitable[i] = 93 + i; //alpha
}
for(i = 30; i<39; i++) //number1-9
{
mojitable[i] = 19 + i;
}
mojitable[39] = 48; //number0*
mojitable[40] = 13; //enter
mojitable[41] = 27; //escape (ESP)
mojitable[42] = 8; //Backspace (BS)
mojitable[43] = 9; //Tab
mojitable[44] = 32; //Keyboard space
mojitable[45] = 45; // -
mojitable[46] = 61; // =
mojitable[47] = 91; // [
mojitable[48] = 93; // ]
mojitable[49] = 92; // \
//mojitable[50] = 96; // `
mojitable[51] = 59; // ;
mojitable[52] = 39; // '
//mojitable[53] = ; //
mojitable[54] = 44; // ,
mojitable[55] = 46; // .
mojitable[56] = 47; // /
//Shift
for(i = 57; i<83; i++)
{
mojitable[i] = 8 + i; //ALPHA
}
mojitable[83] = 33; // !
mojitable[84] = 64; // @
mojitable[85] = 35; // #
mojitable[86] = 36; // $
mojitable[87] = 37; // %
mojitable[88] = 94; // ^
mojitable[89] = 38; // &
mojitable[90] = 42; // *
mojitable[91] = 40; // (
mojitable[92] = 41; // )
//mojitable[93] = ;
//mojitable[94] = ;
//mojitable[95] = ;
//mojitable[96] = ;
//mojitable[97] = ;
mojitable[98] = 95; // _
mojitable[99] = 43; // +
mojitable[100] = 123; // {
mojitable[101] = 125; // }
mojitable[102] = 124; // |
//mojitable[103] = 126; // ~
mojitable[104] = 58; // :
mojitable[105] = 34; // "
//mojitable[106] = ; //
mojitable[107] = 60; // <
mojitable[108] = 62; // >
mojitable[109] = 63; // ?
}
/*
Moji_table (Hex)
Low | High Nibble
Nibble | 0 1 2 3 4 5 6 7
________|_______________________________________________________________________
|
0 | m 3 ] H X
|
1 | n 4 \ I Y
|
2 | o 5 J Z _
|
3 | p 6 ; K ! +
|
4 | a q 7 ' L @ {
|
5 | b r 8 M # }
|
6 | c s 9 , N $ |
|
7 | d t 0 . O %
|
8 | e u Enter / P ^ :
|
9 | f v ESC A Q & "
|
A | g w BS B R *
|
B | h x Tab C S ( <
|
C | i y Space D T ) >
|
D | j z - E U ?
|
E | k 1 = F V
|
F | l 2 [ G W
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -