optimize high frequency 0x02 SetStateData

This commit is contained in:
awalol
2026-05-09 14:21:21 +08:00
parent c323c14f19
commit c45ceea535
3 changed files with 54 additions and 14 deletions
+25 -6
View File
@@ -40,6 +40,22 @@ struct audio_raw_element {
float data[512 * 2];
};
uint8_t interrupt_out_data[63] = {
0xfd, 0xf7, 0x0, 0x0,
0x7f, 0x7f, // Headphones, Speaker
0xff, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa,
0x7, 0x0, 0x0, 0x2, 0x1,
0x00,
0xff, 0xd7, 0x00, // RGB LED: R, G, B (Nijika Color!)✨
};
void set_interrupt_out_data(const uint8_t* data, const uint8_t len) {
memcpy(interrupt_out_data, data, len);
}
void set_headset(bool state) {
plug_headset = state;
}
@@ -115,16 +131,19 @@ void audio_loop() {
pkt[8] = buf_len; // 这 4 个字节的作用未知,调整没有效果
pkt[9] = buf_len; // audio buffer length 只有调整这个字节生效。
pkt[10] = packetCounter++;
pkt[11] = 0x12 | 0 << 6 | 1 << 7;
pkt[12] = SAMPLE_SIZE;
memcpy(pkt + 13, haptic_buf, SAMPLE_SIZE);
pkt[77] = (plug_headset ? 0x16 : 0x13) | 0 << 6 | 1 << 7; // Speaker: 0x13
pkt[11] = 0x10 | 0 << 6 | 1 << 7;
pkt[12] = 63;
memcpy(pkt + 13, interrupt_out_data, sizeof(interrupt_out_data));
pkt[76] = 0x12 | 0 << 6 | 1 << 7;
pkt[77] = SAMPLE_SIZE;
memcpy(pkt + 78, haptic_buf, SAMPLE_SIZE);
pkt[142] = (plug_headset ? 0x16 : 0x13) | 0 << 6 | 1 << 7; // Speaker: 0x13
// L Headset Mono: 0x14
// L Headset R Speaker: 0x15
// Headset: 0x16
pkt[78] = 200;
pkt[143] = 200;
critical_section_enter_blocking(&opus_cs);
memcpy(pkt + 79, opus_buf, 200);
memcpy(pkt + 144, opus_buf, 200);
critical_section_exit(&opus_cs);
bt_write(pkt, sizeof(pkt));