Skip to content

Commit 441e81e

Browse files
committed
wakeup time command
1 parent fabc814 commit 441e81e

3 files changed

Lines changed: 107 additions & 0 deletions

File tree

software/script/chameleon_cli_unit.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3473,6 +3473,75 @@ def on_exec(self, args: argparse.Namespace):
34733473
print(AnimationMode(self.cmd.get_animation_mode()))
34743474

34753475

3476+
@hw_settings.group('wakeuptime')
3477+
class HWSettingsWakeupTime(DeviceRequiredUnit):
3478+
def args_parser(self) -> ArgumentParserNoExit:
3479+
parser = ArgumentParserNoExit()
3480+
return parser
3481+
3482+
def on_exec(self, args: argparse.Namespace):
3483+
# Show help if no subcommand is provided
3484+
self.args_parser().print_help()
3485+
3486+
3487+
@HWSettingsWakeupTime.command('button')
3488+
class HWSettingsWakeupTimeButton(DeviceRequiredUnit):
3489+
def args_parser(self) -> ArgumentParserNoExit:
3490+
parser = ArgumentParserNoExit()
3491+
parser.description = 'Get or set the button wake-up time (1000-60000 ms)'
3492+
parser.add_argument('-s', '--set', type=int, required=False,
3493+
help='Set wake-up time in milliseconds (1000-60000)')
3494+
return parser
3495+
3496+
def on_exec(self, args: argparse.Namespace):
3497+
if args.set is not None:
3498+
if not 1000 <= args.set <= 60000:
3499+
print(f"{CR}Error: Wake-up time must be between 1000 and 60000 milliseconds{C0}")
3500+
return
3501+
3502+
resp = self.cmd.set_wakeup_button_time(args.set)
3503+
if resp.status == Status.SUCCESS:
3504+
print(f"Successfully set button wake-up time to {args.set} ms")
3505+
print(f"{CY}Do not forget to store your settings in flash!{C0}")
3506+
else:
3507+
print(f"Failed to set button wake-up time: {Status(resp.status)}")
3508+
else:
3509+
resp = self.cmd.get_wakeup_button_time()
3510+
if resp.status == Status.SUCCESS:
3511+
print(f"Button wake-up time: {resp.parsed} ms")
3512+
else:
3513+
print(f"Failed to get button wake-up time: {Status(resp.status)}")
3514+
3515+
3516+
@HWSettingsWakeupTime.command('field')
3517+
class HWSettingsWakeupTimeField(DeviceRequiredUnit):
3518+
def args_parser(self) -> ArgumentParserNoExit:
3519+
parser = ArgumentParserNoExit()
3520+
parser.description = 'Get or set the field detection wake-up time (1000-60000 ms)'
3521+
parser.add_argument('-s', '--set', type=int, required=False,
3522+
help='Set wake-up time in milliseconds (1000-60000)')
3523+
return parser
3524+
3525+
def on_exec(self, args: argparse.Namespace):
3526+
if args.set is not None:
3527+
if not 1000 <= args.set <= 60000:
3528+
print(f"{CR}Error: Wake-up time must be between 1000 and 60000 milliseconds{C0}")
3529+
return
3530+
3531+
resp = self.cmd.set_wakeup_field_time(args.set)
3532+
if resp.status == Status.SUCCESS:
3533+
print(f"Successfully set field detection wake-up time to {args.set} ms")
3534+
print(f"{CY}Do not forget to store your settings in flash!{C0}")
3535+
else:
3536+
print(f"Failed to set field detection wake-up time: {Status(resp.status)}")
3537+
else:
3538+
resp = self.cmd.get_wakeup_field_time()
3539+
if resp.status == Status.SUCCESS:
3540+
print(f"Field detection wake-up time: {resp.parsed} ms")
3541+
else:
3542+
print(f"Failed to get field detection wake-up time: {Status(resp.status)}")
3543+
3544+
34763545
@hw_settings.command('bleclearbonds')
34773546
class HWSettingsBleClearBonds(DeviceRequiredUnit):
34783547

software/script/chameleon_cmd.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,38 @@ def get_ble_pairing_enable(self):
10861086
def set_ble_pairing_enable(self, enabled: bool):
10871087
data = struct.pack('!B', enabled)
10881088
return self.device.send_cmd_sync(Command.SET_BLE_PAIRING_ENABLE, data)
1089+
1090+
@expect_response(Status.SUCCESS)
1091+
def get_wakeup_button_time(self):
1092+
"""Get the button wake-up time in milliseconds (1000-60000)"""
1093+
resp = self.device.send_cmd_sync(Command.GET_WAKEUP_BUTTON_TIME)
1094+
if resp.status == Status.SUCCESS and len(resp.data) >= 2:
1095+
resp.parsed = int.from_bytes(resp.data[:2], byteorder='little')
1096+
return resp
1097+
1098+
@expect_response(Status.SUCCESS)
1099+
def set_wakeup_button_time(self, time_ms: int):
1100+
"""Set the button wake-up time (1000-60000 ms)"""
1101+
if not 1000 <= time_ms <= 60000:
1102+
raise ValueError("Wake-up time must be between 1000 and 60000 milliseconds")
1103+
data = time_ms.to_bytes(2, byteorder='little')
1104+
return self.device.send_cmd_sync(Command.SET_WAKEUP_BUTTON_TIME, data)
1105+
1106+
@expect_response(Status.SUCCESS)
1107+
def get_wakeup_field_time(self):
1108+
"""Get the field detection wake-up time in milliseconds (1000-60000)"""
1109+
resp = self.device.send_cmd_sync(Command.GET_WAKEUP_FIELD_TIME)
1110+
if resp.status == Status.SUCCESS and len(resp.data) >= 2:
1111+
resp.parsed = int.from_bytes(resp.data[:2], byteorder='little')
1112+
return resp
1113+
1114+
@expect_response(Status.SUCCESS)
1115+
def set_wakeup_field_time(self, time_ms: int):
1116+
"""Set the field detection wake-up time (1000-60000 ms)"""
1117+
if not 1000 <= time_ms <= 60000:
1118+
raise ValueError("Wake-up time must be between 1000 and 60000 milliseconds")
1119+
data = time_ms.to_bytes(2, byteorder='little')
1120+
return self.device.send_cmd_sync(Command.SET_WAKEUP_FIELD_TIME, data)
10891121

10901122

10911123
def test_fn():

software/script/chameleon_enum.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class Command(enum.IntEnum):
5757
SET_BLE_PAIRING_ENABLE = 1037
5858
GET_LONG_PRESS_THRESHOLD = 1038
5959
SET_LONG_PRESS_THRESHOLD = 1039
60+
61+
# Wake-up time configuration
62+
GET_WAKEUP_BUTTON_TIME = 1040
63+
SET_WAKEUP_BUTTON_TIME = 1041
64+
GET_WAKEUP_FIELD_TIME = 1042
65+
SET_WAKEUP_FIELD_TIME = 1043
6066

6167
HF14A_SCAN = 2000
6268
MF1_DETECT_SUPPORT = 2001

0 commit comments

Comments
 (0)