6 Commits
Author SHA1 Message Date
MrBlake 5b526ab5f5 Release v0.1.2 2026-10-23 21:29:30 +02:00
MrBlakeandClaude Opus 5.5 ea88e87a3d Send the LED list with every lighting effect
Most hardware effects (color wave, shift, pulse, rain, watercolor,
typing, visor) only run on the LEDs listed after the colors. Without
the list they lit nothing. Add the K65 PLUS LED indices (US/ISO/UK)
and always send the color count, so random-color effects get the
right layout too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 21:29:30 +02:00
MrBlake 2a12166615 Release v0.1.1 2026-10-23 21:15:47 +02:00
MrBlakeandClaude Opus 5.5 d0fd799aeb Fix keyboard always shown as asleep
Replies carry the target as an index (0x08 -> 0x00, 0x09 -> 0x01),
not the target byte itself, so every reply was discarded. Also put the
receiver into software mode before reading its pairing list and read
firmware and serial independently.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 21:15:47 +02:00
MrBlakeandClaude Opus 5.5 a483d6226d release.sh: push with the Gitea token
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 21:11:39 +02:00
MrBlakeandClaude Opus 5.5 133b80c83b Add pacman packaging and Gitea release script
PKGBUILD builds from the release tag and ships the udev rule;
packaging/release.sh tags, pushes, builds and publishes a release.
Keep .gitea-token out of git.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 21:11:29 +02:00
9 changed files with 166 additions and 31 deletions

No files matched your search

+1
View File
@@ -1,2 +1,3 @@
__pycache__/ __pycache__/
*.pyc *.pyc
.gitea-token
+17 -7
View File
@@ -8,17 +8,17 @@ Entwickelt unter CachyOS für den Slipstream-Empfänger `1b1c:2b07`.
## Installation ## Installation
Paket aus den [Releases](https://git.mrblake.cc/MrBlake/CosairRGBforCachy/releases) laden und installieren:
```sh ```sh
sudo pacman -S --needed pyside6 # falls noch nicht vorhanden sudo pacman -U k65studio-<version>-1-any.pkg.tar.zst
./install.sh
``` ```
`install.sh` installiert die App nach `~/.local/share/k65studio`, einen Starter `k65studio` und Das Paket bringt die udev-Regel mit, sodass dein Benutzer ohne Root-Rechte auf die Tastatur
einen Menüeintrag. Außerdem richtet es (mit `sudo`) die udev-Regel zugreifen darf. Danach im Startmenü **K65 Studio** öffnen.
`/etc/udev/rules.d/60-k65studio.rules` ein, damit dein Benutzer ohne Root-Rechte auf die
Tastatur zugreifen darf.
Ohne Installation direkt aus dem Repository starten (die udev-Regel muss trotzdem installiert sein): Alternativ ohne Paket: `./install.sh` installiert nach `~/.local` und richtet die udev-Regel mit
`sudo` ein. Oder direkt aus dem Repository starten (udev-Regel muss installiert sein):
```sh ```sh
python3 -m k65studio python3 -m k65studio
@@ -59,6 +59,16 @@ python3 -m unittest discover -s tests
python3 -m k65studio --debug python3 -m k65studio --debug
``` ```
## Release
```sh
packaging/release.sh 0.2.0 # --prerelease für Vorabversionen
```
Setzt die Version, taggt `v0.2.0`, pusht, baut das pacman-Paket aus dem Tag und legt ein
Gitea-Release mit Paket und `PKGBUILD` an. Der API-Token kommt aus `.gitea-token` (nicht
eingecheckt) oder `$GITEA_TOKEN`.
## Lizenz ## Lizenz
GPL-3.0-or-later GPL-3.0-or-later
+1 -1
View File
@@ -1 +1 @@
__version__ = "0.1.0" __version__ = "0.1.2"
+17 -10
View File
@@ -144,19 +144,26 @@ class Rgb:
LIGHTING_BLOCK_SIZE = 96 LIGHTING_BLOCK_SIZE = 96
# LEDs of the K65 PLUS (US, ISO and UK layouts). The index equals the key's HID usage,
# except the space bar, which has three LEDs (0, 1, 44).
K65_LEDS = bytes([
0, 1, *range(4, 70), 74, 75, 76, *range(78, 83), 100, 105, 106, 107, 108, 109, 110, 111, 122,
])
def lighting_packets(target: int, effect: int, color_mode: int = COLORS_NONE, speed: int = 0, def lighting_packets(target: int, effect: int, color_mode: int = COLORS_NONE, speed: int = 0,
direction: int = 0, colors: list[Rgb] | tuple[Rgb, ...] = ()) -> list[bytes]: direction: int = 0, colors: list[Rgb] | tuple[Rgb, ...] = (),
"""Hardware lighting effect: id, color mode, speed, direction, then colors as (A, B, G, R).""" leds: bytes = K65_LEDS) -> list[bytes]:
"""Hardware lighting effect: id, color mode, speed, direction, colors as (A, B, G, R),
then the LEDs the effect runs on. Without the LED list most effects light nothing."""
body = bytearray(struct.pack("<H", effect)) body = bytearray(struct.pack("<H", effect))
body += bytes([color_mode, speed, direction, 0x00]) body += bytes([color_mode, speed, direction, 0x00, len(colors)])
if colors: for c in colors:
body.append(len(colors)) body += bytes([0xFF, c.b, c.g, c.r])
for c in colors: body += bytes([len(leds)]) + leds
body += bytes([0xFF, c.b, c.g, c.r]) body = body.ljust(LIGHTING_BLOCK_SIZE, b"\x00")
# Same declared lengths OpenLinkHub uses; everything past the colors is zero padding. # The length excludes the effect id and color mode (93 for a plain static color).
declared = 93 if effect == FX_STATIC else 89 return block_packets(target, bytes(body), len(body) - 3)
return block_packets(target, bytes(body.ljust(LIGHTING_BLOCK_SIZE, b"\x00")), declared)
def parse_u16(resp: bytes, offset: int = 3) -> int: def parse_u16(resp: bytes, offset: int = 3) -> int:
+10 -6
View File
@@ -62,7 +62,8 @@ class Transport:
deadline = time.monotonic() + timeout deadline = time.monotonic() + timeout
while (left := deadline - time.monotonic()) > 0: while (left := deadline - time.monotonic()) > 0:
resp = self.dev.read(left) resp = self.dev.read(left)
if resp and resp[0] == pkt[0] and resp[1] == pkt[1]: # Replies carry the target as an index (0x08 -> 0, 0x09 -> 1) and echo the command.
if resp and resp[0] == pkt[0] & 0x07 and resp[1] == pkt[1]:
return resp return resp
raise DeviceError(f"no response to {pkt[:4].hex(' ')}") raise DeviceError(f"no response to {pkt[:4].hex(' ')}")
@@ -256,11 +257,14 @@ class DeviceService:
self._h = _Handles(transport, notify, Keyboard(transport, target), receiver) self._h = _Handles(transport, notify, Keyboard(transport, target), receiver)
self._set(receiver=True, wireless=wireless, error="") self._set(receiver=True, wireless=wireless, error="")
if receiver: if receiver:
try: # Software mode first: the receiver refuses the pairing list in hardware mode.
self._set(receiver_firmware=receiver.firmware(), serial=self._paired_serial()) for step in (lambda: receiver.set_mode(bragi.MODE_SOFTWARE),
receiver.set_mode(bragi.MODE_SOFTWARE) lambda: self._set(receiver_firmware=receiver.firmware()),
except DeviceError as e: lambda: self._set(serial=self._paired_serial())):
log.warning("receiver init: %s", e) try:
step()
except DeviceError as e:
log.warning("receiver init: %s", e)
self._init_keyboard() self._init_keyboard()
return True return True
+32
View File
@@ -0,0 +1,32 @@
# Maintainer: Louis <[email protected]>
pkgname=k65studio
pkgver=0.1.2
pkgrel=1
pkgdesc="Beleuchtung, Spielmodus, Akku und Profile für die Corsair K65 PLUS Wireless"
arch=('any')
url="https://git.mrblake.cc/MrBlake/CosairRGBforCachy"
license=('GPL-3.0-or-later')
depends=('python' 'pyside6')
makedepends=('git')
install=$pkgname.install
source=("$pkgname::git+$url.git#tag=v$pkgver")
sha256sums=('SKIP')
package() {
cd "$srcdir/$pkgname"
install -d "$pkgdir/usr/share/$pkgname"
cp -r k65studio "$pkgdir/usr/share/$pkgname/"
find "$pkgdir/usr/share/$pkgname" -name __pycache__ -prune -exec rm -rf {} +
python -m compileall -q -d "/usr/share/$pkgname" "$pkgdir/usr/share/$pkgname"
install -Dm755 /dev/stdin "$pkgdir/usr/bin/$pkgname" <<EOF
#!/bin/sh
PYTHONPATH="/usr/share/$pkgname\${PYTHONPATH:+:\$PYTHONPATH}" exec python3 -m k65studio "\$@"
EOF
install -Dm644 packaging/60-k65studio.rules "$pkgdir/usr/lib/udev/rules.d/60-k65studio.rules"
install -Dm644 packaging/k65studio.desktop "$pkgdir/usr/share/applications/k65studio.desktop"
install -Dm644 k65studio/assets/k65studio.svg "$pkgdir/usr/share/icons/hicolor/scalable/apps/k65studio.svg"
install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
+8
View File
@@ -0,0 +1,8 @@
post_install() {
udevadm trigger --subsystem-match=hidraw 2>/dev/null || true
echo "K65 Studio: Falls die Tastatur nicht erkannt wird, den Empfänger einmal neu einstecken."
}
post_upgrade() {
post_install
}
+64
View File
@@ -0,0 +1,64 @@
#!/bin/sh
# Usage: packaging/release.sh <version> [--prerelease]
# Bumps the version, tags v<version>, pushes, builds the pacman package from that tag and
# publishes a Gitea release with the package and PKGBUILD attached.
# Token: $GITEA_TOKEN or the file .gitea-token in the repository root.
set -eu
VERSION="${1:?Version angeben, z.B. packaging/release.sh 0.2.0}"
PRERELEASE=false
[ "${2:-}" = "--prerelease" ] && PRERELEASE=true
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
API="https://git.mrblake.cc/api/v1/repos/MrBlake/CosairRGBforCachy"
TOKEN="${GITEA_TOKEN:-$(cat .gitea-token 2>/dev/null || true)}"
[ -n "$TOKEN" ] || { echo "Kein Token (.gitea-token oder GITEA_TOKEN)"; exit 1; }
[ -z "$(git status --porcelain)" ] || { echo "Arbeitsverzeichnis nicht sauber"; exit 1; }
[ "$(git branch --show-current)" = "main" ] || { echo "Nicht auf main"; exit 1; }
git rev-parse -q --verify "refs/tags/v$VERSION" >/dev/null && { echo "Tag v$VERSION existiert schon"; exit 1; }
python3 -m unittest discover -s tests -q
PREV_TAG="$(git describe --tags --abbrev=0 2>/dev/null || true)"
NOTES="$(git log --no-merges --pretty='- %s' ${PREV_TAG:+$PREV_TAG..}HEAD)"
sed -i "s/^__version__ = .*/__version__ = \"$VERSION\"/" k65studio/__init__.py
sed -i "s/^pkgver=.*/pkgver=$VERSION/; s/^pkgrel=.*/pkgrel=1/" packaging/PKGBUILD
git diff --quiet || git commit -qam "Release v$VERSION"
git tag -a "v$VERSION" -m "v$VERSION"
AUTH="$(printf 'MrBlake:%s' "$TOKEN" | base64 -w0)"
git -c http.extraHeader="Authorization: Basic $AUTH" push -q origin main "v$VERSION"
BUILD="$(mktemp -d)"
trap 'rm -rf "$BUILD"' EXIT
cp packaging/PKGBUILD packaging/k65studio.install "$BUILD/"
(cd "$BUILD" && PKGDEST="$BUILD/out" makepkg -f --nodeps --noconfirm >/dev/null)
PKG="$(ls "$BUILD"/out/*.pkg.tar.zst)"
BODY="$(python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))' <<EOF
## Installation
\`\`\`sh
sudo pacman -U $(basename "$PKG")
\`\`\`
Danach im Startmenü **K65 Studio** öffnen. Die udev-Regel wird mitinstalliert.
## Änderungen
$NOTES
EOF
)"
RELEASE_ID="$(curl -sf -X POST "$API/releases" \
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
-d "{\"tag_name\": \"v$VERSION\", \"name\": \"K65 Studio $VERSION\", \"body\": $BODY, \"prerelease\": $PRERELEASE}" \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')"
for f in "$PKG" packaging/PKGBUILD; do
curl -sf -X POST "$API/releases/$RELEASE_ID/assets?name=$(basename "$f")" \
-H "Authorization: token $TOKEN" -F "attachment=@$f" >/dev/null
done
echo "Release v$VERSION veröffentlicht: https://git.mrblake.cc/MrBlake/CosairRGBforCachy/releases/tag/v$VERSION"
+16 -7
View File
@@ -6,27 +6,36 @@ from k65studio.profiles import Config, Profile
class PacketTests(unittest.TestCase): class PacketTests(unittest.TestCase):
def test_static_color_matches_known_good_capture(self): def test_static_color(self):
pkts = effects.encode(bragi.TARGET_PAIRED, "static", ["#ff0080"], False, "medium") pkts = effects.encode(bragi.TARGET_PAIRED, "static", ["#ff0080"], False, "medium")
self.assertEqual(len(pkts), 2) self.assertEqual(len(pkts), 2)
self.assertEqual(pkts[0][:15].hex(" "), "09 06 01 5d 00 00 00 7e 20 01 00 00 00 01 ff") self.assertEqual(pkts[0][:7].hex(" "), "09 06 01 5e 00 00 00") # 97 byte body - 3
self.assertEqual(pkts[0][15:18], bytes([0x80, 0x00, 0xFF])) # B, G, R self.assertEqual(pkts[0][7:14].hex(" "), "7e 20 01 00 00 00 01")
self.assertEqual(pkts[0][14:18], bytes([0xFF, 0x80, 0x00, 0xFF])) # A, B, G, R
self.assertEqual(pkts[0][18], len(bragi.K65_LEDS))
self.assertEqual(pkts[1][:3], bytes([0x09, 0x07, 0x01])) self.assertEqual(pkts[1][:3], bytes([0x09, 0x07, 0x01]))
def test_rainbow_wave_header(self): def test_rainbow_wave_header(self):
pkt = effects.encode(bragi.TARGET_PAIRED, "rainbow_wave", [], False, "fast")[0] pkt = effects.encode(bragi.TARGET_PAIRED, "rainbow_wave", [], False, "fast")[0]
self.assertEqual(pkt[3:12].hex(" "), "59 00 00 00 4c b9 00 05 04") self.assertEqual(pkt[7:14].hex(" "), "4c b9 00 05 04 00 00")
self.assertEqual(pkt[14], len(bragi.K65_LEDS))
def test_random_colors_have_no_color_list(self): def test_random_colors_have_no_color_list(self):
pkt = effects.encode(bragi.TARGET_PAIRED, "color_shift", ["#ffffff"], True, "slow")[0] pkt = effects.encode(bragi.TARGET_PAIRED, "color_shift", ["#ffffff"], True, "slow")[0]
self.assertEqual(pkt[7:13].hex(" "), "fa a5 02 03 00 00") self.assertEqual(pkt[7:14].hex(" "), "fa a5 02 03 00 00 00")
self.assertEqual(pkt[13], 0) self.assertEqual(pkt[14], len(bragi.K65_LEDS))
def test_two_specific_colors(self): def test_two_specific_colors_then_leds(self):
pkt = effects.encode(bragi.TARGET_PAIRED, "color_pulse", ["#010203", "#040506"], False, "medium")[0] pkt = effects.encode(bragi.TARGET_PAIRED, "color_pulse", ["#010203", "#040506"], False, "medium")[0]
self.assertEqual(pkt[9], bragi.COLORS_SPECIFIC) self.assertEqual(pkt[9], bragi.COLORS_SPECIFIC)
self.assertEqual(pkt[13], 2) self.assertEqual(pkt[13], 2)
self.assertEqual(pkt[14:22], bytes([0xFF, 3, 2, 1, 0xFF, 6, 5, 4])) self.assertEqual(pkt[14:22], bytes([0xFF, 3, 2, 1, 0xFF, 6, 5, 4]))
self.assertEqual(pkt[22], len(bragi.K65_LEDS))
self.assertEqual(pkt[23:26], bytes([0, 1, 4]))
def test_led_list_covers_all_layouts(self):
self.assertEqual(len(bragi.K65_LEDS), 85)
self.assertEqual(len(set(bragi.K65_LEDS)), 85)
def test_packets_fit_report(self): def test_packets_fit_report(self):
for key in effects.EFFECTS: for key in effects.EFFECTS: