X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FInput%2FMouse%2Fmain.c;h=8c27f132bc9263f758abb147555d492f014c4a53;hb=ad12abcd42d1c8f0bd196c6c824a054545cf66d2;hp=7e9b4aa1ca9481d6e0910ec02071c056bcf74b78;hpb=2667cb207a1aa17947b7ba582e1e2e3b9a9dea07;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/Input/Mouse/main.c b/KernelLand/Modules/Input/Mouse/main.c index 7e9b4aa1..8c27f132 100644 --- a/KernelLand/Modules/Input/Mouse/main.c +++ b/KernelLand/Modules/Input/Mouse/main.c @@ -15,12 +15,12 @@ // === PROTOTYPES === int Mouse_Install(char **Arguments); -void Mouse_Cleanup(void); + int Mouse_Cleanup(void); // - "User" side -char *Mouse_Root_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name); + int Mouse_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); +tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data); -size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data); +size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data, Uint Flags); // - Device Side tMouse *Mouse_Register(const char *Name, int NumButtons, int NumAxies); void Mouse_RemoveInstance(tMouse *Handle); @@ -38,7 +38,7 @@ tVFS_NodeType gMouse_DevNodeType = { }; tDevFS_Driver gMouse_DevInfo = { NULL, "Mouse", - { .Flags = VFS_FFLAG_DIRECTORY, .Type = &gMouse_RootNodeType } + { .Flags = VFS_FFLAG_DIRECTORY, .Type = &gMouse_RootNodeType, .Size = 1 } }; tPointer gMouse_Pointer; @@ -53,6 +53,8 @@ int Mouse_Install(char **Arguments) gMouse_Pointer.Node.Type = &gMouse_DevNodeType; gMouse_Pointer.Node.ImplPtr = &gMouse_Pointer; + gMouse_Pointer.FileHeader = (void*)gMouse_Pointer.FileData; + gMouse_Pointer.Axies = (void*)( gMouse_Pointer.FileHeader + 1 ); return 0; } @@ -60,18 +62,21 @@ int Mouse_Install(char **Arguments) /** * \brief Pre-unload cleanup function */ -void Mouse_Cleanup(void) +int Mouse_Cleanup(void) { + return 0; } // --- VFS Interface --- -char *Mouse_Root_ReadDir(tVFS_Node *Node, int Pos) +int Mouse_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) { - if( Pos != 0 ) return NULL; - return strdup("system"); + if( Pos != 0 ) + return -EINVAL; + strcpy(Dest, "system"); + return 0; } -tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { if( strcmp(Name, "system") != 0 ) return NULL; return &gMouse_Pointer.Node; @@ -92,6 +97,7 @@ int Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data) case JOY_IOCTL_GETSETAXISLIMIT: if( !numval || !CheckMem(numval, sizeof(*numval)) ) return -1; + LOG("GetSetAxisLimit %i = %i", numval->Num, numval->Value); if(numval->Num < 0 || numval->Num >= ptr->FileHeader->NAxies) return 0; if(numval->Value != -1) @@ -113,12 +119,14 @@ int Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data) /** * \brief Read from a device */ -size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data) +size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data, Uint Flags) { tPointer *ptr = Node->ImplPtr; int n_buttons = ptr->FileHeader->NButtons; int n_axies = ptr->FileHeader->NAxies; + ENTER("pNode iLength pData", Node, Length, Data); + // TODO: Locking (Acquire) Length = MIN( @@ -155,6 +163,7 @@ size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data) // TODO: Locking (Release) + LEAVE('i', Length); return Length; } @@ -192,7 +201,7 @@ tMouse *Mouse_Register(const char *Name, int NumButtons, int NumAxies) // TODO: Locking ret->Next = target->FirstDev; target->FirstDev = ret; - if( ret->NumAxies <= MAX_AXIES && ret->NumAxies > target->FileHeader->NAxies ) { + if( ret->NumAxies > target->FileHeader->NAxies ) { // Clear new axis data memset( target->Axies + target->FileHeader->NAxies, @@ -202,7 +211,7 @@ tMouse *Mouse_Register(const char *Name, int NumButtons, int NumAxies) target->FileHeader->NAxies = ret->NumAxies; target->Buttons = (void*)( target->Axies + ret->NumAxies ); } - if( ret->NumButtons <= MAX_BUTTONS && ret->NumButtons > target->FileHeader->NButtons ) { + if( ret->NumButtons > target->FileHeader->NButtons ) { // No need to move as buttons can expand out into space target->FileHeader->NButtons = ret->NumButtons; } @@ -225,18 +234,25 @@ void Mouse_RemoveInstance(tMouse *Instance) */ void Mouse_HandleEvent(tMouse *Handle, Uint32 ButtonState, int *AxisDeltas) { - tPointer *ptr = Handle->Pointer; + tPointer *ptr; - Handle->ButtonState = ButtonState; + ENTER("pHandle xButtonState pAxisDeltas", Handle, ButtonState, AxisDeltas); + ptr = Handle->Pointer; + + // Update device state + Handle->ButtonState = ButtonState; memcpy(Handle->LastAxisVal, AxisDeltas, sizeof(*AxisDeltas)*Handle->NumAxies); + // Update cursor position // TODO: Acceleration? - for( int i = 0; i < Handle->NumAxies; i ++ ) { ptr->Axies[i].CursorPos = MIN(MAX(0, ptr->Axies[i].CursorPos+AxisDeltas[i]), ptr->AxisLimits[i]); + LOG("Axis %i: delta = %i, pos = %i", i, AxisDeltas[i], ptr->Axies[i].CursorPos); } + VFS_MarkAvaliable( &ptr->Node, 1 ); + LEAVE('-'); }