耳机插拔

1. android系统启动完成会发送Intent.ACTION_BOOT_COMPLETED事件,我们在 base/services/java/com/android/server/WiredAccessoryObserver.java中可以看到类似代码
    linux-3.0/drivers/switch/ switch_headset.c中会根据无耳机,三段耳机,四段耳机和四段耳机是否有hook键按下4个状态更新state的值为0 ,1, 2,3,并且切换机台
    MIC和耳机   
    private static final String uEventInfo[][] = { {"DEVPATH=/devices/virtual/switch/h2w",
                                                     "/sys/class/switch/h2w/state",
                                                     "/sys/class/switch/h2w/name"},
                                                    {"DEVPATH=/devices/virtual/switch/usb_audio",
                                                     "/sys/class/switch/usb_audio/state",
                                                    "/sys/class/switch/usb_audio/name"},
                                                    {"DEVPATH=/devices/virtual/switch/hdmi",
                                                     "/sys/class/switch/hdmi/state",
                                                      "/sys/class/switch/hdmi/name"} };
    大体流程是用定时器每200ms检查一次是否有耳机插入,如果有4段耳机,延时30ms检查hook key是否按下,这样,如果旧的state和新的state不相等,就用uevent上报状态改变
    事件
    可参考电路图P11的说明:
        检测耳机插入:
        1、0V-0.2V 则判定为3节耳机;
        2、1V-2.5V 则判定为4节耳机;
        3、检测为4接耳机后如果ADC再次检测为0V则认为HOOK见按下。

你可能感兴趣的:(耳机插拔)