Buchempfehlung
Windows System Programming
Windows System Programming
Das Kompendium liefert viele interessante Informationen zur Windows-Programmierung auf Englisch. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

xidusd_uinput.bi

Uploader:MitgliedThePuppetMaster
Datum/Zeit:12.12.2013 03:14:57
Hinweis: Dieser Quelltext ist Bestandteil des Projekts LINUX XID Userspace Treiber, zu dem es auf FreeBASIC-Portal.de eine Projektseite gibt.

'##############################################################################################################################################################
#Include Once "crt/errno.bi"
#Include Once "crt/unistd.bi"
#Include Once "crt/fcntl.bi"
#Include Once "crt/sys/types.bi"
#Include Once "crt/stdlib.bi"
#Include Once "crt/stdio.bi"
#Include Once "crt/sys/linux/time.bi"



'##############################################################################################################################################################
#Define EV_SYN                  &H00
#Define EV_KEY                  &H01
#Define EV_REL                  &H02
#Define EV_ABS                  &H03
#Define EV_MSC                  &H04
#Define EV_SW                   &H05
#Define EV_LED                  &H11
#Define EV_SND                  &H12
#Define EV_REP                  &H14
#Define EV_FF                   &H15
#Define EV_PWR                  &H16
#Define EV_FF_STATUS            &H17
#Define EV_MAX                  &H1f
#Define EV_CNT                  (EV_MAX + 1)



'##############################################################################################################################################################
#Define _IOC_NRBITS             8
#Define _IOC_TYPEBITS           8
#Define _IOC_SIZEBITS           14
#Define _IOC_DIRBITS            2
#Define _IOC_NRMASK             ((1 shl _IOC_NRBITS) - 1)
#Define _IOC_TYPEMASK           ((1 shl _IOC_TYPEBITS) - 1)
#Define _IOC_SIZEMASK           ((1 shl _IOC_SIZEBITS) - 1)
#Define _IOC_DIRMASK            ((1 shl _IOC_DIRBITS) - 1)
#Define _IOC_NRSHIFT            0
#Define _IOC_TYPESHIFT          (_IOC_NRSHIFT + _IOC_NRBITS)
#Define _IOC_SIZESHIFT          (_IOC_TYPESHIFT + _IOC_TYPEBITS)
#Define _IOC_DIRSHIFT           (_IOC_SIZESHIFT + _IOC_SIZEBITS)
#Define _IOC_NONE               0
#Define _IOC_WRITE              1
#Define _IOC_READ               2
#Define _IOC(dir,type,nr,size)  (((dir) shl _IOC_DIRSHIFT) or ((type) shl _IOC_TYPESHIFT) or ((nr) shl _IOC_NRSHIFT) or ((size) shl _IOC_SIZESHIFT))
#Define _IO(type,nr)            _IOC(_IOC_NONE, (type), (nr), 0)
#Define _IOR(type,nr,size)      _IOC(_IOC_READ, (type), (nr), sizeof(size))
#Define _IOW(type,nr,size)      _IOC(_IOC_WRITE, (type), (nr), sizeof(size))
#Define _IOWR(type,nr,size)     _IOC(_IOC_READ or _IOC_WRITE, (type), (nr), sizeof(size))



'##############################################################################################################################################################
#Define UINPUT_IOCTL_BASE       asc("U")
#Define UI_DEV_CREATE           _IO(UINPUT_IOCTL_BASE, 1)
#Define UI_DEV_DESTROY          _IO(UINPUT_IOCTL_BASE, 2)
#Define UI_SET_EVBIT            _IOW(UINPUT_IOCTL_BASE, 100, Integer)
#Define UI_SET_KEYBIT           _IOW(UINPUT_IOCTL_BASE, 101, Integer)
#Define UI_SET_RELBIT           _IOW(UINPUT_IOCTL_BASE, 102, Integer)
#Define UI_SET_ABSBIT           _IOW(UINPUT_IOCTL_BASE, 103, Integer)
#Define UI_SET_MSCBIT           _IOW(UINPUT_IOCTL_BASE, 104, Integer)
#Define UI_SET_LEDBIT           _IOW(UINPUT_IOCTL_BASE, 105, Integer)
#Define UI_SET_SNDBIT           _IOW(UINPUT_IOCTL_BASE, 106, Integer)
#Define UI_SET_FFBIT            _IOW(UINPUT_IOCTL_BASE, 107, Integer)
#Define UI_SET_SWBIT            _IOW(UINPUT_IOCTL_BASE, 109, Integer)
#Define UI_SET_PROPBIT          _IOW(UINPUT_IOCTL_BASE, 110, Integer)



'##############################################################################################################################################################
#Define ABS_X                   &H00
#Define ABS_Y                   &H01
#Define ABS_Z                   &H02
#Define ABS_RX                  &H03
#Define ABS_RY                  &H04
#Define ABS_RZ                  &H05
#Define ABS_THROTTLE            &H06
#Define ABS_RUDDER              &H07
#Define ABS_WHEEL               &H08
#Define ABS_GAS                 &H09
#Define ABS_BRAKE               &H0a
#Define ABS_HAT0X               &H10
#Define ABS_HAT0Y               &H11
#Define ABS_HAT1X               &H12
#Define ABS_HAT1Y               &H13
#Define ABS_HAT2X               &H14
#Define ABS_HAT2Y               &H15
#Define ABS_HAT3X               &H16
#Define ABS_HAT3Y               &H17
#Define ABS_PRESSURE            &H18
#Define ABS_DISTANCE            &H19
#Define ABS_VOLUME              &H20
#Define ABS_MISC                &H28



'##############################################################################################################################################################
#Define BTN_BACK                &H116
#Define BTN_A                   &H130
#Define BTN_B                   &H131
#Define BTN_C                   &H132
#Define BTN_X                   &H133
#Define BTN_Y                   &H134
#Define BTN_Z                   &H135
#Define BTN_TL                  &H136
#Define BTN_TR                  &H137
#Define BTN_TL2                 &H138
#Define BTN_TR2                 &H139
#Define BTN_SELECT              &H13a
#Define BTN_START               &H13b
#Define BTN_MODE                &H13c
#Define BTN_THUMBL              &H13d
#Define BTN_THUMBR              &H13e
#Define BTN_1                   &H101
#Define BTN_2                   &H102
#Define BTN_3                   &H103
#Define BTN_4                   &H104
#Define BTN_5                   &H105
#Define BTN_6                   &H106
#Define BTN_7                   &H107
#Define BTN_8                   &H108
#Define BTN_FORWARD             &H115
#define BTN_TRIGGER_HAPPY1      &H2c0
#define BTN_TRIGGER_HAPPY2      &H2c1
#define BTN_TRIGGER_HAPPY3      &H2c2
#define BTN_TRIGGER_HAPPY4      &H2c3
#define BTN_TRIGGER_HAPPY5      &H2c4
#define BTN_TRIGGER_HAPPY6      &H2c5
#define BTN_TRIGGER_HAPPY7      &H2c6
#define BTN_TRIGGER_HAPPY8      &H2c7



'##############################################################################################################################################################
#Define BUS_USB                 &H03



'##############################################################################################################################################################
#Define UINPUT_MAX_NAME_SIZE    80
#Define ABS_MAX                 &H3F



'##############################################################################################################################################################
Type input_id
    bustype                     as UShort
    vendor                      as UShort
    product                     as UShort
    version                     as UShort
End type



'##############################################################################################################################################################
Type uinput_user_dev
    name                        as ZString * UINPUT_MAX_NAME_SIZE
    id                          as input_id
    ff_effects_max              as Integer
    absmax(0 to ABS_MAX)        as Integer
    absmin(0 to ABS_MAX)        as Integer
    absfuzz(0 to ABS_MAX)       as Integer
    absflat(0 to ABS_MAX)       as Integer
End Type



'##############################################################################################################################################################
Type input_event
    time                        as timeval
    type                        as UShort
    code                        as UShort
    value                       as Integer
End Type



'##############################################################################################################################################################
Function XIDUSD_UInput_Term(V_Controler as XIDUSD_Controler_Type Ptr) as Integer
If V_Controler = 0 Then Return -1
close_(V_Controler->V_UInput_FID)
V_Controler->V_UInput_FID = 0
Return 1
End Function



'##############################################################################################################################################################
Function XIDUSD_UInput_Init(V_Controler as XIDUSD_Controler_Type Ptr) as Integer
If V_Controler = 0 Then Return -1
V_Controler->V_UInput_FID = open_("/dev/input/uinput", O_WRONLY or O_NONBLOCK)
If V_Controler->V_UInput_FID < 0 Then Print "Cant open uinput": Return -1

If ioctl(V_Controler->V_UInput_FID, UI_SET_EVBIT, EV_ABS) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl EVBIT!": Return -1
Dim TUInputDev as uinput_user_dev
Dim TCode as Integer
Dim TMPtr as XIDUSD_ControlerInputMask_Type Ptr = V_Controler->V_Masks_F
Do Until TMPtr = 0
    With *TMPtr
        For X as Integer = 0 to 255
            TCode = -1
            Select Case .V_Value(X)
                Case XIDUSD_CIMT_GET_Axis_1             : TCode = ABS_X
                Case XIDUSD_CIMT_GET_Axis_2             : TCode = ABS_Y
                Case XIDUSD_CIMT_GET_Axis_3             : TCode = ABS_RX
                Case XIDUSD_CIMT_GET_Axis_4             : TCode = ABS_RY
                Case XIDUSD_CIMT_GET_Axis_5             : TCode = ABS_GAS
                Case XIDUSD_CIMT_GET_Axis_6             : TCode = ABS_BRAKE
                Case XIDUSD_CIMT_GET_Axis_7             : TCode = ABS_Z
                Case XIDUSD_CIMT_GET_Axis_8             : TCode = ABS_RZ
            End Select
            If TCode >= 0 Then
                'Print "IOCTL: >" & TCode & "<___>" & .V_Min & "<___>" & .V_Max & "<"
                If ioctl(V_Controler->V_UInput_FID, UI_SET_ABSBIT, TCode) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl EVBIT!": Return -1
                TUInputDev.absmin(TCode)        = .V_Min
                TUInputDev.absmax(TCode)        = .V_Max
            End If
        Next
    End WIth
    TMPtr = TMPtr->V_Next
Loop

If ioctl(V_Controler->V_UInput_FID, UI_SET_EVBIT, EV_KEY) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_A) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_B) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_X) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_Y) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_C) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_Z) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_TL) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_TR) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_BACK) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_START) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_SET_KEYBIT, BTN_MODE) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_SET_ABSBIT!": Return -1

With TUInputDev
    .name               = V_Controler->V_Name
    .id.bustype         = BUS_USB
    .id.vendor          = CUShort(V_Controler->V_Device->descriptor.idVendor)
    .id.product         = CUShort(V_Controler->V_Device->descriptor.idProduct)
    .id.version         = 1
End With

If write_(V_Controler->V_UInput_FID, @TUInputDev, SizeOf(TUInputDev)) <> SizeOf(TUInputDev) Then XIDUSD_UInput_Term(V_Controler): Print "Failed write DeviceHeader!": Return -1
If ioctl(V_Controler->V_UInput_FID, UI_DEV_CREATE) <> 0 Then XIDUSD_UInput_Term(V_Controler): Print "Failed set ioctl UI_DEV_CREATE!": Return -1

Return 1
End Function