Coder Social home page Coder Social logo

fan4metal / razer-mouse-battery-windows Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hsutungyu/razer-mouse-battery-windows

0.0 0.0 0.0 88 KB

A Python script that shows the battery level of a Razer Mamba Wireless mouse (or other Razer mouse with modification) as a tray notification in Windows. By using the Task Scheduler, the tray notification can be showed regularly.

License: GNU General Public License v3.0

Python 83.04% PowerShell 16.96%

razer-mouse-battery-windows's Introduction

Mamba Wireless Battery Indicator

Introduction

Notification Screenshot
This is a script for Windows written in Python 3.10 that gets the battery level of a Razer Mamba Wireless and shows a tray notification.
Combining with the Task Scheduler, the notification can be regularly shown with self-defined interval (the default is a notification every 15 minutes).

Instruction

  1. Clone this repository
  2. Go to the website of libusb to download the Latest Windows Binaries
  3. In the .7z file downloaded, extract \VS2019\MS64\dll\libusb-1.0.dll to C:\Windows\System32 and \VS2019\MS32\dll\libusb-1.0.dll to C:\Windows\SysWOW64
  4. If you can run PowerShell script on your system, run . .\mamba.ps1 in a PowerShell inside the directory
  5. Input a time interval in minutes, or press Enter for the default of 15 minutes when prompted
  • The script installs the needed Python packages and sets up the scheduled tasks with a 15-minute time interval

If you cannot/do not want to run the PowerShell script

  1. Run the PowerShell script, then run python -m pip install -r requirements.txt inside the directory
  2. Go to Task Scheduler by searching in the start menu
  3. In the Actions menu on the right hand side, click Create Task...
  4. Enter a name and a description as you like
  5. Go to Actions and click New...
  6. Enter the details in the dialog box that appears:
Field To Enter Example
Program/script: \path\to\pythonw.exe C:\Python310\pythonw.exe
Add arguments (optional): mamba.pyw mamba.pyw
Start in (optional): the path that you put mamba.pyw the directory that you cloned this repo
  1. Go to Triggers and click New...
  2. Enter the details in the dialog box that appears:
Field To Enter Example
Repeat task every: enable; the notification would appear every x minutes 15 minutes = 1 notification every 15 minutes
for a duration of: Indefinitely
  1. Click OK, done! Now the notification would appear every 15 minutes (or the time interval that you choose)

Credit

This script is written by looking into OpenRazer, a GNU/Linux driver for controlling razer devices.
Also, I have referenced the blog post and the script by Roland Smith in the process of writing this script.

How to adapt the Python script for your Razer device

Warning: This process may brick your device (although my mouse did not). TRY AT YOUR OWN RISK!
To adapt the script for your Razer mouse, follow the steps below:

  1. Get the PIDs of your mouse in both the wireless and wired mode

Go to Device Manager -> Find your mouse -> Right click -> Properties -> Details -> Hardware Ids -> Repeat in the other state

  • e.g., in wireless state, the entries of Hardware Ids contain VID_1532&PID_0072, then 0x0072 is the PID of my mouse in the wireless state
  • In wired state, the entries contain VID_1532&PID_0073, then 0x0073 is the PID of my mouse in the wired state
  1. git clone https://github.com/openrazer/openrazer.git
  2. Look at openrazer/driver/razermouse_driver.c in the cloned repository
  3. Search for battery in the .c file to find the function razer_attr_read_charge_level
  4. If the name of your mouse appears inside the switch statement, write down the transaction_id.id
  • e.g., I see USB_DEVICE_ID_RAZER_MAMBA_WIRELESS_RECEIVER inside the switch statement, so the transaction_id.id for my mouse is 0x3f
  • If you do not see your mouse name inside, then the transaction_id.id is 0xff
  1. Open mamba.pyw and change the values of WIRELESS_RECEIVER, WIRELESS_WIRED and TRAN_ID according to your findings above
  2. Done!

Troubleshooting

If the script is not working, you could try the following steps:

  • Turn off Focus Assist in the action center, accessed by the dialog button on the bottom right corner of the taskbar
  • Try a different USB port
  • Uninstall any WinUSB driver (upper filter) that you have installed
  • Try closing Razer Synapse
  • Try uninstalling the driver of your mouse in Device Manager, and then replug the USB receiver
  • If the mouse is not responsive after executing the script, replug usb receiver should solve the problem

License

GNU General Public License v2.0

razer-mouse-battery-windows's People

Contributors

hsutungyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.