Example #1
0
        public static void Main(string[] args)
        {
            var aquaPicEnvironment = string.Empty;
            var aquaPicSettings    = string.Empty;

            // Call the Gtk library hack because Windows sucks at everything
            if (Utils.ExecutingOperatingSystem == Platform.Windows)
            {
                CheckWindowsGtk();

                //Get the AquaPic directory environment
                aquaPicEnvironment = Environment.GetEnvironmentVariable("AquaPic");
                if (aquaPicEnvironment.IsEmpty())
                {
                    var path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                    path = Path.Combine(path, "AquaPicEnvironment.txt");
                    if (File.Exists(path))
                    {
                        var lines = File.ReadAllLines(path);
                        aquaPicEnvironment = lines[0];
                    }
                }

                if (aquaPicEnvironment.IsNotEmpty())
                {
                    var path = aquaPicEnvironment;
                    if (!Directory.Exists(path))
                    {
                        Console.WriteLine("Path to AquaPic directory environment is incorrect");
                        Console.WriteLine("Incorrect path was {0}", path);
                        aquaPicEnvironment = string.Empty;
                    }
                }

                if (aquaPicEnvironment.IsEmpty())
                {
                    Console.WriteLine("Please edit the AquaPicEnvironment.txt file to point to the path of the AquaPicRuntime directory.");
                    Console.WriteLine("For example if the AquaPicRuntime directory is located at /home/user/AquaPicRuntimeProject/,");
                    Console.WriteLine("then add \"/home/user/AquaPicRuntimeProject/\" to the first line of the file.");
                    return;
                }
            }
            else
            {
                aquaPicEnvironment = Environment.GetEnvironmentVariable("HOME");
                aquaPicEnvironment = Path.Combine(aquaPicEnvironment, ".config");
                aquaPicEnvironment = Path.Combine(aquaPicEnvironment, "AquaPic");

                if (!Directory.Exists(aquaPicEnvironment))
                {
                    Directory.CreateDirectory(aquaPicEnvironment);
                    Directory.CreateDirectory(Path.Combine(aquaPicEnvironment, "DataLogging"));
                    Directory.CreateDirectory(Path.Combine(aquaPicEnvironment, "Logs"));
                    Directory.CreateDirectory(Path.Combine(aquaPicEnvironment, "TestProcedures"));
                }
            }

            if (args.Length > 0)
            {
                Console.WriteLine("Arguments {0}", args[0]);
                if (args[0].Contains("-empty"))
                {
                    aquaPicSettings = Path.Combine(aquaPicEnvironment, "Settings.Empty");
                }
                else if (args[0].Contains("-full"))
                {
                    aquaPicSettings = Path.Combine(aquaPicEnvironment, "Settings.Full");
                }
                else
                {
                    aquaPicSettings = Path.Combine(aquaPicEnvironment, "Settings");
                }
            }
            else
            {
                aquaPicSettings = Path.Combine(aquaPicEnvironment, "Settings");
            }

            if (!Directory.Exists(aquaPicSettings))
            {
                Directory.CreateDirectory(aquaPicSettings);
            }

            //Setup
            Utils.AquaPicEnvironment = aquaPicEnvironment;
            Utils.AquaPicSettings    = aquaPicSettings;
            Application.Init();
            Logger.Add("Executing operating system is {0}", Utils.GetDescription(Utils.ExecutingOperatingSystem));

#if DEBUG
            try {
#endif
            Driver.AddFromJson();
            Sensors.AddSensors();
            Devices.AddDevices();
            Temperature.Init();
            WaterLevel.Init();
            AutoTopOff.Init();
#if DEBUG
        }
        catch (Exception ex) {
            Logger.AddError(ex.ToString());
            return;
        }
#endif

#if DEBUG
            Driver.AnalogInput.SetChannelMode("Right Overflow, Temperature Probe", Mode.Manual);
            Driver.AnalogInput.SetChannelValue("Right Overflow, Temperature Probe", 2796.5);
            Driver.AnalogInput.SetChannelMode("Left Overflow, Temperature Probe", Mode.Manual);
            Driver.AnalogInput.SetChannelValue("Left Overflow, Temperature Probe", 2796.5);
            Driver.AnalogInput.SetChannelMode("Sump, Temperature Probe", Mode.Manual);
            Driver.AnalogInput.SetChannelValue("Sump, Temperature Probe", 2796.5);
            Driver.AnalogInput.SetChannelMode("Salt Mixing, Temperature Probe", Mode.Manual);
            Driver.AnalogInput.SetChannelValue("Salt Mixing, Temperature Probe", 2796.5);

            Driver.AnalogInput.SetChannelMode("Return Chamber, Water Level Sensor", Mode.Manual);
            Driver.AnalogInput.SetChannelValue("Return Chamber, Water Level Sensor", 1803);
            Driver.AnalogInput.SetChannelMode("ATO Reservoir, Water Level Sensor", Mode.Manual);
            Driver.AnalogInput.SetChannelValue("ATO Reservoir, Water Level Sensor", 3878);
            Driver.AnalogInput.SetChannelMode("Salt Reservoir, Water Level Sensor", Mode.Manual);
            Driver.AnalogInput.SetChannelValue("Salt Reservoir, Water Level Sensor", 2048);

            Driver.DigitalInput.SetChannelMode("Sump High, Float Switch", Mode.Manual);
            Driver.DigitalInput.SetChannelValue("Sump High, Float Switch", true);
            Driver.DigitalInput.SetChannelMode("Sump Low, Float Switch", Mode.Manual);
            Driver.DigitalInput.SetChannelValue("Sump Low, Float Switch", true);
            Driver.DigitalInput.SetChannelMode("Sump ATO, Float Switch", Mode.Manual);

            Driver.PhOrp.SetChannelMode("Sump, pH Probe", Mode.Manual);
            Driver.PhOrp.SetChannelValue("Sump, pH Probe", 2282);
#endif

            // Run the control
            var win = AquaPicGui.CreateInstance();
            win.Show();

            Application.Run();

            // Cleanup
            if (AquaPicBus.isOpen)
            {
                AquaPicBus.Close();
            }

#if DELETE_DATA_FILES
            // For some reason this doesn't like to be in the destroyed event
            var groups = Temperature.GetAllTemperatureGroupNames();
            foreach (var group in groups)
            {
                var dataLogger = (DataLoggerIoImplementation)Temperature.GetTemperatureGroupDataLogger(group);
                if (dataLogger != null)
                {
                    dataLogger.DeleteAllLogFiles();
                }
            }
            groups = WaterLevel.GetAllWaterLevelGroupNames();
            foreach (var group in groups)
            {
                var dataLogger = (DataLoggerIoImplementation)WaterLevel.GetWaterLevelGroupDataLogger(group);
                if (dataLogger != null)
                {
                    dataLogger.DeleteAllLogFiles();
                }
            }
            var phProbes = Sensors.PhProbes.GetAllGadgetNames();
            foreach (var probe in phProbes)
            {
                var dataLogger = (DataLoggerIoImplementation)Sensors.PhProbes.GetPhProbeDataLogger(probe);
                if (dataLogger != null)
                {
                    dataLogger.DeleteAllLogFiles();
                }
            }
#endif
        }