AcessNative - Mouse implimented, woot!
authorJohn Hodge <[email protected]>
Sun, 7 Oct 2012 10:59:52 +0000 (18:59 +0800)
committerJohn Hodge <[email protected]>
Sun, 7 Oct 2012 10:59:52 +0000 (18:59 +0800)
AcessNative/acesskernel_src/include/mouse_int.h [new file with mode: 0644]
AcessNative/acesskernel_src/main.c
AcessNative/acesskernel_src/mouse.c
AcessNative/acesskernel_src/server.c
AcessNative/acesskernel_src/syscalls.c
AcessNative/acesskernel_src/ui.h
AcessNative/acesskernel_src/ui_sdl.c

diff --git a/AcessNative/acesskernel_src/include/mouse_int.h b/AcessNative/acesskernel_src/include/mouse_int.h
new file mode 100644 (file)
index 0000000..d18d566
--- /dev/null
@@ -0,0 +1,35 @@
+
+#ifndef _ACESSNATIVE__MOUSE_INT_H_
+#define _ACESSNATIVE__MOUSE_INT_H_
+
+#include <api_drv_joystick.h>
+
+typedef struct sPointer        tPointer;
+
+#define MAX_BUTTONS    5
+#define MAX_AXIES      2
+#define MAX_FILESIZE   (sizeof(tJoystick_FileHeader) + MAX_AXIES*sizeof(tJoystick_Axis) + MAX_BUTTONS)
+
+/**
+ */
+struct sPointer
+{
+       tPointer        *Next;
+
+       // Node
+       tVFS_Node       Node;
+
+       // Data
+       Uint8   FileData[MAX_FILESIZE];
+       tJoystick_FileHeader    *FileHeader;
+       tJoystick_Axis  *Axies;
+       Uint8   *Buttons;
+
+       // Limits for axis positions
+       Uint16  AxisLimits[MAX_AXIES];
+};
+
+extern void    Mouse_HandleEvent(Uint32 ButtonState, int *AxisDeltas, int *AxisValues);
+
+#endif
+
index 671fff9..eb0883d 100644 (file)
@@ -26,6 +26,7 @@ extern int    NativeKeyboard_Install(char **Arguments);
 extern int     NativeFS_Install(char **Arguments);
 extern void    Debug_SetKTerminal(char *Path);
 extern int     VT_Install(char **Arguments);
+extern int     Mouse_Install(char **Arguments);
 extern int     VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options);
 extern int     VFS_MkDir(const char *Path);
 extern int     SyscallServer(void);
@@ -94,6 +95,7 @@ int main(int argc, char *argv[])
                Log_Error("Init", "Unable to load NativeKeyboard");
        }
        NativeFS_Install(NULL);
+       Mouse_Install(NULL);
        // - Start VTerm
        {
                char    *args[] = {
index e69de29..0ff9e8a 100644 (file)
@@ -0,0 +1,170 @@
+/*
+ * Acess2 Kernel - Mouse Mulitplexing Driver
+ * - By John Hodge (thePowersGang)
+ *
+ * main.c
+ * - Mouse mulitplexing
+ */
+#define DEBUG  0
+#define VERSION        VER2(0,1)
+#include <acess.h>
+#include <modules.h>
+#include <fs_devfs.h>
+#include "include/mouse_int.h"
+
+// === PROTOTYPES ===
+ int   Mouse_Install(char **Arguments);
+ int   Mouse_Cleanup(void);
+// - "User" side
+ int   Mouse_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]);
+tVFS_Node      *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name);
+ 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);
+// - Device Side
+void   Mouse_HandleEvent(Uint32 ButtonState, int *AxisDeltas, int *AxisValues);
+
+// === GLOBALS ===
+tVFS_NodeType  gMouse_RootNodeType = {
+       .ReadDir = Mouse_Root_ReadDir,
+       .FindDir = Mouse_Root_FindDir
+};
+tVFS_NodeType  gMouse_DevNodeType = {
+       .IOCtl = Mouse_Dev_IOCtl,
+       .Read = Mouse_Dev_Read
+};
+tDevFS_Driver  gMouse_DevInfo = {
+       NULL, "Mouse",
+       { .Flags = VFS_FFLAG_DIRECTORY, .Type = &gMouse_RootNodeType, .Size = 1 }
+};
+tPointer       gMouse_Pointer;
+
+// === CODE ===
+/**
+ * \brief Initialise the keyboard driver
+ */
+int Mouse_Install(char **Arguments)
+{
+       /// - Register with DevFS
+       DevFS_AddDevice( &gMouse_DevInfo );
+
+       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 );
+       gMouse_Pointer.Buttons = (void*)( gMouse_Pointer.Axies + MAX_AXIES );
+       gMouse_Pointer.FileHeader->NAxies = MAX_AXIES;
+       gMouse_Pointer.FileHeader->NButtons = MAX_BUTTONS;
+
+       return 0;
+}
+
+/**
+ * \brief Pre-unload cleanup function
+ */
+int Mouse_Cleanup(void)
+{
+       return 0;
+}
+
+// --- VFS Interface ---
+int Mouse_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX])
+{
+       if( Pos != 0 )
+               return -EINVAL;
+       strcpy(Dest, "system");
+       return 0;
+}
+
+tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name)
+{
+       if( strcmp(Name, "system") != 0 )       return NULL;
+       return &gMouse_Pointer.Node;
+}
+
+static const char *csaIOCTL_NAMES[] = {DRV_IOCTLNAMES, DRV_JOY_IOCTLNAMES, NULL};
+/**
+ * \brief IOCtl handler for the mouse
+ */
+int Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data)
+{
+       tJoystick_NumValue      *numval = Data;
+       tPointer        *ptr = Node->ImplPtr;
+       switch(ID)
+       {
+       BASE_IOCTLS(DRV_TYPE_MOUSE, "Mouse", VERSION, csaIOCTL_NAMES);
+
+       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)
+                       ptr->AxisLimits[numval->Num] = numval->Value;
+               return ptr->AxisLimits[numval->Num];
+
+       case JOY_IOCTL_GETSETAXISPOSITION:
+               if( !numval || !CheckMem(numval, sizeof(*numval)) )
+                       return -1;
+               if(numval->Num < 0 || numval->Num >= ptr->FileHeader->NAxies)
+                       return 0;
+               if(numval->Value != -1)
+                       ptr->Axies[numval->Num].CursorPos = numval->Value;
+               return ptr->Axies[numval->Num].CursorPos;
+       }
+       return -1;
+}
+
+/**
+ * \brief Read from a device
+ */
+size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data)
+{
+       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(
+               Length, 
+               sizeof(tJoystick_FileHeader) + n_axies*sizeof(tJoystick_Axis) + n_buttons
+               );
+
+       // Mark as checked
+       VFS_MarkAvaliable( Node, 0 );
+
+       memcpy( Data, ptr->FileData, Length );
+
+       // TODO: Locking (Release)
+
+       LEAVE('i', Length);
+       return Length;
+}
+
+// --- Device Interface ---
+/*
+ * Handle a mouse event (movement or button press/release)
+ * - See Input/Mouse/include/mouse.h
+ */
+void Mouse_HandleEvent(Uint32 ButtonState, int *AxisDeltas, int *AxisValues)
+{
+       tPointer *ptr = &gMouse_Pointer;
+       
+       ENTER("pHandle xButtonState pAxisDeltas", Handle, ButtonState, AxisDeltas);
+
+       // Update cursor position
+       for( int i = 0; i < 2; i ++ )
+       {
+               ptr->Axies[i].CursorPos = AxisValues[i];
+               ptr->Axies[i].CurValue = AxisDeltas ? AxisDeltas[i] : 0;
+       }
+       for( int i = 0; i < 5; i ++ )
+               ptr->Buttons[i] = ButtonState & (1 << i) ? 255 : 0;
+
+       VFS_MarkAvaliable( &ptr->Node, 1 );
+       LEAVE('-');
+}
+
index 4891467..5ee6967 100644 (file)
@@ -136,7 +136,6 @@ int Server_WorkerThread(void *ClientPtr)
        Log_Debug("Server", "Worker %p", ClientPtr);    
 
        #if USE_TCP
-
        while( *((volatile typeof(Client->Socket)*)&Client->Socket) == 0 )
                ;
        Threads_SetThread( Client->ClientID );
@@ -161,7 +160,7 @@ int Server_WorkerThread(void *ClientPtr)
                        char    lbuf[sizeof(tRequestHeader) + ciMaxParamCount*sizeof(tRequestValue)];
                        tRequestHeader  *hdr = (void*)lbuf;
                        size_t  len = recv(Client->Socket, (void*)hdr, sizeof(*hdr), 0);
-                       Log_Debug("Server", "%i bytes of header", len);
+//                     Log_Debug("Server", "%i bytes of header", len);
                        if( len == 0 )  break;
                        if( len == -1 ) {
                                perror("recv header");
@@ -185,7 +184,7 @@ int Server_WorkerThread(void *ClientPtr)
                        if( hdr->NParams > 0 )
                        {
                                len = recv(Client->Socket, (void*)hdr->Params, hdr->NParams*sizeof(tRequestValue), 0);
-                               Log_Debug("Server", "%i bytes of params", len);
+//                             Log_Debug("Server", "%i bytes of params", len);
                                if( len != hdr->NParams*sizeof(tRequestValue) ) {
                                        // Oops.
                                        perror("recv params");
@@ -195,7 +194,7 @@ int Server_WorkerThread(void *ClientPtr)
                        }
                        else
                        {
-                               Log_Debug("Server", "No params?");
+//                             Log_Debug("Server", "No params?");
                        }
 
                        // Get buffer size
@@ -221,7 +220,7 @@ int Server_WorkerThread(void *ClientPtr)
                                while( rem )
                                {
                                        len = recv(Client->Socket, ptr, rem, 0);
-                                       Log_Debug("Server", "%i bytes of data", len);
+//                                     Log_Debug("Server", "%i bytes of data", len);
                                        if( len == -1 ) {
                                                // Oops?
                                                perror("recv data");
@@ -235,8 +234,8 @@ int Server_WorkerThread(void *ClientPtr)
                                        break;
                                }
                        }
-                       else
-                               Log_Debug("Server", "no data");
+//                     else
+//                             Log_Debug("Server", "no data");
 
                         int    retlen;
                        tRequestHeader  *retHeader;
index 9cee8e3..86c6d71 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Syscall Distribution
  */
-#define DEBUG  1
+#define DEBUG  0
 #include <acess.h>
 #include <threads.h>
 #include <events.h>
index 80241da..3c43cc5 100644 (file)
@@ -20,5 +20,6 @@ extern void   UI_Redraw(void);
 
 typedef void (*tUI_KeybardCallback)(Uint32 Key);
 extern tUI_KeybardCallback     gUI_KeyboardCallback;
+extern void    Mouse_HandleEvent(Uint32 ButtonState, int *AxisDeltas, int *AxisValues);
 
 #endif
index 25f2964..7e97cbe 100644 (file)
@@ -70,7 +70,6 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym)
        if( gUI_Keymap[shiftState][Sym] )
                return gUI_Keymap[shiftState][Sym];
 
-       // Enter key on acess returns \n, but SDL returns \r
        switch(Sym)
        {
        case SDLK_a ... SDLK_z:
@@ -79,11 +78,12 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym)
        case SDLK_0 ... SDLK_9:
                ret = Sym - SDLK_0 + KEYSYM_0;
                break;
+       case SDLK_CAPSLOCK:     ret = KEYSYM_CAPS;      break;
+       case SDLK_TAB:  ret = KEYSYM_TAB;       break;
        case SDLK_UP:   ret = KEYSYM_UPARROW;   break;
        case SDLK_DOWN: ret = KEYSYM_DOWNARROW; break;
        case SDLK_LEFT: ret = KEYSYM_LEFTARROW; break;
        case SDLK_RIGHT:ret = KEYSYM_RIGHTARROW;break;
-       case SDLK_CAPSLOCK:     ret = KEYSYM_CAPS;      break;
        case SDLK_F1:   ret = KEYSYM_F1;        break;
        case SDLK_F2:   ret = KEYSYM_F2;        break;
        case SDLK_F3:   ret = KEYSYM_F3;        break;
@@ -97,9 +97,14 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym)
        case SDLK_F11:  ret = KEYSYM_F11;       break;
        case SDLK_F12:  ret = KEYSYM_F12;       break;
        case SDLK_RETURN:       ret = KEYSYM_RETURN;    break;
-       case SDLK_LALT: ret = KEYSYM_LEFTALT;   break;
-       case SDLK_RALT: ret = KEYSYM_RIGHTALT;  break;
+       case SDLK_LALT:         ret = KEYSYM_LEFTALT;   break;
+       case SDLK_LCTRL:        ret = KEYSYM_LEFTCTRL;  break;
+       case SDLK_LSHIFT:       ret = KEYSYM_LEFTSHIFT; break;
        case SDLK_LSUPER:       ret = KEYSYM_LEFTGUI;   break;
+       case SDLK_RALT:         ret = KEYSYM_RIGHTALT;  break;
+       case SDLK_RCTRL:        ret = KEYSYM_RIGHTCTRL; break;
+       case SDLK_RSHIFT:       ret = KEYSYM_RIGHTSHIFT;        break;
+       case SDLK_RSUPER:       ret = KEYSYM_RIGHTGUI;  break;
        default:
                printf("Unhandled key code %i\n", Sym);
                break;
@@ -109,6 +114,17 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym)
        return ret;
 }
 
+Uint32 UI_GetButtonBits(Uint8 sdlstate)
+{
+       Uint32  rv = 0;
+       rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_LEFT)    ? (1 << 0) : 0;
+       rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_RIGHT)   ? (1 << 1) : 0;
+       rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_MIDDLE)  ? (1 << 2) : 0;
+       rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_X1)      ? (1 << 3) : 0;
+       rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_X2)      ? (1 << 4) : 0;
+       return rv;
+}
+
 void UI_MainLoop(void)
 {
        SDL_Event       event;
@@ -126,7 +142,10 @@ void UI_MainLoop(void)
                                
                        case SDL_KEYDOWN:
                                acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym);
-                               
+                               // Enter key on acess returns \n, but SDL returns \r
+                               if(event.key.keysym.sym == SDLK_RETURN)
+                                       event.key.keysym.unicode = '\n';                                
+
                                if( gUI_KeyboardCallback ) {
                                        gUI_KeyboardCallback(KEY_ACTION_RAWSYM|acess_sym);
                                        gUI_KeyboardCallback(KEY_ACTION_PRESS|event.key.keysym.unicode);
@@ -145,7 +164,18 @@ void UI_MainLoop(void)
                        case SDL_USEREVENT:
                                SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height);
                                SDL_Flip(gScreen);
-                               break;          
+                               break;
+                       
+                       case SDL_MOUSEMOTION: {
+                               int abs[] = {event.motion.x, event.motion.y};
+                               int delta[] = {event.motion.xrel, event.motion.yrel};
+                               Mouse_HandleEvent(UI_GetButtonBits(SDL_GetMouseState(NULL, NULL)), delta, abs);
+                               break; }
+                       case SDL_MOUSEBUTTONUP:
+                       case SDL_MOUSEBUTTONDOWN: {
+                               int abs[] = {event.button.x, event.button.y};
+                               Mouse_HandleEvent(UI_GetButtonBits(SDL_GetMouseState(NULL, NULL)), NULL, abs);
+                               break; }
        
                        default:
                                break;

UCC git Repository :: git.ucc.asn.au