使用 absolute_time_t 替代 time_us_32 作为计时器

This commit is contained in:
awalol
2026-05-05 18:47:39 +08:00
parent c665eab4d5
commit a887c6fb39
3 changed files with 15 additions and 10 deletions
+9 -9
View File
@@ -37,7 +37,7 @@ static bt_data_callback_t bt_data_callback = nullptr;
unordered_map<uint8_t, vector<uint8_t> > feature_data;
static queue<vector<uint8_t> > send_queue;
static critical_section_t queue_lock;
uint32_t inactive_time = 0; // 手柄长时间静默
absolute_time_t inactive_time = 0; // 手柄长时间静默
void bt_register_data_callback(bt_data_callback_t callback) {
bt_data_callback = callback;
@@ -321,10 +321,10 @@ static void l2cap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t
return;
}
if (packet[3] < 120 || packet[3] > 140) {
inactive_time = time_us_32();
}else if (time_us_32() - inactive_time > 1800 * 1000 * 1000){
inactive_time = get_absolute_time();
} else if (absolute_time_diff_us(inactive_time, get_absolute_time()) > get_config().inactive_time * 60 * 1000 * 1000) {
printf("disconnect when inactive\n");
inactive_time = time_us_32();
inactive_time = get_absolute_time();
bt_disconnect();
}
} else if (channel == hid_control_cid) {
@@ -360,7 +360,7 @@ static void l2cap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t
if (!get_config().disable_pico_led) {
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
}
inactive_time = time_us_32();
inactive_time = get_absolute_time();
printf("Init DualSense\n");
@@ -490,16 +490,16 @@ vector<uint8_t> get_feature_data(uint8_t reportId, uint16_t len) {
return ret;
}
void set_feature_data(uint8_t reportId, uint8_t* data,uint16_t len) {
void set_feature_data(uint8_t reportId, uint8_t *data, uint16_t len) {
if (hid_control_cid != 0) {
uint8_t get_feature[len + 2];
get_feature[0] = 0x53;
get_feature[1] = reportId;
memcpy(get_feature + 2,data,len);
fill_feature_report_checksum(get_feature + 1,len + 1);
memcpy(get_feature + 2, data, len);
fill_feature_report_checksum(get_feature + 1, len + 1);
l2cap_send(hid_control_cid, get_feature, len + 2);
printf("[L2CAP] Requesting Set Feature Report 0x%02X\n", reportId);
printf_hexdump(get_feature,len + 2);
printf_hexdump(get_feature, len + 2);
}
}
+4
View File
@@ -53,6 +53,10 @@ void config_valid() {
body->speaker_volume = 2.0f;
printf("[Config] Speaker Volume is invalid\n");
}
if (body->inactive_time < 10 || body->inactive_time > 60) {
body->inactive_time = 30;
printf("[Config] Inactive time is invalid\n");
}
if (body->disable_inactive_disconnect > 1) {
body->disable_inactive_disconnect = 0;
printf("[Config] disable_auto_disconnect is invalid\n");
+2 -1
View File
@@ -10,11 +10,12 @@
struct __attribute__((packed)) Config_body {
float haptics_gain; // [1.0,2.0]
float speaker_volume; // [1.0,2.0]
uint8_t inactive_time; // [10,60] min
uint8_t disable_inactive_disconnect; // bool: 0 disable,1 enable
uint8_t disable_pico_led; // bool
uint8_t polling_rate_mode; // 0: 250Hz,1: 500Hz,2: instant
uint8_t haptics_buffer_length; // [16,255]
uint8_t controller_mode; // 0: DS5, 1: DSE
uint8_t controller_mode; // 0: DS5, 1: DSE 自动切换识别太麻烦了,懒的做了,期待pr
};
struct __attribute__((packed)) Config {