示例#1
0
        //Handle received socket string
        public static async Task <string> SocketStringHandle(string[] socketStringArray)
        {
            try
            {
                string messageType  = socketStringArray[0].Replace("GET /?", string.Empty);
                string messageValue = string.Empty;
                if (socketStringArray.Count() > 1)
                {
                    messageValue = AVFunctions.StringRemoveAfter(socketStringArray[1], " ", 0);
                }

                if (messageType.Contains("LedSwitch"))
                {
                    await LedSwitch(LedSwitches.Automatic);
                }
                else if (messageType.Contains("LedBrightness"))
                {
                    SettingsFunction.Save("LedBrightness", messageValue);
                }
                else if (messageType.Contains("LedMode"))
                {
                    SettingsFunction.Save("LedMode", messageValue);
                    await LedSwitch(LedSwitches.Restart);
                }
            }
            catch { }
            return("Ok");
        }
示例#2
0
文件: AppTray.cs 项目: dumbie/AmbiPro
 private static async void OnChangeMode(object sender, EventArgs e)
 {
     try
     {
         MenuItem ClickMenuItem = (sender as MenuItem);
         if (ClickMenuItem.Text == "Screen capture")
         {
             SettingsFunction.Save("LedMode", "0");
         }
         else if (ClickMenuItem.Text == "Solid color")
         {
             SettingsFunction.Save("LedMode", "1");
         }
         else if (ClickMenuItem.Text == "Color loop")
         {
             SettingsFunction.Save("LedMode", "2");
         }
         else if (ClickMenuItem.Text == "Color spectrum")
         {
             SettingsFunction.Save("LedMode", "3");
         }
         await LedSwitch(LedSwitches.Restart);
     }
     catch { }
 }
示例#3
0
        //Application Startup
        public async Task Application_Startup()
        {
            try
            {
                Debug.WriteLine("Welcome to AmbiPro.");

                //Check the application status
                await Application_LaunchCheck("AmbiPro", "AmbiPro", ProcessPriorityClass.High, false);

                //Check application settings
                SettingsFunction.SettingsCheck();

                //Create application tray menu
                AppTray.CreateTrayMenu();

                //Register application timers
                AppTimers.ApplicationTimersRegister();

                //Settings screen if first run
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["FirstLaunch2"]))
                {
                    Debug.WriteLine("First launch, showing the settings screen.");
                    App.vFormSettings.Show();
                    return;
                }

                //Start updating the leds
                bool turnLedsOn = false;
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["LedAutoOnOffBefore"]) || Convert.ToBoolean(ConfigurationManager.AppSettings["LedAutoOnOffAfter"]))
                {
                    DateTime LedTimeBefore = DateTime.Parse(ConfigurationManager.AppSettings["LedAutoTimeBefore"], vAppCultureInfo);
                    if (DateTime.Now.TimeOfDay < LedTimeBefore.TimeOfDay)
                    {
                        turnLedsOn = true;
                    }
                    DateTime LedTimeAfter = DateTime.Parse(ConfigurationManager.AppSettings["LedAutoTimeAfter"], vAppCultureInfo);
                    if (DateTime.Now.TimeOfDay >= LedTimeAfter.TimeOfDay)
                    {
                        turnLedsOn = true;
                    }
                }
                else
                {
                    turnLedsOn = true;
                }

                if (turnLedsOn)
                {
                    await LedSwitch(LedSwitches.Automatic);
                }

                //Enable the socket server
                await EnableSocketServer();

                //Check for available application update
                await AppUpdate.CheckForAppUpdate(true);
            }
            catch { }
        }
示例#4
0
        //Update the leds in loop
        private static async Task LoopUpdateLeds()
        {
            try
            {
                //Update the led settings
                UpdateSettings();

                //Calculate bytes size
                int InitByteSize  = 3;
                int LedByteSize   = setLedCountTotal * 3;
                int TotalByteSize = InitByteSize + LedByteSize;

                //Connect to the device
                vSerialComPort = new SerialPort(setSerialPortName, setSerialBaudRate);
                vSerialComPort.Open();
                Debug.WriteLine("Connected to the com port device: " + setSerialPortName + "/" + setSerialBaudRate);

                //Create led byte array
                byte[] SerialBytes = new byte[TotalByteSize];
                SerialBytes[0] = Encoding.Unicode.GetBytes("A").First();
                SerialBytes[1] = Encoding.Unicode.GetBytes("d").First();
                SerialBytes[2] = Encoding.Unicode.GetBytes("a").First();

                //Reset default variables
                ResetVariables();

                //Set first launch setting to false
                SettingsFunction.Save("FirstLaunch2", "False");

                //Check led display mode
                if (setLedMode == 0)
                {
                    await ModeScreenCapture(InitByteSize, SerialBytes);
                }
                else if (setLedMode == 1)
                {
                    await ModeSolidColor(InitByteSize, SerialBytes);
                }
                else if (setLedMode == 2)
                {
                    await ModeColorLoop(InitByteSize, SerialBytes);
                }
                else if (setLedMode == 3)
                {
                    await ModeColorSpectrum(InitByteSize, SerialBytes);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to update the leds: " + ex.Message);
                ShowFailedConnectionMessage();
            }
        }
示例#5
0
        //Update the led settings
        public static void UpdateSettings()
        {
            try
            {
                //Device settings
                setSerialPortName = "COM" + ConfigurationManager.AppSettings["ComPort"].ToString();
                setSerialBaudRate = Convert.ToInt32(ConfigurationManager.AppSettings["BaudRate"]);

                //Led settings
                setAdjustBlackBars          = Convert.ToBoolean(ConfigurationManager.AppSettings["AdjustBlackBars"]);
                setAdjustBlackbarRate       = Convert.ToInt32(ConfigurationManager.AppSettings["AdjustBlackbarRate"]);
                setAdjustBlackbarRange      = Convert.ToInt32(ConfigurationManager.AppSettings["AdjustBlackbarRange"]);
                setAdjustBlackBarBrightness = Convert.ToInt32(ConfigurationManager.AppSettings["AdjustBlackBarBrightness"]);
                setUpdateRate            = Convert.ToInt32(ConfigurationManager.AppSettings["UpdateRate"]);
                setLedSmoothing          = Convert.ToInt32(ConfigurationManager.AppSettings["LedSmoothing"]);
                setLedBottomGap          = Convert.ToInt32(ConfigurationManager.AppSettings["LedBottomGap"]);
                setLedContrast           = Convert.ToDouble(ConfigurationManager.AppSettings["LedContrast"]) / 100;
                setLedBrightness         = Convert.ToDouble(ConfigurationManager.AppSettings["LedBrightness"]) / 100;
                setLedMinBrightness      = Convert.ToByte(ConfigurationManager.AppSettings["LedMinBrightness"]);
                setLedGamma              = Convert.ToDouble(ConfigurationManager.AppSettings["LedGamma"]) / 100;
                setLedSaturation         = Convert.ToDouble(ConfigurationManager.AppSettings["LedSaturation"]) / 100;
                setLedTemperature        = Convert.ToDouble(ConfigurationManager.AppSettings["LedTemperature"]) / 100;
                setColorLoopSpeed        = Convert.ToInt32(ConfigurationManager.AppSettings["ColorLoopSpeed"]);
                setSpectrumRotationSpeed = Convert.ToInt32(ConfigurationManager.AppSettings["SpectrumRotationSpeed"]);
                setSolidLedColor         = ConfigurationManager.AppSettings["SolidLedColor"].ToString();
                setLedHue          = Convert.ToDouble(ConfigurationManager.AppSettings["LedHue2"]);
                setLedMinColor     = Convert.ToInt32(ConfigurationManager.AppSettings["LedMinColor"]);
                setLedColorRed     = Convert.ToDouble(ConfigurationManager.AppSettings["LedColorRed"]) / 100;
                setLedColorGreen   = Convert.ToDouble(ConfigurationManager.AppSettings["LedColorGreen"]) / 100;
                setLedColorBlue    = Convert.ToDouble(ConfigurationManager.AppSettings["LedColorBlue"]) / 100;
                setLedCaptureRange = Convert.ToInt32(ConfigurationManager.AppSettings["LedCaptureRange"]);
                setLedOutput       = (LedOutputTypes)Convert.ToInt32(ConfigurationManager.AppSettings["LedOutput"]);
                setLedMode         = Convert.ToInt32(ConfigurationManager.AppSettings["LedMode"]);
                setLedSideFirst    = (LedSideTypes)Convert.ToInt32(ConfigurationManager.AppSettings["LedSideFirst"]);
                setLedSideSecond   = (LedSideTypes)Convert.ToInt32(ConfigurationManager.AppSettings["LedSideSecond"]);
                setLedSideThird    = (LedSideTypes)Convert.ToInt32(ConfigurationManager.AppSettings["LedSideThird"]);
                setLedSideFourth   = (LedSideTypes)Convert.ToInt32(ConfigurationManager.AppSettings["LedSideFourth"]);
                setLedCountFirst   = Convert.ToInt32(ConfigurationManager.AppSettings["LedCountFirst"]);
                setLedCountSecond  = Convert.ToInt32(ConfigurationManager.AppSettings["LedCountSecond"]);
                setLedCountThird   = Convert.ToInt32(ConfigurationManager.AppSettings["LedCountThird"]);
                setLedCountFourth  = Convert.ToInt32(ConfigurationManager.AppSettings["LedCountFourth"]);
                setLedCountTotal   = setLedCountFirst + setLedCountSecond + setLedCountThird + setLedCountFourth;

                //Debug settings
                setDebugMode     = Convert.ToBoolean(ConfigurationManager.AppSettings["DebugMode"]);
                setDebugBlackBar = Convert.ToBoolean(ConfigurationManager.AppSettings["DebugBlackBar"]);
                setDebugColor    = Convert.ToBoolean(ConfigurationManager.AppSettings["DebugColor"]);
                setDebugSave     = Convert.ToBoolean(ConfigurationManager.AppSettings["DebugSave"]);

                //Update the rotation based on ratio
                string ScreenRatio = AVFunctions.ScreenAspectRatio(vScreenOutputWidth, vScreenOutputHeight, false);
                if (SettingsFunction.Check("LedRotate" + ScreenRatio))
                {
                    setLedRotate = Convert.ToInt32(ConfigurationManager.AppSettings["LedRotate" + ScreenRatio]);
                }
                else
                {
                    setLedRotate = 0;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed updating the settings: " + ex.Message);
            }
        }
示例#6
0
 public SettingsFunctionTests()
 {
     _settingsHandlerStub   = new SettingsHandlerStub();
     _securityValidatorStub = new SecurityValidatorStub();
     _settingsFunction      = new SettingsFunction(NullLogger <SettingsFunction> .Instance, _settingsHandlerStub, _securityValidatorStub);
 }