Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed user_id from config #69

Merged
merged 2 commits into from
Oct 30, 2023
Merged
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Config options:
| Option | Description | Default |
| -------------------- | -------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| `mac_address` | The MAC address (or UUID on MacOS) of the desk. This is required. | |
| `user_id` | The user ID (in hex) to use when connecting to the desk. This should not need to be changed. | `01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11` |
| `base_height` | The lowest possible height (mm) of the desk top from the floor. | `620`. |
| `movement_range` | How far above base height the desk can extend (mm). | `650`. |
| `adapter_name` | The adapter name for the bluetooth adapter to use for the connection (Linux only). | `hci0` |
Expand Down
7 changes: 0 additions & 7 deletions idasen_controller/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Commands(str, Enum):
class Config:
# Config
mac_address: Optional[str] = None
user_id: str = "01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11"
base_height: int = DEFAULT_BASE_HEIGHT
max_height: int = DEFAULT_BASE_HEIGHT + DEFAULT_MOVEMENT_RANGE
movement_range: int = DEFAULT_MOVEMENT_RANGE
Expand Down Expand Up @@ -70,12 +69,6 @@ def __init__(self):
type=str,
help="Mac address of the Linak desk",
)
parser.add_argument(
"--user-id",
dest="user_id",
type=str,
help="User ID to use when connecting to the desk",
)
parser.add_argument(
"--base-height",
dest="base_height",
Expand Down
38 changes: 24 additions & 14 deletions idasen_controller/desk.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,34 @@
)
from .config import config
from .util import bytes_to_hex, Height, Speed
import struct


class Desk:
@classmethod
async def initialise(cls, client: BleakClient) -> None:
# Read the user id

# Read capabilities
capabilities = cls.decode_capabilities(await DPGService.dpg_command(client, DPGService.DPG.CMD_GET_CAPABILITIES))
print("Capabilities: {}".format(capabilities))

user_id = (await DPGService.dpg_command(client, DPGService.DPG.CMD_USER_ID))[2:]
user_id_hex = bytes_to_hex(user_id)
print("User ID: {}".format(user_id_hex))
if user_id_hex != config.user_id:
print("Setting user ID to".format(config.user_id))
await DPGService.dpg_command(client, DPGService.DPG.CMD_USER_ID, bytearray.fromhex(config.user_id))


# Read the user id
user_id = (await DPGService.dpg_command(client, DPGService.DPG.CMD_USER_ID))
print("User ID: {}".format(bytes_to_hex(user_id)))
if user_id and user_id[0] != 1:
# Set user_id to more privileged
user_id[0] = 1
print("Setting user ID to {}".format(bytes_to_hex(user_id)))
await DPGService.dpg_command(client, DPGService.DPG.CMD_USER_ID, user_id)

# Check if base height should be taken from controller
if config.base_height == 0:
resp = (await DPGService.dpg_command(client, DPGService.DPG.CMD_BASE_OFFSET))
if resp:
base_height = struct.unpack("<H", resp[1:])[0]
print("base_height taken from controller {}".format(base_height))
config.base_height = base_height/10
config.max_height = config.base_height + config.movement_range



@classmethod
Expand All @@ -44,8 +55,8 @@ async def move_to(cls, client: BleakClient, target: Height) -> None:
if initial_height.value == target.value:
return

await ControlService.wakeup(client)
await ControlService.stop(client)
await cls.wakeup(client)
await cls.stop(client)

data = ReferenceInputService.encode_height(target.value)

Expand Down Expand Up @@ -86,8 +97,7 @@ async def stop(cls, client: BleakClient) -> None:
pass

@classmethod
def decode_capabilities(cls, data: bytearray) -> dict:
caps = data[2:]
def decode_capabilities(cls, caps: bytearray) -> dict:
if len(caps) < 2:
return {}
capByte = caps[0]
Expand Down
1 change: 0 additions & 1 deletion idasen_controller/example/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mac_address: AA:AA:AA:AA:AA:AA
user_id: "01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11"
scan_timeout: 5
connection_timeout: 10
movement_timeout: 30
Expand Down
7 changes: 6 additions & 1 deletion idasen_controller/gatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class DPGDPGCharacteristic(Characteristic):
uuid = "99fa0011-338a-1024-8a49-009c0215f78a"

CMD_GET_CAPABILITIES = 128
CMD_BASE_OFFSET = 129
CMD_USER_ID = 134

@classmethod
Expand Down Expand Up @@ -202,4 +203,8 @@ async def dpg_command(
await cls.DPG.read_command(client, command)
async for sender, data in iter:
# Return the first response from the callback
return data
if data[0] == 1:
return data[2:]
else:
return None