Skip to content

Instantly share code, notes, and snippets.

@stecman
stecman / _readme.md
Last active July 4, 2024 12:24
Brother P-Touch PT-P300BT bluetooth driver python

Controlling the Brother P-Touch Cube label maker from a computer

The Brother PTP300BT label maker is intended to be controlled using the official Brother P-Touch Design & Print iOS/Android app. The app has arbitrary limits on what you can print (1 text object and up to 3 preset icons), so I thought it would be a fun challenge to reverse engineer the protocol to print whatever I wanted.

Python code at the bottom if you want to skip the fine details.

Process

Intitially I had a quick peek at the Android APK to see if there was any useful information inside. The code that handles the communication with the printer in Print&Design turned out to be a native library, but the app clearly prepares a bitmap image and passes it to this native library for printing. Bitmaps are definitely something we can work with.

@wickman
wickman / rformat.py
Created November 20, 2015 00:09
recursive version of python str.format
from string import Formatter
class RecursiveFormatter(Formatter):
def _contains_underformatted_field_names(self, format_tuple):
literal_text, field_name, format_spec, conversion = format_tuple
if field_name is not None:
return any(component[1] is not None for component in self.parse(field_name))
return False
@liuw
liuw / ctype_async_raise.py
Created April 17, 2012 16:02
Nasty hack to raise exception for other threads
#!/usr/bin/env python
# liuw
# Nasty hack to raise exception for other threads
import ctypes # Calm down, this has become standard library since 2.5
import threading
import time
NULL = 0