brilliant-monocle-driver


Namebrilliant-monocle-driver JSON
Version 0.1.3 PyPI version JSON
download
home_page
SummaryA driver to connect to and control a Brilliant Labs Monocle peripheral
upload_time2023-04-04 00:01:13
maintainer
docs_urlNone
author
requires_python>=3.9
licenseISC Licence Copyright © 2023 Mark T. Tomczak Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
keywords brilliant labs ar bluetooth
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Brilliant Monocle Driver

`brilliant-monocle-driver` is a simple Python library that uses
[Bleak](https://github.com/hbldh/bleak) to connect to and control a [Brilliant Labs Monocle](https://www.brilliantmonocle.com/) display device.

# Install

`pip install brilliant-monocle-driver`


# Usage examples

## Display battery and then blank screen

``` Python
import asyncio
from brilliant_monocle_driver import Monocle

def callback(channel, text_in):
  """
  Callback to handle incoming text from the Monocle.
  """
  print(text_in)

# Simple MicroPython command that prints battery level for five seconds
# and then blanks the screen
COMMAND = """
import display
import device
import time
from brilliant_monocle_driver import Monocle

def show_battery(count):
  batLvl = str(device.battery_level())
  display.fill(0x000066)
  display.text("bat: {} {}".format(batLvl, count), 5, 5, 0xffffff)
  display.show()

count = 0
while (count < 5):
  show_battery(count)
  time.sleep(1)
  count += 1

display.fill(0x000000)
display.show()

print("Done")

"""

async def execute():
    mono = Monocle(callback)
    async with mono:
        await mono.send(COMMAND)

asyncio.run(execute())

```

## Receive touch events

```Python
import asyncio
from brilliant_monocle_driver import Monocle

def a_touch():
    print("A touch!")

def b_touch():
    print("B touch!")

async def execute():
    mono = Monocle()
    async with mono:
        await mono.install_touch_events()
        mono.set_a_touch_callback(a_touch)
        mono.set_b_touch_callback(b_touch)
        await asyncio.sleep(30000)

asyncio.run(execute())
```

# Details

`brilliant-monocle-driver` attaches to a Monocle via the UART characteristics exposed over
BLE in Monocle's default firmware, as specified in the
[Monocle documentation](https://docs.brilliantmonocle.com/micropython/micropython/#under-the-hood). Once
connection is established, commands can be sent directly to the Monocle as
MicroPython. The driver avoids MTU overflow and does some convenience /
correction massaging (sending `Ctrl-C` to stop any running command and wrapping
the incoming command in `Ctrl-A | Ctrl-D` to avoid interference from the REPL's
echo and auto-formatting convenience behaviors).


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "brilliant-monocle-driver",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "Brilliant Labs,AR,Bluetooth",
    "author": "",
    "author_email": "\"Mark T. Tomczak\" <iam@fixermark.com>",
    "download_url": "https://files.pythonhosted.org/packages/05/e3/5b295b81c0e5fa5c7a6785b71000dab4acd1f014c9ed13cd862a1ff45fe6/brilliant-monocle-driver-0.1.3.tar.gz",
    "platform": null,
    "description": "# Brilliant Monocle Driver\n\n`brilliant-monocle-driver` is a simple Python library that uses\n[Bleak](https://github.com/hbldh/bleak) to connect to and control a [Brilliant Labs Monocle](https://www.brilliantmonocle.com/) display device.\n\n# Install\n\n`pip install brilliant-monocle-driver`\n\n\n# Usage examples\n\n## Display battery and then blank screen\n\n``` Python\nimport asyncio\nfrom brilliant_monocle_driver import Monocle\n\ndef callback(channel, text_in):\n  \"\"\"\n  Callback to handle incoming text from the Monocle.\n  \"\"\"\n  print(text_in)\n\n# Simple MicroPython command that prints battery level for five seconds\n# and then blanks the screen\nCOMMAND = \"\"\"\nimport display\nimport device\nimport time\nfrom brilliant_monocle_driver import Monocle\n\ndef show_battery(count):\n  batLvl = str(device.battery_level())\n  display.fill(0x000066)\n  display.text(\"bat: {} {}\".format(batLvl, count), 5, 5, 0xffffff)\n  display.show()\n\ncount = 0\nwhile (count < 5):\n  show_battery(count)\n  time.sleep(1)\n  count += 1\n\ndisplay.fill(0x000000)\ndisplay.show()\n\nprint(\"Done\")\n\n\"\"\"\n\nasync def execute():\n    mono = Monocle(callback)\n    async with mono:\n        await mono.send(COMMAND)\n\nasyncio.run(execute())\n\n```\n\n## Receive touch events\n\n```Python\nimport asyncio\nfrom brilliant_monocle_driver import Monocle\n\ndef a_touch():\n    print(\"A touch!\")\n\ndef b_touch():\n    print(\"B touch!\")\n\nasync def execute():\n    mono = Monocle()\n    async with mono:\n        await mono.install_touch_events()\n        mono.set_a_touch_callback(a_touch)\n        mono.set_b_touch_callback(b_touch)\n        await asyncio.sleep(30000)\n\nasyncio.run(execute())\n```\n\n# Details\n\n`brilliant-monocle-driver` attaches to a Monocle via the UART characteristics exposed over\nBLE in Monocle's default firmware, as specified in the\n[Monocle documentation](https://docs.brilliantmonocle.com/micropython/micropython/#under-the-hood). Once\nconnection is established, commands can be sent directly to the Monocle as\nMicroPython. The driver avoids MTU overflow and does some convenience /\ncorrection massaging (sending `Ctrl-C` to stop any running command and wrapping\nthe incoming command in `Ctrl-A | Ctrl-D` to avoid interference from the REPL's\necho and auto-formatting convenience behaviors).\n\n",
    "bugtrack_url": null,
    "license": "ISC Licence  Copyright \u00a9 2023 Mark T. Tomczak  Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.  THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.",
    "summary": "A driver to connect to and control a Brilliant Labs Monocle peripheral",
    "version": "0.1.3",
    "split_keywords": [
        "brilliant labs",
        "ar",
        "bluetooth"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae5019eb4dac188b5b25eb0b94ac3af2d42a5f56544120b9e66e62865d6ef3be",
                "md5": "3701aef9f3599634f93088841126ee56",
                "sha256": "6b8fd210fdb33d35fd19e4839fcb0459d8802e6db33a7575009919abb8b41bf9"
            },
            "downloads": -1,
            "filename": "brilliant_monocle_driver-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3701aef9f3599634f93088841126ee56",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7139,
            "upload_time": "2023-04-04T00:01:11",
            "upload_time_iso_8601": "2023-04-04T00:01:11.716084Z",
            "url": "https://files.pythonhosted.org/packages/ae/50/19eb4dac188b5b25eb0b94ac3af2d42a5f56544120b9e66e62865d6ef3be/brilliant_monocle_driver-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "05e35b295b81c0e5fa5c7a6785b71000dab4acd1f014c9ed13cd862a1ff45fe6",
                "md5": "31ea9c0e8a5b23f1a4c8737b14ea05db",
                "sha256": "cda6261cd24d896820ab764a02ca2c603a9cdad930cd9037989073ba7dace516"
            },
            "downloads": -1,
            "filename": "brilliant-monocle-driver-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "31ea9c0e8a5b23f1a4c8737b14ea05db",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 6299,
            "upload_time": "2023-04-04T00:01:13",
            "upload_time_iso_8601": "2023-04-04T00:01:13.349144Z",
            "url": "https://files.pythonhosted.org/packages/05/e3/5b295b81c0e5fa5c7a6785b71000dab4acd1f014c9ed13cd862a1ff45fe6/brilliant-monocle-driver-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-04 00:01:13",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "brilliant-monocle-driver"
}
        
Elapsed time: 0.46745s