使用 absolute_time_t 替代 time_us_32 作为计时器
This commit is contained in:
+5
-5
@@ -37,7 +37,7 @@ static bt_data_callback_t bt_data_callback = nullptr;
|
|||||||
unordered_map<uint8_t, vector<uint8_t> > feature_data;
|
unordered_map<uint8_t, vector<uint8_t> > feature_data;
|
||||||
static queue<vector<uint8_t> > send_queue;
|
static queue<vector<uint8_t> > send_queue;
|
||||||
static critical_section_t queue_lock;
|
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) {
|
void bt_register_data_callback(bt_data_callback_t callback) {
|
||||||
bt_data_callback = callback;
|
bt_data_callback = callback;
|
||||||
@@ -321,10 +321,10 @@ static void l2cap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (packet[3] < 120 || packet[3] > 140) {
|
if (packet[3] < 120 || packet[3] > 140) {
|
||||||
inactive_time = time_us_32();
|
inactive_time = get_absolute_time();
|
||||||
}else if (time_us_32() - inactive_time > 1800 * 1000 * 1000){
|
} else if (absolute_time_diff_us(inactive_time, get_absolute_time()) > get_config().inactive_time * 60 * 1000 * 1000) {
|
||||||
printf("disconnect when inactive\n");
|
printf("disconnect when inactive\n");
|
||||||
inactive_time = time_us_32();
|
inactive_time = get_absolute_time();
|
||||||
bt_disconnect();
|
bt_disconnect();
|
||||||
}
|
}
|
||||||
} else if (channel == hid_control_cid) {
|
} 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) {
|
if (!get_config().disable_pico_led) {
|
||||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
|
||||||
}
|
}
|
||||||
inactive_time = time_us_32();
|
inactive_time = get_absolute_time();
|
||||||
|
|
||||||
printf("Init DualSense\n");
|
printf("Init DualSense\n");
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ void config_valid() {
|
|||||||
body->speaker_volume = 2.0f;
|
body->speaker_volume = 2.0f;
|
||||||
printf("[Config] Speaker Volume is invalid\n");
|
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) {
|
if (body->disable_inactive_disconnect > 1) {
|
||||||
body->disable_inactive_disconnect = 0;
|
body->disable_inactive_disconnect = 0;
|
||||||
printf("[Config] disable_auto_disconnect is invalid\n");
|
printf("[Config] disable_auto_disconnect is invalid\n");
|
||||||
|
|||||||
+2
-1
@@ -10,11 +10,12 @@
|
|||||||
struct __attribute__((packed)) Config_body {
|
struct __attribute__((packed)) Config_body {
|
||||||
float haptics_gain; // [1.0,2.0]
|
float haptics_gain; // [1.0,2.0]
|
||||||
float speaker_volume; // [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_inactive_disconnect; // bool: 0 disable,1 enable
|
||||||
uint8_t disable_pico_led; // bool
|
uint8_t disable_pico_led; // bool
|
||||||
uint8_t polling_rate_mode; // 0: 250Hz,1: 500Hz,2: instant
|
uint8_t polling_rate_mode; // 0: 250Hz,1: 500Hz,2: instant
|
||||||
uint8_t haptics_buffer_length; // [16,255]
|
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 {
|
struct __attribute__((packed)) Config {
|
||||||
|
|||||||
Reference in New Issue
Block a user