Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accurate Battery Level Indicator #38

Open
dconz13 opened this issue Dec 6, 2024 · 0 comments
Open

Accurate Battery Level Indicator #38

dconz13 opened this issue Dec 6, 2024 · 0 comments

Comments

@dconz13
Copy link

dconz13 commented Dec 6, 2024

Hey there GEIGEIGEIST! Thanks for making the Totem! It's an awesome board. I'm looking for guidance on getting more accurate battery information through ZMK. I've tried charging both halves of the board via the USB on my PC as well as 5V usb adapters and haven't seen the battery go up higher than ~50% on the right half and ~80% on the left. Do you know the answers to the follow:

Does the power switch need to be turned on for the battery to charge?
Is there a ZMK configuration that can be added for the seeedxiao to get more accurate battery information?

I'm using the below script to check the battery on Linux:

from dbus_next.aio import MessageBus
from dbus_next.constants import BusType
import asyncio
BLUEZ = "org.bluez"
#replace hci0 with your bluetooth adapter name and FF_FF_FF_FF_FF_FF with your keyboard address
BLUEZ_PATH = "/org/bluez/hci0/dev_FF_FF_FF_FF_FF_FF"
GATT_SERVICE = 'org.bluez.GattService1'
GATT_CHARACTERISCITC = 'org.bluez.GattCharacteristic1'
GATT_CHARACTERISCITC_DESCR = 'org.bluez.GattDescriptor1'
BATTERY_UUID = "0000180f-0000-1000-8000-00805f9b34fb"
BATTERY_LEVEL_UUID = "00002a19-0000-1000-8000-00805f9b34fb"
BATTERY_USER_DESC = "00002901-0000-1000-8000-00805f9b34fb"


loop = asyncio.get_event_loop()


async def main():
    bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
    # the introspection xml would normally be included in your project, but
    # this is convenient for development
    introspection = await bus.introspect(BLUEZ, BLUEZ_PATH)

    device = bus.get_proxy_object(BLUEZ, BLUEZ_PATH, introspection)

    for svc in device.child_paths:
        intp = await bus.introspect(BLUEZ, svc)
        proxy = bus.get_proxy_object(BLUEZ, svc, intp)
        intf = proxy.get_interface(GATT_SERVICE)
        if BATTERY_UUID == await intf.get_uuid():
            for char in proxy.child_paths:
                intp = await bus.introspect(BLUEZ, char)
                proxy = bus.get_proxy_object(BLUEZ, char, intp)
                intf = proxy.get_interface(GATT_CHARACTERISCITC)
                level = int.from_bytes(await intf.call_read_value({}))
                if BATTERY_LEVEL_UUID == await intf.get_uuid():
                    props = proxy.get_interface('org.freedesktop.DBus.Properties')    
                    for desc in proxy.child_paths:
                        intp = await bus.introspect(BLUEZ, desc)
                        proxy = bus.get_proxy_object(BLUEZ, desc, intp)
                        intf = proxy.get_interface(GATT_CHARACTERISCITC_DESCR)
                        name = "Main"
                        if BATTERY_USER_DESC == await intf.get_uuid():
                            name = bytearray(await intf.call_read_value({})).decode()
                    print(name + ": ", str(level))

loop.run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant