8000 Add a Bluetooth LE transport by lagnat · Pull Request #452 · inkcut/inkcut · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions inkcut/device/drivers/manifest.enaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@ def load_drivers():
return []


enamldef Cameo4Driver(DeviceDriver):
""" Silhouette Cameo 4. Variants override what differs. """
manufacturer = 'Silhouette'
model = 'Cameo 4'
width = '300cm'
length = '30.5cm'
protocols = ['gpgl']
connections = ['printer', 'ble']
default_config = {
'scale': [ 5.64, 5.64 ],
'swap_xy': True,
'mirror_x': True,
'mirror_y': True,
'connection': {
'ble': {
'service_uuid': 'e2088282-4fde-42f9-bb22-6ec3c7ed8f91',
'write_uuid': '6d92661d-f429-4d67-929b-28e7a9780912',
'read_uuid': '8dcf199a-30e7-4bd4-beb6-beb57dca866c',
'notify_uuid': '61490654-b5b4-458c-a867-9e15bc1471e0',
'name_filter': 'cameo,silhouette',
}
},
'protocol': {
'gpgl': {
'append_etx': True,
}
}
}


enamldef DriversManifest(PluginManifest):
""" Device drivers manifest.

Expand Down Expand Up @@ -136,19 +166,12 @@ enamldef DriversManifest(PluginManifest):
protocols = ['hpgl', 'gpgl']
connections = ['serial']

DeviceDriver:
manufacturer = 'Silhouette'
model = 'Cameo 4'
width = '300cm'
length = '30.5cm'
protocols = ['gpgl']
connections = ['printer']
default_config = {
'scale': [ 5.64, 5.64 ],
'swap_xy': True,
'mirror_x': True,
'mirror_y': True
}
Cameo4Driver:
pass

Cameo4Driver:
model = 'Cameo 4 Plus'
length = '38.1cm'

DeviceDriver:
manufacturer = 'Silhouette'
Expand Down
2 changes: 2 additions & 0 deletions inkcut/device/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ def start(self):
from .transports.printer.manifest import PrinterManifest
from .transports.disk.manifest import FileManifest
from .transports.parallelport.manifest import ParallelManifest
from .transports.ble.manifest import BLEManifest
from inkcut.device.protocols.manifest import ProtocolManifest
from inkcut.device.drivers.manifest import DriversManifest
from inkcut.device.filters.manifest import FiltersManifest
Expand All @@ -1099,6 +1100,7 @@ def start(self):
plugins.append(PrinterManifest)
plugins.append(FileManifest)
plugins.append(ParallelManifest)
plugins.append(BLEManifest)
plugins.append(ProtocolManifest)
plugins.append(DriversManifest)
plugins.append(FiltersManifest)
Expand Down
23 changes: 19 additions & 4 deletions inkcut/device/protocols/gpgl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,36 @@
@author: jrm
@author: lwernars
"""
from atom.api import Bool, Instance
from inkcut.core.api import Model
from inkcut.device.plugin import DeviceProtocol


class GPGLConfig(Model):
#: Terminate each command with ETX (0x03). Machines like the Cameo 4
#: do not run a command until it is terminated.
append_etx = Bool().tag(config=True)


class GPGLProtocol(DeviceProtocol):
config = Instance(GPGLConfig, ()).tag(config=True)

async def write(self, data):
if self.config.append_etx:
data += "\x03"
await super().write(data)

async def init(self):
await self.write("H")
await self.write("\x03\x03H")

async def move(self, x, y, z, absolute=True):
await self.write("%s%i,%i"%('D' if z else 'M', x, y))
await self.write("\x03%s%i,%i"%('D' if z else 'M', x, y))

async def set_velocity(self, v):
await self.write('!%i' % v)
await self.write('\x03!%i' % v)

async def set_force(self, f):
await self.write("FX%i,1" % f)
await self.write("\x03FX%i,1" % f)

async def set_pen(self, p):
pass
12 changes: 10 additions & 2 deletions inkcut/device/protocols/manifest.enaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ from inkcut.device.extensions import DEVICE_PROTOCOL_POINT, DeviceProtocol


def gpgl_factory(driver, declaration):
from .gpgl import GPGLProtocol
return GPGLProtocol(declaration=declaration)
from .gpgl import GPGLProtocol, GPGLConfig
return GPGLProtocol(declaration=declaration,
config=GPGLConfig(**driver.get_protocol_config('gpgl')))


def gpgl_config_view():
with enaml.imports():
from .view import GPGLConfigView
return GPGLConfigView


def hpgl_factory(driver, declaration):
Expand Down Expand Up @@ -74,6 +81,7 @@ enamldef ProtocolManifest(PluginManifest):
id = 'gpgl'
name = 'GPGL'
factory = gpgl_factory
config_view = gpgl_config_view

DeviceProtocol:
id = 'hpgl'
Expand Down
8 changes: 8 additions & 0 deletions inkcut/device/protocols/view.enaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,11 @@ enamldef HPGLConfigView(Container):
CheckBox:
checked := model.separate_z_moves
text = QApplication.translate("protocols", "Send pen up/down commands separately from move commands")


enamldef GPGLConfigView(Container):
attr model
CheckBox:
text = QApplication.translate("protocols", "Append ETX terminator")
checked := model.append_etx
tool_tip = QApplication.translate("protocols", "End each command with ETX (0x03). Silhouette machines do not run a command until it is terminated.")
1 change: 1 addition & 0 deletions inkcut/device/transports/ble/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
38 changes: 38 additions & 0 deletions inkcut/device/transports/ble/manifest.enaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
"""
Bluetooth LE transport manifest.
"""
import enaml
from enaml.workbench.api import Extension
from enaml.workbench.plugin_manifest import PluginManifest
from inkcut.device.extensions import DeviceTransport, DEVICE_TRANSPORT_POINT


def transport_factory(driver, declaration, protocol):
from .plugin import BLETransport, BLEConfig
config = BLEConfig(**driver.get_connection_config('ble'))
return BLETransport(declaration=declaration, protocol=protocol,
config=config)


def config_view_factory():
with enaml.imports():
from .settings import BLESettingsView
return BLESettingsView


enamldef BLEManifest(PluginManifest):
""" Talk to cutters that expose their command stream over a BLE
GATT service instead of a serial port.

"""
id = 'inkcut.device.transport.ble'
Extension:
id = 'transports'
point = DEVICE_TRANSPORT_POINT

DeviceTransport:
id = 'ble'
name = 'Bluetooth LE'
factory = transport_factory
config_view = config_view_factory
Loading
0