(feature: &Feature)
| 789 | // ─── Output Getter/Setter (0x2c) ──────────────────────────────────────────── |
| 790 | |
| 791 | fn output_get(feature: &Feature) -> f32 { |
| 792 | debug!("Querying output device"); |
| 793 | |
| 794 | let mut payload = [0u8; 65]; |
| 795 | payload[1] = 0x5a; |
| 796 | payload[2] = 0x2c; |
| 797 | payload[3] = 0x01; |
| 798 | payload[4] = 0x01; |
| 799 | |
| 800 | DEVICE_CONNECTION |
| 801 | .get() |
| 802 | .expect("Device connection must be initialized") |
| 803 | .lock() |
| 804 | .unwrap() |
| 805 | .write(&payload) |
| 806 | .expect("Failed to send Query to Device"); |
| 807 | |
| 808 | for attempt in 0..MAX_READ_ATTEMPTS { |
| 809 | let Some(response) = read_packet() else { |
| 810 | error!( |
| 811 | "No response on attempt {}/{} for Output", |
| 812 | attempt + 1, |
| 813 | MAX_READ_ATTEMPTS |
| 814 | ); |
| 815 | continue; |
| 816 | }; |
| 817 | |
| 818 | // expected: 5a 2c 05 01 [mode] ... |
| 819 | if response[0] == 0x5a && response[1] == 0x2c { |
| 820 | let value = match response[4] { |
| 821 | 0x02 => { |
| 822 | info!("Current output: Speakers"); |
| 823 | 0.0 |
| 824 | } |
| 825 | 0x04 => { |
| 826 | info!("Current output: Headphones"); |
| 827 | 1.0 |
| 828 | } |
| 829 | other => { |
| 830 | error!("Unknown output mode: 0x{:02x}", other); |
| 831 | f32::NAN |
| 832 | } |
| 833 | }; |
| 834 | *feature.value.lock().unwrap() = value; |
| 835 | return value; |
| 836 | } |
| 837 | |
| 838 | debug!( |
| 839 | "Discarded stale packet on attempt {}: {:02x?}", |
| 840 | attempt + 1, |
| 841 | &response[..12] |
| 842 | ); |
| 843 | } |
| 844 | |
| 845 | error!( |
| 846 | "No matching response after {} attempts for Output", |
| 847 | MAX_READ_ATTEMPTS |
| 848 | ); |
nothing calls this directly
no test coverage detected