Skip to content

Commit b0386b2

Browse files
authored
Expose timeout time to server
* Send multipress to server * Hold to pair on boot only, update LED patterns/priorities * More lenient TX error clear rate * Fit firmware on nRF52820/32 * Ignore button hold if tracker is sleeping * Add full_name to all board.yml Fix compilation on sdk >=3.3.0 * Expose timeout time to server
1 parent ddcefad commit b0386b2

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

src/connection/connection.c

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ void connection_update_sensor_temp(float temp)
121121
sensor_temp = ((temp - 25) * 2 + 128.5f); // -38.5 - +88.5 -> 1-255
122122
}
123123

124+
static int64_t timeout_time = INT64_MAX;
125+
126+
void connection_update_sensor_timeout_time(int64_t timeout)
127+
{
128+
timeout_time = timeout;
129+
}
130+
124131
void connection_update_battery(bool battery_available, bool plugged, bool charged, uint32_t battery_pptt, int battery_mV) // format for packet send
125132
{
126133
if (!battery_available) // No battery, and voltage is <=1500mV
@@ -164,6 +171,13 @@ void connection_update_button(int button)
164171
button_update_time = k_uptime_get();
165172
}
166173

174+
static bool shutdown = false;
175+
176+
void connection_set_shutdown(void)
177+
{
178+
shutdown = true;
179+
}
180+
167181
//|b0 |b1 |b2 |b3 |b4 |b5 |b6 |b7 |b8 |b9 |b10 |b11 |b12 |b13 |b14 |b15 |
168182
//|type |id |packet data |
169183
//|0 |id |batt |batt_v |temp |brd_id |mcu_id |resv |imu_id |mag_id |fw_date |major |minor |patch |rssi |
@@ -172,8 +186,10 @@ void connection_update_button(int button)
172186
//|3 |id |svr_stat|status |resv |rssi |
173187
//|4 |id |q0 |q1 |q2 |q3 |m0 |m1 |m2 |
174188
//|5 |id |runtime |resv |rssi |
175-
//|6 |id |button |resv |rssi |
176-
//|7 |id |button |resv |q_buf |a0 |a1 |a2 |rssi |
189+
//|6 |id |button |sleeptime | |rssi |
190+
//|7 |id |button |sleeptime |q_buf |a0 |a1 |a2 |rssi |
191+
192+
// runtime is in microseconds (overkill), sleeptime is in milliseconds (overkill but less)
177193

178194
void connection_write_packet_0() // device info
179195
{
@@ -315,12 +331,19 @@ void connection_write_packet_5() // runtime
315331
hid_write_packet_n(data); // TODO:
316332
}
317333

318-
void connection_write_packet_6() // reduced precision quat and accel with button
334+
void connection_write_packet_6() // reduced precision quat and accel with button and sleep time
319335
{
320336
uint8_t data[16] = {0};
321337
data[0] = 6; // packet 6
322338
data[1] = tracker_id;
323339
data[2] = tracker_button;
340+
uint16_t *buf = (uint16_t *)&data[3];
341+
if (shutdown)
342+
buf = 1;
343+
else
344+
buf = timeout_time < 1 ? 1 : timeout_time;
345+
if (k_ticks_to_ms_floor64(sys_get_battery_remaining_time_estimate()) < 60000 && timeout_time == UINT16_MAX)
346+
timeout_time = UINT16_MAX - 1;
324347
data[15] = 0; // rssi (supplied by receiver)
325348
k_mutex_lock(&data_buffer_mutex, K_FOREVER);
326349
memcpy(data_buffer, data, sizeof(data));
@@ -335,12 +358,19 @@ void connection_write_packet_6() // reduced precision quat and accel with button
335358
hid_write_packet_n(data); // TODO:
336359
}
337360

338-
void connection_write_packet_7() // button
361+
void connection_write_packet_7() // button and sleep time
339362
{
340363
uint8_t data[16] = {0};
341364
data[0] = 7; // packet 7
342365
data[1] = tracker_id;
343366
data[2] = tracker_button;
367+
uint16_t *buf = (uint16_t *)&data[3];
368+
if (shutdown)
369+
buf = 1;
370+
else
371+
buf = timeout_time < 1 ? 1 : timeout_time;
372+
if (k_ticks_to_ms_floor64(sys_get_battery_remaining_time_estimate()) < 60000 && timeout_time == UINT16_MAX)
373+
timeout_time = UINT16_MAX - 1;
344374
float v[3] = {0};
345375
q_fem(sensor_q, v); // exponential map
346376
for (int i = 0; i < 3; i++)
@@ -383,7 +413,6 @@ static int64_t last_status2_time = 0;
383413

384414
void connection_thread(void)
385415
{
386-
bool use_button = !CONFIG_0_SETTINGS_READ(CONFIG_0_USER_EXTRA_ACTIONS); // TODO: until info2 has extra data, it can be disabled for now if extra actions overrides button
387416
uint8_t data_copy[21];
388417
// TODO: checking for connection_update events from sensor_loop, here we will time and send them out
389418
while (1)
@@ -417,7 +446,7 @@ void connection_thread(void)
417446
continue;
418447
}
419448
// if time for info2 and precise quat not needed
420-
else if (use_button && quat_update_time && !send_precise_quat && k_uptime_get() - last_info2_time > 100)
449+
else if (quat_update_time && !send_precise_quat && k_uptime_get() - last_info2_time > 100)
421450
{
422451
quat_update_time = 0;
423452
last_quat_time = k_uptime_get();
@@ -439,7 +468,7 @@ void connection_thread(void)
439468
connection_write_packet_0();
440469
continue;
441470
}
442-
else if (use_button && k_uptime_get() - last_info2_time > 100)
471+
else if (k_uptime_get() - last_info2_time > 100)
443472
{
444473
last_info2_time = k_uptime_get();
445474
connection_write_packet_6();

src/connection/connection.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ void connection_update_sensor_ids(int imu_id, int mag_id);
3535
void connection_update_sensor_data(float *q, float *a, int64_t data_time); // ticks
3636
void connection_update_sensor_mag(float *m);
3737
void connection_update_sensor_temp(float temp);
38+
void connection_update_sensor_timeout_time(int64_t timeout);
3839
void connection_update_battery(bool battery_available, bool plugged, bool charged, uint32_t battery_pptt, int battery_mV);
3940
void connection_update_status(int status);
4041
void connection_update_button(int button);
4142

42-
void connection_write_packet_0();
43-
void connection_write_packet_1();
44-
void connection_write_packet_2();
45-
void connection_write_packet_3();
46-
void connection_write_packet_4();
47-
void connection_write_packet_5();
43+
void connection_set_shutdown(void);
44+
45+
void connection_write_packet_0(void);
46+
void connection_write_packet_1(void);
47+
void connection_write_packet_2(void);
48+
void connection_write_packet_3(void);
49+
void connection_write_packet_4(void);
50+
void connection_write_packet_5(void);
4851

4952
#endif

src/sensor/sensor.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static int64_t last_temp_time = -1000;
8585

8686
static int64_t last_suspend_attempt_time = 0;
8787
static int64_t last_data_time;
88+
static int64_t sensor_timeout_time = INT64_MAX;
8889

8990
static float max_gyro_speed_square;
9091
static bool mag_use_oneshot;
@@ -622,6 +623,21 @@ static void sensor_update_sensor_state(void)
622623
sys_request_WOM(false, false);
623624
sensor_timeout = SENSOR_SENSOR_TIMEOUT_IMU_ELAPSED; // only try to suspend once
624625
}
626+
// Update timeout estimate
627+
switch (sensor_timeout)
628+
{
629+
case SENSOR_SENSOR_TIMEOUT_ACTIVITY:
630+
connection_update_sensor_timeout_time(CONFIG_3_SETTINGS_READ(CONFIG_3_ACTIVE_TIMEOUT_DELAY) - last_data_delta);
631+
break;
632+
case SENSOR_SENSOR_TIMEOUT_IMU:
633+
if (CONFIG_1_SETTINGS_READ(CONFIG_1_USE_IMU_TIMEOUT) && CONFIG_0_SETTINGS_READ(CONFIG_0_USE_IMU_WAKE_UP))
634+
{
635+
connection_update_sensor_timeout_time(imu_timeout - last_data_delta);
636+
break;
637+
}
638+
default:
639+
connection_update_sensor_timeout_time(INT64_MAX);
640+
}
625641
}
626642
else
627643
{
@@ -631,6 +647,7 @@ static void sensor_update_sensor_state(void)
631647
if (sensor_timeout == SENSOR_SENSOR_TIMEOUT_IMU_ELAPSED) // Resetting IMU timeout
632648
sensor_timeout = SENSOR_SENSOR_TIMEOUT_IMU;
633649
sensor_mode = SENSOR_SENSOR_MODE_LOW_NOISE;
650+
connection_update_sensor_timeout_time(INT64_MAX);
634651
}
635652
}
636653

src/system/system.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,10 @@ bool stby_read(void)
426426
int sys_user_shutdown(void)
427427
{
428428
int64_t start_time = k_uptime_get();
429-
bool use_shutdown = CONFIG_0_SETTINGS_READ(CONFIG_0_USER_SHUTDOWN);
430-
if (use_shutdown)
431-
set_led(SYS_LED_PATTERN_ONESHOT_POWEROFF, SYS_LED_PRIORITY_USER);
432-
else // return if shutdown isn't enabled
429+
if (!CONFIG_0_SETTINGS_READ(CONFIG_0_USER_SHUTDOWN)) // return if shutdown isn't enabled
433430
return 1;
431+
connection_set_shutdown(); // propogate shutdown
432+
set_led(SYS_LED_PATTERN_ONESHOT_POWEROFF, SYS_LED_PRIORITY_USER);
434433
while (button_read()) // If alternate button is available and still pressed, wait for the user to stop pressing the button
435434
k_msleep(1);
436435
LOG_INF("User shutdown requested");

0 commit comments

Comments
 (0)