From 1ff0be6ed8e8a1ba956ee80886a70ce91ebeca55 Mon Sep 17 00:00:00 2001 From: Nemanja Nedeljkovic Date: Wed, 23 Aug 2023 19:29:03 +0200 Subject: [PATCH] Add long press command --- software/script/chameleon_cli_unit.py | 10 +++++++++- software/script/chameleon_cmd.py | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index 9f99ec9..35312b6 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -1318,9 +1318,12 @@ class HWButtonSettingsGet(DeviceRequiredUnit): print("") for button in button_list: resp = self.cmd.get_button_press_fun(button) + resp_long = self.cmd.get_long_button_press_fun(button) button_fn = chameleon_cmd.ButtonPressFunction.from_int(resp.data[0]) + button_long_fn = chameleon_cmd.ButtonPressFunction.from_int(resp_long.data[0]) print(f" - {colorama.Fore.GREEN}{button}{colorama.Style.RESET_ALL}: {button_fn}") print(f" usage: {button_fn.usage()}") + print(f" long press usage: {button_long_fn.usage()}") print("") print(" - Successfully get button function from settings") @@ -1330,6 +1333,7 @@ class HWButtonSettingsSet(DeviceRequiredUnit): def args_parser(self) -> ArgumentParserNoExit: parser = ArgumentParserNoExit() + parser.add_argument('-l', '--long', type=int, required=True, help="1 is Long or 0 Short", choices=[0, 1]) parser.add_argument('-b', type=str, required=True, help="Change the function of the pressed button(?).", choices=chameleon_cmd.ButtonType.list_str()) @@ -1344,5 +1348,9 @@ class HWButtonSettingsSet(DeviceRequiredUnit): def on_exec(self, args: argparse.Namespace): button = chameleon_cmd.ButtonType.from_str(args.b) function = chameleon_cmd.ButtonPressFunction.from_int(args.f) - self.cmd.set_button_press_fun(button, function) + long = args.l == 1 + if long: + self.cmd.set_long_button_press_fun(button, function) + else: + self.cmd.set_button_press_fun(button, function) print(" - Successfully set button function to settings") diff --git a/software/script/chameleon_cmd.py b/software/script/chameleon_cmd.py index 33f4e39..a3ef8c7 100644 --- a/software/script/chameleon_cmd.py +++ b/software/script/chameleon_cmd.py @@ -42,6 +42,9 @@ DATA_CMD_GET_BATTERY_INFO = 1025 DATA_CMD_GET_BUTTON_PRESS_CONFIG = 1026 DATA_CMD_SET_BUTTON_PRESS_CONFIG = 1027 +DATA_CMD_GET_LONG_BUTTON_PRESS_CONFIG = 1028 +DATA_CMD_SET_LONG_BUTTON_PRESS_CONFIG = 1029 + DATA_CMD_SCAN_14A_TAG = 2000 DATA_CMD_MF1_SUPPORT_DETECT = 2001 DATA_CMD_MF1_NT_LEVEL_DETECT = 2002 @@ -769,6 +772,24 @@ class ChameleonCMD: bytearray([button, function]) ) + @expect_response(chameleon_status.Device.STATUS_DEVICE_SUCCESS) + def get_long_button_press_fun(self, button: ButtonType): + """ + Get config of button press function + """ + return self.device.send_cmd_sync(DATA_CMD_GET_LONG_BUTTON_PRESS_CONFIG, 0x00, bytearray([button])) + + @expect_response(chameleon_status.Device.STATUS_DEVICE_SUCCESS) + def set_long_button_press_fun(self, button: ButtonType, function: ButtonPressFunction): + """ + Set config of button press function + """ + return self.device.send_cmd_sync( + DATA_CMD_SET_LONG_BUTTON_PRESS_CONFIG, + 0x00, + bytearray([button, function]) + ) + if __name__ == '__main__': # connect to chameleon dev = chameleon_com.ChameleonCom()