zoukankan      html  css  js  c++  java
  • WM手机,如何实现震动

    public class LedLib
        {
            private int m_count;
            private const int NLED_COUNT_INFO_ID = 0;
            private const int NLED_SUPPORTS_INFO_ID = 1;

            public LedLib()
            {
                NLED_COUNT_INFO pOutput = new NLED_COUNT_INFO();
                if (!NLedGetDeviceCount(0, ref pOutput))
                {
                    throw new Exception("震动模块初始化错误!");
                }
                this.m_count = (int)pOutput.cLeds;
            }

            [DllImport("coredll.dll", EntryPoint = "NLedGetDeviceInfo")]
            private static extern bool NLedGetDeviceCount(short nID, ref NLED_COUNT_INFO pOutput);
            [DllImport("coredll.dll", EntryPoint = "NLedGetDeviceInfo")]
            private static extern bool NLedGetDeviceSupports(short nID, ref NLED_SUPPORTS_INFO pOutput);
            [DllImport("coredll.dll")]
            private static extern bool NLedSetDevice(short nID, ref NLED_SETTINGS_INFO pOutput);
            public void SetLedStatus(uint led, LedState newState)
            {
                NLED_SETTINGS_INFO pOutput = new NLED_SETTINGS_INFO();
                pOutput.LedNum = led;
                pOutput.OffOnBlink = (int)newState;
                bool flag = NLedSetDevice(2, ref pOutput);
            }

            public enum LedState
            {
                Off,
                On,
                Blink
            }

            [StructLayout(LayoutKind.Sequential)]
            private struct NLED_COUNT_INFO
            {
                public uint cLeds;
            }

            [StructLayout(LayoutKind.Sequential)]
            private struct NLED_SETTINGS_INFO
            {
                public uint LedNum;
                public int OffOnBlink;
                public int TotalCycleTime;
                public int OnTime;
                public int OffTime;
                public int MetaCycleOn;
                public int MetaCycleOff;
            }

            [StructLayout(LayoutKind.Sequential)]
            private struct NLED_SUPPORTS_INFO
            {
                public uint LedNum;
                public int lCycleAdjust;
                public bool fAdjustTotalCycleTime;
                public bool fAdjustOnTime;
                public bool fAdjustOffTime;
                public bool fMetaCycleOn;
                public bool fMetaCycleOff;
            }
        }

            /// <summary>
            /// 实现震动
            /// </summary>
            /// <param name="setTimes">震动毫秒数</param>
            public static void Play(int setTimes)
            {
                try
                {
                    LedLib led = new LedLib();
                    led.SetLedStatus(1, LedLib.LedState.On);
                    Thread.Sleep(setTimes);
                    led.SetLedStatus(1, LedLib.LedState.Off);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }

     

    转:http://blog.csdn.net/zhaojiangang/archive/2009/01/12/3760993.aspx

  • 相关阅读:
    Thrift实现C#调用Java开发步骤详解
    微信小程序项目实战之豆瓣天气
    带有关闭按钮的alertView
    基于olami开放语义平台的微信小程序遥知之源码实现
    iOS-仿智联字符图片验证码
    微信 支付宝支付 友盟登录分享 统计
    优化VMware提高虚拟机运行速度的技巧
    区块链与密码学
    在 Ubuntu 16.04 中安装支持 CPU 和 GPU 的 Google TensorFlow 神经网络软件
    Ubuntu+anaconda环境里安装opencv
  • 原文地址:https://www.cnblogs.com/moses/p/1472884.html
Copyright © 2011-2022 走看看