};
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;
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;
}
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)
int n_buttons = ptr->FileHeader->NButtons;
int n_axies = ptr->FileHeader->NAxies;
+ ENTER("pNode iLength pData", Node, Length, Data);
+
// TODO: Locking (Acquire)
Length = MIN(
// TODO: Locking (Release)
+ LEAVE('i', Length);
return Length;
}
// 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,
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;
}
*/
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('-');
}
#include <acess.h>\r
#include <modules.h>\r
#include <vfs.h>\r
-#include <fs_devfs.h>\r
-#include <api_drv_common.h>\r
-#include <api_drv_joystick.h>\r
+#include <Input/Mouse/include/mouse.h>\r
#include "common.h"\r
\r
// == CONSTANTS ==\r
// - Internal -\r
int PS2Mouse_Install(char **Arguments);\r
void PS2Mouse_HandleInterrupt(Uint8 InputByte);\r
-// - Filesystem -\r
-size_t PS2Mouse_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);\r
- int PS2Mouse_IOCtl(tVFS_Node *Node, int ID, void *Data);\r
\r
// == GLOBALS ==\r
-void (*gpMouse_EnableFcn)(void);\r
+void (*gpPS2Mouse_EnableFcn)(void);\r
// - Settings\r
- int giMouse_Sensitivity = 1;\r
- int giMouse_MaxX = 640, giMouse_MaxY = 480;\r
-// - File Data\r
-Uint8 gMouse_FileData[sizeof(tJoystick_FileHeader) + NUM_AXIES*sizeof(tJoystick_Axis) + NUM_BUTTONS];\r
-tJoystick_FileHeader *gMouse_FileHeader = (void *)gMouse_FileData;\r
-tJoystick_Axis *gMouse_Axies;\r
-Uint8 *gMouse_Buttons;\r
-tJoystick_Callback gMouse_Callback;\r
- int gMouse_CallbackArg;\r
- int giMouse_AxisLimits[2];\r
+ int giPS2Mouse_Sensitivity = 1;\r
// - Internal State\r
- int giMouse_Cycle = 0; // IRQ Position\r
-Uint8 gaMouse_Bytes[4] = {0,0,0,0};\r
-// - Driver definition\r
-tVFS_NodeType gMouse_NodeType = {\r
- .Read = PS2Mouse_Read,\r
- .IOCtl = PS2Mouse_IOCtl\r
-};\r
-tDevFS_Driver gMouse_DriverStruct = {\r
- NULL, "PS2Mouse",\r
- {\r
- .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX,\r
- .Type = &gMouse_NodeType\r
- }\r
-};\r
+ int giPS2Mouse_Cycle = 0; // IRQ Position\r
+Uint8 gaPS2Mouse_Bytes[4] = {0,0,0,0};\r
+tMouse *gpPS2Mouse_Handle;\r
\r
// == CODE ==\r
int PS2Mouse_Install(char **Arguments)\r
{\r
- \r
-\r
- // Set up variables\r
- gMouse_Axies = (void*)&gMouse_FileData[4];\r
- gMouse_Buttons = (void*)&gMouse_Axies[NUM_AXIES];\r
+ gpPS2Mouse_Handle = Mouse_Register("PS2Mouse", NUM_AXIES, NUM_BUTTONS);\r
\r
- gMouse_FileHeader->NAxies = 2; gMouse_FileHeader->NButtons = 3;\r
- gMouse_Axies[0].MinValue = -10; gMouse_Axies[0].MaxValue = 10;\r
- gMouse_Axies[1].MinValue = -10; gMouse_Axies[1].MaxValue = 10;\r
- \r
// Initialise Mouse Controller\r
- giMouse_Cycle = 0; // Set Current Cycle position\r
- gpMouse_EnableFcn();\r
- \r
- DevFS_AddDevice(&gMouse_DriverStruct);\r
- \r
+ giPS2Mouse_Cycle = 0; // Set Current Cycle position\r
+ gpPS2Mouse_EnableFcn();\r
+\r
return MODULE_ERR_OK;\r
}\r
\r
{\r
Uint8 flags;\r
int d[2], d_accel[2];\r
- int i;\r
\r
// Gather mouse data\r
- gaMouse_Bytes[giMouse_Cycle] = InputByte;\r
- LOG("gaMouse_Bytes[%i] = 0x%02x", gMouse_Axies[0].MaxValue);\r
+ gaPS2Mouse_Bytes[giPS2Mouse_Cycle] = InputByte;\r
// - If bit 3 of the first byte is not set, it's not a valid packet?\r
- if(giMouse_Cycle == 0 && !(gaMouse_Bytes[0] & 0x08) )\r
- return ;\r
- giMouse_Cycle++;\r
- if(giMouse_Cycle < 3)\r
+ if(giPS2Mouse_Cycle == 0 && !(gaPS2Mouse_Bytes[0] & 0x08) )\r
return ;\r
\r
- giMouse_Cycle = 0;\r
+ // 3 bytes per packet\r
+ giPS2Mouse_Cycle++;\r
+ if(giPS2Mouse_Cycle < 3)\r
+ return ;\r
+ giPS2Mouse_Cycle = 0;\r
\r
// Actual Processing (once we have all bytes) \r
- flags = gaMouse_Bytes[0];\r
+ flags = gaPS2Mouse_Bytes[0];\r
\r
LOG("flags = 0x%x", flags);\r
\r
if(flags & 0xC0) return;\r
\r
// Calculate dX and dY\r
- d[0] = gaMouse_Bytes[1]; if(flags & 0x10) d[0] = -(256-d[0]); // x\r
- d[1] = gaMouse_Bytes[2]; if(flags & 0x20) d[1] = -(256-d[1]); // y\r
+ d[0] = gaPS2Mouse_Bytes[1]; if(flags & 0x10) d[0] = -(256-d[0]); // x\r
+ d[1] = gaPS2Mouse_Bytes[2]; if(flags & 0x20) d[1] = -(256-d[1]); // y\r
d[1] = -d[1]; // Y is negated\r
LOG("RAW dx=%i, dy=%i\n", d[0], d[1]);\r
// Apply scaling\r
// TODO: Apply a form of curve to the mouse movement (dx*log(dx), dx^k?)\r
// TODO: Independent sensitivities?\r
// TODO: Disable acceleration via a flag?\r
- d_accel[0] = d[0]*giMouse_Sensitivity;\r
- d_accel[1] = d[1]*giMouse_Sensitivity;\r
+ d_accel[0] = d[0]*giPS2Mouse_Sensitivity;\r
+ d_accel[1] = d[1]*giPS2Mouse_Sensitivity;\r
\r
- // Set Buttons (Primary)\r
- for( i = 0; i < 3; i ++ )\r
- {\r
- Uint8 newVal = (flags & (1 << i)) ? 0xFF : 0;\r
- if(newVal != gMouse_Buttons[i]) {\r
- if( gMouse_Callback )\r
- gMouse_Callback(gMouse_CallbackArg, 0, i, newVal - gMouse_Buttons[i]);\r
- gMouse_Buttons[i] = newVal;\r
- }\r
- }\r
- \r
- // Update X and Y Positions\r
- for( i = 0; i < 2; i ++ )\r
- {\r
- Sint16 newCursor = 0;\r
- if( giMouse_AxisLimits[i] )\r
- newCursor = MIN( MAX(0, gMouse_Axies[i].CursorPos + d_accel[i]), giMouse_AxisLimits[i] );;\r
- \r
- if( gMouse_Callback )\r
- {\r
- if(giMouse_AxisLimits[i] && gMouse_Axies[i].CursorPos != newCursor)\r
- gMouse_Callback(gMouse_CallbackArg, 1, i, newCursor - gMouse_Axies[i].CursorPos);\r
- if(!giMouse_AxisLimits[i] && gMouse_Axies[i].CurValue != d_accel[i])\r
- gMouse_Callback(gMouse_CallbackArg, 1, i, d_accel[i] - gMouse_Axies[i].CurValue);\r
- }\r
- \r
- gMouse_Axies[i].CurValue = d_accel[i];\r
- gMouse_Axies[i].CursorPos = newCursor;\r
- }\r
-\r
-// Log("Mouse at %ix%i", gMouse_Axies[0].CursorPos, gMouse_Axies[1].CursorPos);\r
- \r
- VFS_MarkAvaliable(&gMouse_DriverStruct.RootNode, 1);\r
-}\r
-\r
-/* Read mouse state (coordinates)\r
- */\r
-size_t PS2Mouse_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)\r
-{\r
- if(Offset > sizeof(gMouse_FileData)) return 0;\r
- if(Length > sizeof(gMouse_FileData)) Length = sizeof(gMouse_FileData);\r
- if(Offset + Length > sizeof(gMouse_FileData)) Length = sizeof(gMouse_FileData) - Offset;\r
-\r
- memcpy(Buffer, &gMouse_FileData[Offset], Length);\r
- \r
- VFS_MarkAvaliable(Node, 0);\r
- return Length;\r
-}\r
-\r
-static const char *csaIOCtls[] = {DRV_IOCTLNAMES, DRV_JOY_IOCTLNAMES, NULL};\r
-/* Handle messages to the device\r
- */\r
-int PS2Mouse_IOCtl(tVFS_Node *Node, int ID, void *Data)\r
-{\r
- tJoystick_NumValue *info = Data;\r
-\r
- switch(ID)\r
- {\r
- BASE_IOCTLS(DRV_TYPE_JOYSTICK, "PS2Mouse", 0x100, csaIOCtls);\r
-\r
- case JOY_IOCTL_SETCALLBACK: // TODO: Implement\r
- return -1;\r
- \r
- case JOY_IOCTL_SETCALLBACKARG: // TODO: Implement\r
- return -1;\r
- \r
- case JOY_IOCTL_GETSETAXISLIMIT:\r
- if(!info) return 0;\r
- if(info->Num < 0 || info->Num >= 2) return 0;\r
- if(info->Value != -1)\r
- giMouse_AxisLimits[info->Num] = info->Value;\r
- return giMouse_AxisLimits[info->Num];\r
- \r
- case JOY_IOCTL_GETSETAXISPOSITION:\r
- if(!info) return 0;\r
- if(info->Num < 0 || info->Num >= 2) return 0;\r
- if(info->Value != -1)\r
- gMouse_Axies[info->Num].CursorPos = info->Value;\r
- return gMouse_Axies[info->Num].CursorPos;\r
-\r
- case JOY_IOCTL_GETSETAXISFLAGS:\r
- return -1;\r
- \r
- case JOY_IOCTL_GETSETBUTTONFLAGS:\r
- return -1;\r
-\r
- default:\r
- return 0;\r
- }\r
+ // TODO: Scroll wheel? \r
+ Mouse_HandleEvent(gpPS2Mouse_Handle, (flags & 7), d_accel);\r
}\r
\r
if(FD_ISSET(giMouseFD, set))
{
+ const int c_n_axies = 4;
+ const int c_n_buttons = 5;
int i;
struct sMouseAxis {
int16_t MinValue;
uint16_t NAxies;
uint16_t NButtons;
} *mouseinfo;
- char data[sizeof(*mouseinfo) + sizeof(*axies)*3 + 5];
+ char data[sizeof(*mouseinfo) + sizeof(*axies)*c_n_axies + c_n_buttons];
mouseinfo = (void*)data;
seek(giMouseFD, 0, SEEK_SET);
i = read(giMouseFD, data, sizeof(data));
i -= sizeof(*mouseinfo);
- if( i < 0 )
+ if( i < 0 ) {
+ _SysDebug("Mouse data undersized (no header)");
return ;
- if( i < sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons )
+ }
+ if( mouseinfo->NAxies > c_n_axies || mouseinfo->NButtons > c_n_buttons ) {
+ _SysDebug(
+ "%i axies, %i buttons above prealloc counts (%i, %i)",
+ mouseinfo->NAxies, mouseinfo->NButtons, c_n_axies, c_n_buttons
+ );
+ return ;
+ }
+ if( i < sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons ) {
+ _SysDebug("Mouse data undersized (body doesn't fit %i < %i)",
+ i, sizeof(*axies)*mouseinfo->NAxies + mouseinfo->NButtons
+ );
return ;
+ }
// What? No X/Y?
if( mouseinfo->NAxies < 2 )
// Handle movement
Video_SetCursorPos( axies[0].CursorPos, axies[1].CursorPos );
- _SysDebug("Mouse to %i,%i", axies[0].CursorPos, axies[1].CursorPos);
+// _SysDebug("Mouse to %i,%i", axies[0].CursorPos, axies[1].CursorPos);
WM_Input_MouseMoved(
giInput_MouseX, giInput_MouseY,