Skip to content
Open
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
26 changes: 26 additions & 0 deletions firmware/application/src/app_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,30 @@ static data_frame_tx_t *cmd_processor_set_ble_pairing_enable(uint16_t cmd, uint1
return data_frame_make(cmd, STATUS_SUCCESS, 0, NULL);
}

static data_frame_tx_t *cmd_processor_get_long_press_threshold(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
// Ignore unused parameters
(void)status;
(void)length;
(void)data;

uint16_t duration = settings_get_long_press_threshold();
uint8_t resp_data[2];
// Pack as big-endian (network byte order)
resp_data[0] = (uint8_t)(duration >> 8);
resp_data[1] = (uint8_t)(duration & 0xFF);
return data_frame_make(cmd, STATUS_SUCCESS, sizeof(resp_data), resp_data);
}

static data_frame_tx_t *cmd_processor_set_long_press_threshold(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
if (length != 2) { // Check for 2 bytes
return data_frame_make(cmd, STATUS_PAR_ERR, 0, NULL);
}
// Unpack uint16_t from data (assuming big-endian/network byte order)
uint16_t duration = ((uint16_t)data[0] << 8) | data[1];
settings_set_long_press_threshold(duration);
return data_frame_make(cmd, STATUS_SUCCESS, 0, NULL);
}

#if defined(PROJECT_CHAMELEON_ULTRA)

static data_frame_tx_t *cmd_processor_hf14a_scan(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
Expand Down Expand Up @@ -1278,6 +1302,8 @@ static cmd_data_map_t m_data_cmd_map[] = {
{ DATA_CMD_GET_DEVICE_CAPABILITIES, NULL, cmd_processor_get_device_capabilities, NULL },
{ DATA_CMD_GET_BLE_PAIRING_ENABLE, NULL, cmd_processor_get_ble_pairing_enable, NULL },
{ DATA_CMD_SET_BLE_PAIRING_ENABLE, NULL, cmd_processor_set_ble_pairing_enable, NULL },
{ DATA_CMD_GET_LONG_PRESS_THRESHOLD, NULL, cmd_processor_get_long_press_threshold, NULL },
{ DATA_CMD_SET_LONG_PRESS_THRESHOLD, NULL, cmd_processor_set_long_press_threshold, NULL },

#if defined(PROJECT_CHAMELEON_ULTRA)

Expand Down
2 changes: 1 addition & 1 deletion firmware/application/src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static void timer_button_event_handle(void *arg) {
uint32_t now = app_timer_cnt_get();
uint32_t ticks = app_timer_cnt_diff_compute(now, m_last_btn_press);

bool is_long_press = ticks > APP_TIMER_TICKS(1000);
bool is_long_press = ticks > APP_TIMER_TICKS(settings_get_long_press_threshold());

if (pin == BUTTON_1 && m_is_b_btn_press == true) {
// If button is disabled, we can't dispatch key event.
Expand Down
2 changes: 2 additions & 0 deletions firmware/application/src/data_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#define DATA_CMD_GET_DEVICE_CAPABILITIES (1035)
#define DATA_CMD_GET_BLE_PAIRING_ENABLE (1036)
#define DATA_CMD_SET_BLE_PAIRING_ENABLE (1037)
#define DATA_CMD_GET_LONG_PRESS_THRESHOLD (1038)
#define DATA_CMD_SET_LONG_PRESS_THRESHOLD (1039)

//
// ******************************************************************
Expand Down
22 changes: 22 additions & 0 deletions firmware/application/src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ void settings_init_ble_pairing_enable_config(void) {
config.ble_pairing_enable = false;
}

// add on version6
void settings_init_long_press_threshold_config(void) {
config.long_press_threshold = 1000; // default 1000ms
}

void settings_init_config(void) {
settings_update_version_for_config();
config.animation_config = SettingsAnimationModeFull; // add on version1
settings_init_button_press_config();
settings_init_button_long_press_config();
settings_init_ble_connect_key_config();
settings_init_ble_pairing_enable_config();
settings_init_long_press_threshold_config();
}

void settings_migrate(void) {
Expand All @@ -80,6 +86,9 @@ void settings_migrate(void) {
case 4:
settings_init_ble_pairing_enable_config();

case 5:
settings_init_long_press_threshold_config();

/*
* Add new migration steps ABOVE THIS COMMENT
* `settings_update_version_for_config()` and `break` statements should only be used on the last migration step, all the previous steps must fall
Expand Down Expand Up @@ -291,3 +300,16 @@ bool settings_get_ble_pairing_enable(void) {
bool settings_get_ble_pairing_enable_first_load(void) {
return m_ble_pairing_enable_first_load_value;
}

uint16_t settings_get_long_press_threshold(void) {
return config.long_press_threshold;
}

void settings_set_long_press_threshold(uint16_t duration) {
// Enforce minimum value of 200ms
if (duration < 200) {
duration = 200;
}
// Maximum value is implicitly handled by uint16_t
config.long_press_threshold = duration;
}
7 changes: 6 additions & 1 deletion firmware/application/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "utils.h"

#define SETTINGS_CURRENT_VERSION 5
#define SETTINGS_CURRENT_VERSION 6
#define BLE_PAIRING_KEY_LEN 6
#define DEFAULT_BLE_PAIRING_KEY "123456" // length must == 6

Expand Down Expand Up @@ -47,6 +47,9 @@ typedef struct ALIGN_U32 {
// 6 byte
uint8_t ble_connect_key[6];

// 2 bytes
uint16_t long_press_threshold; // in ms

// 1 byte
uint8_t reserved1; // see bottom.

Expand Down Expand Up @@ -74,4 +77,6 @@ void settings_set_ble_connect_key(uint8_t *key);
void settings_set_ble_pairing_enable(bool enable);
bool settings_get_ble_pairing_enable(void);
bool settings_get_ble_pairing_enable_first_load(void);
uint16_t settings_get_long_press_threshold(void);
void settings_set_long_press_threshold(uint16_t duration);
#endif
29 changes: 29 additions & 0 deletions software/script/chameleon_cli_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3005,6 +3005,35 @@ def on_exec(self, args: argparse.Namespace):
print(f" - Successfully change ble pairing to {CR}Disabled{C0}.")
print(f"{CY}Do not forget to store your settings in flash!{C0}")

@hw_settings.command('longpressthreshold')
class HWLongPressThreshold(DeviceRequiredUnit):
def args_parser(self) -> ArgumentParserNoExit:
parser = ArgumentParserNoExit(description='Get or set the long press threshold')
parser.description = 'Configure threshold in ms to be considered as long press'
parser.add_argument('--get', action='store_true', help='Get current long press threshold')
parser.add_argument('--set', type=int, help='Set long press threshold in milliseconds (200-65535)')
return parser

def on_exec(self, args: argparse.Namespace):
if args.get:
resp = self.cmd.get_long_press_threshold()
if resp is not None and resp.parsed is not None:
print(f"Current long press threshold: {resp.parsed}ms")
else:
print("Error: Failed to get long press threshold")
elif args.set is not None:
if args.set < 200:
print("Error: Long press threshold must be at least 200ms")
return
if args.set > 65535:
print("Error: Long press threshold must be at most 65535ms")
return
self.cmd.set_long_press_threshold(args.set)
print(f"Long press threshold set to {args.set}ms")
print(f"{CY}Do not forget to store your settings in flash!{C0}")
else:
print("Error: Must specify either --get or --set")


@hw.command('raw')
class HWRaw(DeviceRequiredUnit):
Expand Down
22 changes: 22 additions & 0 deletions software/script/chameleon_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,28 @@ def set_ble_pairing_enable(self, enabled: bool):
data = struct.pack('!B', enabled)
return self.device.send_cmd_sync(Command.SET_BLE_PAIRING_ENABLE, data)

def get_long_press_threshold(self):
"""
Get the long press threshold in milliseconds
"""
resp = self.device.send_cmd_sync(Command.GET_LONG_PRESS_THRESHOLD)
if resp is not None and resp.status == Status.SUCCESS and len(resp.data) == 2:
resp.parsed, = struct.unpack('!H', resp.data)
else:
# Ensure resp exists before trying to assign to resp.parsed
if resp is not None:
resp.parsed = None
# If resp itself is None, we can't assign parsed = None.
# The function will return None in this case.
return resp

def set_long_press_threshold(self, duration: int):
"""
Set the long press threshold in milliseconds
"""
data = struct.pack('!H', duration)
return self.device.send_cmd_sync(Command.SET_LONG_PRESS_THRESHOLD, data)


def test_fn():
# connect to chameleon
Expand Down
2 changes: 2 additions & 0 deletions software/script/chameleon_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Command(enum.IntEnum):
GET_DEVICE_CAPABILITIES = 1035
GET_BLE_PAIRING_ENABLE = 1036
SET_BLE_PAIRING_ENABLE = 1037
GET_LONG_PRESS_THRESHOLD = 1038
SET_LONG_PRESS_THRESHOLD = 1039

HF14A_SCAN = 2000
MF1_DETECT_SUPPORT = 2001
Expand Down
Loading