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
30 changes: 30 additions & 0 deletions fdserial/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Iterable
from fdserial.utils import getFreeDeckPort
from serial import Serial
from more_itertools import chunked

# you should wait (number of displays * 30ms) after a page changing command
# if you want to immediately call the api again to give the freedeck time
Expand All @@ -9,6 +10,8 @@
commands = {
"init": 0x3,
"getFirmwareVersion": 0x10,
"readConfig": 0x20,
"writeConfig": 0x21,
"getCurrentPage": 0x30,
"setCurrentPage": 0x31,
"getPageCount": 0x32
Expand Down Expand Up @@ -69,3 +72,30 @@ def setCurrentPage(self, page: int):

def getPageCount(self):
return int(self.readWrite([commands['init'], commands['getPageCount']]))

def readConfig(self, filename):
configSizeStr = self.readWrite([commands['init'], commands['readConfig']])
configSize = int(configSizeStr)

configData = self.freedeck.read(configSize)

with open(filename, "wb") as configFile:
configFile.write(configData)

return configSize

def writeConfig(self, filename):
with open(filename, "rb") as configFile:
configData = configFile.read()

configFileSize = len(configData)

self.writeOnly([commands['init'],
commands['writeConfig'],
self.intToAsciiVal(configFileSize)])

# Every 4KiB of data, the firmware sends back over the number of bytes
# received.
for chunk in chunked(configData, 4096):
self.freedeck.write(chunk)
bytes_received = self.freedeck.read_all()
8 changes: 6 additions & 2 deletions fdserial/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/python3
import os
import serial.tools.list_ports


def execBash(command):
Expand All @@ -14,8 +15,11 @@ def binaryToString(binary):


def findFreeDeckDeviceWin():
return "COM14" # automate this

ports = serial.tools.list_ports.comports()
for port, desc, hwid in sorted(ports):
if ("2341:8037" in hwid) or ("f1f0:4005" in hwid):
return port
raise Exception('no device found')

def findFreeDeckDeviceLinux():
import subprocess
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
packages=["fdserial"],
include_package_data=True,
install_requires=["pyserial==3.5"],
install_requires=["pyserial==3.5", "more-itertools==8.12.0"],
entry_points={
"console_scripts": [
"fdserialtest=fdserial.__main__:main",
Expand Down