summaryrefslogtreecommitdiff
path: root/plugins/MirandaG15
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2015-05-11 15:50:49 +0000
committerKirill Volinsky <mataes2007@gmail.com>2015-05-11 15:50:49 +0000
commitcc9fc711fee11a1be132ca9fb9c3f34880ed44a9 (patch)
tree6e3a1e88c1eed738072f30c59e0842526ce6ce16 /plugins/MirandaG15
parent683a19c3328e3a13916684de8827651990cf07ed (diff)
minus CreateThread
git-svn-id: http://svn.miranda-ng.org/main/trunk@13545 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirandaG15')
-rw-r--r--plugins/MirandaG15/src/LCDFramework/CLCDConnectionLogitech.cpp570
-rw-r--r--plugins/MirandaG15/src/LCDFramework/stdafx.h2
2 files changed, 291 insertions, 281 deletions
diff --git a/plugins/MirandaG15/src/LCDFramework/CLCDConnectionLogitech.cpp b/plugins/MirandaG15/src/LCDFramework/CLCDConnectionLogitech.cpp
index 870d1d9009..eb3f2bf513 100644
--- a/plugins/MirandaG15/src/LCDFramework/CLCDConnectionLogitech.cpp
+++ b/plugins/MirandaG15/src/LCDFramework/CLCDConnectionLogitech.cpp
@@ -3,63 +3,64 @@
#include "CLCDOutputManager.h"
DWORD WINAPI softButtonCallback(IN int device,
- IN DWORD dwButtons,
- IN const PVOID pContext) {
+ IN DWORD dwButtons,
+ IN const PVOID pContext) {
((CLCDConnectionLogitech*)pContext)->OnSoftButtonCB(dwButtons);
return 0;
}
DWORD WINAPI notificationCallback(IN int connection,
- IN const PVOID pContext,
- IN DWORD notificationCode,
- IN DWORD notifyParm1,
- IN DWORD notifyParm2,
- IN DWORD notifyParm3,
- IN DWORD notifyParm4) {
- ((CLCDConnectionLogitech*)pContext)->OnNotificationCB(notificationCode,notifyParm1,notifyParm2,notifyParm3,notifyParm4);
+ IN const PVOID pContext,
+ IN DWORD notificationCode,
+ IN DWORD notifyParm1,
+ IN DWORD notifyParm2,
+ IN DWORD notifyParm3,
+ IN DWORD notifyParm4) {
+ ((CLCDConnectionLogitech*)pContext)->OnNotificationCB(notificationCode, notifyParm1, notifyParm2, notifyParm3, notifyParm4);
return 0;
}
-DWORD WINAPI initializeDrawingThread( LPVOID pParam ) {
+void __cdecl initializeDrawingThread(void *pParam)
+{
((CLCDConnectionLogitech*)pParam)->runDrawingThread();
- return 0;
}
void CLCDConnectionLogitech::runDrawingThread() {
- m_hStopEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
- m_hDrawEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
+ m_hStopEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ m_hDrawEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
DWORD dwRes = 0;
- while(1) {
+ while (1) {
HANDLE hArray[2] = { m_hStopEvent, m_hDrawEvent };
dwRes = WaitForMultipleObjects(2, hArray, FALSE, INFINITE);
- if(dwRes == WAIT_OBJECT_0) {
+ if (dwRes == WAIT_OBJECT_0) {
break;
- } else if(dwRes == WAIT_OBJECT_0+1) {
+ }
+ else if (dwRes == WAIT_OBJECT_0 + 1) {
DWORD rc;
- if(GetConnectionState() != CONNECTED) {
+ if (GetConnectionState() != CONNECTED) {
continue;
}
// do a sync update if the applet is in the foreground, or every 500 ms
// the delay is there because sync updates can take up to 33ms to fail
- if(m_dwForegroundCheck < GetTickCount())
+ if (m_dwForegroundCheck < GetTickCount())
{
m_dwForegroundCheck = GetTickCount() + 500;
rc = lgLcdUpdateBitmap(m_hDevice, &m_lcdBitmap.hdr, LGLCD_SYNC_COMPLETE_WITHIN_FRAME(m_iPriority));
- if(rc == ERROR_ACCESS_DENIED)
+ if (rc == ERROR_ACCESS_DENIED)
{
rc = ERROR_SUCCESS;
m_bIsForeground = false;
}
- else if(rc == ERROR_SUCCESS)
+ else if (rc == ERROR_SUCCESS)
m_bIsForeground = true;
}
else
rc = lgLcdUpdateBitmap(m_hDevice, &m_lcdBitmap.hdr, LGLCD_ASYNC_UPDATE(m_iPriority));
-
- if(rc != ERROR_SUCCESS) {
+
+ if (rc != ERROR_SUCCESS) {
HandleErrorFromAPI(rc);
}
}
@@ -91,7 +92,7 @@ CLCDConnectionLogitech::CLCDConnectionLogitech()
m_pConnectedDevice = NULL;
m_hKeyboardHook = NULL;
m_bVolumeWheelHook = false;
-
+
m_dwButtonState = 0;
m_bConnected = false;
m_bSetAsForeground = false;
@@ -100,15 +101,15 @@ CLCDConnectionLogitech::CLCDConnectionLogitech()
m_hHIDDeviceHandle = NULL;
m_hConnection = LGLCD_INVALID_CONNECTION;
m_hDevice = LGLCD_INVALID_DEVICE;
-
+
m_bIsForeground = false;
-
+
m_hDrawEvent = NULL;
m_hStopEvent = NULL;
CLCDConnectionLogitech::m_pInstance = this;
- m_hDrawingThread = CreateThread( 0, 0, initializeDrawingThread, (void*)this, 0, 0);
+ m_hDrawingThread = mir_forkthread(initializeDrawingThread, (void*)this);
}
//************************************************************************
@@ -118,9 +119,9 @@ CLCDConnectionLogitech::~CLCDConnectionLogitech()
{
do {
SetEvent(m_hStopEvent);
- } while(WaitForSingleObject(m_hDrawingThread,500) == WAIT_TIMEOUT);
+ } while (WaitForSingleObject(m_hDrawingThread, 500) == WAIT_TIMEOUT);
- if(m_pDrawingBuffer != NULL) {
+ if (m_pDrawingBuffer != NULL) {
free(m_pDrawingBuffer);
}
SetVolumeWheelHook(false);
@@ -129,32 +130,33 @@ CLCDConnectionLogitech::~CLCDConnectionLogitech()
//************************************************************************
// Initializes the connection to the LCD
//************************************************************************
-bool CLCDConnectionLogitech::Initialize(tstring strAppletName,bool bAutostart, bool bConfigDialog)
+bool CLCDConnectionLogitech::Initialize(tstring strAppletName, bool bAutostart, bool bConfigDialog)
{
-
+
m_strAppletName = strAppletName;
// initialize the library
- if(lgLcdInit() != ERROR_SUCCESS)
+ if (lgLcdInit() != ERROR_SUCCESS)
return false;
memset(&m_connectContext, 0, sizeof(m_connectContext));
- m_connectContext.connection = LGLCD_INVALID_CONNECTION;
-
- m_connectContext.appFriendlyName = m_strAppletName.c_str();
- m_connectContext.isAutostartable = bAutostart;
- m_connectContext.isPersistent = bAutostart;
+ m_connectContext.connection = LGLCD_INVALID_CONNECTION;
+
+ m_connectContext.appFriendlyName = m_strAppletName.c_str();
+ m_connectContext.isAutostartable = bAutostart;
+ m_connectContext.isPersistent = bAutostart;
m_connectContext.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_BW | LGLCD_APPLET_CAP_QVGA;
m_connectContext.onNotify.notificationCallback = notificationCallback;
m_connectContext.onNotify.notifyContext = (PVOID)this;
- if(bConfigDialog) {
+ if (bConfigDialog) {
m_connectContext.onConfigure.configCallback = CLCDOutputManager::configDialogCallback;
- } else {
+ }
+ else {
m_connectContext.onConfigure.configCallback = NULL;
}
m_connectContext.onConfigure.configContext = NULL;
-
- lgLcdSetDeviceFamiliesToUse(m_connectContext.connection,LGLCD_DEVICE_FAMILY_ALL,NULL);
+
+ lgLcdSetDeviceFamiliesToUse(m_connectContext.connection, LGLCD_DEVICE_FAMILY_ALL, NULL);
return true;
}
@@ -163,9 +165,10 @@ bool CLCDConnectionLogitech::Initialize(tstring strAppletName,bool bAutostart, b
// returns the name of the attached device
//************************************************************************
tstring CLCDConnectionLogitech::GetDeviceName() {
- if(m_pConnectedDevice->GetIndex() == LGLCD_DEVICE_BW) {
+ if (m_pConnectedDevice->GetIndex() == LGLCD_DEVICE_BW) {
return _T("G15/Z10");
- } else {
+ }
+ else {
return _T("G19");
}
}
@@ -175,8 +178,8 @@ tstring CLCDConnectionLogitech::GetDeviceName() {
//************************************************************************
CLgLCDDevice* CLCDConnectionLogitech::GetAttachedDevice(int iIndex) {
std::vector<CLgLCDDevice*>::iterator i = m_lcdDevices.begin();
- for(;i!=m_lcdDevices.end();i++) {
- if((*i)->GetIndex() == iIndex) {
+ for (; i != m_lcdDevices.end(); i++) {
+ if ((*i)->GetIndex() == iIndex) {
return *i;
}
}
@@ -188,20 +191,20 @@ CLgLCDDevice* CLCDConnectionLogitech::GetAttachedDevice(int iIndex) {
// disconnects the device
//************************************************************************
bool CLCDConnectionLogitech::Disconnect() {
- if(!m_bConnected)
+ if (!m_bConnected)
return false;
- if(m_pConnectedDevice != NULL) {
+ if (m_pConnectedDevice != NULL) {
delete m_pConnectedDevice;
m_pConnectedDevice = NULL;
}
m_bReconnect = false;
-
+
HIDDeInit();
lgLcdClose(m_hDevice);
m_hDevice = LGLCD_INVALID_DEVICE;
-
+
CLCDOutputManager::GetInstance()->OnDeviceDisconnected();
m_bConnected = false;
@@ -222,14 +225,14 @@ bool CLCDConnectionLogitech::Connect(int iIndex)
{
DWORD rc;
lgLcdOpenByTypeContext OpenContext;
- if(m_bConnected && (iIndex == 0 || iIndex == GetConnectedDevice()->GetIndex()))
+ if (m_bConnected && (iIndex == 0 || iIndex == GetConnectedDevice()->GetIndex()))
return true;
- if(m_hConnection == LGLCD_INVALID_CONNECTION)
+ if (m_hConnection == LGLCD_INVALID_CONNECTION)
{
- rc = lgLcdConnectEx(&m_connectContext);
+ rc = lgLcdConnectEx(&m_connectContext);
// establish the connection
- if(ERROR_SUCCESS == rc)
+ if (ERROR_SUCCESS == rc)
{
m_hConnection = m_connectContext.connection;
m_hDevice = LGLCD_INVALID_CONNECTION;
@@ -243,55 +246,55 @@ bool CLCDConnectionLogitech::Connect(int iIndex)
// check if the specified device exists
m_pConnectedDevice = GetAttachedDevice(iIndex);
- if(m_pConnectedDevice == NULL) {
+ if (m_pConnectedDevice == NULL) {
iIndex = (!iIndex || iIndex == LGLCD_DEVICE_BW) ? LGLCD_DEVICE_BW : LGLCD_DEVICE_QVGA;
m_pConnectedDevice = GetAttachedDevice(iIndex);
- if(m_pConnectedDevice == NULL) {
+ if (m_pConnectedDevice == NULL) {
return false;
}
}
// close the lcd device before we open up another
- if (LGLCD_INVALID_DEVICE != m_hDevice) {
+ if (LGLCD_INVALID_DEVICE != m_hDevice) {
Disconnect();
}
// Now lets open the LCD. We must initialize the g_OpenContext structure.
- memset(&OpenContext, 0, sizeof(OpenContext));
- OpenContext.connection = m_hConnection;
+ memset(&OpenContext, 0, sizeof(OpenContext));
+ OpenContext.connection = m_hConnection;
OpenContext.deviceType = m_pConnectedDevice->GetIndex();//LGLCD_DEVICE_QVGA;
OpenContext.device = LGLCD_INVALID_DEVICE;
- // softbutton callbacks are not needed
- OpenContext.onSoftbuttonsChanged.softbuttonsChangedCallback = softButtonCallback;
- OpenContext.onSoftbuttonsChanged.softbuttonsChangedContext = (PVOID)this;
+ // softbutton callbacks are not needed
+ OpenContext.onSoftbuttonsChanged.softbuttonsChangedCallback = softButtonCallback;
+ OpenContext.onSoftbuttonsChanged.softbuttonsChangedContext = (PVOID)this;
// open the lcd
- rc = lgLcdOpenByType(&OpenContext);
+ rc = lgLcdOpenByType(&OpenContext);
// failed to open the lcd
- if(rc != ERROR_SUCCESS)
+ if (rc != ERROR_SUCCESS)
return false;
-
+
m_hDevice = OpenContext.device;
-
+
// Create the pixel buffer
- m_lcdBitmap.hdr.Format = OpenContext.deviceType==LGLCD_DEVICE_QVGA?LGLCD_BMP_FORMAT_QVGAx32:LGLCD_BMP_FORMAT_160x43x1;
- if(m_pDrawingBuffer != NULL) {
+ m_lcdBitmap.hdr.Format = OpenContext.deviceType == LGLCD_DEVICE_QVGA ? LGLCD_BMP_FORMAT_QVGAx32 : LGLCD_BMP_FORMAT_160x43x1;
+ if (m_pDrawingBuffer != NULL) {
free(m_pDrawingBuffer);
}
-
- m_pPixels = OpenContext.deviceType==LGLCD_DEVICE_QVGA? m_lcdBitmap.bmp_qvga32.pixels:m_lcdBitmap.bmp_mono.pixels;
- m_iPixels = OpenContext.deviceType==LGLCD_DEVICE_QVGA? sizeof(m_lcdBitmap.bmp_qvga32.pixels):sizeof(m_lcdBitmap.bmp_mono.pixels);
- m_pDrawingBuffer = (PBYTE) malloc(m_iPixels);
+
+ m_pPixels = OpenContext.deviceType == LGLCD_DEVICE_QVGA ? m_lcdBitmap.bmp_qvga32.pixels : m_lcdBitmap.bmp_mono.pixels;
+ m_iPixels = OpenContext.deviceType == LGLCD_DEVICE_QVGA ? sizeof(m_lcdBitmap.bmp_qvga32.pixels) : sizeof(m_lcdBitmap.bmp_mono.pixels);
+ m_pDrawingBuffer = (PBYTE)malloc(m_iPixels);
memset(m_pDrawingBuffer, 0, m_iPixels);
-
+
m_iPriority = LGLCD_PRIORITY_NORMAL;
m_bConnected = true;
HIDInit();
-
+
m_bReconnect = true;
-
+
CLCDOutputManager::GetInstance()->OnDeviceConnected();
return true;
}
@@ -304,14 +307,14 @@ bool CLCDConnectionLogitech::Shutdown()
m_bConnected = false;
SetVolumeWheelHook(false);
-
+
Disconnect();
- if (LGLCD_INVALID_CONNECTION != m_hDevice)
+ if (LGLCD_INVALID_CONNECTION != m_hDevice)
lgLcdDisconnect(m_hConnection);
- lgLcdDeInit();
-
+ lgLcdDeInit();
+
return true;
}
@@ -320,35 +323,35 @@ bool CLCDConnectionLogitech::Shutdown()
//************************************************************************
bool CLCDConnectionLogitech::HIDReadData(BYTE* data) {
static OVERLAPPED olRead;
- static HANDLE hReadEvent = CreateEvent(NULL,false,true,_T("ReadEvent"));
+ static HANDLE hReadEvent = CreateEvent(NULL, false, true, _T("ReadEvent"));
static BYTE privateBuffer[9];
-
+
DWORD TransBytes;
- if(!m_bConnected) {
+ if (!m_bConnected) {
SetEvent(hReadEvent);
return false;
}
- DWORD dwRes = WaitForSingleObject(hReadEvent,0);
- if(dwRes == WAIT_OBJECT_0) {
+ DWORD dwRes = WaitForSingleObject(hReadEvent, 0);
+ if (dwRes == WAIT_OBJECT_0) {
bool bRes = false;
- if(GetOverlappedResult(m_hHIDDeviceHandle,&olRead,&TransBytes,false)) {
- memcpy(data,privateBuffer,9*sizeof(BYTE));
+ if (GetOverlappedResult(m_hHIDDeviceHandle, &olRead, &TransBytes, false)) {
+ memcpy(data, privateBuffer, 9 * sizeof(BYTE));
bRes = true;
- }
+ }
- memset(&olRead,0,sizeof(OVERLAPPED));
+ memset(&olRead, 0, sizeof(OVERLAPPED));
olRead.hEvent = hReadEvent;
- if(!ReadFile(m_hHIDDeviceHandle,privateBuffer,9,&TransBytes,&olRead)) {
+ if (!ReadFile(m_hHIDDeviceHandle, privateBuffer, 9, &TransBytes, &olRead)) {
DWORD error = GetLastError();
- if(error != ERROR_IO_PENDING) {
+ if (error != ERROR_IO_PENDING) {
return false;
}
}
return bRes;
- }
-
+ }
+
return false;
}
@@ -356,51 +359,52 @@ void CLCDConnectionLogitech::OnSoftButtonCB(DWORD state) {
m_dwButtonState = state;
}
-void CLCDConnectionLogitech::OnNotificationCB( DWORD notificationCode, DWORD notifyParm1, DWORD notifyParm2, DWORD notifyParm3, DWORD notifyParm4) {
+void CLCDConnectionLogitech::OnNotificationCB(DWORD notificationCode, DWORD notifyParm1, DWORD notifyParm2, DWORD notifyParm3, DWORD notifyParm4) {
CLgLCDDevice *device;
-
- switch(notificationCode) {
- case LGLCD_NOTIFICATION_DEVICE_ARRIVAL: {
- int *counter = notifyParm1 == LGLCD_DEVICE_QVGA ? &m_iNumQVGADevices : &m_iNumBWDevices;
- if(*counter == 0) {
- SIZE size;
- if(notifyParm1 == LGLCD_DEVICE_QVGA) {
- size.cx = 320;
- size.cy = 240;
- device = new CLgLCDDevice(notifyParm1,size,7,4);
- } else {
- size.cx = 160;
- size.cy = 43;
- device = new CLgLCDDevice(notifyParm1,size,4,1);
- }
- m_lcdDevices.push_back(device);
- }
- (*counter)++;
- break;
+ switch (notificationCode) {
+ case LGLCD_NOTIFICATION_DEVICE_ARRIVAL: {
+ int *counter = notifyParm1 == LGLCD_DEVICE_QVGA ? &m_iNumQVGADevices : &m_iNumBWDevices;
+ if (*counter == 0) {
+ SIZE size;
+ if (notifyParm1 == LGLCD_DEVICE_QVGA) {
+ size.cx = 320;
+ size.cy = 240;
+ device = new CLgLCDDevice(notifyParm1, size, 7, 4);
+ }
+ else {
+ size.cx = 160;
+ size.cy = 43;
+ device = new CLgLCDDevice(notifyParm1, size, 4, 1);
+ }
+ m_lcdDevices.push_back(device);
}
- case LGLCD_NOTIFICATION_DEVICE_REMOVAL: {
- int *counter = notifyParm1 == LGLCD_DEVICE_QVGA ? &m_iNumQVGADevices : &m_iNumBWDevices;
- (*counter)--;
- if(*counter == 0) {
- std::vector<CLgLCDDevice*>::iterator i = m_lcdDevices.begin();
- for(;i!=m_lcdDevices.end();i++) {
- if((*i)->GetIndex() == notifyParm1) {
- device = *i;
-
- if(device == m_pConnectedDevice) {
- HandleErrorFromAPI(ERROR_DEVICE_NOT_CONNECTED);
- }
-
- m_lcdDevices.erase(i);
- delete device;
-
- break;
+
+ (*counter)++;
+ break;
+ }
+ case LGLCD_NOTIFICATION_DEVICE_REMOVAL: {
+ int *counter = notifyParm1 == LGLCD_DEVICE_QVGA ? &m_iNumQVGADevices : &m_iNumBWDevices;
+ (*counter)--;
+ if (*counter == 0) {
+ std::vector<CLgLCDDevice*>::iterator i = m_lcdDevices.begin();
+ for (; i != m_lcdDevices.end(); i++) {
+ if ((*i)->GetIndex() == notifyParm1) {
+ device = *i;
+
+ if (device == m_pConnectedDevice) {
+ HandleErrorFromAPI(ERROR_DEVICE_NOT_CONNECTED);
}
+
+ m_lcdDevices.erase(i);
+ delete device;
+
+ break;
}
}
- break;
}
+ break;
+ }
}
}
@@ -410,50 +414,53 @@ void CLCDConnectionLogitech::OnNotificationCB( DWORD notificationCode, DWORD not
bool CLCDConnectionLogitech::Update()
{
// check for lcd devices
- if (LGLCD_INVALID_DEVICE == m_hDevice )
- {
- if(m_bReconnect) {
+ if (LGLCD_INVALID_DEVICE == m_hDevice)
+ {
+ if (m_bReconnect) {
Connect();
}
}
BYTE buffer[9];
- if(HIDReadData(buffer)) {
+ if (HIDReadData(buffer)) {
int button = 0;
// mr key
- if(buffer[7] & 0x40) {
+ if (buffer[7] & 0x40) {
button = 20;
- // lightbulb key
- } else if(buffer[1] & 0x80) {
+ // lightbulb key
+ }
+ else if (buffer[1] & 0x80) {
button = 21;
}
// m1,m2,m3
- for(int i=0,w=1;i<3;i++,w*=2) {
- if(buffer[6+i] & w) {
- button = 30+i;
+ for (int i = 0, w = 1; i < 3; i++, w *= 2) {
+ if (buffer[6 + i] & w) {
+ button = 30 + i;
}
}
// g1 to g18
- if(buffer[8] & 0x40) {
+ if (buffer[8] & 0x40) {
button = 18;
- } else {
- for(int j=0;j<3;j++) {
- int p = 1,w = 1;
- if(j == 1) {
+ }
+ else {
+ for (int j = 0; j < 3; j++) {
+ int p = 1, w = 1;
+ if (j == 1) {
p = 2;
- } else if(j == 2) {
+ }
+ else if (j == 2) {
w = 4;
}
- for(int i=0;i<6;i++,w*=2) {
- if(buffer[p+i] & w) {
- button = 1+j*6+i;
+ for (int i = 0; i < 6; i++, w *= 2) {
+ if (buffer[p + i] & w) {
+ button = 1 + j * 6 + i;
}
}
}
}
- if(button != 0) {
- TRACE(_T("GKey pressed: %d \n"),button);
+ if (button != 0) {
+ TRACE(_T("GKey pressed: %d \n"), button);
}
}
@@ -464,8 +471,8 @@ bool CLCDConnectionLogitech::Update()
// returns the id of the specified button
//************************************************************************
int CLCDConnectionLogitech::GetButtonId(int iButton) {
- if(m_pConnectedDevice->GetIndex() == LGLCD_DEVICE_BW) {
- switch(iButton)
+ if (m_pConnectedDevice->GetIndex() == LGLCD_DEVICE_BW) {
+ switch (iButton)
{
case 0: return LGLCDBUTTON_BUTTON0; break;
case 1: return LGLCDBUTTON_BUTTON1; break;
@@ -476,8 +483,9 @@ int CLCDConnectionLogitech::GetButtonId(int iButton) {
case 6: return LGLCDBUTTON_BUTTON6; break;
case 7: return LGLCDBUTTON_BUTTON7; break;
}
- } else {
- switch(iButton)
+ }
+ else {
+ switch (iButton)
{
case 0: return LGLCDBUTTON_LEFT; break;
case 1: return LGLCDBUTTON_RIGHT; break;
@@ -497,12 +505,12 @@ int CLCDConnectionLogitech::GetButtonId(int iButton) {
//************************************************************************
bool CLCDConnectionLogitech::GetButtonState(int iButton)
{
- if(!GetConnectionState()==CONNECTED)
+ if (!GetConnectionState() == CONNECTED)
return false;
DWORD dwButton = GetButtonId(iButton);
- if(m_dwButtonState & dwButton)
+ if (m_dwButtonState & dwButton)
return true;
return false;
}
@@ -512,13 +520,13 @@ bool CLCDConnectionLogitech::GetButtonState(int iButton)
//************************************************************************
bool CLCDConnectionLogitech::HideApplet()
{
- if(!GetConnectionState()==CONNECTED)
+ if (!GetConnectionState() == CONNECTED)
return false;
DWORD rc;
rc = lgLcdUpdateBitmap(m_hDevice, &m_lcdBitmap.hdr, LGLCD_ASYNC_UPDATE(LGLCD_PRIORITY_IDLE_NO_SHOW));
- if(rc != ERROR_SUCCESS)
+ if (rc != ERROR_SUCCESS)
return false;
return true;
@@ -529,10 +537,10 @@ bool CLCDConnectionLogitech::HideApplet()
//************************************************************************
bool CLCDConnectionLogitech::Draw()
{
- if(!GetConnectionState()==CONNECTED || !m_hDrawEvent)
+ if (!GetConnectionState() == CONNECTED || !m_hDrawEvent)
return false;
- memcpy(m_pPixels,m_pDrawingBuffer,m_iPixels);
+ memcpy(m_pPixels, m_pDrawingBuffer, m_iPixels);
SetEvent(m_hDrawEvent);
return true;
}
@@ -542,7 +550,7 @@ bool CLCDConnectionLogitech::Draw()
//************************************************************************
void CLCDConnectionLogitech::SetAlert(bool bAlert)
{
- m_iPriority = bAlert?LGLCD_PRIORITY_ALERT:LGLCD_PRIORITY_NORMAL;
+ m_iPriority = bAlert ? LGLCD_PRIORITY_ALERT : LGLCD_PRIORITY_NORMAL;
}
//************************************************************************
@@ -551,12 +559,12 @@ void CLCDConnectionLogitech::SetAlert(bool bAlert)
void CLCDConnectionLogitech::SetAsForeground(bool bSetAsForeground)
{
// TODO: Activate when 1.02 is out
- DWORD dwSet = bSetAsForeground ? LGLCD_LCD_FOREGROUND_APP_YES : LGLCD_LCD_FOREGROUND_APP_NO;
- m_bSetAsForeground = bSetAsForeground;
- if (LGLCD_INVALID_DEVICE != m_hDevice)
- {
- lgLcdSetAsLCDForegroundApp(m_hDevice, bSetAsForeground);
- }
+ DWORD dwSet = bSetAsForeground ? LGLCD_LCD_FOREGROUND_APP_YES : LGLCD_LCD_FOREGROUND_APP_NO;
+ m_bSetAsForeground = bSetAsForeground;
+ if (LGLCD_INVALID_DEVICE != m_hDevice)
+ {
+ lgLcdSetAsLCDForegroundApp(m_hDevice, bSetAsForeground);
+ }
}
//************************************************************************
@@ -572,9 +580,9 @@ bool CLCDConnectionLogitech::IsForeground()
//************************************************************************
SIZE CLCDConnectionLogitech::GetDisplaySize()
{
- SIZE size = {0,0};
+ SIZE size = { 0, 0 };
- if(!GetConnectionState()==CONNECTED)
+ if (!GetConnectionState() == CONNECTED)
return size;
return m_pConnectedDevice->GetDisplaySize();
@@ -585,7 +593,7 @@ SIZE CLCDConnectionLogitech::GetDisplaySize()
//************************************************************************
int CLCDConnectionLogitech::GetButtonCount()
{
- if(!GetConnectionState()==CONNECTED)
+ if (!GetConnectionState() == CONNECTED)
return 0;
return m_pConnectedDevice->GetButtonCount();
@@ -596,7 +604,7 @@ int CLCDConnectionLogitech::GetButtonCount()
//************************************************************************
int CLCDConnectionLogitech::GetColorCount()
{
- if(!GetConnectionState()==CONNECTED)
+ if (!GetConnectionState() == CONNECTED)
return 0;
return m_pConnectedDevice->GetColorCount();
@@ -607,7 +615,7 @@ int CLCDConnectionLogitech::GetColorCount()
//************************************************************************
PBYTE CLCDConnectionLogitech::GetPixelBuffer()
{
- if(!GetConnectionState()==CONNECTED)
+ if (!GetConnectionState() == CONNECTED)
return NULL;
return (PBYTE)m_pDrawingBuffer;
@@ -618,30 +626,30 @@ PBYTE CLCDConnectionLogitech::GetPixelBuffer()
//************************************************************************
void CLCDConnectionLogitech::HandleErrorFromAPI(DWORD dwRes)
{
- switch(dwRes)
- {
- // all is well
- case ERROR_SUCCESS:
- break;
- // we lost our device
- case ERROR_DEVICE_NOT_CONNECTED:
+ switch (dwRes)
+ {
+ // all is well
+ case ERROR_SUCCESS:
+ break;
+ // we lost our device
+ case ERROR_DEVICE_NOT_CONNECTED:
TRACE(_T("CLCDConnectionLogitech::HandleErrorFromAPI(): Device was unplugged, closing device\n"));
Disconnect();
SetReconnect(true);
SetVolumeWheelHook(false);
-
+
break;
- default:
+ default:
TRACE(_T("CLCDConnectionLogitech::HandleErrorFromAPI(): FATAL ERROR, closing device and connection\n"));
Disconnect();
SetReconnect(true);
-
+
lgLcdDisconnect(m_hConnection);
- m_hConnection = LGLCD_INVALID_CONNECTION;
+ m_hConnection = LGLCD_INVALID_CONNECTION;
SetVolumeWheelHook(false);
- break;
- }
+ break;
+ }
}
//************************************************************************
@@ -654,11 +662,11 @@ int CLCDConnectionLogitech::GetConnectionState()
bool CLCDConnectionLogitech::HIDInit()
{
- if(GetConnectionState() != CONNECTED ||
+ if (GetConnectionState() != CONNECTED ||
m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //LGLCD_DEVICE_FAMILY_KEYBOARD_G15)
return false;
-// Logitech G15
+ // Logitech G15
int VendorID = 0x046d;
int ProductID = 0xc222;
@@ -668,11 +676,11 @@ bool CLCDConnectionLogitech::HIDInit()
SP_DEVICE_INTERFACE_DATA devInfoData;
bool LastDevice = FALSE;
int MemberIndex = 0;
- LONG Result;
-
+ LONG Result;
+
DWORD Length = 0;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = NULL;
- HANDLE hDevInfo =NULL;
+ HANDLE hDevInfo = NULL;
GUID HidGuid;
ULONG Required = 0;
@@ -684,20 +692,20 @@ bool CLCDConnectionLogitech::HIDInit()
Returns: the GUID in HidGuid.
*/
- HidD_GetHidGuid(&HidGuid);
-
+ HidD_GetHidGuid(&HidGuid);
+
/*
API function: SetupDiGetClassDevs
Returns: a handle to a device information set for all installed devices.
Requires: the GUID returned by GetHidGuid.
*/
-
- hDevInfo=SetupDiGetClassDevs
- (&HidGuid,
- NULL,
- NULL,
- DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
-
+
+ hDevInfo = SetupDiGetClassDevs
+ (&HidGuid,
+ NULL,
+ NULL,
+ DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
+
devInfoData.cbSize = sizeof(devInfoData);
//Step through the available devices looking for the one we want.
@@ -718,11 +726,11 @@ bool CLCDConnectionLogitech::HIDInit()
An index to specify a device.
*/
- Result=SetupDiEnumDeviceInterfaces
- (hDevInfo,
- 0,
- &HidGuid,
- MemberIndex,
+ Result = SetupDiEnumDeviceInterfaces
+ (hDevInfo,
+ 0,
+ &HidGuid,
+ MemberIndex,
&devInfoData);
if (Result != 0)
@@ -739,41 +747,41 @@ bool CLCDConnectionLogitech::HIDInit()
Requires:
A DeviceInfoSet returned by SetupDiGetClassDevs
The SP_DEVICE_INTERFACE_DATA structure returned by SetupDiEnumDeviceInterfaces.
-
+
The final parameter is an optional pointer to an SP_DEV_INFO_DATA structure.
- This application doesn't retrieve or use the structure.
- If retrieving the structure, set
+ This application doesn't retrieve or use the structure.
+ If retrieving the structure, set
MyDeviceInfoData.cbSize = length of MyDeviceInfoData.
and pass the structure's address.
*/
-
+
//Get the Length value.
//The call will return with a "buffer too small" error which can be ignored.
- Result = SetupDiGetDeviceInterfaceDetail
- (hDevInfo,
- &devInfoData,
- NULL,
- 0,
- &Length,
+ Result = SetupDiGetDeviceInterfaceDetail
+ (hDevInfo,
+ &devInfoData,
+ NULL,
+ 0,
+ &Length,
NULL);
//Allocate memory for the hDevInfo structure, using the returned Length.
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length);
-
+
//Set cbSize in the detailData structure.
- detailData -> cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
+ detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
//Call the function again, this time passing it the returned buffer size.
- Result = SetupDiGetDeviceInterfaceDetail
- (hDevInfo,
- &devInfoData,
- detailData,
- Length,
- &Required,
+ Result = SetupDiGetDeviceInterfaceDetail
+ (hDevInfo,
+ &devInfoData,
+ detailData,
+ Length,
+ &Required,
NULL);
// Open a handle to the device.
@@ -788,13 +796,13 @@ bool CLCDConnectionLogitech::HIDInit()
returned by SetupDiGetDeviceInterfaceDetail.
*/
- m_hHIDDeviceHandle=CreateFile
- (detailData->DevicePath,
- FILE_GENERIC_READ | FILE_GENERIC_WRITE,
- FILE_SHARE_READ|FILE_SHARE_WRITE,
+ m_hHIDDeviceHandle = CreateFile
+ (detailData->DevicePath,
+ FILE_GENERIC_READ | FILE_GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES)NULL,
- OPEN_EXISTING,
- FILE_FLAG_OVERLAPPED,
+ OPEN_EXISTING,
+ FILE_FLAG_OVERLAPPED,
NULL);
/*
@@ -811,64 +819,64 @@ bool CLCDConnectionLogitech::HIDInit()
Attributes.Size = sizeof(Attributes);
- Result = HidD_GetAttributes
- (m_hHIDDeviceHandle,
+ Result = HidD_GetAttributes
+ (m_hHIDDeviceHandle,
&Attributes);
-
+
//Is it the desired device?
MyDeviceDetected = FALSE;
-
+
if (Attributes.VendorID == VendorID)
{
if (Attributes.ProductID == ProductID)
{
//Both the Vendor ID and Product ID match.
MyDeviceDetected = TRUE;
- }
+ }
else
CloseHandle(m_hHIDDeviceHandle);
- }
+ }
else
CloseHandle(m_hHIDDeviceHandle);
- //Free the memory used by the detailData structure (no longer needed).
- free(detailData);
+ //Free the memory used by the detailData structure (no longer needed).
+ free(detailData);
}
else
- LastDevice=TRUE;
+ LastDevice = TRUE;
MemberIndex = MemberIndex + 1;
} //do
while ((LastDevice == FALSE) && (MyDeviceDetected == FALSE));
- if(MyDeviceDetected)
+ if (MyDeviceDetected)
{
PHIDP_PREPARSED_DATA PreparsedData;
- HidD_GetPreparsedData
- (m_hHIDDeviceHandle,
- &PreparsedData);
-
- HidP_GetCaps
- (PreparsedData,
- &m_HIDCapabilities);
-
+ HidD_GetPreparsedData
+ (m_hHIDDeviceHandle,
+ &PreparsedData);
+
+ HidP_GetCaps
+ (PreparsedData,
+ &m_HIDCapabilities);
+
HidD_FreePreparsedData(PreparsedData);
}
//Free the memory reserved for hDevInfo by SetupDiClassDevs.
SetupDiDestroyDeviceInfoList(hDevInfo);
-
+
return MyDeviceDetected;
}
bool CLCDConnectionLogitech::HIDDeInit()
{
- if(!m_hHIDDeviceHandle)
+ if (!m_hHIDDeviceHandle)
return false;
-
+
CloseHandle(m_hHIDDeviceHandle);
m_hHIDDeviceHandle = NULL;
return true;
@@ -883,8 +891,8 @@ SG15LightStatus CLCDConnectionLogitech::GetLightStatus()
status.bMRKey = false;
status.eKBDBrightness = KBD_OFF;
status.eLCDBrightness = LCD_OFF;
-
- if(GetConnectionState() != CONNECTED ||
+
+ if (GetConnectionState() != CONNECTED ||
m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15)
return status;
@@ -895,14 +903,14 @@ SG15LightStatus CLCDConnectionLogitech::GetLightStatus()
data[2] = 0x00;
data[3] = 0x00;
- HidD_GetFeature(m_hHIDDeviceHandle,data,m_HIDCapabilities.FeatureReportByteLength);
+ HidD_GetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength);
+
-
// data[1] = Keys
status.eKBDBrightness = (EKBDBrightness)data[1];
-
+
// data[2] = LCD
- switch(data[2])
+ switch (data[2])
{
case 0x02:
status.eLCDBrightness = LCD_ON;
@@ -918,7 +926,7 @@ SG15LightStatus CLCDConnectionLogitech::GetLightStatus()
status.bMKey[0] = !(data[3] & G15_M1_LIGHT);
status.bMKey[1] = !(data[3] & G15_M2_LIGHT);
status.bMKey[2] = !(data[3] & G15_M3_LIGHT);
-
+
// MRKey
status.bMRKey = !(data[3] & G15_MR_LIGHT);
@@ -927,9 +935,9 @@ SG15LightStatus CLCDConnectionLogitech::GetLightStatus()
return status;
}
-void CLCDConnectionLogitech::SetMKeyLight(bool bM1,bool bM2,bool bM3,bool bMR)
+void CLCDConnectionLogitech::SetMKeyLight(bool bM1, bool bM2, bool bM3, bool bMR)
{
- if(GetConnectionState() != CONNECTED ||
+ if (GetConnectionState() != CONNECTED ||
m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15)
return;
@@ -937,25 +945,25 @@ void CLCDConnectionLogitech::SetMKeyLight(bool bM1,bool bM2,bool bM3,bool bMR)
data[0] = 0x02;
data[1] = 0x04;
data[2] = 0x00;
-
- if(!bM1)
+
+ if (!bM1)
data[2] |= G15_M1_LIGHT;
- if(!bM2)
+ if (!bM2)
data[2] |= G15_M2_LIGHT;
- if(!bM3)
+ if (!bM3)
data[2] |= G15_M3_LIGHT;
- if(!bMR)
+ if (!bMR)
data[2] |= G15_MR_LIGHT;
- data[3] = 0x00;
+ data[3] = 0x00;
- HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength);
+ HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength);
delete[] data;
}
void CLCDConnectionLogitech::SetLCDBacklight(ELCDBrightness eBrightness)
{
- if(GetConnectionState() != CONNECTED ||
+ if (GetConnectionState() != CONNECTED ||
m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15)
return;
@@ -964,16 +972,16 @@ void CLCDConnectionLogitech::SetLCDBacklight(ELCDBrightness eBrightness)
data[0] = 0x02;
data[1] = 0x02;
data[2] = eBrightness;
- data[3] = 0x00;
+ data[3] = 0x00;
- HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength);
+ HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength);
delete[] data;
}
void CLCDConnectionLogitech::SetKBDBacklight(EKBDBrightness eBrightness)
{
- if(GetConnectionState() != CONNECTED ||
+ if (GetConnectionState() != CONNECTED ||
m_pConnectedDevice->GetIndex() != LGLCD_DEVICE_BW) //m_lcdDeviceDesc.deviceFamilyId != LGLCD_DEVICE_FAMILY_KEYBOARD_G15)
return;
@@ -982,38 +990,38 @@ void CLCDConnectionLogitech::SetKBDBacklight(EKBDBrightness eBrightness)
data[0] = 0x02;
data[1] = 0x01;
data[2] = eBrightness;
- data[3] = 0x00;
+ data[3] = 0x00;
- HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength);
+ HidD_SetFeature(m_hHIDDeviceHandle, data, m_HIDCapabilities.FeatureReportByteLength);
free(data);
}
void CLCDConnectionLogitech::SetVolumeWheelHook(bool bEnable)
{
- if(bEnable == m_bVolumeWheelHook)
+ if (bEnable == m_bVolumeWheelHook)
return;
m_bVolumeWheelHook = bEnable;
- if(bEnable)
+ if (bEnable)
m_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, CLCDConnectionLogitech::KeyboardHook, GetModuleHandle(NULL), 0);
- else if(m_hKeyboardHook)
+ else if (m_hKeyboardHook)
UnhookWindowsHookEx(m_hKeyboardHook);
}
LRESULT CALLBACK CLCDConnectionLogitech::KeyboardHook(int Code, WPARAM wParam, LPARAM lParam)
{
- if(Code == HC_ACTION && wParam == WM_KEYDOWN)
- {
+ if (Code == HC_ACTION && wParam == WM_KEYDOWN)
+ {
KBDLLHOOKSTRUCT *key = reinterpret_cast<KBDLLHOOKSTRUCT *>(lParam);
- if(key->vkCode == VK_VOLUME_UP || key->vkCode == VK_VOLUME_DOWN)
+ if (key->vkCode == VK_VOLUME_UP || key->vkCode == VK_VOLUME_DOWN)
{
- if(m_pInstance->IsForeground())
- {
- if(key->vkCode == VK_VOLUME_UP)
+ if (m_pInstance->IsForeground())
+ {
+ if (key->vkCode == VK_VOLUME_UP)
CLCDOutputManager::GetInstance()->OnLCDButtonDown(LGLCDBUTTON_UP);
- else if(key->vkCode == VK_VOLUME_DOWN)
- CLCDOutputManager::GetInstance()->OnLCDButtonDown(LGLCDBUTTON_DOWN);
+ else if (key->vkCode == VK_VOLUME_DOWN)
+ CLCDOutputManager::GetInstance()->OnLCDButtonDown(LGLCDBUTTON_DOWN);
return 1;
}
}
diff --git a/plugins/MirandaG15/src/LCDFramework/stdafx.h b/plugins/MirandaG15/src/LCDFramework/stdafx.h
index 0ff159a86f..2195cdf02e 100644
--- a/plugins/MirandaG15/src/LCDFramework/stdafx.h
+++ b/plugins/MirandaG15/src/LCDFramework/stdafx.h
@@ -19,6 +19,8 @@ using namespace std;
#define tstring string
#endif
+#include <m_core.h>
+
#include "debug.h"
#include "misc.h"