2525#include "esb.h"
2626#include "build_defines.h"
2727#include "hid.h"
28+ #include "system/battery_tracker.h"
2829
2930#include <zephyr/kernel.h>
3031#include <zephyr/sys/crc.h>
@@ -158,6 +159,8 @@ void connection_update_status(int status)
158159//|1 |id |q0 |q1 |q2 |q3 |a0 |a1 |a2 |
159160//|2 |id |batt |batt_v |temp |q_buf |a0 |a1 |a2 |rssi |
160161//|3 |id |svr_stat|status |resv |rssi |
162+ //|1 |id |q0 |q1 |q2 |q3 |m0 |m1 |m2 |
163+ //|5 |id |runtime |resv |rssi |
161164
162165void connection_write_packet_0 () // device info
163166{
@@ -281,6 +284,21 @@ void connection_write_packet_4() // full precision quat and magnetometer
281284 hid_write_packet_n (data ); // TODO:
282285}
283286
287+ void connection_write_packet_5 () // runtime
288+ {
289+ uint8_t data [16 ] = {0 };
290+ data [0 ] = 4 ; // packet 4
291+ data [1 ] = tracker_id ;
292+ int64_t * buf = (uint16_t * )& data [2 ];
293+ buf [0 ] = k_ticks_to_us_floor64 (sys_get_battery_remaining_time_estimate ());
294+ k_mutex_lock (& data_buffer_mutex , K_FOREVER );
295+ memcpy (data_buffer , data , sizeof (data ));
296+ last_data_time = k_uptime_get (); // TODO: use ticks
297+ // esb_write(data); // TODO: schedule in thread
298+ k_mutex_unlock (& data_buffer_mutex );
299+ hid_write_packet_n (data ); // TODO:
300+ }
301+
284302// TODO: get radio channel from receiver
285303// TODO: new packet format
286304
@@ -293,6 +311,7 @@ void connection_write_packet_4() // full precision quat and magnetometer
293311
294312static int64_t last_info_time = 0 ;
295313static int64_t last_status_time = 0 ;
314+ static int64_t last_status2_time = 0 ;
296315
297316void connection_thread (void )
298317{
@@ -348,6 +367,12 @@ void connection_thread(void)
348367 connection_write_packet_3 ();
349368 continue ;
350369 }
370+ else if (k_uptime_get () - last_status2_time > 1000 )
371+ {
372+ last_status2_time = k_uptime_get ();
373+ connection_write_packet_5 ();
374+ continue ;
375+ }
351376 else
352377 {
353378 connection_clocks_request_stop ();
0 commit comments