headphones_probe.cpp 742 B

12345678910111213141516171819
  1. // headphones_probe [seconds]: prints Detectors::HeadphonesDetector's answer whenever it changes (headphones_reconnect.sh)
  2. #include "WallpaperEngine/Audio/Drivers/Detectors/HeadphonesDetector.h"
  3. #include <chrono>
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <thread>
  7. int main (int argc, char** argv) {
  8. WallpaperEngine::Audio::Drivers::Detectors::HeadphonesDetector detector;
  9. const int secs = argc > 1 ? atoi (argv[1]) : 20;
  10. bool last = !detector.headphones ();
  11. for (int i = 0; i < secs * 10; i++) {
  12. if (detector.headphones () != last) {
  13. last = detector.headphones ();
  14. printf ("%.1f headphones %d\n", i / 10.0, last);
  15. fflush (stdout);
  16. }
  17. std::this_thread::sleep_for (std::chrono::milliseconds (100));
  18. }
  19. }