-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem:
when you reconnect the headphones (in my case headphones), rainmeter doesn't update the skin so it stays at "BT: -" and you have to manually refresh the skin.
Fix:
This ini now automatically updates the skin:
[Rainmeter]
Update=1000
[Metadata]
Name=BTChargeLevel
Author=ForegroundProcess
Information=Displays current charge level and connectivity of a Bluetooth device. See README.md for details.
;------------------------------------------------------------
; STYLES
;------------------------------------------------------------
[Style01]
FontColor=255, 255, 255, 180
FontSize=32
FontFace=Segoe UI
StringEffect=SHADOW
AntiAlias=1
ClipString=0
;------------------------------------------------------------
; BT Charge level
;------------------------------------------------------------
[measureBTChargeLevel]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Software\ForegroundProcess\BTChargeLevel
RegValue=BTChargeLevel
OutputType=Value
IfCondition=measureBTChargeLevel>=20
IfTrueAction=[!SetOption meterBTCharge FontColor 255,255,255,255][!Redraw]
IfFalseAction=[!SetOption meterBTCharge FontColor 255,0,0,255][!Redraw]
[measureConnectivity]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Software\ForegroundProcess\BTChargeLevel
RegValue=IsConnected
IfMatch=True
IfMatchAction=[!SetOption meterBTCharge Text "YOUR_DEVICE_NAME_HERE: %1%"][!Redraw]
IfNotMatchAction=[!SetOption meterBTCharge FontColor 255,255,255,255][!SetOption meterBTCharge Text ""][!Redraw][!SetOption meterBTCharge Text "BT: -"][!Redraw]
IfMatchMode=1
[meterBTCharge]
Meter=String
DynamicVariables=1
MeterStyle=Style01
MeasureName=measureBTChargeLevel
Text="YOUR_DEVICE_NAME_HERE: %1%"
W=530
H=100
Another issue I had:
I also had to make a new ps1 script to get the proper connection and battery measurements in my Soundcore headphones, since they don't seem to use the same "friendlyname" to send the battery and the connectivity signals. This is not a "problem" in the script, but a workaround was needed and I'm sure many bluetooth devices do the same.
In my case, the connectivity was sent to the "Headphone" device and the battery was sent to "Headset" device. If it gets hard to understand let's quickly say that a bluetooth device can have many "virtual" devices in it.
With help of GPTChat I was able to make this ps1 script to force the reading on the correct device instanceid:
# This script looks for Bluetooth device battery charge level and connection status,
# writes them to the Windows registry, and logs the results to a file on the desktop (if enabled).
# Change the value below to the exact name of your device as shown in the Bluetooth system settings.
$BTDeviceFriendlyName = "Soundcore Life Q35"
$BTHDevices = Get-PnpDevice -FriendlyName "*$($BTDeviceFriendlyName)*"
$BTChargeLevel = $null
$IsConnected = $false
$HardCodedInstanceId = "BTHENUM\DEV_E8EECC0719F6\A&1556D1F2&0&BLUETOOTHDEVICE_E8EECC0719F6"
# Set to $true to enable debug logging or $false to disable logging
$EnableDebugLogging = $false
if ($EnableDebugLogging) {
# Prepare log file on Desktop
$DesktopPath = [System.Environment]::GetFolderPath("Desktop")
$LogFile = Join-Path $DesktopPath "BTDeviceLog.txt"
$LogMessage = "----- Log Entry: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') -----`r`n"
}
if ($BTHDevices) {
foreach ($Device in $BTHDevices) {
$BTDeviceProperties = Get-PnpDeviceProperty -InstanceId $Device.InstanceId
foreach ($BTDeviceProperty in $BTDeviceProperties) {
if (($BTDeviceProperty.KeyName -eq "{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2") -and ($null -ne $BTDeviceProperty.Data)) {
$BTChargeLevel = $BTDeviceProperty.Data
if ($EnableDebugLogging) {
$LogMessage += "Charge level found: $BTChargeLevel`r`n"
}
}
# Check if the device matches the hardcoded InstanceId and the property key is for connection status
if (($Device.InstanceId -eq $HardCodedInstanceId) -and
($BTDeviceProperty.KeyName -eq "{83DA6326-97A6-4088-9453-A1923F573B29} 15") -and
($null -ne $BTDeviceProperty.Data)) {
$IsConnected = $BTDeviceProperty.Data
if ($EnableDebugLogging) {
$LogMessage += "Connection status found: $IsConnected`r`n"
}
}
}
}
# If connection status was found, update the registry and log the results
if ($null -ne $IsConnected) {
if (!(Test-Path HKCU:\Software\ForegroundProcess\BTChargeLevel)) {
New-Item -Path HKCU:\Software\ForegroundProcess\BTChargeLevel -Force
}
Set-ItemProperty -Path HKCU:\Software\ForegroundProcess\BTChargeLevel -Name BTChargeLevel -Value $BTChargeLevel
Set-ItemProperty -Path HKCU:\Software\ForegroundProcess\BTChargeLevel -Name IsConnected -Value $IsConnected
if ($EnableDebugLogging) {
$LogMessage += "Registry updated: BTChargeLevel = $BTChargeLevel, IsConnected = $IsConnected`r`n"
}
}
else {
if ($EnableDebugLogging) {
$LogMessage += "No connection status found for device $BTDeviceFriendlyName.`r`n"
}
}
}
else {
if ($EnableDebugLogging) {
$LogMessage += "No devices found matching $BTDeviceFriendlyName.`r`n"
}
}
if ($EnableDebugLogging) {
$LogMessage += "----------------------------------------`r`n"
# Append the log message to the log file on the desktop
Add-Content -Path $LogFile -Value $LogMessage
}
Hope this helps someone, I've lost an entire day doing this.