!7 cmodule HeadphoneDetection > DynBigNumber { Bool pluggedIn; // null if unknown int minValue = 100, maxValue; start { setDescription("HEADPHONES"); if (!isLinux()) ret with setValue("Linux only, sorry"); doEveryAndNow(10.0, r actualUpdate); dm_registerAs('headphoneDetector); } void actualUpdate enter { //time "Headphone detect" { int raw = linux_rawHeadphonesCount(); setField(minValue := min(minValue, raw)); setField(maxValue := max(maxValue, raw)); if (setField(pluggedIn := minValue == maxValue ? null : raw > minValue)) vmBus_sendMessage('headphoneChange, pluggedIn); setValue(nullFalseTrue(pluggedIn, "Please plug/unplug headphones once to enable detection", "NO", "YES")); //} } // API Bool headphonesDetected() { ret pluggedIn; } }