sanraith / razer-taskbar

Display the battery state of Razer products using log messages from Razer Synapse.
MIT License
21 stars 3 forks source link

wrong battery charging state when using Viper + Dock #7

Open kongomongo opened 4 weeks ago

kongomongo commented 4 weeks ago

Heya,

thanks for your awesome project!

I tried using it with my Viper Ultimate. I am using the mouse wirelessly and I have a Mouse Dock Chroma connected to the PC via USB.

Right from the start razer-taskbar found the mouse correctly and showed the correct battery percentage, but wrongly showed "Charging" while it was not.

I dug into the log and found that my "state" is always 1. Most probably due to the Dock Chroma being connected. In the log the only reliable info I could find was not in the _OnBatteryLevelChanged event but rather in the "Battery Get By Device Handle" event. Here the true Charging state of the mouse is shown in "Battery State:".

As I have no knowledge whether using that event to get charging state would break compatibility with current setups I am asking here...

Thanks!

2024-06-05 09:18:05.4375 INFO 1 Battery Get By Device Handle: 
Battery Percentage: 25
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:33:05.5424 INFO 1 Battery Get By Device Handle: 
Battery Percentage: 25
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:44:29.0177 INFO 107 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
2024-06-05 09:47:41.6286 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:48:01.7592 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:48:02.8867 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:48:02.9902 INFO 16 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:48:03.6456 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:48:04.7929 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:48:04.8570 INFO 16 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:48:07.5544 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: NotCharging
Device on Dock State: WiredCharging
Id: 0 state: True
2024-06-05 09:54:18.8663 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:54:18.9297 INFO 85 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: Charging
Device on Dock State: WiredCharging
Id: 0 state: False
2024-06-05 09:54:19.4694 INFO 84 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:54:19.6270 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: Charging
Device on Dock State: DockCharging
Id: 0 state: True
2024-06-05 09:54:19.9398 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:54:19.9872 INFO 107 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 24
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:54:53.0046 INFO 101 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 25 state 1
2024-06-05 09:56:17.5818 INFO 39 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 26 state 1
2024-06-05 09:57:25.9721 INFO 87 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 27 state 1
Id: 0 state: False
2024-06-05 09:58:34.3340 INFO 86 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:58:34.3807 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: NotCharging
Device on Dock State: WiredCharging
Id: 0 state: True
2024-06-05 09:58:37.9327 INFO 111 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:58:38.0422 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: NotCharging
Device on Dock State: DockCharging
Id: 0 state: False
2024-06-05 09:58:38.5691 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:58:38.6816 INFO 111 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
Id: 0 state: True
2024-06-05 09:58:39.0565 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:58:39.1358 INFO 86 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
Id: 0 state: False
2024-06-05 09:58:39.6006 INFO 86 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:58:39.7606 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
Id: 0 state: True
2024-06-05 09:58:40.1823 INFO 86 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:58:40.2463 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
Id: 0 state: False
2024-06-05 09:58:40.8372 INFO 110 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:58:40.9018 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
Id: 0 state: True
2024-06-05 09:58:41.1626 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:58:41.2103 INFO 86 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 27
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:58:45.4942 INFO 22 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 28 state 1
Id: 0 state: False
2024-06-05 09:58:51.9937 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 09:58:52.0731 INFO 51 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: NotCharging
Device on Dock State: WiredCharging
Id: 0 state: True
2024-06-05 09:59:08.2682 INFO 51 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 09:59:08.3164 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: Charging
Device on Dock State: DockCharging
Id: 0 state: False
2024-06-05 10:00:05.3942 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 10:00:05.4424 INFO 111 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: NotCharging
Device on Dock State: WiredCharging
Id: 0 state: True
2024-06-05 10:00:09.4368 INFO 111 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 10:00:09.5153 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: Charging
Device on Dock State: DockCharging
Id: 0 state: False
2024-06-05 10:00:09.9973 INFO 3 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 10:00:10.1097 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: Charging
Device on Dock State: DockCharging
Id: 0 state: True
2024-06-05 10:00:10.3408 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 10:00:10.4198 INFO 57 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 28
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 10:00:14.0271 INFO 96 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 29 state 1
2024-06-05 10:02:21.7687 INFO 58 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 30 state 1
2024-06-05 10:03:07.9521 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 30
Battery State: Charging
Device on Dock State: DockCharging
2024-06-05 10:04:27.6254 INFO 118 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 31 state 1
2024-06-05 10:06:19.2929 INFO 78 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 32 state 1
2024-06-05 10:08:25.0914 INFO 132 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 33 state 1
2024-06-05 10:10:19.7915 INFO 125 _OnBatteryLevelChanged: device Name: Razer Viper Ultimate
Id: 0 level 34 state 1
Id: 0 state: False
2024-06-05 10:11:25.4423 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 34
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 10:11:25.4908 INFO 83 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 34
Battery State: NotCharging
Device on Dock State: WiredCharging
2024-06-05 10:18:08.3978 INFO 1 Battery Get By Device Handle:3836875793 is 
Battery Percentage: 34
Battery State: NotCharging
Device on Dock State: WiredCharging

full log attached. log.txt

Currently using Synapse: Version 3.9.516.51517

kongomongo commented 4 weeks ago

Also: I haven't tried v4 (didn't even know it existed), would that solve the problems?

kongomongo commented 4 weeks ago

PR https://github.com/sanraith/razer-taskbar/pull/8

Here if you want to try

sanraith commented 4 weeks ago

Hey, Thanks for the in-depth description. Does this work for you when you don't have the Razer Synapse window open? (so that its icon just sits in the tray area)

I tried to use this method originally, but in my testing I found that I very rarely get the "Battery Get By Device Handle" messages in my log when I do not have Razer Synapse open. So using this method caused my app to show an outdated percentage value that would only update to the real one when I opened up Razer Synapse again.

Because of this I cannot take the PR as-is, but when I find the time I'll add something like another "mode" in the settings or just the ability to disable the charging display altogether.

In the meantime trying V4 might help you, since that one logs the state in a different way.

kongomongo commented 4 weeks ago

hey,

Yes it is completely independent of Synapse open or not.

Here is a quick check of the timings: image chart.xlsx

It looks like during charging more OnBatteryLevelChanged events are produced, when discharging the opposite is true. However, I'd reckon both are sufficient for the application.

sanraith commented 3 weeks ago

While I dont have a good fix that works for both your case and mine, for now I added an option to disable the charging display: https://github.com/sanraith/razer-taskbar/releases/tag/v0.11.0

kongomongo commented 3 weeks ago

Thanks for the update. I'm using a patched fork for now, until v4 is out of beta then I'll try that.

Thanks!