Code de-clutter
This commit is contained in:
parent
e82ecadbb3
commit
1e267dbdb6
4 changed files with 6 additions and 21 deletions
|
|
@ -2,7 +2,7 @@
|
|||
Gicisky - A Python library for interacting with Gicisky electronic ink display tags.
|
||||
"""
|
||||
|
||||
__version__ = "0.1.0"
|
||||
__version__ = "0.1.1"
|
||||
__author__ = "MassiveBox"
|
||||
__email__ = "box@massive.box"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,20 +5,13 @@ from typing import Optional
|
|||
from ble.interface import BLEInterface, Advertisement
|
||||
from logger.logger import GiciskyLogger, LogCategory
|
||||
|
||||
# Default UUIDs for Gicisky tags
|
||||
BASE_SERVICE = 0xFEF0
|
||||
SERVICE_UUID = f"0000{BASE_SERVICE:04x}-0000-1000-8000-00805f9b34fb"
|
||||
CHAR_CMD_UUID = f"0000{BASE_SERVICE+1:04x}-0000-1000-8000-00805f9b34fb"
|
||||
CHAR_IMG_UUID = f"0000{BASE_SERVICE+2:04x}-0000-1000-8000-00805f9b34fb"
|
||||
|
||||
# Constants
|
||||
CHUNK_SIZE = 240 # 480 hex chars (as seen in the JS uploader)
|
||||
MTU_WAIT = 0.03 # delay between chunks (adjustable)
|
||||
DEBUG = True
|
||||
|
||||
def log(msg):
|
||||
if DEBUG:
|
||||
print(f"[LOG] {msg}", flush=True)
|
||||
CHUNK_SIZE = 240
|
||||
MTU_WAIT = 0.03
|
||||
|
||||
class GiciskyProtocol:
|
||||
|
||||
|
|
@ -42,6 +35,7 @@ class GiciskyProtocol:
|
|||
self.logger.info("Starting image upload", LogCategory.DATA_TRANSFER)
|
||||
await self.send_command(3)
|
||||
elif hx.startswith("05"):
|
||||
# Image upload loop
|
||||
self.logger.debug(f"Handling response: {hx}, err: {hx[2:4]}, part: {hx[4:12]}", LogCategory.NOTIFICATION)
|
||||
err = hx[2:4]
|
||||
if err == "00": # continue sending chunks
|
||||
|
|
|
|||
|
|
@ -66,27 +66,21 @@ def convert_to_gicisky_bytes(img: Image.Image, model: ModelId, lum_threshold: in
|
|||
Returns:
|
||||
bytes: Processed image data in Gicisky format
|
||||
"""
|
||||
# Get device specifications
|
||||
|
||||
specs = DEVICE_SPECS.get(model)
|
||||
if not specs:
|
||||
raise ValueError("Unknown model")
|
||||
|
||||
width, height = specs.size
|
||||
|
||||
# Resize image to device dimensions
|
||||
img = img.convert("RGB").resize((width, height), Image.Resampling.LANCZOS)
|
||||
|
||||
# Apply TFT transformation if enabled
|
||||
if specs.tft:
|
||||
# Resize to half width and double height
|
||||
img = img.resize((width // 2, height * 2), Image.Resampling.LANCZOS)
|
||||
width, height = img.size
|
||||
|
||||
# Apply mirroring if enabled
|
||||
if specs.mirror:
|
||||
img = img.transpose(Image.FLIP_TOP_BOTTOM)
|
||||
|
||||
# Convert to numpy array
|
||||
arr = np.array(img)
|
||||
|
||||
# Process pixels - column-major order
|
||||
|
|
@ -99,7 +93,6 @@ def convert_to_gicisky_bytes(img: Image.Image, model: ModelId, lum_threshold: in
|
|||
r, g, b = arr[y, x] # Note: numpy uses [y, x] indexing
|
||||
luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||
|
||||
# Apply thresholding based on compression setting
|
||||
if specs.compression:
|
||||
# When compression is enabled, dark pixels set bits
|
||||
if luminance < lum_threshold:
|
||||
|
|
@ -125,7 +118,6 @@ def convert_to_gicisky_bytes(img: Image.Image, model: ModelId, lum_threshold: in
|
|||
byte_data.append(current_byte)
|
||||
red_byte_data.append(current_red_byte)
|
||||
|
||||
# Apply compression if enabled
|
||||
if specs.compression:
|
||||
byte_data_compressed = _apply_compression(byte_data, red_byte_data, width, height, specs.second_color)
|
||||
else:
|
||||
|
|
@ -156,7 +148,6 @@ def _apply_compression(byte_data: List[int], red_byte_data: List[int],
|
|||
byte_per_line = height // 8
|
||||
current_pos = 0
|
||||
|
||||
# Process black/white data
|
||||
for i in range(width):
|
||||
# Add line header
|
||||
byte_data_compressed.extend([
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -8,7 +8,7 @@ with open("requirements.txt", "r", encoding="utf-8") as fh:
|
|||
|
||||
setup(
|
||||
name="gicisky",
|
||||
version="0.1.0",
|
||||
version="0.1.1",
|
||||
author="MassiveBox",
|
||||
author_email="box@massive.box",
|
||||
description="A Python library for interacting with Gicisky E-Ink display tags via Bluetooth Low Energy",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue