Skip to content

Commit 479cc86

Browse files
committed
Fix release build by bumping msbuild github module
Rip out a bunch of useless bluetooth characteristic iteration code Use proper volume stepping functions
1 parent 55d8c24 commit 479cc86

File tree

5 files changed

+42
-158
lines changed

5 files changed

+42
-158
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
cmd.exe /c call build_wx.bat release
2323
2424
- name: Setup MSBuild
25-
uses: microsoft/[email protected].1
25+
uses: microsoft/[email protected].2
2626

2727
- name: Build PowerMateTray Release
2828
run: |

Application.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ bool Application::OnInit()
9494
m_TrayIcon = new TrayIcon( this );
9595

9696
StartupVolume();
97-
StartupPowerMateBluetooth();
98-
StartupPowerMateUSB();
97+
98+
bool bFoundBluetooth = StartupPowerMateBluetooth();
99+
bool bFoundUSB = StartupPowerMateUSB();
100+
if (!bFoundBluetooth && !bFoundUSB)
101+
{
102+
wxMessageBox("Could not locate a Bluetooth LE or USB PowerMate!", "Connection Error", wxICON_ERROR);
103+
}
99104

100105
return true;
101106
}

PowerMateBluetooth.cpp

Lines changed: 31 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static HANDLE OpenBluetoothDevice(const GUID* interfaceGUID)
5252

5353
if (SetupDiGetDeviceInterfaceDetail(hDevInfo, &deviceInterfaceData, pInterfaceDetailData, size, &size, &devInfoData))
5454
{
55-
OutputDebugFormat(_T("Found PowerMate Bluetooth: %s"), pInterfaceDetailData->DevicePath);
55+
OutputDebugFormat(_T("Found PowerMate Bluetooth: %s\n"), pInterfaceDetailData->DevicePath);
5656
hResult = CreateFile(
5757
pInterfaceDetailData->DevicePath,
5858
GENERIC_READ,
@@ -83,55 +83,35 @@ static void ValueChangedEventHandler(BTH_LE_GATT_EVENT_TYPE EventType, PVOID Eve
8383

8484
PBLUETOOTH_GATT_VALUE_CHANGED_EVENT ValueChangedEventParameters = (PBLUETOOTH_GATT_VALUE_CHANGED_EVENT)EventOutParameter;
8585

86-
switch (ValueChangedEventParameters->CharacteristicValue->DataSize)
86+
if (ValueChangedEventParameters->CharacteristicValue->DataSize == 1)
8787
{
88-
case 0:
88+
char data = ValueChangedEventParameters->CharacteristicValue->Data[0];
89+
switch (data)
8990
{
90-
OutputDebugFormat("Notification obtained ValueChangedEventParameters->CharacteristicValue->DataSize=0\n");
91+
case 101:
92+
OutputDebugFormat("Notification obtained Knob Press\n");
93+
ToggleMute();
9194
break;
92-
}
93-
case 1:
94-
{
95-
char data = ValueChangedEventParameters->CharacteristicValue->Data[0];
96-
switch (data)
97-
{
98-
case 104:
99-
OutputDebugFormat("Notification obtained Knob Right\n");
100-
IncreaseVolume();
101-
break;
10295

103-
case 103:
104-
OutputDebugFormat("Notification obtained Knob Left\n");
105-
DecreaseVolume();
106-
break;
107-
108-
case 101:
109-
OutputDebugFormat("Notification obtained Knob Press\n");
110-
ToggleMute();
111-
break;
96+
case 103:
97+
OutputDebugFormat("Notification obtained Knob Left\n");
98+
DecreaseVolume();
99+
break;
112100

113-
default:
114-
OutputDebugFormat("Notification obtained Unknown atom %d\n", data);
115-
break;
116-
}
101+
case 104:
102+
OutputDebugFormat("Notification obtained Knob Right\n");
103+
IncreaseVolume();
117104
break;
118-
}
105+
119106
default:
120-
{
121-
#if 0
122-
char hex[256];
123-
char buf = hex;
124-
for (ULONG i = 0; i < ValueChangedEventParameters->CharacteristicValue->DataSize; i++)
125-
{
126-
size_t count = hex + sizeof(hex) - buf - 1;
127-
int result = snprintf(buf, count, "%0X", ValueChangedEventParameters->CharacteristicValue->Data[i]);
128-
buf += result;
129-
}
130-
OutputDebugFormat("Notification obtained %s\n", buf);
107+
OutputDebugFormat("Notification obtained unknown event\n");
131108
break;
132-
#endif
133109
}
134110
}
111+
else
112+
{
113+
OutputDebugFormat("Notification obtained unknown data size %d\n", ValueChangedEventParameters->CharacteristicValue->DataSize);
114+
}
135115
}
136116

137117
HANDLE hBluetoothDevice = INVALID_HANDLE_VALUE;
@@ -162,10 +142,6 @@ bool StartupPowerMateBluetooth()
162142
{
163143
OutputDebugFormat("BluetoothGATTGetServices returned unexpected HRESULT: %d\n", hr);
164144
}
165-
else
166-
{
167-
OutputDebugFormat("Got %d services from the device\n", serviceCount);
168-
}
169145
if (serviceCount)
170146
{
171147
pServiceBuffer = (PBTH_LE_GATT_SERVICE)malloc(sizeof(BTH_LE_GATT_SERVICE) * serviceCount);
@@ -187,10 +163,6 @@ bool StartupPowerMateBluetooth()
187163
{
188164
OutputDebugFormat("BluetoothGATTGetCharacteristics returned unexpected HRESULT: %d\n", hr);
189165
}
190-
else
191-
{
192-
OutputDebugFormat("Got %d characteristics from the device\n", characteristicCount);
193-
}
194166
if (characteristicCount)
195167
{
196168
pCharacteristicBuffer = (PBTH_LE_GATT_CHARACTERISTIC)malloc(sizeof(BTH_LE_GATT_CHARACTERISTIC) * characteristicCount);
@@ -205,120 +177,31 @@ bool StartupPowerMateBluetooth()
205177
}
206178

207179
// iterate the characteristics and attach event handler
208-
PBTH_LE_GATT_CHARACTERISTIC currentCharacteristic = NULL;
209-
for (int characteristicIndex = 0; characteristicIndex < characteristicCount; characteristicIndex++)
180+
if (characteristicCount >= 2)
210181
{
211-
currentCharacteristic = &pCharacteristicBuffer[characteristicIndex];
212-
213-
USHORT descriptorCount;
214-
hr = BluetoothGATTGetDescriptors(hBluetoothDevice, currentCharacteristic, 0, NULL, &descriptorCount, BLUETOOTH_GATT_FLAG_NONE);
215-
if (HRESULT_FROM_WIN32(ERROR_MORE_DATA) != hr)
216-
{
217-
OutputDebugFormat("BluetoothGATTGetDescriptors returned unexpected HRESULT: %d\n", hr);
218-
}
219-
else
220-
{
221-
OutputDebugFormat("Characteristic %d has %d descriptors\n", characteristicIndex, descriptorCount);
222-
}
223-
224-
AutoFreePointer<BTH_LE_GATT_DESCRIPTOR> pDescriptorBuffer = NULL;
225-
if (descriptorCount)
226-
{
227-
pDescriptorBuffer = (PBTH_LE_GATT_DESCRIPTOR)malloc(sizeof(BTH_LE_GATT_DESCRIPTOR) * descriptorCount);
228-
ZeroMemory(pDescriptorBuffer, sizeof(BTH_LE_GATT_DESCRIPTOR) * descriptorCount);
229-
230-
hr = BluetoothGATTGetDescriptors(hBluetoothDevice, currentCharacteristic, descriptorCount, pDescriptorBuffer, &descriptorCount, BLUETOOTH_GATT_FLAG_NONE);
231-
if (S_OK != hr)
232-
{
233-
OutputDebugFormat("BluetoothGATTGetDescriptors returned unexpected HRESULT: %d\n", hr);
234-
}
235-
236-
for (int descriptorIndex = 0; descriptorIndex < descriptorCount; descriptorIndex++)
237-
{
238-
PBTH_LE_GATT_DESCRIPTOR currentDescriptor = &pDescriptorBuffer[descriptorIndex];
239-
240-
USHORT descValueDataSize;
241-
hr = BluetoothGATTGetDescriptorValue(hBluetoothDevice, currentDescriptor, 0, NULL, &descValueDataSize, BLUETOOTH_GATT_FLAG_NONE);
242-
if (HRESULT_FROM_WIN32(ERROR_MORE_DATA) != hr)
243-
{
244-
OutputDebugFormat("BluetoothGATTGetDescriptorValue returned unexpected HRESULT: %d\n", hr);
245-
}
246-
else
247-
{
248-
OutputDebugFormat("Characteristic %d, descriptor %d has value data size %d\n", characteristicIndex, descriptorIndex, descValueDataSize);
249-
}
250-
AutoFreePointer<BTH_LE_GATT_DESCRIPTOR_VALUE> pDescValueBuffer = (PBTH_LE_GATT_DESCRIPTOR_VALUE)malloc(descValueDataSize);
251-
ZeroMemory(pDescValueBuffer, descValueDataSize);
252-
hr = BluetoothGATTGetDescriptorValue(hBluetoothDevice, currentDescriptor, (ULONG)descValueDataSize, pDescValueBuffer, NULL, BLUETOOTH_GATT_FLAG_NONE);
253-
if (S_OK != hr)
254-
{
255-
OutputDebugFormat("BluetoothGATTGetDescriptorValue returned unexpected HRESULT: %d\n", hr);
256-
}
257-
258-
//you may also get a descriptor that is read (and not notify) and i am guessing the attribute handle is out of limits
259-
// we set all descriptors that are notifiable to notify us via IsSubstcibeToNotification
260-
if (currentDescriptor->DescriptorType != CharacteristicUserDescription)
261-
{
262-
BTH_LE_GATT_DESCRIPTOR_VALUE newValue;
263-
ZeroMemory(&newValue, sizeof(BTH_LE_GATT_DESCRIPTOR_VALUE));
264-
newValue.DescriptorType = ClientCharacteristicConfiguration;
265-
newValue.ClientCharacteristicConfiguration.IsSubscribeToNotification = TRUE;
266-
267-
hr = BluetoothGATTSetDescriptorValue(hBluetoothDevice, currentDescriptor, &newValue, BLUETOOTH_GATT_FLAG_NONE);
268-
if (S_OK != hr)
269-
{
270-
if (E_ACCESSDENIED != hr)
271-
{
272-
OutputDebugFormat("BluetoothGATTGetDescriptorValue returned unexpected HRESULT: %d\n", hr);
273-
}
274-
}
275-
else
276-
{
277-
OutputDebugFormat("Set notification for service handle %d\n", currentDescriptor->ServiceHandle);
278-
}
279-
}
280-
}
281-
}
282-
283-
// set the appropriate callback function when the descriptor change value
284-
BLUETOOTH_GATT_EVENT_HANDLE hValueChangedEvent = INVALID_HANDLE_VALUE;
182+
// 2 is the magic characteristic, BTLE is obnoxious about characteristic identity
183+
PBTH_LE_GATT_CHARACTERISTIC currentCharacteristic = &pCharacteristicBuffer[2];
285184
if (currentCharacteristic->IsNotifiable)
286185
{
287-
OutputDebugFormat("Setting Notification for ServiceHandle %d\n", currentCharacteristic->ServiceHandle);
288-
289186
BLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION eventRegistration;
290187
ZeroMemory(&eventRegistration, sizeof(BLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION));
291188
eventRegistration.Characteristics[0] = *currentCharacteristic;
292189
eventRegistration.NumCharacteristics = 1;
190+
BLUETOOTH_GATT_EVENT_HANDLE hValueChangedEvent = INVALID_HANDLE_VALUE;
293191
hr = BluetoothGATTRegisterEvent(hBluetoothDevice, CharacteristicValueChangedEvent, &eventRegistration, ValueChangedEventHandler, NULL, &hValueChangedEvent, BLUETOOTH_GATT_FLAG_NONE);
294192
if (S_OK != hr)
295193
{
296194
OutputDebugFormat("BluetoothGATTRegisterEvent returned unexpected HRESULT: %d\n", hr);
297195
}
298-
}
299-
300-
if (currentCharacteristic->IsReadable)
301-
{
302-
USHORT valueDataSize;
303-
hr = BluetoothGATTGetCharacteristicValue(hBluetoothDevice, currentCharacteristic, 0, NULL, &valueDataSize, BLUETOOTH_GATT_FLAG_NONE);
304-
if (HRESULT_FROM_WIN32(ERROR_MORE_DATA) != hr)
305-
{
306-
OutputDebugFormat("BluetoothGATTGetCharacteristicValue returned unexpected HRESULT: %d\n", hr);
307-
}
308-
AutoFreePointer<BTH_LE_GATT_CHARACTERISTIC_VALUE> pValueBuffer = (PBTH_LE_GATT_CHARACTERISTIC_VALUE)malloc(valueDataSize);
309-
ZeroMemory(pValueBuffer, valueDataSize);
310-
hr = BluetoothGATTGetCharacteristicValue(hBluetoothDevice, currentCharacteristic, (ULONG)valueDataSize, pValueBuffer, NULL, BLUETOOTH_GATT_FLAG_NONE);
311-
if (S_OK != hr)
312-
{
313-
OutputDebugFormat("BluetoothGATTGetCharacteristicValue returned unexpected HRESULT: %d\n", hr);
314-
}
315-
316-
OutputDebugFormat("Read characterstic value: ");
317-
for (ULONG dataIndex = 0; dataIndex < pValueBuffer->DataSize; dataIndex++)
196+
else
318197
{
319-
OutputDebugFormat("%0X", pValueBuffer->Data[dataIndex]);
198+
OutputDebugFormat("Registered for Event Notification\n");
320199
}
321-
OutputDebugFormat("\n");
200+
}
201+
else
202+
{
203+
OutputDebugFormat("Expected characteristic isn't notifiable!\n");
204+
return false;
322205
}
323206
}
324207

PowerMateUSB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static HANDLE OpenUSBDevice(const GUID* interfaceGUID)
5555
{
5656
if (NULL != _tcsstr((TCHAR*)pInterfaceDetailData->DevicePath, _T("vid_077d&pid_0410")))
5757
{
58-
OutputDebugFormat(_T("Found PowerMate USB: %s"), pInterfaceDetailData->DevicePath);
58+
OutputDebugFormat(_T("Found PowerMate USB: %s\n"), pInterfaceDetailData->DevicePath);
5959
hResult = CreateFile(
6060
pInterfaceDetailData->DevicePath,
6161
GENERIC_READ|GENERIC_WRITE,

Volume.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ void ShutdownVolume()
3737

3838
void IncreaseVolume()
3939
{
40-
float level;
41-
pAudioEndpointVolume->GetMasterVolumeLevel(&level);
42-
pAudioEndpointVolume->SetMasterVolumeLevel(level + 1.f, NULL);
40+
pAudioEndpointVolume->VolumeStepUp(nullptr);
4341
}
4442

4543
void DecreaseVolume()
4644
{
47-
float level;
48-
pAudioEndpointVolume->GetMasterVolumeLevel(&level);
49-
pAudioEndpointVolume->SetMasterVolumeLevel(level - 1.f, NULL);
45+
pAudioEndpointVolume->VolumeStepDown(nullptr);
5046
}
5147

5248
void ToggleMute()

0 commit comments

Comments
 (0)