Exemplo n.º 1
0
        private void BtnLoadDefault_Click(object sender, EventArgs e)
        {
            // Load default value
            LastErrCode = HotKey_API.ControlPanel_LoadDefaultValue();
            if (LastErrCode != IMCAPIErrCode.IMC_ERR_NO_ERROR)
            {
                ShowWanringMessage("Fails to load default value", LastErrCode);
                return;
            }
            // Reset the firmware into normal mode

            lock (LockReadWrite)
            {
                LastErrCode = HotKey_API.ControlPanel_ResetFirmware(HotKey_API.IMC_RESET_INTO_NORMAL_MODE);
            }
            if (LastErrCode != IMCAPIErrCode.IMC_ERR_NO_ERROR)
            {
                ShowWanringMessage("Fails to reset the firmware into normal mode", LastErrCode);
                return;
            }
            MessageBox.Show("The parameters are all reset !\nPlease re-open the HotKey dialog", "Warning");
            IMCWin32API.PostMessage(Handle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
        }
Exemplo n.º 2
0
        // The events
        private void HotKeyForm_Load(object sender, EventArgs e)
        {
            ChkShowScrollbar(PanelInner);

            nCOMPortNo = 1;
            FormWait   = new IMCWaitForm();
            FormWait.Show();
            int nRealSize;

            try
            {
                // Get library version
                byte[] byLibVersion = new byte[HotKey_API.IMC_LIB_VERSION_SIZE];
                unsafe
                {
                    fixed(byte *pVersion = byLibVersion)
                    {
                        LastErrCode = HotKey_API.ControlPanel_GetVersion(pVersion);
                    }
                }

                if (LastErrCode != IMCAPIErrCode.IMC_ERR_NO_ERROR)
                {
                    ShowWanringMessage("Fails to get library version", LastErrCode);
                    NotifyLibInitFail(Text);
                    return;
                }
                StaticLibVersionValue.Text = ConvertByte2String(byLibVersion, byLibVersion.Length, out nRealSize);
            }
            catch (System.Exception ex)
            {
                bDllExist = false;
                MessageBox.Show(ex.Message, "Error");
                IMCWin32API.PostMessage(Handle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                //                IMCWin32API.PostQuitMessage(0);
                return;
            }

            // Initialize the ControlPanel library.
            hEvtInitLibraryDone = IMCWin32API.CreateEvent(IntPtr.Zero, true, false, null);
            Thread InitControlPanelLibraryThread = new Thread(InitControlPanelLibraryWorkerThread);

            InitControlPanelLibraryThread.Start();
            // Wait for the worker thread
            IMCCmnFunc.WaitForWorkerThread(hEvtInitLibraryDone, 20);

            if (LastErrCode != IMCAPIErrCode.IMC_ERR_NO_ERROR)
            {
                ShowWanringMessage("Fails to initialize the library", LastErrCode);
                NotifyLibInitFail(Text);
                return;
            }

            // Get the firmware version
            HotKey_API.IMC_CONTROLPANEL_FIRMWARE_INFO info = new HotKey_API.IMC_CONTROLPANEL_FIRMWARE_INFO();
            LastErrCode = HotKey_API.ControlPanel_GetFirmwareInformation(out info);
            if (LastErrCode != IMCAPIErrCode.IMC_ERR_NO_ERROR)
            {
                ShowWanringMessage("Fails to get firmware information", LastErrCode);
                NotifyLibInitFail(Text);
                return;
            }

            //  Add the new future for TREK-306DH
            //  If the model name was 306D that means it fully supports temperature sensor function
            unsafe
            {
                if (info.model_name[6] == 'D')
                {
                    StaticTemperatureSensor.Enabled        = true;
                    StaticTemperatureSensorValue.Enabled   = true;
                    EditTemperatureSeonsorGetValue.Enabled = true;
                    nEnabledTemperatureSensor = true;
                }
            }

            byte[] byFWVersion        = new byte[HotKey_API.IMC_FIRMWARE_VERSION_SIZE];
            string strFWFormatVersion = String.Empty;

            byte[] byFWModelName = new byte[HotKey_API.IMC_FIRMWARE_MODEL_NAME_SIZE];
            unsafe
            {
                ConvertPointer2Array(info.version, byFWVersion, HotKey_API.IMC_FIRMWARE_VERSION_SIZE);
                FormatFirmwareVersion(byFWVersion, HotKey_API.IMC_FIRMWARE_VERSION_SIZE, ref strFWFormatVersion);
                ConvertPointer2Array(info.model_name, byFWModelName, HotKey_API.IMC_FIRMWARE_MODEL_NAME_SIZE);
            }
            StaticFirmwareVersionValue.Text   = strFWFormatVersion;
            StaticFirmwareModelNameValue.Text = ConvertByte2String(byFWModelName, HotKey_API.IMC_FIRMWARE_MODEL_NAME_SIZE, out nRealSize);

            HotKey_API.HotKey_RegisterOnPressAndReleaseEventMonitor(OnPressAndReleaseDelegateCallbackFunc);

// Start to read the hot key status
            StartReadHotKeyStatus();

            SetReadDataModeString();

            FormWait.Hide();
            FormWait = null;

// Create a worker thread to read the value of light sensor
            Thread LightSensorWorkerThread = new Thread(ReadLightSensorWorkerThread);

            LightSensorWorkerThread.IsBackground = true;
            LightSensorWorkerThread.Start();

            IMCCmnFunc.SetWindowZOrder(Handle, IMCWin32API.HWND_TOPMOST);
        }