Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

30
LINES

< > BotCompany Repo | #1023193 // Headphone Detection [Linux]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (4320L/22K).

!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; }
}

Author comment

Began life as a copy of #1020549

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1023193
Snippet name: Headphone Detection [Linux]
Eternal ID of this version: #1023193/13
Text MD5: bf4e08d6b72e774a04c01009490de5c3
Transpilation MD5: e752990eafbc6e057eff3cfff1ceaba6
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-05-17 01:03:03
Source code size: 880 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 310 / 2305
Version history: 12 change(s)
Referenced in: