Es sollte theoretisch sogar möglich sein eine G15 UND eine G19 gleichzeitig anzusprechen (wer immer sowas braucht...)
Code: Alles auswählen
;/---------------------------------
;|
;| G15_G19.pbi V2.00
;|
;| Main Include for playing with
;| the Logitech G15/G19 Keyboard-Display
;|
;|
;| lglcd.h (c)Logitech,
;| G15_G19.pbi (PB-Version) (c)HeX0R 2010-2016
;| SoS 2010
;|
;| You can support both Keyboard-Displays with this one.
;/---------------------------------
#LOGI_LCD_TYPE_MONO = $00000001
#LOGI_LCD_TYPE_COLOR = $00000002
#LOGI_LCD_MONO_BUTTON_0 = $00000001
#LOGI_LCD_MONO_BUTTON_1 = $00000002
#LOGI_LCD_MONO_BUTTON_2 = $00000004
#LOGI_LCD_MONO_BUTTON_3 = $00000008
#LOGI_LCD_COLOR_BUTTON_LEFT = $00000100
#LOGI_LCD_COLOR_BUTTON_RIGHT = $00000200
#LOGI_LCD_COLOR_BUTTON_OK = $00000400
#LOGI_LCD_COLOR_BUTTON_CANCEL = $00000800
#LOGI_LCD_COLOR_BUTTON_UP = $00001000
#LOGI_LCD_COLOR_BUTTON_DOWN = $00002000
#LOGI_LCD_COLOR_BUTTON_MENU = $00004000
#LOGI_LCD_MONO_WIDTH = 160
#LOGI_LCD_MONO_HEIGHT = 43
#LOGI_LCD_COLOR_WIDTH = 320
#LOGI_LCD_COLOR_HEIGHT = 240
DeclareModule LOGILCD
#LOGI_LCD_TYPE_MONO = $00000001
#LOGI_LCD_TYPE_COLOR = $00000002
#LOGI_LCD_MONO_BUTTON_0 = $00000001
#LOGI_LCD_MONO_BUTTON_1 = $00000002
#LOGI_LCD_MONO_BUTTON_2 = $00000004
#LOGI_LCD_MONO_BUTTON_3 = $00000008
#LOGI_LCD_COLOR_BUTTON_LEFT = $00000100
#LOGI_LCD_COLOR_BUTTON_RIGHT = $00000200
#LOGI_LCD_COLOR_BUTTON_OK = $00000400
#LOGI_LCD_COLOR_BUTTON_CANCEL = $00000800
#LOGI_LCD_COLOR_BUTTON_UP = $00001000
#LOGI_LCD_COLOR_BUTTON_DOWN = $00002000
#LOGI_LCD_COLOR_BUTTON_MENU = $00004000
#LOGI_LCD_MONO_WIDTH = 160
#LOGI_LCD_MONO_HEIGHT = 43
#LOGI_LCD_COLOR_WIDTH = 320
#LOGI_LCD_COLOR_HEIGHT = 240
Declare Init(AppName.s, lcdType = #LOGI_LCD_TYPE_COLOR)
Declare IsConnected(lcdType = #LOGI_LCD_TYPE_COLOR)
Declare IsButtonPressed(button)
Declare Update()
Declare Shutdown()
Declare SetText(Text.s, Line, Color = #White, Type = #LOGI_LCD_TYPE_COLOR)
Declare SetTitle(Text.s, Color)
Declare SetBackgroundImage(Image, Type = #LOGI_LCD_TYPE_COLOR, AutoUpdate = #False)
Declare AddKeyboardWatcher(Window, WindowEvent)
EndDeclareModule
Module LOGILCD
Structure lgLcdBitmap
bmp_color.l[#LOGI_LCD_COLOR_WIDTH * #LOGI_LCD_COLOR_HEIGHT]
EndStructure
Structure WATCHERDATA
Window.i
WindowEvent.i
EndStructure
PrototypeC.i LogiLcdInit(friendlyName.p-unicode, lcdType)
PrototypeC.i LogiLcdIsConnected(lcdType)
PrototypeC.i LogiLcdIsButtonPressed(button)
PrototypeC LogiLcdUpdate()
PrototypeC LogiLcdShutdown()
PrototypeC.i LogiLcdMonoSetBackground(*monoBitmap)
PrototypeC.i LogiLcdMonoSetText(lineNumber, text.p-unicode)
PrototypeC.i LogiLcdColorSetBackground(*colorBitmap)
PrototypeC.i LogiLcdColorSetTitle(text.p-unicode, red, green, blue)
PrototypeC.i LogiLcdColorSetText(lineNumber, text.p-unicode, red, green, blue)
Global LogiLcdInit.LogiLcdInit
Global LogiLcdIsConnected.LogiLcdIsConnected
Global LogiLcdIsButtonPressed.LogiLcdIsButtonPressed
Global LogiLcdUpdate.LogiLcdUpdate
Global LogiLcdShutdown.LogiLcdShutdown
Global LogiLcdMonoSetBackground.LogiLcdMonoSetBackground
Global LogiLcdMonoSetText.LogiLcdMonoSetText
Global LogiLcdColorSetBackground.LogiLcdColorSetBackground
Global LogiLcdColorSetTitle.LogiLcdColorSetTitle
Global LogiLcdColorSetText.LogiLcdColorSetText
Global IsInitialized, ThreadID, EndThread, MyWindow, MyWindowEvent, LastButtons, DLL
Macro IsDLLLoaded
If DLL = 0
ProcedureReturn #False
EndIf
EndMacro
Procedure.s GetDLLPath()
Protected Result.s, PATH.s, hKey, lpcbData, *lpData, lpType
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
PATH = "SOFTWARE\Classes\WOW6432Node\CLSID\{d0e790a5-01a7-49ae-ae0b-e986bdd0c21b}\ServerBinary"
CompilerElse
PATH = "SOFTWARE\Classes\CLSID\{d0e790a5-01a7-49ae-ae0b-e986bdd0c21b}\ServerBinary"
CompilerEndIf
If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, PATH, 0, #KEY_READ, @hKey) = #ERROR_SUCCESS
If RegQueryValueEx_(hKey, "", 0, 0, 0, @lpcbData) = #ERROR_SUCCESS
*lpData = AllocateMemory(lpcbData)
If *lpData
If RegQueryValueEx_(hKey, "", 0, @lpType, *lpData, @lpcbData) = #ERROR_SUCCESS
Result = PeekS(*lpData)
EndIf
FreeMemory(*lpData)
EndIf
EndIf
RegCloseKey_(hKey)
EndIf
ProcedureReturn Result
EndProcedure
Procedure Init(AppName.s, lcdType = #LOGI_LCD_TYPE_COLOR)
Protected PATH2DLL.s
If DLL
CloseLibrary(DLL)
EndIf
PATH2DLL = GetDLLPath()
If PATH2DLL = ""
ProcedureReturn #False
EndIf
DLL = OpenLibrary(#PB_Any, PATH2DLL)
If DLL = 0
ProcedureReturn #False
EndIf
LogiLcdInit = GetFunction(DLL, "LogiLcdInit")
LogiLcdIsConnected = GetFunction(DLL, "LogiLcdIsConnected")
LogiLcdIsButtonPressed = GetFunction(DLL, "LogiLcdIsButtonPressed")
LogiLcdUpdate = GetFunction(DLL, "LogiLcdUpdate")
LogiLcdShutdown = GetFunction(DLL, "LogiLcdShutdown")
LogiLcdMonoSetBackground = GetFunction(DLL, "LogiLcdMonoSetBackground")
LogiLcdMonoSetText = GetFunction(DLL, "LogiLcdMonoSetText")
LogiLcdColorSetBackground = GetFunction(DLL, "LogiLcdColorSetBackground")
LogiLcdColorSetTitle = GetFunction(DLL, "LogiLcdColorSetTitle")
LogiLcdColorSetText = GetFunction(DLL, "LogiLcdColorSetText")
If LogiLcdInit = 0 Or LogiLcdIsConnected = 0 Or LogiLcdIsButtonPressed = 0 Or LogiLcdUpdate = 0 Or LogiLcdShutdown = 0
CloseLibrary(DLL)
DLL = #False
ProcedureReturn #False
ElseIf LogiLcdMonoSetBackground = 0 Or LogiLcdMonoSetText = 0 Or LogiLcdColorSetBackground = 0 Or LogiLcdColorSetTitle = 0 Or LogiLcdColorSetText = 0
CloseLibrary(DLL)
DLL = #False
ProcedureReturn #False
EndIf
If LogiLcdInit(AppName, lcdType)
IsInitialized = lcdType
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Procedure IsConnected(lcdType = #LOGI_LCD_TYPE_COLOR)
IsDLLLoaded
ProcedureReturn LogiLcdIsConnected(lcdType)
EndProcedure
Procedure IsButtonPressed(button)
IsDLLLoaded
ProcedureReturn LogiLcdIsButtonPressed(button)
EndProcedure
Procedure KeyboardWatcher(Dummy)
Protected PressedButtons, i, j
While EndThread = #False
PressedButtons = 0
j = 1
For i = 1 To 4
If LogiLcdIsButtonPressed(j)
PressedButtons | j
If LastButtons & j = 0
;this one is new so send a message
PostEvent(MyWindowEvent, MyWindow, #False, #False, j)
EndIf
EndIf
j << 1
Next i
j = $100
For i = 1 To 7
If LogiLcdIsButtonPressed(j)
PressedButtons | j
If LastButtons & j = 0
;this one is new so send a message
PostEvent(MyWindowEvent, MyWindow, #False, #False, j)
EndIf
EndIf
j << 1
Next i
LastButtons = PressedButtons
Delay(5)
Wend
EndProcedure
Procedure AddKeyboardWatcher(Window, WindowEvent)
IsDLLLoaded
If ThreadID And IsThread(ThreadID)
EndThread = #True
WaitThread(ThreadID)
EndIf
LastButtons = 0
EndThread = #False
MyWindow = Window
MyWindowEvent = WindowEvent
ThreadID = CreateThread(@KeyboardWatcher(), 0)
ProcedureReturn ThreadId
EndProcedure
Procedure Update()
IsDLLLoaded
LogiLcdUpdate()
EndProcedure
Procedure Shutdown()
If ThreadId And IsThread(ThreadID)
EndThread = #True
WaitThread(ThreadID)
EndIf
ThreadID = 0
If DLL
LogiLcdShutdown()
CloseLibrary(DLL)
DLL = #False
EndIf
IsInitialized = #Null
EndProcedure
Procedure SetText(Text.s, Line, Color = #White, Type = #LOGI_LCD_TYPE_COLOR)
Protected Result = 0
IsDLLLoaded
If Type & #LOGI_LCD_TYPE_COLOR And IsConnected(#LOGI_LCD_TYPE_COLOR)
Result + LogiLcdColorSetText(Line, Text, Red(Color), Green(Color), Blue(Color))
EndIf
If Type & #LOGI_LCD_TYPE_MONO And IsConnected(#LOGI_LCD_TYPE_MONO)
Result + LogiLcdMonoSetText(Line, Text)
EndIf
ProcedureReturn Result
EndProcedure
Procedure SetTitle(Text.s, Color)
Protected Result
IsDLLLoaded
If IsInitialized
If IsConnected(#LOGI_LCD_TYPE_COLOR)
Result = LogiLcdColorSetTitle(Text, Red(Color), Green(Color), Blue(Color))
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Procedure SetBackgroundImage(Image.i, Type = #LOGI_LCD_TYPE_COLOR, AutoUpdate = #False)
IsDLLLoaded
Protected w, h, i, k, Result, hDC, *bmi.BITMAPINFO, *bitmap.lgLcdBitmap, *L.LONG, IsColor, Img, DoLoops
;/--------------
;| This Procedure will check if the ImageSize is o.k.,
;| otherwise will resize it to fit the display.
;| Then the image will be sent to the G15 or G19 display
;| (with the given Priority)
;| Easiest is to use only 32 Bit Images.
;|
;/--------------
If IsImage(Image) = 0 Or IsInitialized = #Null
ProcedureReturn #False
EndIf
*bitmap = AllocateMemory(SizeOf(lgLcdBitmap))
If *bitmap = #Null
ProcedureReturn #ERROR_NOT_ENOUGH_MEMORY
EndIf
w = ImageWidth(Image)
h = ImageHeight(Image)
DoLoops = 1
If Type = #LOGI_LCD_TYPE_COLOR | #LOGI_LCD_TYPE_MONO And IsConnected(#LOGI_LCD_TYPE_COLOR | #LOGI_LCD_TYPE_MONO) = #LOGI_LCD_TYPE_COLOR | #LOGI_LCD_TYPE_MONO
;picture should be send to both and both are really connected!
DoLoops = 2
EndIf
Repeat
If Type & #LOGI_LCD_TYPE_COLOR And IsConnected(#LOGI_LCD_TYPE_COLOR)
IsColor = #True
If w > #LOGI_LCD_COLOR_WIDTH
w = #LOGI_LCD_COLOR_WIDTH
h = h * #LOGI_LCD_COLOR_WIDTH / ImageWidth(Image)
If h > #LOGI_LCD_COLOR_HEIGHT
h = #LOGI_LCD_COLOR_HEIGHT
w = w * #LOGI_LCD_COLOR_HEIGHT / ImageHeight(Image)
EndIf
ElseIf h > #LOGI_LCD_COLOR_HEIGHT
h = #LOGI_LCD_COLOR_HEIGHT
w = w * #LOGI_LCD_COLOR_HEIGHT / ImageHeight(Image)
If w > #LOGI_LCD_COLOR_WIDTH
w = #LOGI_LCD_COLOR_WIDTH
h = h * #LOGI_LCD_COLOR_WIDTH / ImageWidth(Image)
EndIf
EndIf
ElseIf Type & #LOGI_LCD_TYPE_MONO And IsConnected(#LOGI_LCD_TYPE_MONO)
If w > #LOGI_LCD_MONO_WIDTH
w = #LOGI_LCD_MONO_WIDTH
h = h * #LOGI_LCD_MONO_WIDTH / ImageWidth(Image)
If h > #LOGI_LCD_MONO_HEIGHT
h = #LOGI_LCD_MONO_HEIGHT
w = w * #LOGI_LCD_MONO_HEIGHT / ImageHeight(Image)
EndIf
ElseIf h > #LOGI_LCD_MONO_HEIGHT
h = #LOGI_LCD_MONO_HEIGHT
w = w * #LOGI_LCD_MONO_HEIGHT / ImageHeight(Image)
If w > #LOGI_LCD_MONO_WIDTH
w = #LOGI_LCD_MONO_WIDTH
h = h * #LOGI_LCD_MONO_WIDTH / ImageWidth(Image)
EndIf
EndIf
Else
Break
EndIf
If w <> ImageWidth(Image) Or h <> ImageHeight(Image)
Img = CopyImage(Image, #PB_Any)
ResizeImage(Img, w, h)
Else
Img = Image
EndIf
hDC = StartDrawing(ImageOutput(Img))
If hDC
*bmi = AllocateMemory(SizeOf(BITMAPINFO) + 255 * SizeOf(RGBQUAD))
If *bmi
*bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
*bmi\bmiheader\biWidth = w
*bmi\bmiheader\biHeight = - h
*bmi\bmiheader\biPlanes = 1
*bmi\bmiheader\biCompression = #BI_RGB
If IsColor
*bmi\bmiheader\biBitCount = 32
Result = GetDIBits_(hDC, ImageID(Img), 0, h, *bitmap, *bmi, #DIB_RGB_COLORS)
Else
*bmi\bmiheader\biBitCount = 8
Result = GetDIBits_(hDC, ImageID(Img), 0, h, *bitmap, *bmi, #DIB_RGB_COLORS)
;Swap Colors for G15
;(G15 shows black, when color = white and vice versa)
*L = *bitmap
For i = 0 To (#LOGI_LCD_MONO_WIDTH * #LOGI_LCD_MONO_HEIGHT) / 4
*L\l = *L\l ! $FFFFFFFF
*L + 4
Next i
EndIf
If Result
If IsColor
Result = LogiLcdColorSetBackground(*bitmap)
Else
Result = LogiLcdMonoSetBackground(*bitmap)
EndIf
EndIf
FreeMemory(*bmi)
EndIf
StopDrawing()
EndIf
FreeMemory(*bitmap)
If Img <> Image
FreeImage(Img)
EndIf
DoLoops - 1
Type & #LOGI_LCD_TYPE_MONO
Until DoLoops = 0
If AutoUpdate
Update()
EndIf
ProcedureReturn Result
EndProcedure
EndModule
CompilerIf #PB_Compiler_IsMainFile
#MY_EVENT = #PB_Event_FirstCustomValue
Procedure main()
Protected Text$
OpenWindow(0, 0, 0, 300, 200, "Logitech Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 5, 5, 290, 180, #PB_Editor_ReadOnly)
AddGadgetItem(0, -1, "Press a Button")
If LOGILCD::Init("MYTEST", #LOGI_LCD_TYPE_COLOR | #LOGI_LCD_TYPE_MONO)
LOGILCD::SetTitle("Hello World", #Green)
LOGILCD::SetText("Button Test", 0, #Blue, #LOGI_LCD_TYPE_COLOR | #LOGI_LCD_TYPE_MONO)
LOGILCD::Update()
LOGILCD::AddKeyboardWatcher(0, #MY_EVENT)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #MY_EVENT
Select EventData()
Case #LOGI_LCD_COLOR_BUTTON_LEFT
Text$ = "LEFT Button pressed!"
Case #LOGI_LCD_COLOR_BUTTON_DOWN
Text$ = "DOWN Button pressed!"
Case #LOGI_LCD_COLOR_BUTTON_RIGHT
Text$ = "RIGHT Button pressed!"
Case #LOGI_LCD_COLOR_BUTTON_UP
Text$ = "UP Button pressed!"
Case #LOGI_LCD_COLOR_BUTTON_OK
Text$ = "OK Button pressed!"
Case #LOGI_LCD_COLOR_BUTTON_CANCEL
Text$ = "CANCEL Button pressed!"
Case #LOGI_LCD_COLOR_BUTTON_MENU
Text$ = "MENU Button pressed!"
Case #LOGI_LCD_MONO_BUTTON_0
Text$ = "Button 0 pressed!"
Case #LOGI_LCD_MONO_BUTTON_1
Text$ = "Button 1 pressed!"
Case #LOGI_LCD_MONO_BUTTON_2
Text$ = "Button 2 pressed!"
Case #LOGI_LCD_MONO_BUTTON_3
Text$ = "Button 3 pressed!"
EndSelect
If Text$
AddGadgetItem(0, -1, Text$)
LOGILCD::SetText(Text$, 1, $0000FF)
EndIf
LOGILCD::Update()
EndSelect
ForEver
LOGILCD::Shutdown()
EndIf
EndProcedure
main()
CompilerEndIf
SoS's Verbesserung eingefügt.
Kommentare eingepflegt.
[Edit 12.11.2010]
2. Verbesserung von SoS eingepflegt, Beispiel ein wenig geändert.
[Edit 12.12.2010]
Beispiel leicht verändert, auch um die G15_G19_Devel.pbi zu unterstützen.
Haupt-Include unverändert.
[Edit 11.02.2011]
Import für x64 geändert, Libs müssen nun in Unterordnern x86, bzw. x64 sein.
Ausserdem noch einen kleinen Bug behoben.
[Edit 28.05.2016]
Auf Module umgebastelt.