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).

1  
!7
2  
3  
cmodule HeadphoneDetection > DynBigNumber {
4  
  Bool pluggedIn; // null if unknown
5  
  int minValue = 100, maxValue;
6  
  
7  
  start {
8  
    setDescription("HEADPHONES");
9  
    if (!isLinux()) ret with setValue("Linux only, sorry");
10  
    doEveryAndNow(10.0, r actualUpdate);
11  
    dm_registerAs('headphoneDetector);
12  
  }
13  
  
14  
  void actualUpdate enter {
15  
    //time "Headphone detect" {
16  
      int raw = linux_rawHeadphonesCount();
17  
      setField(minValue := min(minValue, raw));
18  
      setField(maxValue := max(maxValue, raw));
19  
      if (setField(pluggedIn := minValue == maxValue ? null : raw > minValue))
20  
        vmBus_sendMessage('headphoneChange, pluggedIn);
21  
      setValue(nullFalseTrue(pluggedIn, 
22  
        "Please plug/unplug headphones once to enable detection",
23  
        "NO", "YES"));
24  
    //}
25  
  }
26  
  
27  
  // API
28  
  
29  
  Bool headphonesDetected() { ret pluggedIn; }
30  
}

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: 250 / 2228
Version history: 12 change(s)
Referenced in: [show references]